This is the 12th day of my participation in Gwen Challenge
OpenCV is a C++ library, currently popular computer vision programming library, for real-time processing of computer vision problems, it covers a lot of modules in the field of computer vision. In Python, the OpenCV library is often used for image processing.
This article will show you how to draw lines, rectangles, and circles using OpenCV in Python3:
The drawing functions of OpenCV are cv2.line(), cv2.cicle(), cv2.Rectangle (), cv2.ellipse(), and cv2.puttext ().
Line drawing
OpenCV line function cv2.line()
Function, you need to tell the function where the line starts and ends.
The code looks like this:
import numpy as np
importImg = np.zeros(()512.512.3), uint8) #5Cv2.line (img,()0.0), (260.260), (255.0.0),5Cv2.namedwindow (cv2.namedWindow)'image'Cv2.resizewindow (cv2.resizewindow)'image'.1000.1000)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Copy the code
The output is:
Draw a rectangular
Rectangle () = cv2.Rectangle ()
The function needs to be told the coordinates of the top left and bottom right vertices of the rectangle
import numpy as np
importImg = np.zeros(()512.512.3), uint8) #3Rectangle (rectangle(img),(350.0), (500.128), (0.255.0),3Cv2.namedwindow (cv2.namedWindow)'rectangle'Cv2.resizewindow (cv2.resizewindow)'rectangle'.1000.1000)
cv2.imshow('rectangle',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Copy the code
The output is:
A circle
OpenCV draws the rectangle function cv2.circle().
Function, you need to specify the center and radius.
import numpy as np
importImg = np.zeros(()512.512.3Cv2. circle(img,(uint8) #60.60),30, (0.0.213), -1Cv2.namedwindow (cv2.namedWindow)'circle'Cv2.resizewindow (cv2.resizewindow)'circle'.1000.1000)
cv2.imshow('circle',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Copy the code
The output is:
A series of articles will follow this month,
Wonderful article, please pay attention.