2017-05-16 4 views
0

Im folgenden Ausschnitt, wenn ich die posUVZ Werte drucke, sind sie nicht Null, aber nachdem ich sie an ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) übergeben, passieren alle pos3D Werte Null sein. Irgendwie, warum passiert das und wie kann man das beheben?Alle pos3d-Werte sind Null, während posUVZ-Werte nicht Null sind

/*** 
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; 

}; 

Antwort

0

Hier ist die richtige Antwort, den xyzMap aus dem Tiefen Bild UVmap zu erhalten:

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(); 
} 
Verwandte Themen