Python 轮廓检测
我想在实时视频中对2D网格的正方形进行排序 我已使用以下方法对图像执行此操作:Python 轮廓检测,python,opencv,contour,Python,Opencv,Contour,我想在实时视频中对2D网格的正方形进行排序 我已使用以下方法对图像执行此操作: 寻找并绘制等高线 等高线排序 mask2 = np.full(gray.shape, 255, np.uint8) if lines is not None: for line in lines: x1, y1, x2, y2 = line[0] cv2.line(mask2, (x1, y1), (x2, y2), (0, 0, 0), 3 ,cv2.LI
mask2 = np.full(gray.shape, 255, np.uint8)
if lines is not None:
for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(mask2, (x1, y1), (x2, y2), (0, 0, 0), 3 ,cv2.LINE_AA)
cnts = cv2.findContours(mask2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
(cnts, _) = contours.sort_contours(cnts, method="top-to-bottom")
cube_rows = []
row = []
for (i, c) in enumerate(cnts, 1):
row.append(c)
if i % 3 == 0:
(cnts, _) = contours.sort_contours(row, method="left-to-right")
cube_rows.append(cnts)
row = []
number = 0
for row in cube_rows:
for c in row:
x,y,w,h = cv2.boundingRect(c)
cv2.rectangle(mask2, (x, y), (x + w, y + h), (0,0,0), 2)
cv2.putText(mask2, "#{}".format(number + 1), (x,y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0,0,0), 2)
number += 1
问题是什么?你说你已经这样做了。我说我已经这样做了一个图像,现在我想要一个实时视频这个代码看起来很熟悉:)看一看,然后。您可以采用类似的方法对正方形进行排序。要处理实时视频,您可以对每个帧进行排序,并创建一些数据结构来跟踪位置