@@ -9,26 +9,26 @@ using namespace cv::ptcloud;
9
9
10
10
11
11
int main (int argc,char **argv) {
12
- CommandLineParser parser (argc,argv,
13
- " {help h | | print this help}"
14
- " {model_type m | 1 | 1:plane 2:sphere 3:cylinder 4:cluster 0:all}"
15
- " {use_sprt u | false | use sprt evaluation/termination with non-preemptive ransac}"
16
- " {ply P | | load a .ply file}"
17
- " {threshold t | 0.0015 | rejection threshold .001 for planes, 0.1 for spheres, 2.5 for cylinders}"
18
- " {iters i | 10000 | ransac iterations}"
19
- " {cloud c | 15 | or'ed synthetic model types to generate 0:none 1:planes 2:sphere 4:cylinder 8:random 16:noise distortion 32:from ply}"
20
- " {min_inliers M | 60 | rejection inlier count}"
21
- " {min_distance d | 6 | distance for clustering (partition)}"
22
- " {sac_method s | 0 | SacMethodType (0:RANSAC or 1:MSAC)}"
23
- " {preemptive p | 0 | number of hypotheses for preemptive evaluation. set to 0 to disable}"
24
- " {napsac n | 0 | radius for napsac sampling. set to 0 to disable}"
25
- " {max_sphere S | 50 | (sphere only) reject larger spheres}"
26
- " {normal_weight w | 0.5 | (cylinder only) interpolate between point and normal(dot) distance. setting it to 0 will not use (or generate) normals}"
27
- " " );
28
- if (parser.has (" help" )) {
12
+ CommandLineParser parser (argc,argv,
13
+ " {help h | | print this help}"
14
+ " {model_type m | 1 | 1:plane 2:sphere 3:cylinder 4:cluster 0:all}"
15
+ " {use_sprt u | false | use sprt evaluation/termination with non-preemptive ransac}"
16
+ " {ply P | | load a .ply file}"
17
+ " {threshold t | 0.0015 | rejection threshold .001 for planes, 0.1 for spheres, 2.5 for cylinders}"
18
+ " {iters i | 10000 | ransac iterations}"
19
+ " {cloud c | 15 | or'ed synthetic model types to generate 0:none 1:planes 2:sphere 4:cylinder 8:random 16:noise distortion 32:from ply}"
20
+ " {min_inliers M | 60 | rejection inlier count}"
21
+ " {min_distance d | 6 | distance for clustering (partition)}"
22
+ " {sac_method s | 0 | SacMethodType (0:RANSAC or 1:MSAC)}"
23
+ " {preemptive p | 0 | number of hypotheses for preemptive evaluation. set to 0 to disable}"
24
+ " {napsac n | 0 | radius for napsac sampling. set to 0 to disable}"
25
+ " {max_sphere S | 50 | (sphere only) reject larger spheres}"
26
+ " {normal_weight w | 0.5 | (cylinder only) interpolate between point and normal(dot) distance. setting it to 0 will not use (or generate) normals}"
27
+ " " );
28
+ if (parser.has (" help" )) {
29
29
parser.printMessage ();
30
30
return 0 ;
31
- }
31
+ }
32
32
int typ = parser.get <int >(" model_type" );
33
33
int iters = parser.get <int >(" iters" );
34
34
int elems = parser.get <int >(" cloud" );
@@ -43,75 +43,75 @@ int main(int argc,char **argv) {
43
43
bool sprt = parser.get <bool >(" use_sprt" );
44
44
string ply = parser.get <string>(" ply" );
45
45
46
- Mat_<Point3f> pts;
47
- if (! ply.empty ()) {
48
- pts = cv::ppf_match_3d::loadPLYSimple (ply.c_str (), false );
49
- }
50
- if (elems & 1 ) {
51
- generatePlane (pts, vector<double >{0.1 ,.1 ,.8 , .76 }, 64 );
52
- generatePlane (pts, vector<double >{-.2 ,-.7 ,.3 , .16 }, 64 );
53
- }
54
- if (elems & 2 ) {
55
- generateSphere (pts, vector<double >{12 ,15 ,-12 , 5 }, 128 );
56
- generateSphere (pts, vector<double >{-12 ,15 ,-12 , 5 }, 128 );
57
- }
58
- if (elems & 4 ) {
59
- generateCylinder (pts, vector<double >{-12 ,-15 ,-12 , 0 ,0 ,1 , 5 }, 256 );
60
- generateCylinder (pts, vector<double >{20 ,5 ,12 , 0 ,1 ,0 , 5 }, 256 );
61
- }
62
- if (elems & 8 ) {
63
- generateRandom (pts, vector<double >{-12 ,31 ,-5 , 5 }, 32 );
64
- generateRandom (pts, vector<double >{12 ,-21 ,15 , 5 }, 32 );
65
- generateRandom (pts, vector<double >{1 ,-2 ,1 , 25 }, 64 );
66
- }
67
- if (elems & 16 ) {
68
- Mat fuzz (pts.size (), pts.type ());
69
- float F = 0.001 ;
70
- randu (fuzz,Scalar (-F,-F,-F), Scalar (F,F,F));
71
- pts += fuzz;
72
- }
73
- cout << pts.size () << " points." << endl;
74
- cv::ppf_match_3d::writePLY (pts, " cloud.ply" );
46
+ Mat_<Point3f> pts;
47
+ if (! ply.empty ()) {
48
+ pts = cv::ppf_match_3d::loadPLYSimple (ply.c_str (), false );
49
+ }
50
+ if (elems & 1 ) {
51
+ generatePlane (pts, vector<double >{0.1 ,.1 ,.8 , .76 }, 64 );
52
+ generatePlane (pts, vector<double >{-.2 ,-.7 ,.3 , .16 }, 64 );
53
+ }
54
+ if (elems & 2 ) {
55
+ generateSphere (pts, vector<double >{12 ,15 ,-12 , 5 }, 128 );
56
+ generateSphere (pts, vector<double >{-12 ,15 ,-12 , 5 }, 128 );
57
+ }
58
+ if (elems & 4 ) {
59
+ generateCylinder (pts, vector<double >{-12 ,-15 ,-12 , 0 ,0 ,1 , 5 }, 256 );
60
+ generateCylinder (pts, vector<double >{20 ,5 ,12 , 0 ,1 ,0 , 5 }, 256 );
61
+ }
62
+ if (elems & 8 ) {
63
+ generateRandom (pts, vector<double >{-12 ,31 ,-5 , 5 }, 32 );
64
+ generateRandom (pts, vector<double >{12 ,-21 ,15 , 5 }, 32 );
65
+ generateRandom (pts, vector<double >{1 ,-2 ,1 , 25 }, 64 );
66
+ }
67
+ if (elems & 16 ) {
68
+ Mat fuzz (pts.size (), pts.type ());
69
+ float F = 0 .001f ;
70
+ randu (fuzz,Scalar (-F,-F,-F), Scalar (F,F,F));
71
+ pts += fuzz;
72
+ }
73
+ cout << pts.size () << " points." << endl;
74
+ cv::ppf_match_3d::writePLY (pts, " cloud.ply" );
75
75
76
- auto segment = [napsac,normal_weight,max_sphere,preemptive,sprt](const Mat &cloud, std::vector<SACModel> &models, int model_type, float threshold, int max_iters, int min_inlier, int method_type) -> Mat {
77
- Ptr<SACModelFitting> fitting = SACModelFitting::create (cloud, model_type, method_type, threshold, max_iters);
78
- fitting->set_normal_distance_weight (normal_weight);
79
- fitting->set_max_napsac_radius (napsac);
80
- fitting->set_max_sphere_radius (max_sphere);
81
- fitting->set_preemptive_count (preemptive);
82
- fitting->set_min_inliers (min_inlier);
83
- fitting->set_use_sprt (sprt);
76
+ auto segment = [napsac,normal_weight,max_sphere,preemptive,sprt](const Mat &cloud, std::vector<SACModel> &models, int model_type, float threshold, int max_iters, int min_inlier, int method_type) -> Mat {
77
+ Ptr<SACModelFitting> fitting = SACModelFitting::create (cloud, model_type, method_type, threshold, max_iters);
78
+ fitting->set_normal_distance_weight (normal_weight);
79
+ fitting->set_max_napsac_radius (napsac);
80
+ fitting->set_max_sphere_radius (max_sphere);
81
+ fitting->set_preemptive_count (preemptive);
82
+ fitting->set_min_inliers (min_inlier);
83
+ fitting->set_use_sprt (sprt);
84
84
85
- Mat new_cloud;
86
- fitting->segment (models, new_cloud);
85
+ Mat new_cloud;
86
+ fitting->segment (models, new_cloud);
87
87
88
- return new_cloud;
89
- };
88
+ return new_cloud;
89
+ };
90
90
91
91
std::vector<SACModel> models;
92
- if (typ==4 ) { // cluster only
92
+ if (typ==4 ) { // cluster only
93
93
cv::ptcloud::cluster (pts, min_distance, min_inliers, models, pts);
94
- } else
94
+ } else
95
95
if (typ==0 ) { // end to end
96
96
pts = segment (pts, models, 1 , thresh, iters, min_inliers, method);
97
97
cout << pts.total () << " points left." << endl;
98
- pts = segment (pts, models, 2 , 0.145 , iters, min_inliers, method);
99
- cout << pts.total () << " points left." << endl;
100
- pts = segment (pts, models, 3 , 5.0 , iters, min_inliers, method);
101
- cout << pts.total () << " points left." << endl;
102
- cv::ptcloud::cluster (pts, 7 , 20 , models, pts);
98
+ pts = segment (pts, models, 2 , 0 .145f , iters, min_inliers, method);
99
+ cout << pts.total () << " points left." << endl;
100
+ pts = segment (pts, models, 3 , 5 .0f , iters, min_inliers, method);
101
+ cout << pts.total () << " points left." << endl;
102
+ cv::ptcloud::cluster (pts, 7 , 20 , models, pts);
103
103
} else // single model type
104
- pts = segment (pts, models, typ, thresh, iters, min_inliers, method);
104
+ pts = segment (pts, models, typ, thresh, iters, min_inliers, method);
105
105
106
106
string names[] = {" " , " plane" ," sphere" ," cylinder" ," blob" };
107
107
for (size_t i=0 ; i<models.size (); i++) {
108
- SACModel &model = models.at (i);
109
- cout << model.type << " " << model.points .size () << " " << model.score .second << " \t " ;
110
- cout << Mat (model.coefficients ).t () << endl;
111
- cv::ppf_match_3d::writePLY (Mat (model.points ), format (" cloud_%s_%d.ply" ,names[model.type ].c_str (), i+1 ).c_str ());
112
- }
108
+ SACModel &model = models.at (i);
109
+ cout << model.type << " " << model.points .size () << " " << model.score .second << " \t " ;
110
+ cout << Mat (model.coefficients ).t () << endl;
111
+ cv::ppf_match_3d::writePLY (Mat (model.points ), format (" cloud_%s_%d.ply" ,names[model.type ].c_str (), int ( i+1 ) ).c_str ());
112
+ }
113
113
114
114
cout << pts.total () << " points left." << endl;
115
- cv::ppf_match_3d::writePLY (pts, " cloud_left.ply" );
116
- return 0 ;
115
+ cv::ppf_match_3d::writePLY (pts, " cloud_left.ply" );
116
+ return 0 ;
117
117
}
0 commit comments