How to filter based on color using PCL?

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

How to filter based on color using PCL?

Patrick Goebel
Hello PCL users,

I am relatively new to PCL but have been using ROS for quite awhile.  I
have successfully gone through most of the PCL tutorials using a Kinect
and I can nicely segment out certain shapes such as cylinders and spheres.

My question is: can I create a passthrough type filter based on color?  
In particular, I would like to mimic the CamShift filter that is part of
OpenCV.  If there is existing documentation on such methods, please just
point me in that direction.  Otherwise, any hints would be appreciated.

Thanks!
Patrick Goebel

http://www.pirobot.org

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

Re: How to filter based on color using PCL?

Radu B. Rusu
Administrator
Hi Patrick,


The pcl::PassThrough filter can be used for this, but we would have to add a special check for RGB, same as it's done in
the pcl::VoxelGrid filter.

I don't have time today, as I have to prepare some slides for my class, but I can "take a crack" at it tomorrow, if it's
not too late :)

Cheers,
Radu.
--
http://pointclouds.org

On 04/07/2011 11:43 AM, Patrick Goebel wrote:

> Hello PCL users,
>
> I am relatively new to PCL but have been using ROS for quite awhile.  I
> have successfully gone through most of the PCL tutorials using a Kinect
> and I can nicely segment out certain shapes such as cylinders and spheres.
>
> My question is: can I create a passthrough type filter based on color?
> In particular, I would like to mimic the CamShift filter that is part of
> OpenCV.  If there is existing documentation on such methods, please just
> point me in that direction.  Otherwise, any hints would be appreciated.
>
> Thanks!
> Patrick Goebel
>
> http://www.pirobot.org
>
> _______________________________________________
> [hidden email] / http://pointclouds.org
> https://code.ros.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
https://code.ros.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

Patrick Goebel
Thanks Radu.  I'm in absolutely no hurry so just whenever you get a
chance.  In the meantime, I'll look at the source for pcl::VoxelGrid and
see if I can make sense of it.

--patrick

On 04/07/2011 01:54 PM, Radu Bogdan Rusu wrote:

> Hi Patrick,
>
>
> The pcl::PassThrough filter can be used for this, but we would have to
> add a special check for RGB, same as it's done in the pcl::VoxelGrid
> filter.
>
> I don't have time today, as I have to prepare some slides for my
> class, but I can "take a crack" at it tomorrow, if it's not too late :)
>
> Cheers,
> Radu.
> --
> http://pointclouds.org
>
> On 04/07/2011 11:43 AM, Patrick Goebel wrote:
>> Hello PCL users,
>>
>> I am relatively new to PCL but have been using ROS for quite awhile.  I
>> have successfully gone through most of the PCL tutorials using a Kinect
>> and I can nicely segment out certain shapes such as cylinders and
>> spheres.
>>
>> My question is: can I create a passthrough type filter based on color?
>> In particular, I would like to mimic the CamShift filter that is part of
>> OpenCV.  If there is existing documentation on such methods, please just
>> point me in that direction.  Otherwise, any hints would be appreciated.
>>
>> Thanks!
>> Patrick Goebel
>>
>> http://www.pirobot.org
>>
>> _______________________________________________
>> [hidden email] / http://pointclouds.org
>> https://code.ros.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
https://code.ros.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

Michael Ferguson
Patrick, you might also take a look at pcl::PackedRGBComparison, which I believe can be used with the ConditionalRemoval filter, although I think you would need to either adapt it, or use 6 of them to do min/max on all 3 channels.

-Fergs

On Thu, Apr 7, 2011 at 5:01 PM, Patrick Goebel <[hidden email]> wrote:
Thanks Radu.  I'm in absolutely no hurry so just whenever you get a
chance.  In the meantime, I'll look at the source for pcl::VoxelGrid and
see if I can make sense of it.

--patrick

