Drawing shapes in images

I am trying to draw the circle in the center if the images , like the image below

there may be the images of many shapes/size but i want to draw circle/eclipse every time in the same way.

Below is the code i tried for it

        Mat img = imread ("E:\\test.jpg");
int center_img = (img.rows*img.cols)/2;
circle(img,Point(img.rows/2,img.cols/2), img.rows/2,1, 8,0);
imshow ("img" , img);
cvWaitKey(0);

edit retag close merge delete

Sort by ยป oldest newest most voted

Its nothing but you have to draw ellipse() but need to adjust the parameters, like

center=your image centre
axes = Size(img.cols/2,img.rows/2) // width/2 X height/2
angle=0;
startAngle=0;
endAngle=360;


Now draw ellipse using above

ellipse(img,Point(img.cols/2,img.rows/2), Size(img.cols/2,img.rows/2),0,0,360, Scalar(0,0,255), 2, 8,0);


more

Can you please tell me about this axes = Size(img.cols/2,img.rows/2) // width/2 X height/2 why we need to use this , whats its actually functionality

( 2014-04-02 07:53:36 -0500 )edit

It is half of size of ellipse axis, go to docs it's well explained there with picture.

( 2014-04-02 08:48:22 -0500 )edit

i didn't understand from there thats why i asked here

( 2014-04-02 12:06:18 -0500 )edit
1

It is half of the size of ellipse axes, that is the horizontal and vertical lines passing through the centre. If you want to visualize it, just change size to Size(img. cols/4,img.rows/2) and see the major axis of ellipse become(width) reduced.

( 2014-04-02 13:02:28 -0500 )edit
1

what if i want to delete the area in the ellipse and make the ellipse covered area transparent

( 2014-04-30 08:22:37 -0500 )edit