Read Xtion Pro live data with OPENCV

Source: Internet
Author: User

Remember when reading Xtion Pro live depth data and color data, the main use is directly Read NI class. Using this direct method is more troublesome, but also to write a special read program, call NI's function. Now the OPENCV2 integrates the Openni, which can read depth data and color data directly using Videocapture. In contrast, there may be some features that are not so complete.

So how to read Openni directly with OpenCV? The following steps are mainly divided into:
1, install the Openni library and Primesensor Drive.
Refer to http://blog.csdn.net/jasmine_shine/article/details/46235911 for installation.

2, install OPENCV when the configuration and compile Openni.
Refer to http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/for OPENCV configuration. Among them, in cmake-d with_tbb=on-d build_new_python_support=on-d with_v4l=on-d install_c_examples=on-d INSTALL_PYTHON_ examples=on-d build_examples=on-d with_qt=on-d with_opengl=on-d with_vtk=on with_openni=on. When I found the choice to add With_openni error, and did not add this in. Then the Cmake-gui is configured, the With-openni is selected, and the Configure is executed, and then the make is followed. The personal estimate is that Cmake-gui has many properties that are not directly cmake.

3, test.
I am based on the ubuntu12.04 environment, mainly using QT to compile. Create an empty project for QT.
. Pro file:

SOURCES +=     main.cppINCLUDEPATH +=      /usr/local/include######opencv######                    /usr/local/include/opencv                     /usr/local/include/opencv2 LIBS +=     /usr/local/lib/libopencv_highgui.so             /usr/local/lib/libopencv_core.so                /usr/local/lib/libopencv_imgproc.so  \

Main.cpp

#include "opencv2/core/core.hpp"#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include <iostream>using namespaceCvusing namespace STD;intMain () {cout<<"opening device (s)"<< Endl; Videocapture Sensor1;sensor1.open (Cv_cap_openni_asus);//videocapture Sensor2;sensor2.open (cv_cap_openni_asus+1);if(!sensor1.isopened ()) {cout<<"Can not open Capture object 1."<< Endl;return-1;} for(;;) {Mat depth1,depth2;if(!sensor1.grab ()) {cout<<"Sensor1 can not grab images."<< Endl;return-1; }Else if(Sensor1.retrieve (Depth1, Cv_cap_openni_depth_map)) Imshow ("Depth1", depth1);/* if (!sensor2.grab ()) {cout << "Sensor2 can not grab images." << Endl;    return-1; }else if (Sensor2.retrieve (Depth2, Cv_cap_openni_depth_map)) imshow ("Depth2", depth2); * /    if(Waitkey ( -) == -) Break; }}

This is videocapture reading is cv_cap_openni_asus, because I am using ASUS Xtion Pro Live, if it is Kinect, then is Cv_cap_openni.
Test program output:

The above is the raw depth data of 16 bits.

4. Remarks
problem one appears:
The above is only the use of QT for OPENCV testing, and the direct adoption of CMake, but the following error occurred:

*you should manually point CMake variable opencv_dir to your build of OpenCV library.
Call Stack (most recent call first):
Src/cmakelists.txt:9 (find_package) '
CMake Warning at/usr/local/opencv-2.4.9/cmake/opencvconfig.cmake:161 (message):
Found OpenCV Windows Pack But it had not binaries compatible with your
configuration.*

Generally when writing cmakelist files, the main find_package (OPENCV REQUIRED) and Target_link_libraries (My_target_name ${opencv_libs}) are available. The reason is that when compiling with Cmake-gui, there are two opencvconfig.cmake files, one in the build file, one in the CMake file, and the Cmake-gui directly default is the build file, so the above error occurs. Just change the data in the where to build the binaries column to Usr/local/opencv-2.4.9/cmake, configure, and then generate.

Two problems occurred:
The above problem is solved, but then another problem arises:
Warning:target "main" requests linking to Directory "/usr/lib". Targets may link is only to libraries. CMake is dropping the item.
MAKE[2]: * No rules can be created ". /bin/main "The desired target"/usr/local/opencv-2.4.9/cmake/lib/libopencv_videostab.so.2.4.9 ". Stop it.
The program does not pass when generating the executable file, so Cmake-gui back to the previous usr/local/opencv-2.4.9/build,configure,generate and recompile once OPENCV. This problem occurs when I execute make again. Wait until I want to reload the OPENCV, delete the installation package files, execute the project again to make, found can be compiled through. It is estimated that when make was made, Lib was linked to/usr/local/opencv-2.4.9/cmake/lib, but the file does not libopencv_videostab.so.2.4.9 this static library.

So now you can use OPENCV under QT, or you can use it in the form of CMake directly under Ubuntu. It's so frustrating, just to be able to read Xtion Pro live data directly with OPENCV.

Read Xtion Pro live data with OPENCV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.