<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help mapping color to point in Items with no label</title>
    <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622448#M13524</link>
    <description>&lt;P&gt;Have you seen the SDK 2.0 example for creating a point cloud?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud"&gt;https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud&lt;/A&gt; librealsense/examples/pointcloud at master · IntelRealSense/librealsense · GitHub &lt;/P&gt;</description>
    <pubDate>Tue, 20 Mar 2018 08:31:05 GMT</pubDate>
    <dc:creator>MartyG</dc:creator>
    <dc:date>2018-03-20T08:31:05Z</dc:date>
    <item>
      <title>Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622447#M13523</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This has been asked before, and I believe I am doing the right steps but cannot get it work. I am trying to upgrade from RealSense to RealSense2 using SR300 camera. I am trying to abstract getting a point cloud with color (x, y, z, r, g, b) for other uses. I am trying to map the color to the depth points as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Camera() : pipe(), pipeProfile(), depthScale(0) {&lt;/P&gt;&lt;P&gt;     rs2::config cameraConfig;&lt;/P&gt;&lt;P&gt;     cameraConfig.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16);&lt;/P&gt;&lt;P&gt;     cameraConfig.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGB8);&lt;/P&gt;&lt;P&gt;     pipeProfile = pipe.start(cameraConfig);&lt;/P&gt;&lt;P&gt;     depthScale = pipeProfile.get_device().first().get_depth_scale();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void Camera::getCapture() {&lt;/P&gt;&lt;P&gt;     rs2::frameset frames = pipe.wait_for_frames();&lt;/P&gt;&lt;P&gt;     rs2::depth_frame depthFrame = frames.get_depth_frame();&lt;/P&gt;&lt;P&gt;     rs2::video_frame colorFrame = frames.get_color_frame();&lt;/P&gt;&lt;P&gt;     &lt;/P&gt;&lt;P&gt;     rs2_intrinsics depth_intrinsic = depthFrame.get_profile().as().get_intrinsics();&lt;/P&gt;&lt;P&gt;     rs2_intrinsics color_intrinsic = colorFrame.get_profile().as().get_intrinsics();&lt;/P&gt;&lt;P&gt;     rs2_extrinsics depth_to_color = depthFrame.get_profile().get_extrinsics_to(colorFrame.get_profile());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     const uint16_t* depthImage = (const uint16_t*)depthFrame.get_data();&lt;/P&gt;&lt;P&gt;     const unsigned char* colorImage = (const unsigned char*)colorFrame.get_data();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     for (int dy = 0; dy &amp;lt; depth_intrinsic.height; dy++) {&lt;/P&gt;&lt;P&gt;          for (int dx = 0; dx &amp;lt; depth_intrinsic.width; dx++) {&lt;/P&gt;&lt;P&gt;          // get depth value at dy, dx&lt;/P&gt;&lt;P&gt;          unsigned int i = dy * depth_intrinsic.width + dx;&lt;/P&gt;&lt;P&gt;          uint16_t depth_value = depthImage[i];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          // if the depth value is 0, we ignore this points.&lt;/P&gt;&lt;P&gt;          if (depth_value == 0) {&lt;/P&gt;&lt;P&gt;               continue;&lt;/P&gt;&lt;P&gt;          }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          float depth_in_meters = depth_value * depthScale;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          // map the pixel coordinate in depth image to pixel coordinate in color image&lt;/P&gt;&lt;P&gt;          float depth_pixel[2] = {(float)dx - 0.5f, (float)dy - 0.5f};&lt;/P&gt;&lt;P&gt;          float depth_point[3], color_point[3], color_pixel[2];&lt;/P&gt;&lt;P&gt;          rs2_deproject_pixel_to_point(depth_point, &amp;amp;depth_intrinsic, depth_pixel, depth_in_meters);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          // if it's out of acceptable range, skip it&lt;/P&gt;&lt;P&gt;          if (depth_point[2] &amp;gt; maxAcceptDistance) {&lt;/P&gt;&lt;P&gt;               continue;&lt;/P&gt;&lt;P&gt;          }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          rs2_transform_point_to_point(color_point, &amp;amp;depth_to_color, depth_point);&lt;/P&gt;&lt;P&gt;          rs2_project_point_to_pixel(color_pixel, &amp;amp;color_intrinsic, color_point);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          // get closest color pixel obtained from calculations and use as the point's color, or white if ouside color image&lt;/P&gt;&lt;P&gt;          const int cx = static_cast(color_pixel[0] + 0.5f);&lt;/P&gt;&lt;P&gt;          const int cy = static_cast(color_pixel[1] + 0.5f);     &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          // if outside intrinsic parameters, skip the point&lt;/P&gt;&lt;P&gt;          if (cx &amp;lt; 0 || cy &amp;lt; 0 || cx &amp;gt; color_intrinsic.width || cy &amp;gt; color_intrinsic.height) {&lt;/P&gt;&lt;P&gt;               continue;&lt;/P&gt;&lt;P&gt;          }&lt;/P&gt;&lt;P&gt;          const unsigned char* offset = static_cast(colorImage + (cy * color_intrinsic.width + cx) * 3);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          float x = -1 * depth_point[0];&lt;/P&gt;&lt;P&gt;          float y = -1 * depth_point[1];&lt;/P&gt;&lt;P&gt;          float z = depth_point[2];&lt;/P&gt;&lt;P&gt;          unsigned char r = *(offset);&lt;/P&gt;&lt;P&gt;          unsigned char g = *(offset + 1);&lt;/P&gt;&lt;P&gt;          unsigned char b = *(offset + 2);&lt;/P&gt;&lt;P&gt;          }&lt;/P&gt;&lt;P&gt;     }&lt;/P&gt;&lt;P&gt;}   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I only left the redundant parts. Basically, in the end, (r, g, b) are 0 (or they appear black in the image). Any suggestions? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. (Code editor is weird).&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 04:51:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622447#M13523</guid>
      <dc:creator>idata</dc:creator>
      <dc:date>2018-03-20T04:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622448#M13524</link>
      <description>&lt;P&gt;Have you seen the SDK 2.0 example for creating a point cloud?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud"&gt;https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud&lt;/A&gt; librealsense/examples/pointcloud at master · IntelRealSense/librealsense · GitHub &lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 08:31:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622448#M13524</guid>
      <dc:creator>MartyG</dc:creator>
      <dc:date>2018-03-20T08:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622449#M13525</link>
      <description>&lt;P&gt;Hello MartyG,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did see the example, but I couldn't figure out how to use the (u, v) values to obtain the (r, g, b) values from the color frame. Any help with that? Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:37:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622449#M13525</guid>
      <dc:creator>idata</dc:creator>
      <dc:date>2018-03-20T14:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622450#M13526</link>
      <description>&lt;P&gt;I'll link RealSense stream programming expert jb455  into this discussion to seek his wide knowledge on the subject.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:39:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622450#M13526</guid>
      <dc:creator>MartyG</dc:creator>
      <dc:date>2018-03-20T14:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622451#M13527</link>
      <description>&lt;P&gt;So I know that once you do&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rs2::pointcloud pc;&lt;/P&gt;&lt;P&gt;rs2::points points;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rs2::frameset frames = pipe.wait_for_frames();&lt;/P&gt;&lt;P&gt;rs2::depth_frame depth = frames.get_depth_frame();&lt;/P&gt;&lt;P&gt;rs2::video_frame color_frame = frames.get_color_frame();&lt;/P&gt;&lt;P&gt;points = pc.calculate(depth);&lt;/P&gt;&lt;P&gt;pc.map_to(color_frame);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, you can get the texture coordinates that correspond to each vertex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;const rs2::vertex* ptr = points.get_vertices();&lt;/P&gt;&lt;P&gt;const rs2::texture_coordinate* tex_coords = points.get_texture_coordinates();&lt;/P&gt;&lt;P&gt;const unsigned char* colorStream = static_cast(color_frame.get_data());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each texture coordinate has (u, v) value which ranges from [0-1] that can be mapped to the color frame. I did this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int x = tex_coords[i].u * color_intrinsic.width;&lt;/P&gt;&lt;P&gt;int y = tex_coords[i].v * color_intrinsic.height;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int colorLocation = y * color_intrinsic.width + x;&lt;/P&gt;&lt;P&gt;unsigned char color[3] = {colorStream[colorLocation], colorStream[colorLocation +1], colorStream[colorLocation +2]};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, everything comes back as a single color. I stepped through and it seems both u and v are always 0. &lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 16:30:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622451#M13527</guid>
      <dc:creator>idata</dc:creator>
      <dc:date>2018-03-20T16:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help mapping color to point</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622452#M13528</link>
      <description>&lt;P&gt;For anyone that may read this, I had to swap the map_to and calculate statements. However, you also need to get some captures. do as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rs2::pointcloud pc;  &lt;/P&gt;&lt;P&gt;rs2::points points; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; 10; i++) pipe.wait_for_frames();&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;rs2::frameset frames = pipe.wait_for_frames();  &lt;/P&gt;&lt;P&gt;rs2::depth_frame depth = frames.get_depth_frame();  &lt;/P&gt;&lt;P&gt;rs2::video_frame color_frame = frames.get_color_frame();  &lt;/P&gt;&lt;P&gt;pc.map_to(color_frame);&lt;/P&gt;&lt;P&gt;points = pc.calculate(depth);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int width = color_frame.get_width();&lt;/P&gt;&lt;P&gt;int height = color_frame.get_height();&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;const rs2::vertex* ptr = points.get_vertices();  &lt;/P&gt;&lt;P&gt;const rs2::texture_coordinate* tex_coords = points.get_texture_coordinates();  &lt;/P&gt;&lt;P&gt;const unsigned char* colorStream = static_cast&amp;lt;&amp;lt;/span&amp;gt;const unsigned char*&amp;gt;(color_frame.get_data()); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; points.size(); i++) {&lt;/P&gt;&lt;P&gt;     &lt;/P&gt;&lt;P&gt;int x = static_cast(textureCoordinates[i].u * width);&lt;/P&gt;&lt;P&gt;int y = static_cast(textureCoordinates[i].v * height);&lt;/P&gt;&lt;P&gt;if (y &amp;lt; 0 || y &amp;gt;= height) {&lt;/P&gt;&lt;P&gt;continue;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if (x &amp;lt; 0 || x &amp;gt;= width) {&lt;/P&gt;&lt;P&gt;continue;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if (rs_vertices[i].z &amp;lt;= 0 || rs_vertices[i].z &amp;gt; maxAcceptDistance) {          // Rule out values further than this value&lt;/P&gt;&lt;P&gt;continue;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int colorLocation = (y * width + x) * 3;&lt;/P&gt;&lt;P&gt;unsigned char color[3] = {colorData[colorLocation], colorData[colorLocation +1], colorData[colorLocation +2]};   // RGB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;float coordinates[3] = { ptr[i].x, ptr[i].y, ptr[i].z };&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 14:59:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Help-mapping-color-to-point/m-p/622452#M13528</guid>
      <dc:creator>idata</dc:creator>
      <dc:date>2018-03-29T14:59:05Z</dc:date>
    </item>
  </channel>
</rss>

