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,
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);
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Type * bitmap
points toward the bitmap
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
std::vector< vpImagePoint > m_points
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
std::vector< vpContour * > m_children
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT void findContours(const vpImage< unsigned char > &I_original, vpContour &contours, std::vector< std::vector< vpImagePoint > > &contourPts, const vpContourRetrievalType &retrievalMode=vp::CONTOUR_RETR_TREE)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
vpContourType m_contourType
VISP_EXPORT void drawContours(vpImage< unsigned char > &I, const std::vector< std::vector< vpImagePoint > > &contours, unsigned char grayValue=255)
VISP_EXPORT unsigned char autoThreshold(vpImage< unsigned char > &I, const vp::vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
unsigned int getHeight() const
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getWidth() const