Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ image Contour drawing
I am trying to implement a feature of drawing closed contour that defines my region of interest. I would like to manually draw a contour that encloses some object in a image using my mouse. The contour should be closed at the end, something like ImageJ does. I am wondering if there is any tools, 3rd party libs in C++ can help with this. I know probably OpenCV can be a source, but I am trying to implement something light and easy. So is there anyway to do so? Any pointer is appreciated. Thanks. --Nick
Posted 29-Nov-12 6:45am
Comments
Sergey Alexandrovich Kryukov at 29-Nov-12 12:50pm
   
This problem, in general case, is never light or easy -- just think about it.
--SA
YvesDaoust at 30-Nov-12 4:16am
   
You should specify whether the contour needs to follow some object edge/outline in the image or just be a freehand path.
 
First problem is hard; second is trivial.
Nick Tsui at 30-Nov-12 9:22am
   
Free hand drawing, something like the similar function in ImageJ as I mentioned.
YvesDaoust at 30-Nov-12 9:36am
   
I don't know how it is in ImageJ.
 
Capturing the cursor positions is very simple. Just implement a MouseMove event handler and store the coordinates in an array. Implement drawing in the Pain event handler. There is no need for a third party library.
Nick Tsui at 30-Nov-12 9:50am
   
Sounds good. Is that possible to show the user the line they are going to draw when they are moving their mouse? For example, I have clicked my first point, now I am looking for where to put my second. So it would be nice if the program can show the line that links the first point and the second point, so that the user can have more information to decide where the second point goes.
YvesDaoust at 30-Nov-12 10:09am
   
As I sais, implement a Pain handler. You can draw anything you like in it. And use the method Refresh of the form when you want to update the display.
 
As you are not sepcifying a freehand curve, but rather a polygon, you'd better implement a MouseDown handler.
Nick Tsui at 30-Nov-12 14:58pm
   
hmm....thanks. I guess I am not confident with that.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

We used to use PSET (pixel set) command on a picturebox in VB2.
 
I dont know if that command is still available in a picturebox object but its is pretty basic so I shuold assume its still there.
 
As far as i can remember the command used go something like.....
 
MyPictureBox1.Pset(X,Y,Color)
  Permalink  
Comments
Nick Tsui at 30-Nov-12 14:59pm
   
Does C++ have that feature?
Zaf Khan at 30-Nov-12 15:41pm
   
Well I couldnt see the PSET method listed as part of the picturebox itself but I think the graphics attribute/property of the picturebox offers a similar/equivalent method.
 
maybe this page at msdn can help you?
Zaf Khan at 30-Nov-12 15:43pm
   
Zaf Khan at 30-Nov-12 15:45pm
   
Well I couldnt see the method PSET listed for the C++ picturebox but the graphics attribute/property of the picture does make the feature available.
 
Maybe this page at MSDN can help you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Look at this sample i did
http://www.codeproject.com/Questions/505546/howplustoplusdrawplusstraightpluslineplushorizonta">On this website
 

its not in C++ but it shouldn't be too difficult to port
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100