所有pos3d值均为零,而posUVZ值不为零

时间:2017-05-16 02:25:08

标签: c++ arrays realsense

在下面的代码段中,当我打印posUVZ值时,它们不为零,但在我将它们传递给ProjectDepthToCamera(wxhDepth, posUVZ, pos3D)后,所有pos3D值都恰好为零。虽然这是为什么会发生这种情况以及如何解决它?

/***
Reads the depth data from the sensor and fills in the matrix
***/
void SR300Camera::fillInZCoords()
{

    PXCImage::ImageData depthImage;
    PXCImage *depthMap = sample->depth;
    depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
    PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
    int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
    Projection * projection = device->CreateProjection();
    unsigned int wxhDepth = depth_width * depth_height;
    // create the array of depth coordinates + depth value (posUVZ) within the defined ROI
    PXCPoint3DF32* posUVZ = new PXCPoint3DF32[wxhDepth];
    pxcU16 *dpixels = (pxcU16*)depthImage.planes[0];
    unsigned int dpitch = depthImage.pitches[0] / sizeof(pxcU16); /* aligned width */

    for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
    {
        for (unsigned int xx = 0; xx < depth_width; xx++, k++)
        {
            posUVZ[k].x = (pxcF32)xx;
            posUVZ[k].y = (pxcF32)yy;
            posUVZ[k].z = (pxcF32)dpixels[yy * dpitch + xx];
    //      cout << "xx is " << posUVZ[k].x << endl;
    //      cout << "yy is " << posUVZ[k].y << endl;
    //      cout << "zz is " << posUVZ[k].z<< endl;
        }
    }


    // convert the array of depth coordinates + depth value (posUVZ) into the world coordinates (pos3D) in mm
    PXCPoint3DF32* pos3D = new PXCPoint3DF32[wxhDepth];

    projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D);
    /*
    if (projection->ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) < PXC_STATUS_NO_ERROR)
    {
        delete[] posUVZ;
        delete[] pos3D;
        cout << "projection unsucessful"; 
        return;
    }
    */

    for (unsigned int yy = 0, k = 0; yy < depth_height; yy++)
    {
        for (unsigned int xx = 0; xx < depth_width; xx++, k++)
        {
            cout << "xx is " << pos3D[k].x*1000.0 << endl;
            cout << "yy is " << pos3D[k].y*1000.0 << endl;
            cout << "zz is " << pos3D[k].z*1000.0 << endl;
            xyzBuffer.push_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
        }
    }

    /*
    for (int idx = 0; idx < wxhDepth; idx++) {

        cout << "x is " << pos3D[idx].x*1000.0 << endl;
        cout << "y is " << pos3D[idx].y*1000.0 << endl;
        cout << "z is " << pos3D[idx].z*1000.0 << endl;
        xyzBuffer.push_back(cv::Point3f(pos3D[idx].x, pos3D[idx].y, pos3D[idx].z));
    }
    */

    //xyzMap = cv::Mat(xyzMap.size(), xyzMap.type, &pos3D);
    xyzMap = cv::Mat(xyzBuffer);
    cout << "xyzMap = " << endl << " " << xyzMap << endl << endl;

    projection->Release();
    delete[] posUVZ;
    delete[] pos3D;

};

1 个答案:

答案 0 :(得分:0)

这是从深度图像UVmap获取xyzMap的正确答案:

PXCImage::ImageData depthImage;
depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
depth_width = imgInfo.width;
depth_height = imgInfo.height;
num_pixels = depth_width * depth_height;
PXCProjection * projection = device->CreateProjection();
PXCPoint3DF32 *pos3D = new PXCPoint3DF32[num_pixels];
sts = projection->QueryVertices(depthMap, &pos3D[0]);
if (sts < Status::STATUS_NO_ERROR) {
    wprintf_s(L"Projection was unsuccessful! \n");
    sm->Close();
}