Ask Your Question
0

How to convert pxcimage into mat

asked 2015-01-11 07:49:33 -0600

Deepak Kumar gravatar image

updated 2015-01-11 07:57:33 -0600

hi, i want to convert pxcimage into mat variable.

below is my code:

    if (psm->AcquireFrame(true)<PXC_STATUS_NO_ERROR) break;

    // retrieve all available image samples
    PXCCapture::Sample *sample = psm->QuerySample();



    //retrieve the image or frame by type from the sample
    colorIm = sample->color;
    depthIm = sample->depth;

    PXCImage *color_image = colorIm;
    PXCImage *depth_image = depthIm;

    PXCImage::ImageData colorImageData;
    PXCImage::ImageData depthImageData;

    color_image->AcquireAccess( PXCImage::ACCESS_READ, &colorImageData );
    depth_image->AcquireAccess( PXCImage::ACCESS_READ, &depthImageData );

    cvSetData( colorimg, (uchar*)colorImageData.planes[0], colorimg->width * 3 * sizeof(uchar) );
    cvSetData( depthimg, (short*)depthImageData.planes[0], depthimg->width * sizeof(short) );
    cvSetData( UVimg, (float*)depthImageData.planes[2], depthimg->width * sizeof(float) );

here i am trying to store the pxcimage data i.e, colorImageData, depthImageData into mat. as i am following c inteface of opencv. can any one help me to write store the same pxcimage data into mat in c++ inteface.

thanks

edit retag flag offensive close merge delete

Comments

please avoid duplicate questions. rather edit your old one.

berak gravatar imageberak ( 2015-01-11 07:51:01 -0600 )edit

i am not getting my answer thays why :)

Deepak Kumar gravatar imageDeepak Kumar ( 2015-01-11 11:19:10 -0600 )edit

sorry, i could not understand.

Deepak Kumar gravatar imageDeepak Kumar ( 2015-01-12 10:00:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-09-16 08:03:00 -0600

Remy gravatar image

updated 2015-09-16 08:52:14 -0600

You will find the answer here: http://stackoverflow.com/questions/32...

void ConvertPXCImageToOpenCVMat(PXCImage *inImg, Mat *outImg) {
int cvDataType;
int cvDataWidth;


PXCImage::ImageData data;
inImg->AcquireAccess(PXCImage::ACCESS_READ, &data);
PXCImage::ImageInfo imgInfo = inImg->QueryInfo();

switch (data.format) {
    /* STREAM_TYPE_COLOR */
    case PXCImage::PIXEL_FORMAT_YUY2: /* YUY2 image  */
    case PXCImage::PIXEL_FORMAT_NV12: /* NV12 image */
        throw(0); // Not implemented
    case PXCImage::PIXEL_FORMAT_RGB32: /* BGRA layout on a little-endian machine */
        cvDataType = CV_8UC4;
        cvDataWidth = 4;
        break;
    case PXCImage::PIXEL_FORMAT_RGB24: /* BGR layout on a little-endian machine */
        cvDataType = CV_8UC3;
        cvDataWidth = 3;
        break;
    case PXCImage::PIXEL_FORMAT_Y8:  /* 8-Bit Gray Image, or IR 8-bit */
        cvDataType = CV_8U;
        cvDataWidth = 1;
        break;

    /* STREAM_TYPE_DEPTH */
    case PXCImage::PIXEL_FORMAT_DEPTH: /* 16-bit unsigned integer with precision mm. */
    case PXCImage::PIXEL_FORMAT_DEPTH_RAW: /* 16-bit unsigned integer with device specific precision (call device->QueryDepthUnit()) */
        cvDataType = CV_16U;
        cvDataWidth = 2;
        break;
    case PXCImage::PIXEL_FORMAT_DEPTH_F32: /* 32-bit float-point with precision mm. */
        cvDataType = CV_32F;
        cvDataWidth = 4;
        break;

    /* STREAM_TYPE_IR */
    case PXCImage::PIXEL_FORMAT_Y16:          /* 16-Bit Gray Image */
        cvDataType = CV_16U;
        cvDataWidth = 2;
        break;
    case PXCImage::PIXEL_FORMAT_Y8_IR_RELATIVE:    /* Relative IR Image */
        cvDataType = CV_8U;
        cvDataWidth = 1;
        break;
    }

// suppose that no other planes
if (data.planes[1] != NULL) throw(0); // not implemented
// suppose that no sub pixel padding needed
if (data.pitches[0] % cvDataWidth!=0) throw(0); // not implemented

outImg->create(imgInfo.height, data.pitches[0] / cvDataWidth, cvDataType);

memcpy(outImg->data, data.planes[0], imgInfo.height*imgInfo.width*cvDataWidth*sizeof(pxcBYTE));

inImg->ReleaseAccess(&data);
}
edit flag offensive delete link more

Comments

rather make your own answer here, than posting a link to SO.

berak gravatar imageberak ( 2015-09-16 08:07:47 -0600 )edit

Update: check.

Remy gravatar imageRemy ( 2015-09-16 08:52:51 -0600 )edit

cool ;) ....

berak gravatar imageberak ( 2015-09-16 08:54:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-11 07:49:33 -0600

Seen: 1,837 times

Last updated: Sep 16 '15