python - 如何从 OpenCV 点访问 X 和 Y 坐标?
问题描述
所以我正在使用OpenCV进行姿态估计。该函数返回一个对象数组,这些对象用于在视频片段上绘制线框骨架:
#SKELETON DRAWING
if points[idFrom] and points[idTo]:
if i == 1:
print(type(point[idFrom]))
#glUniform1f(xM, float(point[idFrom][0]/width))
#glUniform1f(yM, float(point[idFrom][1]/height))
else:
cv.line(frame, points[idFrom], points[idTo], (0, 255, 0), 3)
cv.ellipse(frame, points[idFrom], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
cv.ellipse(frame, points[idTo], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
我需要获取骨架上点的 x 和 y 坐标,但我不知道该怎么做。这些点显然是一个<class 'int'>。我尝试使用 point[idFrom][0],它给了我这个错误:print(type(point[idFrom][0])) TypeError: 'int' object is not subscriptable
以下是创建点的方式:
points = []
for i in range(len(BODY_PARTS)):
# Slice heatmap of corresponging body's part.
heatMap = out[0, i, :, :]
# Originally, we try to find all the local maximums. To simplify a sample
# we just find a global one. However only a single pose at the same time
# could be detected this way.
_, conf, _, point = cv.minMaxLoc(heatMap)
x = (frameWidth * point[0]) / out.shape[3]
y = (frameHeight * point[1]) / out.shape[2]
# Add a point if it's confidence is higher than threshold.
points.append((int(x), int(y)) if conf > thr else None)
i = 0
解决方案
推荐阅读
- python - 根据第二个列表对具有两个列表的元组列表进行分组
- bash - 在 Bash 中,如何将 git 参数传递给主体为 git 语句的函数
- python - PyCharm 在“datetime”中找不到“utcnow”(Discord.py,Python 3.8)
- mysql - 在 mysql 5.7.32 版本中使用 LIMIT 显示错误
- javascript - Twilio XML 验证警告 12200
- hadoop-yarn - 我们可以使用纱线添加电容器插件吗
- powershell - UI 自动化 - Get-UiaPane:未能在 5000 毫秒内获得控制权
- elasticsearch - 使用嵌套跨度查询时,ElasticSearch 跨度接近查询未产生预期结果
- python-3.x - 当 URL 读取时间过长时如何跳出循环
- ios - Nativescript 角度 RadSideDrawer 未定义