Region-Growing-RGB-PCL-Cpp (50%)
There are two main differences in the color-based algorithm.
The first one is that it uses color instead of normals.
The second is that it uses the merging algorithm for over- and under- segmentation control.
Letโs take a look at how it is done.
After the segmentation, an attempt for merging clusters with close colors is made.
Two neighbouring clusters with a small difference between average color are merged together.
Then the second merging step takes place.
During this step every single cluster is verified by the number of points that it contains.
If this number is less than the user-defined value than current cluster is merged with the closest neighbouring cluster.
#include <iostream>
#include <thread>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/region_growing_rgb.h>
// Color-based region growing segmentation
// http://pointclouds.org/documentation/tutorials/region_growing_rgb_segmentation.php#region-growing-rgb-segmentation
int
main (int argc, char** argv)
{
// *.PCD ํ์ผ ์ฝ๊ธฐ
// https://github.com/adioshun/gitBook_Tutorial_PCL/blob/master/Intermediate/sample/region_growing_rgb_passthrough.pcd
pcl::PointCloud <pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud <pcl::PointXYZRGB>);
pcl::io::loadPCDFile <pcl::PointXYZRGB> ("region_growing_rgb_passthrough.pcd", *cloud);
// ์๊ณ ๋ฆฌ์ฆ์์ ์ฌ์ฉํ๋ Surface Normal ๊ณ์ฐ : Normal ์ ๋ณด ๋์ ์์ ์ ๋ณด๋ฅผ ์ฌ์ฉํ๋ฏ๋ก Normal ๊ณ์ฐ ์์
์ด ๋ถํ์ ํจ
//์คํ์ ํธ ์์ฑ
pcl::search::Search <pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB>);
pcl::RegionGrowingRGB<pcl::PointXYZRGB> reg;
reg.setInputCloud (cloud); // ์
๋ ฅ
reg.setSearchMethod (tree); // ํ์ ๋ฐฉ๋ฒ
reg.setDistanceThreshold (10); // ์ด์(Neighbor)์ผ๋ก ์ง์ ๋๋ ๊ฑฐ๋ฆฌ ์ ๋ณด
reg.setPointColorThreshold (6); // ๋์ผ Cluter์ฌ๋ถ๋ฅผ ํ
์คํธ ํ๊ธฐ ์ํด ์ฌ์ฉ (cf. Just as angle threshold is used for testing points normals )
reg.setRegionColorThreshold (5); // ๋์ผ Cluter์ฌ๋ถ๋ฅผ ํ
์คํธ ํ๊ธฐ ์ํด ์ฌ์ฉ, ํตํฉ(merging)๋จ๊ณ์์ ์ฌ์ฉ๋จ
reg.setMinClusterSize (600); // ์ต์ ํฌ์ธํธ์, ์ง์ ๊ฐ๋ณด๋ค ์์ผ๋ฉด ์ด์ ํฌ์ธํธ์ ํตํฉ ๋จ
std::vector <pcl::PointIndices> clusters;
reg.extract (clusters);
//ํ์ผ ์ ์ฅ
pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud ();
pcl::io::savePCDFile<pcl::PointXYZRGB>("region_growing_rgb_result.pcd", *colored_cloud);
return (0);
}
์๋ณธ ์ฝ๋์ ์คํ๊ฐ ์์ต๋๋ค.
pass.setFilterLimits (0.0, 1.0);
->pass.setFilterLimits (0.0, 5.0);
Last updated
Was this helpful?