
通过像素点位置在图片上画线———Python
知道两个像素点在图片上的的位置,在图片上将其连接起来
例如有两个像素点:(449, 149)、(387, 182)
直线连接
import cv2
file_path = '/data/test_pic/1.jpg'
# 读取图片文件
img = cv2.imread(file_path)
start_point = (449, 149)
end_point = (387, 182)
line_color = (0, 255, 0)
# 开始坐标 结束坐标 线的颜色 线的厚度
cv2.line(img,start_point,end_point, line_color, 2)
# 写入图片
cv2.imwrite(file_path, img)
矩形连接
两点横纵坐标延长组成的矩形
import cv2
file_path = '/data/test_pic/1.jpg'
# 读取图片文件
img = cv2.imread(file_path)
start_point = (449, 149)
end_point = (387, 182)
line_color = (0, 255, 0)
# 开始坐标 结束坐标 线的颜色 线的厚度
cv2.rectangle(img,start_point,end_point, line_color, 2)
# 写入图片
cv2.imwrite(file_path, img)