3 Replies Latest reply on Jun 14, 2017 8:33 PM by HelloIntelWorld

    How to obtain the value of the color component(r,g,b) of a pixel in the color image


      Hi! I am using R200 for 3D scene reconstruction.

      There are point cloud library and opencv library in my project. It is possible to show the point cloud now using vertices. (Projection->QueryVertices())

      But all the 3D points are gray thus I need to obtain the value of the color component in the color image to make the point cloud colorful.

      Firsty I tried Projection->ProjectCameraToColor() to map vertices to color image pixels. Is it right that the color of one pixel and one vertice matched?


      Secondly I tried one function ConvertPXCImageToOpenCVMat(PXCImage *inImg, Mat *outImg) in https://stackoverflow.com/questions/32609341/convert-a-pxcimage-into-an-opencv-mat/32609342#32609342 to convert color image to cv::Mat so that I can obtain the value of (r,g,b). But once I use imshow() to show the converted cv::Mat, the program stops responding. What the heel?


      Anyone can help me? Thanks a lot!

        • 1. Re: How to obtain the value of the color component(r,g,b) of a pixel in the color image
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi HelloIntelWorld,

          Thank you for your interest in our products.
          Given the nature of your issue, it would be a good idea to try to reproduce it. Would it be possible for you to share the code you’re using so that we can test it in our environment? Just to check if the programs crashes too.
          I also suggest you to take a look at this thread, it might give some light on your implementation. https://software.intel.com/en-us/node/585191.

          Pablo M.

          • 2. Re: How to obtain the value of the color component(r,g,b) of a pixel in the color image

            Oops, thank you for reminding me. I`m looking at the thread. Here is my code.


            int width = profiles->depth.imageInfo.width;

            int height = profiles->depth.imageInfo.height;

            PXCPoint3DF32 *myVertices = new PXCPoint3DF32[width * height];

            PXCPointF32 *MappedVertices = new PXCPointF32[width * height];

            // Get the 3D points in world coordinates in mm

            myProjection->QueryVertices(sample->depth, myVertices);

            // Get the 2D coordinates in color image of 3D points. Does every point in "MappedVertices" matches the point in "myVertices"?

            myProjection->ProjectCameraToColor(width * height, myVertices, MappedVertices);


            PXCImage::ImageData c_image;

            PXCImage::ImageInfo inputInfo = sample->color->QueryInfo();

            sample->color->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB32, &c_image);

            // Convert color image to cv::Mat

            cv::Mat rgb = cv::Mat(inputInfo.height, inputInfo.width, CV_8UC4, c_image.planes[0], c_image.pitches[0]);


            // Here comes the issue. Unable to show the cv::Mat image



            for (long i = 0; i < width * height; i++)


                if (myVertices[i].z > 3000) continue;

                if (myVertices[i].x == 0 && myVertices[i].y == 0 && myVertices[i].z == 0) continue;

                // Obtain the point cloud points in world coordinates in mm

                PointT p;

                p.z = myVertices[i].z;

                p.x = myVertices[i].x;

                p.y = myVertices[i].y;

                // To obtain the color of every point

                int m = MappedVertices[i].x;

                int n = MappedVertices[i].y;

                // The programme stops working though m and n are in the reasonable range

                if (m > 0 && n > 0 && m < width && n < height) {

                    p.b = rgb.ptr<uchar>(m)[n*3];

                    p.g = rgb.ptr<uchar>(m)[n*3+1];

                    p.r = rgb.ptr<uchar>(m)[n*3+2];





            delete[] myVertices;

            delete[] MappedVertices;