draw line on image

发布时间 2023-07-03 10:29:49作者: xiaoxuxli

cv2.line(image, start_point, end_point, color, thickness)

# Python program to explain cv2.line() method

# importing cv2
import cv2

image = cv2.imread(path)
start_point = (0, 0)
end_point = (250, 250)
color = (0, 255, 0)

thickness = 9

# Using cv2.line() method
# Draw a diagonal green line with thickness of 9 px
image = cv2.line(image, start_point, end_point, color, thickness)

# Displaying the image
cv2.imshow(window_name, image)

会出现内存不对齐的问题
Layout of the output array img is incompatible with cv::Mat
img = img.copy()

参考:
[1] https://www.geeksforgeeks.org/python-opencv-cv2-line-method/
[2] https://blog.csdn.net/zylooooooooong/article/details/124378274
[3] https://stackoverflow.com/questions/23830618/python-opencv-typeerror-layout-of-the-output-array-incompatible-with-cvmat