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) 12 #include <visp3/core/vpMomentObject.h> 14 #include <visp3/imgproc/vpImgproc.h> 18 int main(
int argc,
char *argv[])
21 #if defined(VISP_HAVE_MODULE_IMGPROC) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV)) 24 std::string input_filename =
"coins1.pgm";
26 bool white_foreground =
false;
28 for (
int i = 1; i < argc; i++) {
29 if (std::string(argv[i]) ==
"--input" && i + 1 < argc) {
30 input_filename = std::string(argv[i + 1]);
31 }
else if (std::string(argv[i]) ==
"--method" && i + 1 < argc) {
33 }
else if (std::string(argv[i]) ==
"--white_foreground") {
34 white_foreground =
true;
35 }
else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"-h") {
36 std::cout <<
"Usage: " << argv[0]
37 <<
" [--input <input image>]" 38 " [--method <0: Huang, 1: Intermodes, 2: IsoData, 3: " 39 "Mean, 4: Otsu, 5: Triangle>]" 40 " [--white_foreground]" 54 #elif defined(VISP_HAVE_GDI) 56 #elif defined(VISP_HAVE_OPENCV) 59 d.
init(I, 0, 0,
"Coins");
64 vp::autoThreshold(I_bin, method, white_foreground ? 0 : 255, white_foreground ? 255 : 0);
89 for (
unsigned int cpt = 0; cpt < I_close.
getSize(); cpt++)
93 std::vector<std::vector<vpImagePoint> > contours;
101 d5.
init(I_draw_contours, 0, 2 * I.
getHeight() + 80,
"Contours");
111 for (
size_t i = 0; i < contours.size(); i++) {
112 std::vector<vpPoint> vec_p;
114 for (
size_t j = 0; j < contours[i].size(); j++) {
116 pt.
set_x(contours[i][j].get_u());
117 pt.
set_y(contours[i][j].get_v());
123 obj.fromVector(vec_p);
127 if (std::fabs(obj.get(0, 0)) >= I.
getSize() / 200) {
129 std::stringstream ss;
130 ss <<
"Coin " << nb_coins;
132 int centroid_x = (int)std::fabs(obj.get(1, 0) / obj.get(0, 0));
133 int centroid_y = (int)std::fabs(obj.get(0, 1) / obj.get(0, 0));
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void dilatation(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
unsigned int getWidth() const
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)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void set_x(const double x)
Set the point x coordinate in the image plane.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class for generic objects.
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)
VISP_EXPORT void fillHoles(vpImage< unsigned char > &I)
Class that defines what is a point.
static void erosion(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
unsigned int getSize() const
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void set_y(const double y)
Set the point y coordinate in the image plane.
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)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const