首页 > 解决方案 > 如何从 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

标签: pythonclassopencv

解决方案


推荐阅读