How to draw a circle on image in Opencv
Video Explanation :
As we all know a image in nothing a 2d graph in which several pixels are there arranging rows and colum
Note : I am assuming that you image is in the same folder where your python code is saving if you then you need to give proper directory
Code :
import cv2
a =cv2.imread("1.jpg")
cv2.circle(a, (500,500),30 ,(255,0,0),2)
cv2.imshow("img",a)
cv2.waitKey(0)
cv2.destroyAllWindows()
Let's try to understand how this code works
- Fist we have import cv2 so that we can use opencv in our code
- After we are reading our image by using command cv2.imread and store this image into a variable called a
- Now we need to define a starting point and ending point of a line .Remember that image is nothing just a 2D graph
- cv2.imshow("line",a)
here "line" is the window name in which we are going to show our image and a is the name of the image that we want to show - if you put the value of thickness -1 then you will get a filled circle
- cv2.waitKey(0)
- cv2.destroyAllWindows()
the purpose of cv2.waitKey(0) that after output it will stay on the screen until any keypad is pressed and cv2.destroyAllWindows() make sure to close out window properly - cv2.circle it takes 5 parameter
(image , center of other circle, radius of the circle , color , thickenss)
In our cases image is a center of circle is (500,500) ,radius is 30 (pixels) ,color is blue (255,0,0) , and thickness of the circle is 2.
0 Comments
if you are not getting it then ask i am glad to help