我正在研究一个项目,该项目可以从3D空间(视频源)中识别出一个物体,并给出其边缘(轮廓)的样本。
我尝试使用模板,并在将Feed转换为Canny模式后尝试检测对象:
sample1 = cv2.imread('./canny detection/sample2.png')
sample1 = cv2.cvtColor(sample1, cv2.COLOR_RGB2GRAY)
sample1 = cv2.Canny(sample1, 100, 150)
template = cv2.imread('./canny detection/cube1.png')
template = cv2.cvtColor(template, cv2.COLOR_RGB2GRAY)
template = cv2.Canny(template, 100, 150)
threshold = 0.7
w, h = template.shape[::-1]
res = cv2.matchTemplate(sample1, template, cv2.TM_CCOEFF_NORMED)
loc = np.where(res >= threshold)
detected = 0
for pt in zip(*loc[::-1]):
if detected < 1:
cv2.rectangle(sample1, pt, (pt[0]+w, pt[1]+h), (50,100,255), 5)
detected = detected + 1
print('detected')
cv2.imshow('sample1', sample1)
cv2.imshow('template', template)
cv2.waitKey(0)
cv2.destroyAllWindows()
但这没用。我将阈值降低到5,从那时开始,这毫无意义。我还尝试过匹配视频供稿中的图片,但这也没有用。