Obtain the Asus xtionprolive depth chart and color chart by using openn20.

Source: Internet
Author: User

There is a problem when opening xtionprolive using openn2. the color image resolution is always set to 320*240, but the depth graph can be set to 640*480, openni1.x can obtain a 640*480 color image.



Color chart



Depth Map after registration to a color chart



Converged Graph



Code:

# Include <opencv2/CORE/core. HPP> # include <opencv2/imgproc. HPP> # include <opencv2/highgui. HPP> # include <opencv2/opencv. HPP> # include <iostream> # include "openni. H "using namespace openni; using namespace CV; using namespace STD; int main () {status rc = status_ OK; // openni function execution result // videoframeref onidepthimg, onicolorimg; // opencv mat cvdepthimg, cvbgrimg, and cvfusionimg; // initialize openni2rc = op Enni: Initialize (); // enable the device of the Kinect or xtion device; const char * deviceurl = openni: any_device; // The device name rc = device. open (deviceurl); // create and open the deep data stream videostream onidepthstream; // The deep data stream rc = onidepthstream. create (device, sensor_depth); // create a deep data stream if (status_ OK = RC) {// set the deep video mode videomode modedepth; modedepth. setresolution (320,240/* 640,480 */); // resolution modepth. setfps (30); // Frame Rate modedepth. setpixelformat (pixel_format _ Depth_1_mm); // The onidepthstream. setvideomode (modedepth); onidepthstream. Start (); // open the deep data stream if (status_ OK! = RC) {cerr <"cannot open deep data streams:" <openni: getextendederror () <Endl; onidepthstream. destroy () ;}} else {cerr <"cannot create a deep data stream:" <openni: getextendederror () <Endl ;} // create and open the color data stream videostream onicolorstream; // RGB data stream rc = onicolorstream. create (device, sensor_color); If (status_ OK = RC) {// sets the color video mode videomode modecolor; // I don't know why, the resolution of a color chart is always 320 * 240modecolor. setresolution (320,240/*, */); // resolution modecolor. setfps (30 ); // Frame Rate modecolor. setpixelformat (pixel_format_rgb888); // sets the registration mode of the Depth graph and the color graph if (device. isimageregistrationmodesupported (image_registration_depth_to_color) {Device. setimageregistrationmode (image_registration_depth_to_color); // depth to color image registration} rc = onicolorstream. start (); // enable the color data stream if (status_ OK! = RC) {cerr <"color data streams cannot be opened:" <openni: getextendederror () <Endl; onicolorstream. destroy () ;}} else {cerr <"you cannot create a color data stream:" <openni: getextendederror () <Endl ;}if (! Onidepthstream. isvalid () |! Onicolorstream. isvalid () {cerr <"invalid color or deep data stream" <Endl; openni: Shutdown (); return 1 ;}namedwindow ("depth "); namedwindow ("RGB"); namedwindow ("fusion"); While (true) {// read a frame of depth graph if (status_ OK = onidepthstream. readframe (& onidepthimg) {mat cvrawimg16u (onidepthimg. getheight (), onidepthimg. getwidth (), cv_16uc1, (void *) onidepthimg. getdata (); cvrawimg16u. convertize (cvdepthimg, cv_8u, 255.0/(onidepthstream. getmaxpixelvalue (); flip (cvdepthimg, cvdepthimg, 1); // horizontal flip imshow ("depth", cvdepthimg );} // read a color chart if (status_ OK = onicolorstream. readframe (& onicolorimg) {mat cvrgbimg (onicolorimg. getheight (), onicolorimg. getwidth (), cv_8uc3, (void *) onicolorimg. getdata (); cvtcolor (cvrgbimg, cvbgrimg, cv_rgb2bgr); flip (cvbgrimg, cvbgrimg, 1); // horizontally flip imshow ("RGB", cvbgrimg );} // fusion map cvtcolor (watermark, cvfusionimg, watermark); addweighted (cvbgrimg, 0.5, cvfusionimg, 0.5, 0, cvfusionimg); flip (cvfusionimg, cvfusionimg, 1 ); // horizontal flip imshow ("fusion", cvfusionimg); waitkey (30); // No waitkey does not show the image} destroywindow ("depth"); destroywindow ("RGB "); destroywindow ("fusion"); onidepthstream. destroy (); onicolorstream. destroy (); device. close (); openni: Shutdown (); Return 0 ;}


Environment:

Xtionprolive, win7 32-bit, vs2010, openni2.1.0, opencv2.4.4


Download source code:

Http://download.csdn.net/detail/masikkk/7582485


Openni2.1 download:

Http://download.csdn.net/detail/masikkk/7582489



Refer:

Kinect + openni study note 2 (obtain the color and depth of the Kinect image)

Kinect + openni study note 4 (image obtained by openni combined with opencv display)

Kinect development tutorial 2: openni reads and displays deep and color images


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.