On 04/07/2011 01:54 PM, Radu Bogdan Rusu wrote:
> Hi Patrick,
>
>
> The pcl::PassThrough filter can be used for this, but we would have to
> add a special check for RGB, same as it's done in the pcl::VoxelGrid
> filter.
>
> I don't have time today, as I have to prepare some slides for my
> class, but I can "take a crack" at it tomorrow, if it's not too late :)
>
> Cheers,
> Radu.
> --
> http://pointclouds.org
>
> On 04/07/2011 11:43 AM, Patrick Goebel wrote:
>> Hello PCL users,
>>
>> I am relatively new to PCL but have been using ROS for quite awhile.  I
>> have successfully gone through most of the PCL tutorials using a Kinect
>> and I can nicely segment out certain shapes such as cylinders and
>> spheres.
>>
>> My question is: can I create a passthrough type filter based on color?
>> In particular, I would like to mimic the CamShift filter that is part of
>> OpenCV.  If there is existing documentation on such methods, please just
>> point me in that direction.  Otherwise, any hints would be appreciated.
>>
>> Thanks!
>> Patrick Goebel
>>
>> http://www.pirobot.org
>>
>> _______________________________________________
>> [hidden email] / http://pointclouds.org
>> https://code.ros.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
https://code.ros.org/mailman/listinfo/pcl-users


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

Re: How to filter based on color using PCL?

Patrick Goebel
Thanks Fergs.  That sounds like a promising direction to try.  But you guys are going to force me to learn more C++ than I thought my brain could handle. :-)    

--patrick

On 4/8/2011 2:01 PM, Michael Ferguson wrote:
Patrick, you might also take a look at pcl::PackedRGBComparison, which I
believe can be used with the ConditionalRemoval filter, although I think you
would need to either adapt it, or use 6 of them to do min/max on all 3
channels.

-Fergs

On Thu, Apr 7, 2011 at 5:01 PM, Patrick Goebel [hidden email] wrote:

  
Thanks Radu.  I'm in absolutely no hurry so just whenever you get a
chance.  In the meantime, I'll look at the source for pcl::VoxelGrid and
see if I can make sense of it.

--patrick

On 04/07/2011 01:54 PM, Radu Bogdan Rusu wrote:
    
Hi Patrick,


The pcl::PassThrough filter can be used for this, but we would have to
add a special check for RGB, same as it's done in the pcl::VoxelGrid
filter.

I don't have time today, as I have to prepare some slides for my
class, but I can "take a crack" at it tomorrow, if it's not too late :)

Cheers,
Radu.
--
http://pointclouds.org

On 04/07/2011 11:43 AM, Patrick Goebel wrote:
      
Hello PCL users,

I am relatively new to PCL but have been using ROS for quite awhile.  I
have successfully gone through most of the PCL tutorials using a Kinect
and I can nicely segment out certain shapes such as cylinders and
spheres.

My question is: can I create a passthrough type filter based on color?
In particular, I would like to mimic the CamShift filter that is part of
OpenCV.  If there is existing documentation on such methods, please just
point me in that direction.  Otherwise, any hints would be appreciated.

Thanks!
Patrick Goebel

http://www.pirobot.org

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

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

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

Re: How to filter based on color using PCL?

Radu B. Rusu
Administrator
In reply to this post by Michael Ferguson
Patrick,

I second Michael's suggestion.

I had a second thought about your problem and I think it would be hard for pcl::PassThrough to handle RGB as it's a very
simplistic filter wrote to do data filtering based on a single pair of [min, max] values. Even if we add the special RGB
case (unpacking the fields, etc), the user would still have a hard time specifying min and max... as they would have to
be packed in the same format, etc.


All these things will be simplified in 2.x. For now, the ConditionalRemoval filter wrote by Louis is the best way to do
this kind of filtering.

Cheers,
Radu.
--
http://pointclouds.org

On 04/08/2011 02:01 PM, Michael Ferguson wrote:

