# 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)
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。