0

我正在尝试从用鼠标单击的像素中提取深度数据。它在我打印 X,Y 坐标时起作用。当我尝试打印像素深度数据时它不起作用。我尝试使用的代码是从如何为单击的像素提取 RGB 值的修改。我遇到的问题是如何解析出要打印的深度数据。当我运行它时,我得到 TypeError: 'NoneType' object is not subscriptable 有什么想法吗?

这是代码:

kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Depth)

while True:
    # --- Getting frames and drawing
    if kinect.has_new_depth_frame():
        frame = kinect.get_last_depth_frame()
        frameD = kinect.get_last_depth_frame()
        frameD = kinect._depth_frame_data
        #frameD = frame.astype(np.uint8)
        frame = frame.astype(np.uint8)
        frame = np.reshape(frame, (424, 512))
        output = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
        def click_event(event, x, y, flags, param):
            if event == cv2.EVENT_LBUTTONDOWN:
                print(x, y)
            if event == cv2.EVENT_RBUTTONDOWN:
                Pixel_Depth = output[x, y , 1]
                print(Pixel_Depth)
        #output = cv2.bilateralFilter(output, 1, 150, 75)
        cv2.imshow('KINECT Video Stream', output)
        cv2.setMouseCallback('KINECT Video Stream', click_event)
        output = None

    key = cv2.waitKey(1)
4

1 回答 1

0

为了让它工作,我必须指定像素数而不是“frameD = kinect._depth_frame_data”的 x,y 坐标

这是代码:

rom pykinect2 import PyKinectV2
from pykinect2.PyKinectV2 import *
from pykinect2 import PyKinectRuntime
import numpy as np
import cv2

kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Depth)

while True:
    # --- Getting frames and drawing
    if kinect.has_new_depth_frame():
        frame = kinect.get_last_depth_frame()
        frameD = kinect._depth_frame_data
        frame = frame.astype(np.uint8)
        frame = np.reshape(frame, (424, 512))
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
        def click_event(event, x, y, flags, param):
            if event == cv2.EVENT_LBUTTONDOWN:
                print(x, y)
            if event == cv2.EVENT_RBUTTONDOWN:
                Pixel_Depth = frameD[((y * 512) + x)]
                print(Pixel_Depth)
        ##output = cv2.bilateralFilter(output, 1, 150, 75)
        cv2.imshow('KINECT Video Stream', frame)
        cv2.setMouseCallback('KINECT Video Stream', click_event)
        output = None

    key = cv2.waitKey(1)
    if key == 27: break
于 2018-12-24T15:26:54.393 回答