> Patrick, you might also take a look at pcl::PackedRGBComparison, which I believe can be used with the ConditionalRemoval
> filter, although I think you would need to either adapt it, or use 6 of them to do min/max on all 3 channels.
>
> -Fergs
>
> On Thu, Apr 7, 2011 at 5:01 PM, Patrick Goebel <[hidden email] <mailto:[hidden email]>> wrote:
>
>     Thanks Radu.  I'm in absolutely no hurry so just whenever you get a
>     chance.  In the meantime, I'll look at the source for pcl::VoxelGrid and
>     see if I can make sense of it.
>
>     --patrick
>
>     On 04/07/2011 01:54 PM, Radu Bogdan Rusu wrote:
>      > Hi Patrick,
>      >
>      >
>      > The pcl::PassThrough filter can be used for this, but we would have to
>      > add a special check for RGB, same as it's done in the pcl::VoxelGrid
>      > filter.
>      >
>      > I don't have time today, as I have to prepare some slides for my
>      > class, but I can "take a crack" at it tomorrow, if it's not too late :)
>      >
>      > Cheers,
>      > Radu.
>      > --
>      > http://pointclouds.org
>      >
>      > On 04/07/2011 11:43 AM, Patrick Goebel wrote:
>      >> Hello PCL users,
>      >>
>      >> I am relatively new to PCL but have been using ROS for quite awhile.  I
>      >> have successfully gone through most of the PCL tutorials using a Kinect
>      >> and I can nicely segment out certain shapes such as cylinders and
>      >> spheres.
>      >>
>      >> My question is: can I create a passthrough type filter based on color?
>      >> In particular, I would like to mimic the CamShift filter that is part of
>      >> OpenCV.  If there is existing documentation on such methods, please just
>      >> point me in that direction.  Otherwise, any hints would be appreciated.
>      >>
>      >> Thanks!
>      >> Patrick Goebel
>      >>
>      >> http://www.pirobot.org
>      >>
>      >> _______________________________________________
>      >> [hidden email] <mailto:[hidden email]> / http://pointclouds.org
>      >> https://code.ros.org/mailman/listinfo/pcl-users
>     _______________________________________________
>     [hidden email] <mailto:[hidden email]> / http://pointclouds.org
>     https://code.ros.org/mailman/listinfo/pcl-users
>
>
>
>
> _______________________________________________
> [hidden email] / http://pointclouds.org
> https://code.ros.org/mailman/listinfo/pcl-users
_______________________________________________
[hidden email] / http://pointclouds.org
https://code.ros.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

Patrick Goebel
Thanks Radu.  I'll look further at the ConditionalRemoval filter then.

--patrick

On 4/14/2011 10:01 PM, Radu Bogdan Rusu wrote:

> Patrick,
>
> I second Michael's suggestion.
>
> I had a second thought about your problem and I think it would be hard for pcl::PassThrough to handle RGB as it's a very
> simplistic filter wrote to do data filtering based on a single pair of [min, max] values. Even if we add the special RGB
> case (unpacking the fields, etc), the user would still have a hard time specifying min and max... as they would have to
> be packed in the same format, etc.
>
>
> All these things will be simplified in 2.x. For now, the ConditionalRemoval filter wrote by Louis is the best way to do
> this kind of filtering.
>
> Cheers,
> Radu.
> --
> http://pointclouds.org
>
> On 04/08/2011 02:01 PM, Michael Ferguson wrote:
>  
>> Patrick, you might also take a look at pcl::PackedRGBComparison, which I believe can be used with the ConditionalRemoval
>> filter, although I think you would need to either adapt it, or use 6 of them to do min/max on all 3 channels.
>>
>> -Fergs
>>
>> On Thu, Apr 7, 2011 at 5:01 PM, Patrick Goebel <[hidden email] <mailto:[hidden email]>> wrote:
>>
>>     Thanks Radu.  I'm in absolutely no hurry so just whenever you get a
>>     chance.  In the meantime, I'll look at the source for pcl::VoxelGrid and
>>     see if I can make sense of it.
>>
>>     --patrick
>>
>>     On 04/07/2011 01:54 PM, Radu Bogdan Rusu wrote:
>>      > Hi Patrick,
>>      >
>>      >
>>      > The pcl::PassThrough filter can be used for this, but we would have to
>>      > add a special check for RGB, same as it's done in the pcl::VoxelGrid
>>      > filter.
>>      >
>>      > I don't have time today, as I have to prepare some slides for my
>>      > class, but I can "take a crack" at it tomorrow, if it's not too late :)
>>      >
>>      > Cheers,
>>      > Radu.
>>      > --
>>      > http://pointclouds.org
>>      >
>>      > On 04/07/2011 11:43 AM, Patrick Goebel wrote:
>>      >> Hello PCL users,
>>      >>
>>      >> I am relatively new to PCL but have been using ROS for quite awhile.  I
>>      >> have successfully gone through most of the PCL tutorials using a Kinect
>>      >> and I can nicely segment out certain shapes such as cylinders and
>>      >> spheres.
>>      >>
>>      >> My question is: can I create a passthrough type filter based on color?
>>      >> In particular, I would like to mimic the CamShift filter that is part of
>>      >> OpenCV.  If there is existing documentation on such methods, please just
>>      >> point me in that direction.  Otherwise, any hints would be appreciated.
>>      >>
>>      >> Thanks!
>>      >> Patrick Goebel
>>      >>
>>      >> http://www.pirobot.org
>>      >>
>>      >> _______________________________________________
>>      >> [hidden email] <mailto:[hidden email]> / http://pointclouds.org
>>      >> https://code.ros.org/mailman/listinfo/pcl-users
>>     _______________________________________________
>>     [hidden email] <mailto:[hidden email]> / http://pointclouds.org
>>     https://code.ros.org/mailman/listinfo/pcl-users
>>
>>
>>
>>
>> _______________________________________________
>> [hidden email] / http://pointclouds.org
>> https://code.ros.org/mailman/listinfo/pcl-users
>>    
> _______________________________________________
> [hidden email] / http://pointclouds.org
> https://code.ros.org/mailman/listinfo/pcl-users
>  
_______________________________________________
[hidden email] / http://pointclouds.org
https://code.ros.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

