A few days ago, a reader ask me about selecting ROI using mouse. I thought that such a code would be useful so I wrote the code below. It loads an image, and you define the ROI by dragging your mouse.
Listing 1: Runtime ROI Selection using Mouse
Some final notes: you define the ROI by dragging the mouse from the upper left corner to the bottom right corner. Otherwise it generates errors. I will leave you to fix the bugs.
Update on April 14th, 2010:
Compiling the code above using C++ compiler generates error:
error C2440: '=' : cannot convert from 'void *' to 'IplImage *'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
This is because cvClone() at line 22 and 38 returns void* while img1 is type of IplImage*. To fix this bug, simply replace:
img1 = cvClone(img0)
with:
img1 = cvCloneImage(img0)
Thanks to sycluap for reporting this.
Learning OpenCV: Computer Vision with the OpenCV Library
By: Gary Bradski, Adrian Kaehler
This book is the "de facto" OpenCV User's Manual. It provides a practical, pragmatic, accessible book on computer vision, with algorithmic explanation and concrete example code snippets. Written by the creators of OpenCV, no doubt you should obtain a copy.
Nash on Apr 14, 2010:
sycluap on Apr 15, 2010:
sycluap on Apr 15, 2010:
Christine X on Apr 17, 2010:
Nash on Apr 19, 2010:
| Tel. | +62 31 8662872 +62 856 338 6017 |
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
sycluap on Apr 14, 2010:
Tried on this Runtime ROI selection using mouse, but encounter error:
error C2440: '=' : cannot convert from 'void *' to 'IplImage *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Tried for a long time, but no clue. Appreciate if you can enlighten me on this matter. Thanks!