本人平臺(tái):nuc11-1165g7 Intel Xe Graphics
一.安裝libfreenect2:
地址:https://github.com/OpenKinect/libfreenect2
1.安裝libusb. The version must be >= 1.0.20:
sudo apt install -y libusb-1.0-0-dev
2.安裝TurboJPEG:
sudo apt install -y libturbojpeg libjpeg-turbo8-dev libturbojpeg0-dev
3.安裝OpenGL:
sudo apt install -y libglfw3-dev
sudo apt install -y libgl1-mesa-dev
sudo apt install -y libglu1-mesa-dev
sudo apt install -y freeglut3-dev
sudo apt install -y libglew1.8 libglew-dev
sudo apt install -y libgl1-mesa-glx
sudo apt install -y libxmu-dev
4.安裝OpenNI2:
sudo apt install -y libopenni2-dev openni2-utils
5.安裝OpenCL的頭文件和庫(kù):
根據(jù)這篇文章(本人的流程有所不同):Ubuntu 16.04.2 下為 Intel 顯卡啟用 OpenCL
1) 首先,安裝官方的包:
sudo apt install ocl-icd-libopencl1
sudo apt install opencl-headers
sudo apt install clinfo
sudo apt install ocl-icd-opencl-dev
sudo apt install beignet-dev
其中clinfo是用來(lái)看系統(tǒng)opencl支持情況的,對(duì)于我11代Intel銳炬核顯,Intel專(zhuān)用的opencl庫(kù)就是beignet-dev(20.04,如果你是18.04這個(gè)包名是beignet),如果你不安裝這個(gè)包,終端輸入clinfo回車(chē)是會(huì)告訴你沒(méi)有匹配的設(shè)備的,只有安裝了這個(gè)包,才會(huì)檢測(cè)到opencl。
雖然libfreenect2倉(cāng)庫(kù)里的自述文件說(shuō)opencl-headers對(duì)應(yīng)AMD核心顯卡,但是教程讓我安我就安了,無(wú)所謂。
2) 接著下載官方的驅(qū)動(dòng):
https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_SDK_release
??!從這之后跟教程不太一樣?。?/h6>
3) 進(jìn)入Intel官方OpenCL倉(cāng)庫(kù):
https://github.com/intel/compute-runtime/releases
下面這一套安裝官方OpenCL的流程就在它倉(cāng)庫(kù)的自述文件里,隨著庫(kù)的更新命令可能會(huì)變化,建議伙伴們還是去它的倉(cāng)庫(kù)里按照它自己的流程走一遍命令
4) 創(chuàng)建一個(gè)暫時(shí)文件夾:
mkdir neo
5) 下載所有的deb包:
cd neo
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.13230.7/intel-igc-core_1.0.13230.7_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.13230.7/intel-igc-opencl_1.0.13230.7_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/intel-level-zero-gpu-dbgsym_1.3.25593.11_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/intel-level-zero-gpu_1.3.25593.11_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/intel-opencl-icd-dbgsym_23.05.25593.11_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/intel-opencl-icd_23.05.25593.11_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/libigdgmm12_22.3.0_amd64.deb
6)驗(yàn)證包的 sha256 總和:
wget https://github.com/intel/compute-runtime/releases/download/23.05.25593.11/ww05.sum
sha256sum -c ww05.sum
7) 安裝所有包:
sudo dpkg -i *.deb
8) OpenCL安裝結(jié)束(over)---------------------------------------------------------------------------------------
6.安裝VAAPI (節(jié)選,只適用于intel,親測(cè)安了之后,運(yùn)行可執(zhí)行文件就運(yùn)行段錯(cuò)誤,在此不給指令了)
7.安裝一些其他的不知道啥用的包:
sudo apt install -y mesa-common-dev libxrandr-dev libxi-dev
8.檢查一下安裝的環(huán)境:
1) 檢查OpenCL:
clinfo
彈出:
Number of platforms 1
Platform Name Intel(R) OpenCL HD Graphics
Platform Vendor Intel(R) Corporation
Platform Version OpenCL 3.0
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_byte_addressable_store cl_khr_device_uuid cl_khr_fp16 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_icd cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_intel_command_queue_families cl_intel_subgroups cl_intel_required_subgroup_size cl_intel_subgroups_short cl_khr_spir cl_intel_accelerator cl_intel_driver_diagnostics cl_khr_priority_hints cl_khr_throttle_hints cl_khr_create_command_queue cl_intel_subgroups_char cl_intel_subgroups_long cl_khr_il_program cl_intel_mem_force_host_memory cl_khr_subgroup_extended_types cl_khr_subgroup_non_uniform_vote cl_khr_subgroup_ballot cl_khr_subgroup_non_uniform_arithmetic cl_khr_subgroup_shuffle cl_khr_subgroup_shuffle_relative cl_khr_subgroup_clustered_reduce cl_intel_device_attribute_query cl_khr_suggested_local_work_size cl_intel_split_work_group_barrier cl_intel_spirv_media_block_io cl_intel_spirv_subgroups cl_khr_spirv_no_integer_wrap_decoration cl_intel_unified_shared_memory cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_intel_planar_yuv cl_intel_packed_yuv cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_3d_image_writes cl_intel_media_block_io cl_intel_va_api_media_sharing cl_intel_sharing_format_query cl_khr_pci_bus_info cl_intel_subgroup_local_block_io
Platform Host timer resolution 1ns
Platform Extensions function suffix INTEL
Platform Name Intel(R) OpenCL HD Graphics
Number of devices 1
Device Name Intel(R) Iris(R) Xe Graphics
Device Vendor Intel(R) Corporation
Device Vendor ID 0x8086
Device Version OpenCL 3.0 NEO
Driver Version 23.05.25593.11
Device OpenCL C Version OpenCL C 1.2
Device Type GPU
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
Max compute units 96
Max clock frequency 1300MHz
Device Partition (core)
Max number of sub-devices 0
Supported partition types None
Supported affinity domains (n/a)
Max work item dimensions 3
Max work item sizes 512x512x512
Max work group size 512
Preferred work group size multiple 64
Max sub-groups per work group 64
Sub-group sizes (Intel) 8, 16, 32
Preferred / native vector sizes
char 16 / 16
short 8 / 8
int 4 / 4
long 1 / 1
half 8 / 8 (cl_khr_fp16)
float 1 / 1
double 0 / 0 (n/a)
Half-precision Floating-point support (cl_khr_fp16)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Correctly-rounded divide and sqrt operations No
Double-precision Floating-point support (n/a)
Address bits 64, Little-Endian
Global memory size 13207846912 (12.3GiB)
Error Correction support No
Max memory allocation 4294959104 (4GiB)
Unified memory for Host and Device Yes
Shared Virtual Memory (SVM) capabilities (core)
Coarse-grained buffer sharing Yes
Fine-grained buffer sharing No
Fine-grained system sharing No
Atomics No
Minimum alignment for any data type 128 bytes
Alignment of base address 1024 bits (128 bytes)
Preferred alignment for atomics
SVM 64 bytes
Global 64 bytes
Local 64 bytes
Max size for global variable 65536 (64KiB)
Preferred total size of global vars 4294959104 (4GiB)
Global Memory cache type Read/Write
Global Memory cache size 3932160 (3.75MiB)
Global Memory cache line size 64 bytes
Image support Yes
Max number of samplers per kernel 16
Max size for 1D images from buffer 268434944 pixels
Max 1D or 2D image array size 2048 images
Base address alignment for 2D image buffers 4 bytes
Pitch alignment for 2D image buffers 4 pixels
Max 2D image size 16384x16384 pixels
Max planar YUV image size 16384x16352 pixels
Max 3D image size 2048x2048x2048 pixels
Max number of read image args 128
Max number of write image args 128
Max number of read/write image args 128
Max number of pipe args 0
Max active pipe reservations 0
Max pipe packet size 0
Local memory type Local
Local memory size 65536 (64KiB)
Max number of constant args 8
Max constant buffer size 4294959104 (4GiB)
Max size of kernel argument 2048 (2KiB)
Queue properties (on host)
Out-of-order execution Yes
Profiling Yes
Queue properties (on device)
Out-of-order execution No
Profiling No
Preferred size 0
Max size 0
Max queues on device 0
Max events on device 0
Prefer user sync for interop Yes
Profiling timer resolution 52ns
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
Sub-group independent forward progress No
IL version SPIR-V_1.2
SPIR versions 1.2
printf() buffer size 4194304 (4MiB)
Built-in kernels (n/a)
Device Extensions cl_khr_byte_addressable_store cl_khr_device_uuid cl_khr_fp16 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_icd cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_intel_command_queue_families cl_intel_subgroups cl_intel_required_subgroup_size cl_intel_subgroups_short cl_khr_spir cl_intel_accelerator cl_intel_driver_diagnostics cl_khr_priority_hints cl_khr_throttle_hints cl_khr_create_command_queue cl_intel_subgroups_char cl_intel_subgroups_long cl_khr_il_program cl_intel_mem_force_host_memory cl_khr_subgroup_extended_types cl_khr_subgroup_non_uniform_vote cl_khr_subgroup_ballot cl_khr_subgroup_non_uniform_arithmetic cl_khr_subgroup_shuffle cl_khr_subgroup_shuffle_relative cl_khr_subgroup_clustered_reduce cl_intel_device_attribute_query cl_khr_suggested_local_work_size cl_intel_split_work_group_barrier cl_intel_spirv_media_block_io cl_intel_spirv_subgroups cl_khr_spirv_no_integer_wrap_decoration cl_intel_unified_shared_memory cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_intel_planar_yuv cl_intel_packed_yuv cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_3d_image_writes cl_intel_media_block_io cl_intel_va_api_media_sharing cl_intel_sharing_format_query cl_khr_pci_bus_info cl_intel_subgroup_local_block_io
NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) Intel(R) OpenCL HD Graphics
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [INTEL]
clCreateContext(NULL, ...) [default] Success [INTEL]
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) Success (1)
Platform Name Intel(R) OpenCL HD Graphics
Device Name Intel(R) Iris(R) Xe Graphics
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (1)
Platform Name Intel(R) OpenCL HD Graphics
Device Name Intel(R) Iris(R) Xe Graphics
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (1)
Platform Name Intel(R) OpenCL HD Graphics
Device Name Intel(R) Iris(R) Xe Graphics
ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.2.11
ICD loader Profile OpenCL 2.1
NOTE: your OpenCL library only supports OpenCL 2.1,
but some installed platforms support OpenCL 3.0.
Programs using 3.0 features may crash
or behave unexpectedly
2) 檢查OpenGL:
glxinfo | grep OpenGL
彈出:
OpenGL vendor string: Intel
OpenGL renderer string: Mesa Intel(R) Xe Graphics (TGL GT2)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 21.2.6
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 21.2.6
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 21.2.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
9.編譯libfreenect2:
cmake里一些要修改的默認(rèn)參數(shù)列出來(lái)了
cd libfreenect2
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -DBUILD_PYTHON3=ON -DENABLE_CXX11=ON -DENABLE_VAAPI=OFF
make -j8
sudo make install
1) 安裝結(jié)束
2) 拔下kinect2的電源或者USB
3) 修改libfreenect2/platform/linux/udev/90-kinect2.rules文件中的USB權(quán)限:
把所有0666
,修改為0777
,即最高權(quán)限。
4) 將kinect2的rules文件拷貝到udev目錄下(build文件夾下open terminal):
sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
10.測(cè)試libfreenect2:
重新插上設(shè)備后,我按照l(shuí)ibfreenect2倉(cāng)庫(kù)和iai_kinect2里的測(cè)試方法嘗試:
# 在build路徑下
./bin/Protonect
./bin/Protonect gl
./bin/Protonect cpu
./bin/Protonect cl
四個(gè)框都有圖像就問(wèn)題不大
二.安裝iai_kinect2:
地址:https://github.com/code-iai/iai_kinect2.git
或者:https://gitcode.net/mirrors/code-iai/iai_kinect2
1.安裝依賴(PCL、eigen3):
sudo apt install libeigen3-dev libeigen3-doc pcl-tools
把iai_kinect2包放到已經(jīng)添加到環(huán)境變量的ROS工作空間下,然后
2.檢查依賴(用官方倉(cāng)庫(kù)的指令會(huì)彈錯(cuò)):
rosdep install --from-paths /你自己的工作空間路徑/src/iai_kinect2 --ignore-src -r
3.運(yùn)行cmake:
這里freenect2_DIR參數(shù)最好自己指定
我這里指定了是因?yàn)槲仪懊姘惭blibfreenect2的時(shí)候指定了make install路徑
catkin_make -DCMAKE_BUILD_TYPE="Release" -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2 -DENABLE_CXX11=ON
4.編譯:
catkin_make
不要擔(dān)心,你肯定會(huì)報(bào)錯(cuò)
5.編譯iai_kinect2最重要的事!?。。。?!
貼一個(gè)我已經(jīng)修改過(guò)的包(在我自己的硬件環(huán)境和軟件環(huán)境下):
鏈接: https://pan.baidu.com/s/1mb1GMAic2L5pK0j6SAp7Pg?pwd=5sqw
提取碼: 5sqw
1) kinect2_bridge/CMakeLists.txt:
find_package(freenect2 REQUIRED HINTS "$ENV{HOME}/freenect2")
在其中我們能看見(jiàn)這個(gè)ros包默認(rèn)make install出來(lái)的freenect2文件夾路徑${HOME}/freenect2,對(duì)應(yīng)前面的cmake -D參數(shù)
2) 本人編譯過(guò)程中遇到的紅色bug:
注意:需要修改這個(gè)包的源文件和cmake文件,最好用vscode打開(kāi)iai_kinect2文件夾
注意:以下任何一個(gè)問(wèn)題,修改了源文件以后,都要重新編譯
(1) PCL庫(kù)有關(guān)的各種error:
這個(gè)問(wèn)題在kinect2_viewer文件夾下的CMakeLists.txt中,它尋找PCL包沒(méi)有找到正確的位置,我在find_package(OpenMP)
這行代碼下增加其絕對(duì)路徑
set(PCL_DIR /usr/include/pcl-1.10/pcl)
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
(2) CXX14 error:
同樣是在kinect2_viewer文件夾下的CMakeLists.txt中,
在開(kāi)頭,把CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
改成CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
后面的一句也改為SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
(3) OpenCV各種宏定義找不到:
我直接一把梭,把所有include了opencv的cpp文件都添加了同樣的庫(kù)文件(用的裝ros自動(dòng)安裝的opencv4.3)
添加
#include <opencv2/imgproc/types_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgcodecs/legacy/constants_c.h>
#include <opencv2/highgui/highgui.hpp>
到
kinect2_bridge/src/kinect2_bridge.cpp
kinect2_calibration/src/kinect2_calibration.cpp
kinect2_viewer/src/viewer.cpp
這些文件的include中
(4) 運(yùn)行kinect2_bridge.launch報(bào)OpenCL registration is not available!的錯(cuò)誤:
這個(gè)問(wèn)題在iai_kinect2的issue里有人提到,是浮點(diǎn)數(shù)的問(wèn)題
這里就是為什么要用vscode打開(kāi)的原因,因?yàn)檫@個(gè)問(wèn)題是在kinect2_registration/src/depth_registration.cl
文件里被造成的
我使用vscode打開(kāi)后,會(huì)提示你安裝opencl有關(guān)的插件,安裝完后,會(huì)給這個(gè)cl文件以高亮,
雖然issue中有人說(shuō)只需要修改文件最后那幾行中const float4 tmp = (float4)(sqrt(2.0));
這段代碼為const float4 tmp = (float4)(sqrt(2.0f));
但我還是把所有插件提示出的所有未加f后綴的浮點(diǎn)數(shù)都加上了f后綴,然后再重新catkin_make
就好了。
但是,如果你不想用或者用不了OpenCL,你可以打開(kāi)kinect2_bridge/launch/kinect2_bridge.launch
文件
修改其中的一個(gè)參數(shù)<arg name="reg_method" default="default"/>
為<arg name="reg_method" default="cpu"/>
也就是不使用OpenCL而是使用CPU。
三.測(cè)試iai_kinect2:
roslaunch kinect2_bridge kinect2_bridge.launch #連接傳感器
rosrun kinect2_viewer kinect2_viewer kinect2 sd image #查看圖像
rosrun kinect2_viewer kinect2_viewer kinect2 sd cloud #查看點(diǎn)云
如果都能正常打開(kāi),就說(shuō)明沒(méi)問(wèn)題了。
四.用iai_kinect2標(biāo)定:
遇見(jiàn)了,顏色和紅外標(biāo)定完,標(biāo)定pose的時(shí)候輸出值全為0的bug
這個(gè)bug在倉(cāng)庫(kù)的pr中被修改了:https://github.com/cbuchxrn/iai_kinect2_opencv4/commit/7123381392f2524f1f85713bb92ab1f2e768190f#diff-7f37e052948300fc492ebf0563b4630d3bdadfcf28020fb7d5e16c833994402c
可以搜這個(gè)標(biāo)題:Added cam calibration and made changes to use with opencv4
暫時(shí)是用matlab那個(gè)工具箱標(biāo)定了rgb相機(jī),標(biāo)定了好幾次,重影問(wèn)題還是很?chē)?yán)重。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-546793.html
五.修改kinect2_bridge在rviz中顯示的點(diǎn)云為垂直于xz平面的(僅在kinect2_link下生效):
用vscode打開(kāi)kinect2_bridge.cpp
文件,查找setRPY,這個(gè)函數(shù)是設(shè)置kinect2_link的初始位姿的,將qZero.setRPY(0,0,0)
改為qZero.setRPY(M_PI/2, M_PI, 0);
,catkin_make
然后運(yùn)行kinect2_bridge.launch
選中kinect2_link坐標(biāo)系,就能看到點(diǎn)云已經(jīng)轉(zhuǎn)過(guò)來(lái)了,我也想修改其它坐標(biāo)系下的點(diǎn)云位姿,但是稍微修改以下上面的那個(gè)rot
變量,kinect2_link坐標(biāo)系下的sd點(diǎn)云也會(huì)跟著變化,故放棄修改其它坐標(biāo)系下的點(diǎn)云位姿了。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-546793.html
六.結(jié)束
到了這里,關(guān)于Ubuntu20.04安裝Kinect2驅(qū)動(dòng)libfreenect2以及對(duì)應(yīng)的ros功能包iai_kinect2(解決編譯報(bào)錯(cuò))的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!