Click here to Skip to main content
12,887,625 members (36,998 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ image 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 5:45am
Sergey Alexandrovich Kryukov 29-Nov-12 12:50pm
This problem, in general case, is never light or easy -- just think about it.
YvesDaoust 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 30-Nov-12 9:22am
Free hand drawing, something like the similar function in ImageJ as I mentioned.
YvesDaoust 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 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 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 30-Nov-12 14:58pm
hmm....thanks. I guess I am not confident with that.
Rate this: bad
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.....

Nick Tsui 30-Nov-12 14:59pm
Does C++ have that feature?
Zaf Khan 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 30-Nov-12 15:43pm
Zaf Khan 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
Please Sign up or sign in to vote.

Solution 2

Look at this sample i did">On this website

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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2017
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