Preparation
Install libfreenect
Note:
libfreenect for Kinect Xbox 360
libfreenect2 for Kinect Xbox One
|
|
Install OpenNI
|
|
Then, copy the freenect driver to OpenNI2 driver repository:
|
|
Build OpenCV with OpenNI
NOTE: Please see how to Build OpenCV on Firefly-RK3399.
|
|
Usage
C++
kinect.cc
:
|
|
./build/bin/kinect
:
Could get complete C++ code here, Python code here.
NOTE: Unable to retrieve correct image using Python code now. Please see this issue.
References
- Using Kinect and other OpenNI compatible depth sensors
- OpenNI2 with OpenCV 3 (macOS)
- How to use Kinect using OpenNI2 with OpenCV 3 on macOS
Issues
Failed to use libfreenect form sudo apt-get install freenect
Install:
|
|
Cause: not install freenect driver.
Failed to build libfreenect on Firefly-RK3399 (aarch64)
Error when build libfreenect:
[ 94%] Building CXX object OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/src/ColorStream.cpp.o
In file included from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/extern/OpenNI-Linux-x64-2.2.0.33/Include/Driver/OniDriverAPI.h:24:0,
from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.hpp:6,
from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.cpp:2:
/home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/extern/OpenNI-Linux-x64-2.2.0.33/Include/OniPlatform.h:49:3: error: #error Xiron Platform Abstraction Layer - Unsupported Platform!
# error Xiron Platform Abstraction Layer - Unsupported Platform!
^
In file included from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/extern/OpenNI-Linux-x64-2.2.0.33/Include/Driver/OniDriverAPI.h:25:0,
from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.hpp:6,
from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.cpp:2:
/home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/extern/OpenNI-Linux-x64-2.2.0.33/Include/OniCTypes.h:115:32: error: expected ')' before '*' token
typedef void (ONI_CALLBACK_TYPE* OniNewFrameCallback)(OniStreamHandle stream, void* pCookie);
^
...
In file included from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.hpp:7:0,
from /home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/ColorStream.cpp:2:
/home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/VideoStream.hpp: In constructor 'FreenectDriver::VideoStream::VideoStream(Freenect::FreenectDevice*)':
/home/firefly/Workspace/libfreenect-0.5.5/OpenNI2-FreenectDriver/src/VideoStream.hpp:34:46: error: 'memset' was not declared in this scope
memset(&cropping, 0, sizeof(cropping));
^
OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/build.make:62: recipe for target 'OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/src/ColorStream.cpp.o' failed
make[2]: *** [OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/src/ColorStream.cpp.o] Error 1
CMakeFiles/Makefile2:902: recipe for target 'OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/all' failed
make[1]: *** [OpenNI2-FreenectDriver/CMakeFiles/FreenectDriver.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Case: not support aarch64 platform if build from latest release v0.5.5.
Solution: use latest code instead of latest release v0.5.5.
See this commit, OpenNI2: Add aarch64 platform detection.
Failed to use OpenNI2 from sudo apt-get install libopenni2-dev
Install:
|
|
Error when run sample:
OpenCV Error: Unspecified error (OpenCVKinect: Device open failed see: DeviceOpen using default: no devices found
) in CvCapture_OpenNI2, file /home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp, line 237
VIDEOIO(cvCreateCameraCapture_OpenNI2(index)): raised OpenCV exception:
/home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp:237: error: (-2) OpenCVKinect: Device open failed see: DeviceOpen using default: no devices found
in function CvCapture_OpenNI2
Case: not found freenect driver! why?
Failed to use OpenNI2 from OpenNI-Linux-Arm-2.2.0.33.tar.bz2
Install:
|
|
Then, copy the freenect driver to OpenNI2 driver repository:
|
|
Error when rebuild OpenCV:
[ 61%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_openni2.cpp.o
In file included from /home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Include/OpenNI.h:24:0,
from /home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp:69:
/home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Include/OniPlatform.h:49:3: error: #error Xiron Platform Abstraction Layer - Unsupported Platform!
# error Xiron Platform Abstraction Layer - Unsupported Platform!
^
In file included from /home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Include/OniCAPI.h:25:0,
from /home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Include/OpenNI.h:28,
from /home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp:69:
/home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Include/OniCTypes.h:115:32: error: expected ')' before '*' token
typedef void (ONI_CALLBACK_TYPE* OniNewFrameCallback)(OniStreamHandle stream, void* pCookie);
^
...
/home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp: In member function 'bool CvCapture_OpenNI2::setDepthGeneratorProperty(int, double)':
/home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp:612:60: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
if( !device.getImageRegistrationMode() == mode )
^
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:206: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_openni2.cpp.o' failed
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_openni2.cpp.o] Error 1
CMakeFiles/Makefile2:3987: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Case: not support aarch64 platform.
Solution:
|
|
Error when rebuild OpenCV again:
[ 60%] Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: skipping incompatible /home/firefly/Workspace/OpenNI-Linux-Arm-2.2/Redist/libOpenNI2.so when searching for -lOpenNI2
/usr/bin/ld: cannot find -lOpenNI2
collect2: error: ld returned 1 exit status
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:281: recipe for target 'lib/libopencv_videoio.so.3.2.0' failed
make[2]: *** [lib/libopencv_videoio.so.3.2.0] Error 1
CMakeFiles/Makefile2:3987: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
Case: not incompatible “libOpenNI2.so”.
Solution: build form source.
Failed to use libfreenect with OpenNI2 (from source)
Error when run sample:
OpenNI2-FreenectDriver: (ERROR) Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE
OpenCV Error: Unspecified error (CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance!
) in readCamerasParams, file /home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp, line 404
write_register: 0x0005 <= 0x00
write_register: 0x0006 <= 0x00
OpenNI2-FreenectDriver: Closing device freenect://0
VIDEOIO(cvCreateCameraCapture_OpenNI2(index)): raised OpenCV exception:
/home/firefly/Workspace/opencv/modules/videoio/src/cap_openni2.cpp:404: error: (-2) CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance!
in function readCamerasParams
Solution: fix this issue, plz see here.