Draw geometry with OpenCV.
Import NumPy as Npimport cv2# Create a black imageimg = Np.zeros ((521,512,3), np.uint8) # Draw a diagonal blue line with th Ickness of 5 px# background data, straight start, line end, color, line weight img = Cv2.line (IMG, (0,0), (511,511), (255,0,0), 5) # Print (IMG) # Drawing rectangle# " Background (contains content previously drawn to IMG) ", upper left corner of rectangle, lower right corner of rectangle, color, line weight img = Cv2.rectangle (IMG, (384,0), (510,128), (0,255,0), 3) # Drawing circle# background data The linetype[-1 represents a solid color fill]img = Cv2.circle (img, (447,63), X, (0,0,255), -1) # Drawing ellipse# background; symmetry Center; long and short axis length The entire ellipse rotation angle (clockwise), # Start angle position, end angle position (shun), color; linetypeimg = Cv2.ellipse (img, (256,256), (100,50), 0,0,180,255,-1) # Drawing polygonpts = Np.array ([[10,5],[20,30],[70,20],[50,10]],np.int32) pts = Pts.reshape (( -1,1,2)) # Polylines (IMG, pts, isClosed, color[, thickness[, linetype[, Shift]]), imgimg = Cv2.polylines (Img,[pts],true, (0,255,255)) # Adding text to Imagefont = Cv2. Font_hershey_simplexcv2.puttext (IMG, ' OpenCV ', (10,500), font,4, (255,255,255), 2,cv2. LINE_AA) cv2.imshow (' Images ', img) cv2.waitkey (0) cv2.destroyallwindows ()
Output:
Python Opencv--geometric