JetSon NANO 编译pyrealsense2运行D455

安装步骤

1、下载源码
下载地址: https://github.com/IntelRealSense/librealsense

$ cd librealsense
$ ./scripts/setup_udev_rules.sh
$ echo 'hid_sensor_custom' | sudo tee -a /etc/modules


2、添加环境变量

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

3、编译

$ mkdir build
$ cd build
$ cmake ../ -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/usr/bin/python3 -DBUILD_WITH_CUDA=true
$ sudo make uninstall && make clean
$ make -j4
$ sudo make install


有时候多核make的时候会报错,可选择直接单核$make

4、添加环境变量 vim ~/.bashrc,记住添加完之后source一下

export PYTHONPATH=$PYTHONPATH:/usr/local/lib:/usr/local/lib/python3.6/pyrealsense2

完成编译安装之后,可在/usr/local/lib/python3.6/pyrealsense2/目录下查看编译好的库文件

pybackend2.cpython-36m-aarch64-linux-gnu.so    
pybackend2.cpython-36m-aarch64-linux-gnu.so.2.49.0  
pyrealsense2.cpython-36m-aarch64-linux-gnu.so.2.49
pybackend2.cpython-36m-aarch64-linux-gnu.so.2  
pyrealsense2.cpython-36m-aarch64-linux-gnu.so       
pyrealsense2.cpython-36m-aarch64-linux-gnu.so.2.49.0

5、测试

import pyrealsense2 as rs
import numpy as np
import cv2

# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 15)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 15)

# Start streaming
pipeline.start(config)

try:
    while True:
        # Wait for a coherent pair of frames: depth and color
        frames = pipeline.wait_for_frames()
        # 深度图
        depth_frame = frames.get_depth_frame()
        # 正常读取的视频流
        color_frame = frames.get_color_frame()
        if not depth_frame or not color_frame:
            continue
        # Convert images to numpy arrays
        depth_image = np.asanyarray(depth_frame.get_data())
        color_image = np.asanyarray(color_frame.get_data())

        # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

        # Stack both images horizontally
        images = np.hstack((color_image, depth_colormap))

        # Show images
        cv2.namedWindow('RealSenseD455', cv2.WINDOW_AUTOSIZE)
        cv2.imshow('RealSenseD455', images)
        cv2.waitKey(1)

finally:

    # Stop streaming
    pipeline.stop()

6、编译过程中可能遇到的错误
1:Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the

$ sudo apt-get install libssl-dev

2:The Xinerama headers were not found

$ sudo apt-get install libsdl2-dev

3:/home/***/projects/librealsense/build/third-party/pybind11/include/pybind11/detail/common.h:124:10: fatal error: Python.h: No such file or directory,CMakeFiles/Makefile2:268: recipe for target 'wrappers/python/CMakeFiles/pybackend2.dir/all' failed

$ sudo apt-get install python3.6-dev

你可能感兴趣的:(python,计算机视觉,边缘计算)