【发布时间】:2020-01-01 14:02:45
【问题描述】:
目标是实时检测墙壁并将距离导出到墙壁。有一个设置,一个封闭的 4 面墙,每面墙上有一组独特且理想的形状(三角形,正方形......)一个机器人带摄像头的将在墙壁内漫游并具有计算机视觉。机器人应检测形状并导出相机与墙壁(或该形状)之间的距离。
我已经通过 Opencv 和形状检测 (cv2.approxPolyDP) 和距离计算(周长计算和边缘计数,然后将像素长度转换为实际距离)实现了这个目标。
它在 90 度角时完美工作,但在其他角度时无效。
任何更好的方法。
谢谢
for cnt in contours[1:]:
# considering countours from 1 because from practical experience whole frame is often considered as a contour
area = cv2.contourArea(cnt)
# area of detected contour
approx = cv2.approxPolyDP(cnt, 0.02*cv2.arcLength(cnt, True), True)
#It predicts and makes pixel connected contour to a shape
x = approx.ravel()[0]
y = approx.ravel()[1]
# detected shape type label text placement
perimeter = cv2.arcLength(cnt,True)
# find perimeter
【问题讨论】:
标签: python-3.x opencv