# Specify the paths for the 2 filesprotoFile = "pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt"weightsFile = "pose/mpi/pose_iter_160000.caffemodel"# Read the network into Memorynet = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
# Read imageframe = cv2.imread("image.jpg")# Specify the input image dimensionsinWidth = 368inHeight = 368# Prepare the frame to be fed to the networkinpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight), (0, 0, 0), swapRB=False, crop=False)# Set the prepared object as the input blob of the networknet.setInput(inpBlob)
H = out.shape[2]W = out.shape[3]# Empty list to store the detected keypointspoints = []for i in range(len()):# confidence map of corresponding body's part. probMap = output[0, i, :, :]# Find global maxima of the probMap. minVal, prob, minLoc, point = cv2.minMaxLoc(probMap)# Scale the point to fit on the original imagex = (frameWidth * point[0]) / Wy = (frameHeight * point[1]) / Hif prob > threshold : cv2.circle(frame, (int(x), int(y)), 15, (0, 255, 255), thickness=-1, lineType=cv.FILLED) cv2.putText(frame, "{}".format(i), (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 1.4, (0, 0, 255), 3, lineType=cv2.LINE_AA)# Add the point to the list if the probability is greater than the threshold points.append((int(x), int(y)))else : points.append(None)cv2.imshow("Output-Keypoints",frame)cv2.waitKey(0)cv2.destroyAllWindows()
步骤4:绘制骨架
由于我们已经绘制了关键点,因此我们现在只需将两对连接即可绘制骨架。
forpair in POSE_PAIRS:partA = pair[0]partB = pair[1]ifpoints[partA] and points[partB]:cv2.line(frameCopy,points[partA], points[partB], (0, 255, 0), 3)
Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。