Depth Stream is not showing

asked 2015-01-09 04:44:53 -0600

Deepak Kumar gravatar image

updated 2015-01-11 06:48:52 -0600

hi,

i converted depth stream into mat variable in opencv.

when i run the code it runs successfully. but nothing is shown in the screen. and after few second the screen become black.

I am not able to figure out what mistake i am doing.

below is the code :

int wmain(int argc, WCHAR* argv[]) 
{
    //Create the IplImage headers
    IplImage* depthimg = cvCreateImageHeader(cvSize(320, 240), 16, 1);

    // create the PXCSenseManager
    PXCSenseManager *psm=0;
    psm = PXCSenseManager::CreateInstance();
    if (!psm) {
        wprintf_s(L"Unable to create the PXCSenseManager\n");
        return 1;
    }

    // select the color stream of size 640x480 and depth stream of size 320x240
    psm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH, 640, 480);

    // initialize the PXCSenseManager
    if(psm->Init() != PXC_STATUS_NO_ERROR) return 2;

    PXCImage *colorIm, *depthIm;

    for (int i=0; i<MAX_FRAMES; i++) 
    {
        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
        depthIm = sample->depth;

        PXCImage *depth_image = depthIm;

        PXCImage::ImageData depthImageData;

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

        cvSetData( depthimg, (short*)depthImageData.planes[0], depthimg->width * sizeof(short) );

        Mat depthMat(depthimg );

        imshow( "depth", depthMat );

        depth_image->ReleaseAccess(&depthImageData);
    }

    waitKey();

    }

thanks !!

edit retag flag offensive close merge delete

Comments

you should change to C++ instead of C ;)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-09 06:02:50 -0600 )edit

can you explain it little more. where should i change

Deepak Kumar gravatar imageDeepak Kumar ( 2015-01-09 08:58:30 -0600 )edit
1

Get rid of the IplImage. This is deprecated since 2010(?). Also use the cv::* functions instead of cv*

FooBar gravatar imageFooBar ( 2015-01-09 10:05:01 -0600 )edit

can you tell me how can i do this : cvSetData( depthimg, (short*)depthImageData.planes[0], depthimg->width * sizeof(short) ) into c++ inteface.

because i m not getting frame from any capture().

Deepak Kumar gravatar imageDeepak Kumar ( 2015-01-10 00:25:13 -0600 )edit

You do not need it anymore, just do

cv::VideoCapture cap(0); // or what your camera id is
cv::Mat frame;
while(true)
{
    cap >> frame;
    if (frame.empty()) break;
    // ...
}
thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-12 02:58:23 -0600 )edit