2017-05-16 3 views
0

Dans l'extrait suivant, lorsque j'imprime les valeurs posUVZ, ils sont, mais après non nul je les passe à ProjectDepthToCamera(wxhDepth, posUVZ, pos3D) toutes les valeurs pos3D arrivent à zéro. Quoi qu'il en soit, pourquoi cela se passe-t-il et comment y remédier?toutes les valeurs pos3d sont égales à zéro alors que les valeurs posUVZ ne sont pas nulles

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

}; 

Répondre

0

Voici la réponse correcte pour obtenir le xyzMap de l'image de profondeur UVmap:

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