-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obtaining RGB values fora colorised PCL point cloud. #1601
Comments
Hi @conorjmcq |
Hi @dorodnic , Thank you for the quick reply. I haven't managed to come to a solution yet unfortunately. You're link definitely helped me to understand the method, but I'm still miles off. This link talks about the same issue but I don't think there's much mention of how they achieved it. If there is anything else you could help me with then I'd greatly appreciate it. If not then thank you very much for your time. |
Hi. I am still struggling with it... I am starting with:
Then, using the Yonatan |
I think I got it!
|
Hi there,
I gave up that pursuit and decided that I was going to color the points
based on depth. It turned out how I wanted it, but thank you very much for
sending this code chunk. I don't know how helpful I may be as I still have
very little experience. I'm currently trying to implement SLAM with the
Realsense.
I'll try your code snippet once I get into College.
Thanks again!
Conor.
…On 8 May 2018 at 20:19, Yonatan Sade ***@***.***> wrote:
I think I got it!
Try this code snippet. worked for me (not all the points got valid color -
any idea?):
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include "../../../examples/example.hpp" // Include short list of convenience functions for rendering
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
#include <pcl/visualization/pcl_visualizer.h>
std::tuple<uint8_t, uint8_t, uint8_t> get_texcolor(rs2::video_frame texture, rs2::texture_coordinate texcoords)
{
const int w = texture.get_width(), h = texture.get_height();
int x = std::min(std::max(int(texcoords.u*w + .5f), 0), w - 1);
int y = std::min(std::max(int(texcoords.v*h + .5f), 0), h - 1);
int idx = x * texture.get_bytes_per_pixel() + y * texture.get_stride_in_bytes();
const auto texture_data = reinterpret_cast<const uint8_t*>(texture.get_data());
return std::tuple<uint8_t, uint8_t, uint8_t>(
texture_data[idx], texture_data[idx + 1], texture_data[idx + 2]);
}
pcl::PointCloud<pcl::PointXYZRGB>::Ptr points_to_pcl(const rs2::points& points, const rs2::video_frame& color)
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
auto sp = points.get_profile().as<rs2::video_stream_profile>();
cloud->width = sp.width();
cloud->height = sp.height();
cloud->is_dense = false;
cloud->points.resize(points.size());
auto tex_coords = points.get_texture_coordinates();
auto vertices = points.get_vertices();
for (int i = 0; i < points.size(); ++i)
{
cloud->points[i].x = vertices[i].x;
cloud->points[i].y = vertices[i].y;
cloud->points[i].z = vertices[i].z;
std::tuple<uint8_t, uint8_t, uint8_t> current_color;
current_color = get_texcolor(color, tex_coords[i]);
cloud->points[i].r = std::get<0>(current_color);
cloud->points[i].g = std::get<1>(current_color);
cloud->points[i].b = std::get<2>(current_color);
}
return cloud;
}
int main(int argc, char * argv[])
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
// Declare pointcloud object, for calculating pointclouds and texture mappings
rs2::pointcloud pc;
// We want the points object to be persistent so we can display the last cloud when a frame drops
rs2::points points;
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Start streaming with default recommended configuration
pipe.start();
while (!viewer->wasStopped())
{
// Wait for the next set of frames from the camera
auto frames = pipe.wait_for_frames();
auto depth = frames.get_depth_frame();
auto color = frames.get_color_frame();
// Generate the pointcloud and texture mappings
points = pc.calculate(depth);
pc.map_to(color);
// Convert to PCL:
auto pcl_points = points_to_pcl(points, color);
viewer->removeAllPointClouds();
viewer->addPointCloud<pcl::PointXYZRGB>(pcl_points);
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(1));
}
return EXIT_SUCCESS;
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1601 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ae1WhCDEHGwk8_4cg1bAYHA3yYW_83tSks5twe--gaJpZM4TiUq5>
.
|
Hello !
The trick is in the type of points you are using with PCL. Grégoire |
[Realsense Customer Engineering Team Comment] |
Yes we can, thank you very much everyone ! |
|---------------------------------|------------------------------------------- |
| Camera Model | {SR300} |
| Operating System & Version | Win (10) |
| Platform | PC|
| SDK Version | { 2.10.3 } |
Issue Description
Hi there,
I'm using the SR300 for a college assignment and am stuck on a bit of an issue.
I am using PCL and have generated the required x, y, z coords for the pointcloud. However I would like to manipulate the data that I have captured depending on the individual RGB values at the desired point. I understand that get_texture_coordinates will return the U, V coords but is there a way to only extract the RGB values, or even obtain them somehow ?
Thank you very much for you time.
The text was updated successfully, but these errors were encountered: