Ask Your Question
1

Drawing shapes in images

asked 2014-04-02 07:14:56 -0500

FLY gravatar image

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

image description

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;
        double radius_img = img.rows/2+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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-04-02 07:47:12 -0500

Haris gravatar image

updated 2014-04-02 07:48:34 -0500

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);

image description

edit flag offensive delete link more

Comments

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

FLY gravatar imageFLY ( 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.

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

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

FLY gravatar imageFLY ( 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.

Haris gravatar imageHaris ( 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

FLY gravatar imageFLY ( 2014-04-30 08:22:37 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-04-02 07:14:56 -0500

Seen: 169 times

Last updated: Apr 02 '14