Skip to content

Commit 5874cfd

Browse files
committed
fix test and float conversions
1 parent 1f37ca3 commit 5874cfd

File tree

11 files changed

+199
-217
lines changed

11 files changed

+199
-217
lines changed

modules/ptcloud/doc/ptcloud.bib

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ @inproceedings{NI03
1515
year={2003}
1616
}
1717

18-
@article{RA13
18+
@article{USAC13
1919
title={USAC: A Universal Framework for Random Sample Consensus},
20-
author={Raguram, Rahul and Chum,Ondrej and Pollefeys, Marc and Matas,Jiri and Frahm, Jan-Michael},
20+
author={Raguram,Rahul and Chum,Ondrej and Pollefeys,Marc and Matas,Jiri and Frahm,Jan-Michael},
2121
journal={IEEE Transactions on Software Engineering},
2222
year={2013},
2323
organization={IEEE}
24+
}
25+
26+
@article{SPRT05
27+
title={Randomized RANSAC with Sequential Probability Ratio Test},
28+
author={Matas,Jirı and Chum,Ondrej},
29+
booktitle={International Conference on Computer Vision (ICCV)},
30+
year={2005},
31+
volume={2},
32+
pages={1727–1732}
2433
}

modules/ptcloud/include/opencv2/ptcloud/sac_segmentation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CV_EXPORTS_W SACModelFitting {
9494
*/
9595
CV_WRAP virtual void set_method_type(int method_type) = 0;
9696

97-
/** @brief Use Wald's Sequential Probabilistic Ratio Test with ransac fitting
97+
/** @brief Use Wald's Sequential Probability Ratio Test with ransac fitting
9898
9999
This will result in less iterations and less evaluated data points, and thus be
100100
much faster, but it might miss some inliers

modules/ptcloud/misc/python/test/test_sac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class sac_test(NewOpenCVTests):
1616

17-
def test_plane():
17+
def test_plane(self):
1818
N = 64;
1919
plane = np.zeros((N,N,3),np.float32)
2020
for i in range(0,N):

modules/ptcloud/perf/perf_main.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
1-
/*M///////////////////////////////////////////////////////////////////////////////////////
2-
//
3-
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4-
//
5-
// By downloading, copying, installing or using the software you agree to this license.
6-
// If you do not agree to this license, do not download, install,
7-
// copy or use the software.
8-
//
9-
//
10-
// License Agreement
11-
// For Open Source Computer Vision Library
12-
//
13-
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14-
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15-
// Third party copyrights are property of their respective owners.
16-
//
17-
// Redistribution and use in source and binary forms, with or without modification,
18-
// are permitted provided that the following conditions are met:
19-
//
20-
// * Redistribution's of source code must retain the above copyright notice,
21-
// this list of conditions and the following disclaimer.
22-
//
23-
// * Redistribution's in binary form must reproduce the above copyright notice,
24-
// this list of conditions and the following disclaimer in the documentation
25-
// and/or other materials provided with the distribution.
26-
//
27-
// * The name of the copyright holders may not be used to endorse or promote products
28-
// derived from this software without specific prior written permission.
29-
//
30-
// This software is provided by the copyright holders and contributors as is and
31-
// any express or implied warranties, including, but not limited to, the implied
32-
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33-
// In no event shall the Intel Corporation or contributors be liable for any direct,
34-
// indirect, incidental, special, exemplary, or consequential damages
35-
// (including, but not limited to, procurement of substitute goods or services;
36-
// loss of use, data, or profits; or business interruption) however caused
37-
// and on any theory of liability, whether in contract, strict liability,
38-
// or tort (including negligence or otherwise) arising in any way out of
39-
// the use of this software, even if advised of the possibility of such damage.
40-
//
41-
//M*/
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
424

435
#include "perf_precomp.hpp"
446

modules/ptcloud/samples/sac_demo.cpp

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ using namespace cv::ptcloud;
99

1010

1111
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")) {
2929
parser.printMessage();
3030
return 0;
31-
}
31+
}
3232
int typ = parser.get<int>("model_type");
3333
int iters = parser.get<int>("iters");
3434
int elems = parser.get<int>("cloud");
@@ -43,75 +43,75 @@ int main(int argc,char **argv) {
4343
bool sprt = parser.get<bool>("use_sprt");
4444
string ply = parser.get<string>("ply");
4545

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");
7575

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);
8484

85-
Mat new_cloud;
86-
fitting->segment(models, new_cloud);
85+
Mat new_cloud;
86+
fitting->segment(models, new_cloud);
8787

88-
return new_cloud;
89-
};
88+
return new_cloud;
89+
};
9090

9191
std::vector<SACModel> models;
92-
if (typ==4) { // cluster only
92+
if (typ==4) { // cluster only
9393
cv::ptcloud::cluster(pts, min_distance, min_inliers, models, pts);
94-
} else
94+
} else
9595
if (typ==0) { // end to end
9696
pts = segment(pts, models, 1, thresh, iters, min_inliers, method);
9797
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);
103103
} 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);
105105

106106
string names[] = {"", "plane","sphere","cylinder","blob"};
107107
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+
}
113113

114114
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;
117117
}

modules/ptcloud/samples/viz/sample_cylinder_fitting.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
#include "opencv2/opencv_modules.hpp"
12
#ifdef HAVE_OPENCV_VIZ
2-
33
#include <opencv2/viz.hpp>
44
#include <opencv2/highgui.hpp>
55
#include <opencv2/viz/widgets.hpp>
@@ -16,7 +16,6 @@ using namespace cv;
1616
using namespace std;
1717

1818
int main() {
19-
// Mat cloud = cv::ppf_match_3d::loadPLYSimple("./data/semi-cylinder-with-normals-usingOpenCV2.ply", true);
2019
Mat cloud = cv::ppf_match_3d::loadPLYSimple("./data/cylinder-big.ply", false);
2120

2221
Mat ptset;

modules/ptcloud/samples/viz/sample_plane_fitting.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "opencv2/opencv_modules.hpp"
12
#ifdef HAVE_OPENCV_VIZ
23
#include <opencv2/viz.hpp>
34
#include <opencv2/highgui.hpp>

modules/ptcloud/samples/viz/sample_sphere_fitting.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "opencv2/opencv_modules.hpp"
12
#ifdef HAVE_OPENCV_VIZ
23
#include <opencv2/viz.hpp>
34
#include <opencv2/highgui.hpp>

0 commit comments

Comments
 (0)