Items with no label
3335 Discussions

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

SL4
Novice
1,267 Views

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 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!

0 Kudos
1 Solution
idata
Employee
308 Views

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 https://software.intel.com/en-us/node/585191.

 

 

Regards,

 

Pablo M.

View solution in original post

0 Kudos
3 Replies
idata
Employee
309 Views

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 https://software.intel.com/en-us/node/585191.

 

 

Regards,

 

Pablo M.
0 Kudos
SL4
Novice
308 Views

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]);

sample->color->ReleaseAccess(&c_image);

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

imshow("rgb",rgb);

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(m)[n*3];

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

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

}

cloud->points.push_back(p);

}

viewer.showCloud(cloud);

delete[] myVertices;

delete[] MappedVertices;

0 Kudos
SL4
Novice
308 Views

Bingo! It works! Thank you so much!

0 Kudos
Reply