OpenMV识别红色激光

黑夜可以清楚看到激光在哪,但白天情况下,激光点并不明显,这时候用OpenMV很难识别激光位置。

OpenMV识别红色激光_第1张图片

 

本篇讲述强光下用OpenMV识别激光点,并实时发送位置,这里介绍一下识别激光的方法,使用的是色块识别。但是激光点面积很小,而且在黑色区域容易被吞掉。因此对图像本身做一定的处理,比如调节曝光度等。主要就是采集,二值化,找块,显示。

sensor.set_auto_exposure(False, exposure_us=1400)改变openmv的曝光度

sensor.set_auto_gain(False)
sensor.skip_frames(20)
sensor.set_auto_exposure(False, exposure_us=1400)
sensor.set_auto_whitebal(False)
red_threshold = (30, 100, 15, 127, -40, 127)  # 红色激光笔的颜色阈值
green_threshold = (9, 86, 10, 71, -2, 66)    # 绿色十字的颜色阈值

对颜色进行二值化(这里red_threshold可以写为数组,设置多个颜色阈值,更加准确)

red_threshold = (30, 100, 15, 127, -40, 127)  # 红色激光笔的颜色阈值
green_threshold = (9, 86, 10, 71, -2, 66)    # 绿色十字的颜色阈值

然后二值化找激光点

def find_blob_center(threshold):
    blobs = img.find_blobs([threshold])
    if blobs:
        b = blobs[0]
        cx = b.cx()
        cy = b.cy()
        return cx, cy
    return None, None

最后while里显示即可

while True:
    clock.tick()
    img = sensor.snapshot().lens_corr(strength=1.6, zoom=1.0)
    img.draw_rectangle(left_roi)

    # 检测红色激光笔的位置
    laser_x, laser_y = find_blob_center(red_threshold)

    if laser_x is not None and laser_y is not None:
        # 绘制绿色十字来表示激光笔的位置
        img.draw_cross(laser_x, laser_y, color=(0, 255, 128))

    # 显示图像
    img.draw_cross(80, 60, color=(255, 0, 0))  # 中心位置绘制红色十字
    img = img.to_rgb565()
    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected

看效果

OpenMV识别红色激光_第2张图片

 

OpenMV识别红色激光_第3张图片

 s

OpenMV识别红色激光_第4张图片

 

openmv寻找轮廓,也是用到了二值化,可以添加各种筛选条件,然后稳定的找到激光点,关键在于调低曝光度让激光点变的明显。

如果觉得对你有用,希望你能点个赞。

OpenMV识别红色激光_第5张图片

 

 

 

你可能感兴趣的:(python,开发语言,算法)