Reading an image to copy color to pointcloud

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading an image to copy color to pointcloud

ramanpreet9
This post was updated on .
I am having an issue with getting the color to copy properly from an image
my code:
"
Mat src = imread(imgfilename);
for each point in a  for loop:

pcl::PointXYZRGB p;
p.x = cloud->points[i].x;
p.y =cloud->points[i].y;
p.z = cloud->points[i].z;
Vec3b intensity = src.at(v, u);
uint8_t b = static_cast (intensity.val[0]);
uint8_t g = static_cast (intensity.val[1]);
uint8_t r = static_cast (intensity.val[2]);
uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 |(uint32_t)b);
p.rgb = *reinterpret_cast<float*>(&rgb);
cloudXYZRGB->points.push_back (p);
"
I keep getting all grey colored points. The problem lies in reading the uchar from images and converting them to proper formatting for pointcloud. but this is the given code for conversion on pcl template at
http://docs.pointclouds.org/1.7.0/structpcl_1_1_point_x_y_z_r_g_b.html



--
Sent from: http://www.pcl-users.org/
_______________________________________________
PCL-users@pointclouds.org / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Reading an image to copy color to pointcloud

Sérgio Agostinho

What you wrote can be done simply like

p.b = intensity.val[0]
p.g = intensity.val[1]
p.r = intensity.val[2]

Depending on the pcl version you might need to set the alpha component to 255. PCL 1.8.1 initializes it as 255 automatically.

Cheers


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users

signature.asc (836 bytes) Download Attachment