微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在python中从pykinect中找到深度?

如何解决如何在python中从pykinect中找到深度?

我正在寻找许多使用 python 中的 kinect 相机查找深度的方法,但我没有找到任何合适的解决方案。我看到了一些使用 pykinect 包实现的示例,但我认为它现在已停止用于 python。我尝试通过 pypi.com 安装它,但在那里不可用。我试图通过 pygame 包来实现它,下面给出了它的代码。但我不知道如何找到深度值或 Z 轴。任何帮助将不胜感激!

import pygame
import numpy as np
import sys
from freenect import sync_get_depth as get_depth


def make_gamma():
    """
    Create a gamma table
    """
    num_pix = 2048 # there's 2048 different possible depth values
    npf = float(num_pix)
    _gamma = np.empty((num_pix,3),dtype=np.uint16)
    for i in range(num_pix):
        v = i / npf
        v = pow(v,3) * 6
        pval = int(v * 6 * 256)
        lb = pval & 0xff
        pval >>= 8
        if pval == 0:
            a = np.array([255,255 - lb,255 - lb],dtype=np.uint8)
        elif pval == 1:
            a = np.array([255,lb,0],dtype=np.uint8)
        elif pval == 2:
            a = np.array([255 - lb,dtype=np.uint8)
        elif pval == 3:
            a = np.array([255 - lb,255,dtype=np.uint8)
        elif pval == 4:
            a = np.array([0,255],dtype=np.uint8)
        elif pval == 5:
            a = np.array([0,dtype=np.uint8)
        else:
            a = np.array([0,dtype=np.uint8)

        _gamma[i] = a
    return _gamma


gamma = make_gamma()


if __name__ == "__main__":
    fpsClock = pygame.time.Clock()
    FPS = 30 # kinect only outputs 30 fps
    disp_size = (640,480)
    pygame.init()
    screen = pygame.display.set_mode(disp_size)
    font = pygame.font.Font('slkscr.ttf',32) # provide your own font 
    num=0
    while True:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                sys.exit()
        fps_text = "FPS: {0:.2f}".format(fpsClock.get_fps())
        # draw the pixels

        depth = np.rot90(get_depth()[0]) # get the depth readinngs from the camera
        
        pixels = gamma[depth] # the colour pixels are the depth readings overlayed onto the gamma table
        temp_surface = pygame.Surface(disp_size)
        print("Pixels===",pixels)
        print("Depth===",pixels)
        my_surface = pygame.pixelcopy.make_surface(pixels,depth=1)
        pygame.image.save(my_surface,("./Output/image_"+str(num)+".jpg"))
        num+=1
        pygame.surfarray.blit_array(temp_surface,pixels)
        pygame.transform.scale(temp_surface,disp_size,screen)
        screen.blit(font.render(fps_text,1,(0,0)),(30,30))
        pygame.display.flip()
        fpsClock.tick(FPS)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。