-4

I want to draw circle using mouse events in opencv.

That is whenever i clicked the left button and drag it means,it should draw the circle according to the x and y position of the mouse.I have tried it for rectangle,its working perfectly.But i don't know how to draw circle..Please help me anyone.

Smern
  • 18,746
  • 21
  • 72
  • 90

1 Answers1

1

you can use the following function to set a callback for window

SetMouseCallback

documentation here:

http://docs.opencv.org/modules/highgui/doc/user_interface.html

for circles you can use the function:

circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

documentation here:

http://opencv.willowgarage.com/documentation/cpp/drawing_functions.html

jamk
  • 836
  • 1
  • 10
  • 24
  • yes for drawing rectangle,i used that and know that for using mouse we need to call SetMouseCallback function...But after that how to proceed.I don't know how to use the circle radius and center via SetMouseCallback function..In that only i was strucking...Please help me.... – user2459619 Jul 29 '13 at 12:38
  • You need first the image where you wannt to draw the circle. It is a recursive operation so you will need a while loop to redraw your image or just redraw it in the callback function. The easy way is to define your img object globally like in here: http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/cpp/ffilldemo.cpp. You could pass the image with the void point of your callback. In your callback you can easy than write cv::circle(img,cv::Point point(x, y),10,cv::Scalar(255, 0, 255));imshow("Window",img); – jamk Jul 30 '13 at 12:00