In this tutorial, we will use an example to show you how to draw lines on an image using cv2.line() in python opencv. You can do it step by step.
1.Read an image and get height and width
import cv2 image = cv2.imread('C:/Users/N/Desktop/test.jpg') height = image.shape[0] width = image.shape[1]
2.Use cv2.line() to draw lines
cv2.line(image, (20,10), (100,10), (255,0,0), 2) cv2.line(image, (0,0), (width, height), (0,0,255), 12)
3.Display image
cv2.imshow("Image", image) cv2.waitKey(0) cv2.destroyAllWindows()
Run this code, you will find: