Ubuntu安装与配置OpenNI2
由于工作原因,需要在UbunTu上使用orbbec Astra s 摄像头。该摄像头是openni驱动的,所以需要安装OpenNI2。
安装openni2有两种方式,如果需要用到openni源码就通过方式一安装,如果只是调用openni接口可通过命令行二进制安装
安装OpenNI2
方法一:源码安装
下载openni2
先装其所需要得依赖
sudo apt-get install -y g++ python libusb-1.0-0-dev freeglut3-dev doxygen graphviz
sudo apt-get install libudev-dev
然后在github上下载openni2的源码,其地址路径为:https://github.com/OpenNI/OpenNI2
下载完后就进行安装了,但在安装之前需要将OpenNI2/ThirdParty/PSCommon/BuildSystem/CommonCppMakefile 中的第74行的G++编译选项-Werror去掉:
CFLAGS += -Werror在这句前加 #或者删除掉这句话
git clone https://github.com/OpenNI/OpenNI2
cd OpenNI2
make
编译过程中的报错与解决方法
问题一:
报错信息:
> make[1]: 进入目录“/home/xj/ubuntu/OpenNI2/ThirdParty/PSCommon/XnLib/Source”
> /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error:
> ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’
> specified bound 256 equals destination size
> [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk
> (__dest, __src, __len, __bos (__dest));
解决办法:
vim /home/{USER}/OpenNI2/ThirdParty/PSCommon/XnLib/Source/Makefile 【USER替换为自己的OpenNI2路径】
添加 “-Wno-error=stringop-truncation”
vim /home/{USER}/OpenNI2/ThirdParty/PSCommon/XnLib/Source/Makefile
CFLAGS += -Wall -Wno-error=stringop-truncation
问题二:
make[1]: 进入目录“/home/xj/ubuntu/OpenNI2/Source/Drivers/PS1080”
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 200 equals destination size [-Werror=stringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
解决办法:
打开 /home/{USER}/OpenNI2/Source/Drivers/PS1080/Makefile【USER替换为自己的OpenNI2路径】
添加 “-Wno-error=array-bounds -Wno-error=address”
vim /home/{USER}/OpenNI2/Source/Drivers/PS1080/Makefile
CFLAGS += -Wall -Wno-error=stringop-truncation -Wno-error=array-bounds -Wno-error=address
问题三:
Formats/XnFormatsMirror.cpp:46:11: error: array subscript -1 is outside array bounds of ‘XnUInt8 [5760]’ {aka ‘unsigned char [5760]’} [-Werror=array-bounds]
46 | XnUInt8* pDestEnd = &pLineBuffer[0] - 1;
| ^~~~~~~~
Formats/XnFormatsMirror.cpp:42:10: note: while referencing ‘pLineBuffer’
42 | XnUInt8 pLineBuffer[XN_MIRROR_MAX_LINE_SIZE];
| ^~~~~~~~~~~
Formats/XnFormatsMirror.cpp: In function ‘XnStatus XnMirrorTwoBytePixels(XnUChar*, XnUInt32, XnUInt32)’:
Formats/XnFormatsMirror.cpp:79:12: error: array subscript -1 is outside array bounds of ‘XnUInt16 [5760]’ {aka ‘short unsigned int [5760]’} [-Werror=array-bounds]
79 | XnUInt16* pDestEnd = &pLineBuffer[0] - 1;
| ^~~~~~~~
Formats/XnFormatsMirror.cpp:75:11: note: while referencing ‘pLineBuffer’
75 | XnUInt16 pLineBuffer[XN_MIRROR_MAX_LINE_SIZE];
| ^~~~~~~~~~~
Formats/XnFormatsMirror.cpp: In function ‘XnStatus XnMirrorThreeBytePixels(XnUChar*, XnUInt32, XnUInt32)’:
Formats/XnFormatsMirror.cpp:115:11: error: array subscript -1 is outside array bounds of ‘XnUInt8 [5760]’ {aka ‘unsigned char [5760]’} [-Werror=array-bounds]
115 | XnUInt8* pDestEnd = &pLineBuffer[0] - 1;
| ^~~~~~~~
Formats/XnFormatsMirror.cpp:111:10: note: while referencing ‘pLineBuffer’
111 | XnUInt8 pLineBuffer[XN_MIRROR_MAX_LINE_SIZE];
| ^~~~~~~~~~~
cc1plus: all warnings being treated as errors
解决办法:
OpenNI2/ThirdParty/PSCommon/BuildSystem/CommonCppMakefile 中的第76行的G++编译选项-Werror去掉
CFLAGS += -Werror在这句前加 #或者删除掉这句话
vim /home/{USER}/OpenNI2/ThirdParty/PSCommon/BuildSystem/CommonCppMakefile
#CFLAGS += -Werror
问题四:
/bin/sh: 1: javac: not found
解决办法:
将OpenNI2/Makefile中的java的编译项全部加#注释掉【我这边目前用不到JAVA这一块所以屏蔽掉了,后续有空在解决这个问题】
问题五:
../../../ThirdParty/GL/glh/glh_linear.h:80:63: error: no match for ‘operator>’ (operand types are ‘const std::error_code’ and ‘float’)
80 | #define equivalent(a,b) (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false)
解决办法:
打开OpenNI2/ThirdParty/GL/glh/glh_linear.h文件,将文件中的equivalent全部改为is_equivalent。
vim /home/(USER)/OpenNI2/ThirdParty/GL/glh/glh_linear.h
问题六:
make[1]: 进入目录“/home/xj/ubuntu/OpenNI2/Source/Tools/NiViewer”
/usr/bin/ld: ../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release/libXnLib.a(XnLinuxMutex.o): undefined reference to symbol 'pthread_mutex_timedlock@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
解决办法:
打开/home/(USER)/ubuntu/OpenNI2/Source/Tools/NiViewer/Makefile【USER替换为自己的OpenNI2路径】
在第27行“USED_LIBS”后边加入pthread库
vim /home/xj/ubuntu/OpenNI2/Source/Tools/NiViewer/Makefile USED_LIBS
+= glut GL pthread
再次make编译
编译安装完成后通过下面的命令查看是否安装成功
pkg-config --modversion libopenni2
xj@hy:~/Work/work_ws$ pkg-config --modversion libopenni2
2.2.0.3
xj@hy:~/Work/work_ws$
方法二:命令行二进制安装
安装相关依赖库
sudo apt-get install -y g++ python libusb-1.0-0-dev freeglut3-dev doxygen graphviz sudo apt-get install libudev-dev
查询当前软件源中支持的openni2;如果没找到,则是源问题,重新更换源;
apt-cache search openni2
xj@hy:~/Work/work_ws$ apt-cache search openni2
libopenni2-0 - framework for sensor-based 'Natural Interaction'
libopenni2-dev - headers for OpenNI 'Natural Interaction' frameworks
openni2-doc - developer documentation for OpenNI frameworks
openni2-utils - debug and test utilities OpenNI2 framework
ros-noetic-openni2-camera - Drivers for the Asus Xtion and Primesense Devices.
ros-noetic-openni2-camera-dbgsym - debug symbols for ros-noetic-openni2-camera
ros-noetic-openni2-launch - Launch files to start the openni2_camera drivers using rgbd_launch.
安装openni2
sudo apt-get install libopenni2-dev
编译安装完成后通过下面的命令查看是否安装成功
pkg-config --modversion libopenni2
xj@hy:~/Work/work_ws$ pkg-config --modversion libopenni2
2.2.0.3
xj@hy:~/Work/work_ws$
配置OpenNI2
安装完成后,进行测试,在终端中运行NiViewer2:
DeviceOpen using default: no devices found
进行配置OpenNI2
由于使用的是orbbec的摄像头,需要将orbbec的文件拷贝到OpenNI2的Drivers里
注:{orbbec}:这里需要修改为自己存放奥比中光SDK的位置
sudo cp 558-orbbec-usb.rules /etc/udev/rules.d/
sudo cp {orbbec}/Redist/OpenNI2/Drivers /usr/lib/OpenNI2/Drivers
sudo cp {orbbec}/Redist/libOpenNI2.* /usr/lib/
sudo cp -r Include /usr/include/openni2
更改rules文件需要重启
相关参考链接
https://blog.csdn.net/linmingan/article/details/80245025
https://blog.csdn.net/Stackingrule/article/details/90724621
https://tvheadend.org/issues/6173
https://blog.csdn.net/llm_hao/article/details/124279032?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2defaultCTRLISTdefault-1-124279032-blog-113791634.pc_relevant_multi_platform_whitelistv1&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2defaultCTRLISTdefault-1-124279032-blog-113791634.pc_relevant_multi_platform_whitelistv1
https://blog.csdn.net/Stackingrule/article/details/90724621