这几天一直在思考这个问题,使用示例代码中的巡线行驶代码,在openmv视野中出现多条直线后,其就不能正确找到需要行走的直线了。请问有什么好的办法吗?
# 鲁棒线性回归例程
#
# 这个例子展示了如何在OpenMV Cam上使用get_regression()方法来获得
# ROI的线性回归。 使用这种方法,你可以轻松地建立一个机器人,它可以
# 跟踪所有指向相同的总方向但实际上没有连接的线。 在线路上使用
# find_blobs(),以便更好地过滤选项和控制。
#
#我们在这个脚本中使用get_regression()的robust = True参数,该脚本使用更稳健的算法计算线性回归...但是可能慢得多。 鲁棒算法在图像上运行O(N ^ 2)时间。 所以,你需要限制像素的数量来使这个算法工作,它可能实际需要秒的时间给你一个结果...非常小心!
THRESHOLD = (0, 64) # Grayscale threshold for dark things...
BINARY_VISIBLE = True # 首先二值化,所以你可以看到什么线性回归正在
# 运行...虽然可能会降低FPS。
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
clock = time.clock() # to process a frame sometimes.
while(True):
clock.tick()
img = sensor.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else sensor.snapshot()
# 返回类似于由find_lines()和find_line_segments()返回的线对象。
# 你有x1(),y1(),x2(),y2(),length(),
# theta()(以度为单位的旋转),rho()和magnitude()。
#
# magnitude() 表示线性回归的工作情况。这对于鲁棒的线性回归意味着不同
# 的东西。一般来说,值越大越好...
line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD], robust = True)
if (line): img.draw_line(line.line(), color = 127)
print("FPS %f, mag = %s" % (clock.fps(), str(line.magnitude()) if (line) else "N/A"))
# About negative rho values:
#
# A [theta+0:-rho] tuple is the same as [theta+180:+rho].没办法。:grinning_face_with_smiling_eyes:
好吧。。谢谢!!!!
我用的find_lines函数 通过对返回值的处理进行判断
如果返回值只有一条线 那就是一条线
如果返回值的线有多个对返回的线进行一些处理和过滤 就可以判断了
@5ami 请问一下这个处理和过滤是应该怎样做呢?有代码吗?如果有的话万分感谢:smiling_face_with_open_mouth: