ubuntu python 通过奥比中光摄像头获取深度图片和彩色图片

1. 依赖

  1. 安装Openni Openni下载Openni添加至环境(要通过全局变量找到Openni头文件和库)

  2. 安装primesense和openni

pip install primesense
pip install openni

2. Python代码

from openni import openni2
import numpy as np
import cv2


def mousecallback(event,x,y,flags,param):
     if event==cv2.EVENT_LBUTTONDBLCLK:
         print(y, x, dpt[y,x])


if __name__ == "__main__": 

    openni2.initialize()

    dev = openni2.Device.open_any()
    print(dev.get_device_info())

    depth_stream = dev.create_depth_stream()
    depth_stream.start()

    cap = cv2.VideoCapture(2)
    cv2.namedWindow('depth')
    cv2.setMouseCallback('depth',mousecallback)

    while True:

        frame = depth_stream.read_frame()
        dframe_data = np.array(frame.get_buffer_as_triplet()).reshape([480, 640, 2])
        dpt1 = np.asarray(dframe_data[:, :, 0], dtype='float32')
        dpt2 = np.asarray(dframe_data[:, :, 1], dtype='float32')
        
        dpt2 *= 255
        dpt = dpt1 + dpt2
        
        cv2.imshow('depth', dpt)

        ret,frame = cap.read()
        cv2.imshow('color', frame)

        key = cv2.waitKey(1)
        if int(key) == ord('q'):
            break

    depth_stream.stop()
    dev.close()


OpenNI2是一个用于开发基于传感器的“自然交互”应用的框架。在Ubuntu系统上,你可以通过在终端中使用apt-cache search openni2命令来搜索和安装相关的软件包。libopenni2-0是用于OpenNI2框架的库文件,libopenni2-dev包含了开发所需的头文件,openni2-utils提供了一些调试和测试工具,openni2-doc是开发者文档。此外,还有一个名为ros-noetic-openni2-camera的软件包,用于驱动Asus Xtion和Primesense设备。 要在Python中使用OpenNI2,你需要确保正确设置了系统的环境变量。在编译程序时,重点要关注WITH_OPENNI2选项,选择它后,编译配置完成后会自动添加OPENNI2_SYS_INCLUDE和其他路径。另外,还需要注意Python的路径设置,特别是numpy库的路径。你可以在终端中输入"python3 -c 'import numpy; print(numpy.__file__)'"来查看numpy库的路径。 因此,如果你想在Ubuntu上使用OpenNI2的Python接口,你可以首先安装相关的软件包,然后确保正确设置了环境变量和Python路径,即可开始编写和运行OpenNI2的代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [(17)深度点云学习--python安装openni打开奥比中光RGBD](https://blog.csdn.net/chencaw/article/details/128282578)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Ubuntu安装与配置OpenNI2](https://blog.csdn.net/weixin_42898354/article/details/94437490)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Ubuntu 20.04LTS 安装openni2、编译opencv、连接Kinect v2](https://blog.csdn.net/SmileJayNew/article/details/124954204)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值