6 Replies Latest reply on Aug 17, 2017 6:40 AM by jb455

    How to find equivalence of a pixel in the color image to the depth image?

    fhfonsecaa

      Good afternoon,

       

      I currently have the code below to perform the mapping of the color image to the depth image.

       

      I know that it creates a map of vertices and it goes over them depending on the size of both images, which works perfectly, however in this moment I need to find the exact coodenate of a specific pixel.

       

      For example my pixel of interest is (150,20) in the color image, of this pixel I need to know the depth and in order to find out the exact depth I need to know what is the equivalence of that pixel in the depth image.

       

      I can not figure out how to do this transformation, I even tried to build a pxcImage with a red dot on it to project it over the depth image but it did not work correctly.

       

      Thank you very much.

       

      PS: I'm working with OpenCV, R200, intel SDK and C ++ in Visual Studio

       

      PXCImage* R200Driver::ColorToDepthByQueryUVMap()
      {
      if (!drawDepth || !projection) return 0;
      
      
      PXCImage::ImageInfo drawDepthInfo = drawDepth->QueryInfo();
      PXCImage::ImageData drawDepthDat;
      if (PXC_STATUS_NO_ERROR > drawDepth->AcquireAccess(PXCImage::ACCESS_WRITE, drawDepthInfo.format, &drawDepthDat))
      return 0;
      
      
      /* Retrieve the color pixels */
      PXCImage::ImageData cdata;
      pxcStatus sts = frameColor->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB32, &cdata);
      if (sts >= PXC_STATUS_NO_ERROR) {
      sts = projection->QueryUVMap(frameDepth, &uvMap[0]);
      if (sts >= PXC_STATUS_NO_ERROR) {
      PXCImage::ImageInfo cinfo = frameColor->QueryInfo();
      PXCImage::ImageInfo dinfo = frameDepth->QueryInfo();
      for (pxcI32 y = 0; y < dinfo.height; y++) {
      pxcI32* pDrawDepthDat = (pxcI32*)(drawDepthDat.planes[0] + y * drawDepthDat.pitches[0]);
      PXCPointF32 *uvTest = &uvMap[y * dinfo.width];
      for (pxcI32 x = 0; x < dinfo.width; x++) {
      pDrawDepthDat[x] = 0;
      if (uvTest[x].x >= 0 && uvTest[x].x < 1 && uvTest[x].y >= 0 && uvTest[x].y < 1) {
      pxcI32 tmpColor = *(pxcI32*)(cdata.planes[0] + (int)(uvTest[x].y * cinfo.height) * cdata.pitches[0] + 4 * (int)(uvTest[x].x * cinfo.width));
      pDrawDepthDat[x] = tmpColor;
      }
      }
      }
      }
      frameColor->ReleaseAccess(&cdata);
      }
      drawDepth->ReleaseAccess(&drawDepthDat);
      return drawDepth;
      }