【发布时间】:2021-10-26 12:01:27
【问题描述】:
我正在尝试根据 AutoCAD 绘图中显示的黄色轮廓检测轮廓计数。
import numpy as np
import cv2
image = cv2.imread('C:/Users/htc/Desktop/capture.png')
original = image.copy()
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower = np.array([0, 208, 94], dtype="uint8")
upper = np.array([179, 255, 232], dtype="uint8")
mask = cv2.inRange(image, lower, upper)
# Find contours
cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Extract contours depending on OpenCV version
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
# Iterate through contours and filter by the number of vertices
for c in cnts:
perimeter = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.04 * perimeter, True)
if len(approx) > 5:
cv2.drawContours(original, [c], -1, (36, 255, 12), -1)
cv2.imshow('mask', mask)
cv2.imshow('original', original)
cv2.waitKey()
我期望检测到这两个轮廓圆(轮廓)但未实现的输出。任何人都可以帮助我解决我做错的地方。
输出
【问题讨论】:
标签: python numpy opencv machine-learning contour