5 #include <visp3/core/vpImage.h>
6 #include <visp3/gui/vpDisplayGDI.h>
7 #include <visp3/gui/vpDisplayOpenCV.h>
8 #include <visp3/gui/vpDisplayX.h>
9 #include <visp3/io/vpImageIo.h>
11 #if defined(VISP_HAVE_MODULE_IMGPROC) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
12 #include <visp3/imgproc/vpImgproc.h>
19 void displayContourInfo(
const vp::vpContour &contour,
const int level)
21 std::cout <<
"\nContour:" << std::endl;
22 std::cout <<
"\tlevel: " << level << std::endl;
25 std::cout <<
"\tcontour size: " << contour.
m_points.size() << std::endl;
26 std::cout <<
"\tnb children: " << contour.
m_children.size() << std::endl;
28 for (std::vector<vp::vpContour *>::const_iterator it = contour.
m_children.begin(); it != contour.
m_children.end();
30 displayContourInfo(**it, level + 1);
38 std::vector<std::vector<vpImagePoint> > contours;
39 contours.push_back(contour.
m_points);
42 for (std::vector<vp::vpContour *>::const_iterator it = contour.
m_children.begin(); it != contour.
m_children.end();
44 drawContoursTree(I, **it);
51 int main(
int argc,
const char **argv)
54 #if defined(VISP_HAVE_MODULE_IMGPROC) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
55 std::string input_filename =
"grid36-03.pgm";
58 bool white_foreground =
false;
61 for (
int i = 1; i < argc; i++) {
62 if (std::string(argv[i]) ==
"--input" && i + 1 < argc) {
63 input_filename = std::string(argv[i + 1]);
64 }
else if (std::string(argv[i]) ==
"--white_foreground") {
65 white_foreground =
true;
66 }
else if (std::string(argv[i]) ==
"--method" && i + 1 < argc) {
68 }
else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
69 std::cout <<
"Usage: " << argv[0]
70 <<
" [--input <input image>] [--method <0: "
71 "CONTOUR_RETR_TREE, 1: CONTOUR_RETR_LIST, 2: "
72 "CONTOUR_RETR_EXTERNAL>]"
73 " [--white_foreground] [--help]"
89 #elif defined(VISP_HAVE_GDI)
91 #elif defined(VISP_HAVE_OPENCV)
94 d.
init(I_bin, 0, 0,
"After binarisation");
95 d2.
init(I_draw_contours, I_bin.getWidth(), 10,
"Contours");
100 for (
unsigned int i = 0; i < I_bin.getSize(); i++) {
101 I_bin.bitmap[i] = 255 * I.
bitmap[i];
106 std::vector<std::vector<vpImagePoint> > contours;
123 drawContoursTree(I_draw_contours, vp_contours);
125 displayContourInfo(vp_contours, 0);