Subject: CGAL users discussion list
List archive
[cgal-discuss] RANSAC shape detection, no primitive detected after multiple runs.
Chronological Thread
- From: AndrewLiu <>
- To:
- Subject: [cgal-discuss] RANSAC shape detection, no primitive detected after multiple runs.
- Date: Sun, 19 Feb 2017 05:25:34 -0800 (PST)
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=None ; spf=None
- Ironport-phdr: 9a23:MXnkYxatkdbrfSrIJAVkOJ7/LSx+4OfEezUN459isYplN5qZr828bnLW6fgltlLVR4KTs6sC0LuL9fm4EjFaqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjSwbLdyIRmssAndqsYajIt8Jq0s1hbHv3xEdvhMy2h1P1yThRH85smx/J5n7Stdvu8q+tBDX6vnYak2VKRUAzs6PW874s3rrgTDQhCU5nQASGUWkwFHDBbD4RrnQ5r+qCr6tu562CmHIc37SK0/VDq+46t3ThLjlSAIOiI3/WzWjsF8lb9XrA68rBB7zYPYfJ2ZOP94c6jAf90VWHBBU95fWSJBHI2ybJYBAOUdMuhXtIT9u1kDoAGiCQWwGO/j1DlFjWL2060g1OQhFBnL0RAmH90TqnTbstv0OqETUeCo0aLFyjHDb/JQ2Tfy6ojIcw4ureuNXLJwbMrc0k8vFwfdjlWKs4DlPima2v4XvGeH9eZvSeSvhnchpgpsrDavwcIshZPIhoIT0l3E8z92z50uKt28VkF3e8KrEJxVtyycKoB4QdsiTnl1tCs71LEKo4C3cSgExZg92hLSZfKKf5KH7x/tTOqdPDZ1iGx/dL6hhxu//1KsxvDyW8S6ylpHrihIn9/RvX4XzRPT8NKISv5l80ehxzmP0wfT5/lBIUE6kqrbMZ0hzqQ2lpUJqkvMBSv2l1vsgKCKcUUk//Ck6+XhYrr4up+RL5J4hwDgPqg0hMCyAeo1PhITU2WV9+mwzrLu8EPhTLVPlPI2k63ZsJ7AJcQco660GwtV0ocl6xawDTem0coXkWMGLVJFZRKKlI7pO1XWIPDiF/u/gk6jnC1xyP/aJLHuHpPNImDZkLj9ZbZ991JcyA0rwN9D6JJbELUBLOvuVU/wr9zXEgI5Mxevw+v8E9V81oYeWXqVDaODMaPSt0WI5uM1LOWWao8VomW1F/9w7PHniTo1mEQWYLKy9ZoRcnGxWPp8cGuDZn+5q9ENC2oVmgsjBLjuiVuNUz9eIWSyQoo64ikhToOvS47IAIur1u/SlBynF4FbMzkVQmuHFm3lIt7cA/o=
Hello,
When I tried to use the "Point Set Shape Detection" package and ran the
example code multiple times, the program seemed normal at first but would
output zero primitive eventually.
It seems that the "clear" operation called by the "set_input" function
doesn't clear everything. Is there anything that I am missing?
Thanks,
Andrew Liu
Here is the code:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/Timer.h>
#include <CGAL/number_utils.h>
#include <CGAL/Shape_detection_3.h>
#include <iostream>
#include <fstream>
// Type declarations
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef std::pair<Kernel::Point_3, Kernel::Vector_3>
Point_with_normal;
typedef std::vector<Point_with_normal> Pwn_vector;
typedef CGAL::First_of_pair_property_map<Point_with_normal> Point_map;
typedef CGAL::Second_of_pair_property_map<Point_with_normal> Normal_map;
// In Efficient_RANSAC_traits the basic types, i.e., Point and Vector types
// as well as iterator type and property maps, are defined.
typedef CGAL::Shape_detection_3::Efficient_RANSAC_traits<Kernel,
Pwn_vector, Point_map, Normal_map> Traits;
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits>
Efficient_ransac;
typedef CGAL::Shape_detection_3::Plane<Traits> Plane;
int main()
{
// Points with normals.
Pwn_vector points;
// Loads point set from a file.
// read_xyz_points_and_normals takes an OutputIterator for storing the
points
// and a property map to store the normal vector with each point.
std::ifstream stream("data/cube.pwn");
if (!stream ||
!CGAL::read_xyz_points_and_normals(stream,
std::back_inserter(points),
Point_map(),
Normal_map()))
{
std::cerr << "Error: cannot read file cube.pwn" << std::endl;
return EXIT_FAILURE;
}
// Instantiates shape detection engine.
Efficient_ransac ransac;
const Pwn_vector pts_origin = points;
for (std::size_t i = 0; i < 30; ++i) {
points = pts_origin;
// Provides the input data.
ransac.set_input(points);
// Registers detection of planes
ransac.add_shape_factory<Plane>();
// Measures time before setting up the shape detection.
CGAL::Timer time;
time.start();
// Build internal data structures.
ransac.preprocess();
// Measures time after preprocessing.
time.stop();
std::cout << "preprocessing took: " << time.time() * 1000 << "ms" <<
std::endl;
// Perform detection several times and choose result with highest
coverage.
Efficient_ransac::Shape_range shapes = ransac.shapes();
FT best_coverage = 0;
for (size_t i = 0; i < 6; i++) {
// Reset timer.
time.reset();
time.start();
// Detects shapes.
ransac.detect();
// Measures time after detection.
time.stop();
// Compute coverage, i.e. ratio of the points assigned to a
shape.
FT coverage = FT(points.size() -
ransac.number_of_unassigned_points())
/ FT(points.size());
// Prints number of assigned shapes and unsassigned points.
std::cout << "time: " << time.time() * 1000 << "ms" <<
std::endl;
std::cout << ransac.shapes().end() - ransac.shapes().begin() <<
" primitives, "
<< coverage << " coverage" << std::endl;
// Choose result with highest coverage.
if (coverage > best_coverage) {
best_coverage = coverage;
// Efficient_ransac::shapes() provides
// an iterator range to the detected shapes.
shapes = ransac.shapes();
}
}
}
return EXIT_SUCCESS;
}
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/RANSAC-shape-detection-no-primitive-detected-after-multiple-runs-tp4662529.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] RANSAC shape detection, no primitive detected after multiple runs., AndrewLiu, 02/19/2017
Archive powered by MHonArc 2.6.18.