【问题标题】:ProjectDepthToCamera returns 0 for all the xyz of pos3dProjectDepthToCamera 为 pos3d 的所有 xyz 返回 0
【发布时间】:2017-05-16 00:58:59
【问题描述】:

我不确定为什么以下代码中的 pos3d 中的所有 x、y、z 值都为零。请提出修复建议:

/***
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();
    cout << "inImg->QueryInfo() " << depthImage.format << endl;
    PXCPoint3DF32 * pos2d = new PXCPoint3DF32[depth_width*depth_height];
    int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);

    for (int y = 0, k = 0; y < depth_height; y++) {
        for (int x = 0; x < depth_width; x++, k++) {
            pos2d[k].x = (pxcF32)x;
            pos2d[k].y = (pxcF32)y;
            pos2d[k].z = ((short *)depthImage.planes[0])[y* depth_stride + x];
        }
    }

    //Point3DF32 * pos3d = NULL;
    PXCPoint3DF32 * pos3d = new Point3DF32[depth_width*depth_height];
    PXCPoint3DF32 * vertices = new PXCPoint3DF32[depth_width * depth_height];
    Projection * projection = device->CreateProjection();
    projection->ProjectDepthToCamera(depth_width*depth_height, pos2d, pos3d);
    cout << "x is " << pos3d->x*1000 << endl;
    cout << "y is " << pos3d->y*1000 << endl;
    cout << "z is " << pos3d->z*1000 << endl;

}

【问题讨论】:

    标签: c++ realsense


    【解决方案1】:

    这是获取 XYZ 贴图超出深度图像 UV 贴图的经过验证的正确答案: 状态 sts = sm ->AcquireFrame(true);

        if (sts < STATUS_NO_ERROR) {
            if (sts == Status::STATUS_STREAM_CONFIG_CHANGED) {
                wprintf_s(L"Stream configuration was changed, re-initilizing\n");
                sm ->Close();
            }
        }
    
        sample = sm->QuerySample();
        PXCImage *depthMap = sample->depth;
        renderd.RenderFrame(sample->depth);
        PXCImage::ImageData depthImage;
        depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
        PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
        int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
        PXCProjection * projection = device->CreateProjection();
        pxcU16 *dpixels = (pxcU16*)depthImage.planes[0];
        unsigned int dpitch = depthImage.pitches[0] / sizeof(pxcU16);
        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();
        }
        for (int k = 0; k < num_pixels; k++) {
    
                if (pos3D[k].x != 0) {
                cout << " xx is: " << pos3D[k].x << endl;
                }
                if (pos3D[k].y != 0) {
                cout << " yy is: " << pos3D[k].y << endl;
                }
                if (pos3D[k].z != 0) {
                cout << " zz is: " << pos3D[k].z << endl;
                }
              }
    

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2014-04-06
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2011-12-14
      相关资源
      最近更新 更多