__author__ = 'ShawDa'
import cv2
import numpy as np
def point2area(points, img, color):
"""
:param points: 点集合
:param img: 图片位置
:param color: BGR三色
:return:将图片上点包围的区域涂上颜色
"""
img = cv2.imread(img)
res = cv2.fillPoly(img, [np.array(points)] ,color)
cv2.imshow('fillpoly', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
points = [(20,20), (70,70), (120,200)]
img = 'lena.png'
color = [255, 255, 255]
point2area(points, img, color)
根据点围成的闭合区间在图片上将这部分填充某一种颜色,结果如图:
更换一下points:
points = [(0,20), (70,70), (120,200), (0,300)]