Strange behavior of PointCloudXYZRGBtoXYZHSV function

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

Strange behavior of PointCloudXYZRGBtoXYZHSV function

ravijoshi
Hi,

I am trying to convert RGB point cloud to HSV using
PointCloudXYZRGBtoXYZHSV. This conversion is strange. I noticed that all the
points in the returned HSV point cloud are zero now.

See the sample code below-
-------------------------------------------------------------------------------
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/point_types_conversion.h>

typedef pcl::PointXYZRGB PointRGB;
typedef pcl::PointXYZHSV PointHSV;
typedef pcl::PointCloud<PointRGB> PointCloudRGB;
typedef pcl::PointCloud<PointHSV> PointCloudHSV;

void create_point_cloud(PointCloudRGB::Ptr rgb_cloud)
{
  rgb_cloud->width  = 4; // sample data
  rgb_cloud->height = 1;
  rgb_cloud->is_dense = false;
  rgb_cloud->points.resize (rgb_cloud->width * rgb_cloud->height);

  uint8_t r = 255, g = 0, b = 0; // red color
  uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);

  for (int i = 0; i < rgb_cloud->points.size (); i++)
  {
    rgb_cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    rgb_cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    rgb_cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
    rgb_cloud->points[i].rgb = *reinterpret_cast<float*>(&rgb);
  }
}

void print_rgb_point_cloud(PointCloudRGB::Ptr rgb_cloud)
{
  std::cout << "rgb_cloud size(): " << rgb_cloud->points.size() <<
std::endl;
  for(int i = 0; i < rgb_cloud->points.size(); i++)
  {
    PointRGB p = rgb_cloud->points[i];
    std::cout << "x: "<< p.x <<"  y: "<< p.y << "  z: " << p.z << "  rgb: "
<< p.rgb << std::endl;
  }
}

void print_hsv_point_cloud(PointCloudHSV::Ptr hsv_cloud)
{
  std::cout  << "hsv_cloud size(): " << hsv_cloud->points.size() <<
std::endl;
  for(int i = 0; i < hsv_cloud->points.size(); i++)
  {
    PointHSV p = hsv_cloud->points[i];
    std::cout << "x: "<< p.x <<"  y: "<< p.y << "  z: " << p.z << "  h: " <<
p.h << "  s: " << p.s << "  v: " << p.v << std::endl;
  }
}

int main (int argc, char** argv)
{
  PointCloudRGB::Ptr rgb_cloud (new PointCloudRGB);
  PointCloudHSV::Ptr hsv_cloud (new PointCloudHSV);

  create_point_cloud(rgb_cloud);
  pcl::PointCloudXYZRGBtoXYZHSV(*rgb_cloud, *hsv_cloud);

  print_rgb_point_cloud(rgb_cloud);
  print_hsv_point_cloud(hsv_cloud);
  return 0;
}
-------------------------------------------------------------------------------
Below is the output is shown in terminal-
-------------------------------------------------------------------------------
rgb_cloud size(): 4
x: 0.352222  y: -0.151883  z: -0.106395  rgb: 2.34181e-38
x: -0.397406  y: -0.473106  z: 0.292602  rgb: 2.34181e-38
x: -0.731898  y: 0.667105  z: 0.441304  rgb: 2.34181e-38
x: -0.734766  y: 0.854581  z: -0.0361733  rgb: 2.34181e-38
hsv_cloud size(): 4
x: 0  y: 0  z: 0  h: 0  s: 1  v: 1
x: 0  y: 0  z: 0  h: 0  s: 1  v: 1
x: 0  y: 0  z: 0  h: 0  s: 1  v: 1
x: 0  y: 0  z: 0  h: 0  s: 1  v: 1
-------------------------------------------------------------------------------

I am using PCL_VERSION 1.7.1 in Ubuntu 14.04 LTS 64 Bit OS.

Thanks




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

Re: Strange behavior of PointCloudXYZRGBtoXYZHSV function

ravijoshi
I installed PCL_VERSION: 1.8.1.99 from GitHub by compiling the source. The
problem is gone. Thanks



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