Shashank Sonkar
This post has NOT been accepted by the mailing list yet.
I am not able to use Conditional Removal technique for RGB. Can you help me? if i use "r" in place of "z", it gives "pcl::FieldComparison::FieldComparison] field not found!"
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

beaverfan
I was able to get my filter by color working by piecing together some examples and wanted to share for someone in the future. It is probably not ideal, but it worked for me to test.  

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/conditional_removal.h>
#include <pcl/io/pcd_io.h>
#include <pcl/console/parse.h>

using namespace std;
using namespace pcl;

int
 main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);
  if (pcl::io::loadPCDFile (argv[1], *cloud) < 0)
  {
    std::cout << "Error loading cloud." << std::endl;
    return (-1);
  }

  // build the condition
  int rMax = 255;
  int rMin = 150;
  int gMax = 100;
  int gMin = 0;
  int bMax = 100;
  int bMin = 0;
  pcl::ConditionAnd<pcl::PointXYZRGB>::Ptr color_cond (new pcl::ConditionAnd<pcl::PointXYZRGB> ());
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("r", pcl::ComparisonOps::LT, rMax)));
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("r", pcl::ComparisonOps::GT, rMin)));
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("g", pcl::ComparisonOps::LT, gMax)));
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("g", pcl::ComparisonOps::GT, gMin)));
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("b", pcl::ComparisonOps::LT, bMax)));
  color_cond->addComparison (pcl::PackedRGBComparison<pcl::PointXYZRGB>::Ptr (new pcl::PackedRGBComparison<pcl::PointXYZRGB> ("b", pcl::ComparisonOps::GT, bMin)));

  // build the filter
  pcl::ConditionalRemoval<pcl::PointXYZRGB> condrem (color_cond);
  condrem.setInputCloud (cloud);
  condrem.setKeepOrganized(true);

  // apply filter
  condrem.filter (*cloud_filtered);
 
  // save cloud after filtering
  if (pcl::io::savePCDFile("filteredCloud.pcd", *cloud_filtered, true) == 0)
  {
     cout << "Saved filteredCloud.pcd " << endl;
  }
  else PCL_ERROR("Problem saving");

  return (0);
}
Reply | Threaded
Open this post in threaded view
|

Re: How to filter based on color using PCL?

cammarasana123
I was able to get things working with a small change on "build the filter"
section:

  // build the filter
  pcl::ConditionalRemoval<pcl::PointXYZRGB> condrem;
  condrem.setCondition (color_cond);
  condrem.setInputCloud (cloud);
  condrem.setKeepOrganized(true);





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