# 导入所需的库 import cv2 import time import numpy as np # 加载OpenPose模型 net = cv2.dnn.readNetFromTensorflow("C:\Users\1\Desktop\onem.jpg") # 配置OpenCV窗口 cv2.namedWindow("OpenPose Demo", cv2.WINDOW_NORMAL) # 加载要测试的图像 image = cv2.imread("C:\Users\1\Desktop\onem.jpg") # 获取图像的宽和高 width = image.shape[1] height = image.shape[0] # 创建一个4D blob,将图像传递给OpenPose模型 blob = cv2.dnn.blobFromImage(image, 1.0 / 255, (368, 368), (0, 0, 0), swapRB=False, crop=False) # 设置输入blob net.setInput(blob) # 运行前向传递,获取OpenPose模型的输出 start = time.time() output = net.forward() end = time.time() # 输出运行时间 print("OpenPose took {:.2f} seconds".format(end - start)) # 获取输出blob的大小 H = output.shape[2] W = output.shape[3] # 创建一个空列表,用于存储检测到的人体姿态 points = [] # 遍历检测到的人体关键点 for i in range(18): # 提取x和y坐标 probMap = output[0, i, :, :] minVal, prob, minLoc, point = cv2.minMaxLoc(probMap) # 如果概率大于阈值,则将其添加到列表中 if prob > 0.1: x = int((width * point[0]) / W) y = int((height * point[1]) / H) points.append((x, y)) # 绘制检测到的人体姿态 for i, point in enumerate(points): cv2.circle(image, point, 5, (0, 255, 255), thickness=-1, lineType=cv2.FILLED) cv2.putText(image, "{}".format(i), point, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA) # 显示结果 cv2.imshow("OpenPose Demo", image) cv2.waitKey(0) cv2.destroyAllWindows()
时间: 2024-01-15 15:04:54 浏览: 169
你的代码有一个错误,是在加载OpenPose模型时指定了图像文件路径而不是模型文件路径。正确的写法应该是:
```
net = cv2.dnn.readNetFromTensorflow("path/to/model")
```
其中,"path/to/model"应该是你的OpenPose模型文件的路径,而不是图像文件的路径。
因此,你需要将这一行代码修改为:
```
net = cv2.dnn.readNetFromTensorflow("path/to/openpose.pb")
```
其中,"path/to/openpose.pb"应该是你的OpenPose模型文件的路径。
阅读全文
相关推荐











