本文参考了以下链接内容: https://blog.csdn.net/Vertira/article/details/123631185
直接上代码,能实现动态绘制直线和多边形。
import cv2
import numpy as np
import copy
class Lines(object):
def __init__(self):
self.start = (0,0)
self.end = (0,0)
class Poly(object):
def __init__(self):
self.points = []
class DrawPoly(object):
def __init__(self,img,color = (0,255,0),thickness=3):
self.img = img
self.img_for_show = img.copy()
self.color = color
self.thickness = thickness
self.polys = []
self.current_poly = Poly()
self.left_button_down = False
self.lines = []
self.current_line = Lines()
self.current_poly = Poly()
@staticmethod
def __clip(value,low,high):
output = max(value,low)
output = min(output,high)
def shrinkpoint(self,x,y):
h