openmv对多种颜色优先级跟踪

  • openmv颜色的识别和追踪,主要根据与颜色的LAB值,确定每种颜色的阈值,然后再通过openmv自带的摄像头对所采集到的颜色进行识别,并且再对采集到的颜色物体边缘标记出来。
  • 首先运行以后程序采集到帧缓冲区的画面,将待识别的颜色物体放入到openmv摄像头下,将程序中断,帧缓冲区画面就停止再中断后的最后一帧画面。
  • 打开工具–>机器视觉–>阈值编辑器–>帧缓冲区,调节LAB的大小,在二值图像中能将待识别的颜色标注成白色,其余背景颜色显示为黑色,将下边显示出来的阈值复制粘贴到程序里边。
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
clock = time.clock()

red_threshold_01 = ((35, 100, 41, 77, 24, 59));
green_threshold_01 = ((79, 62, -57, -16, 12, 74));
yello_threshold_01 = ((59, 100, -60, 10, 9, 127));

while(True):
    clock.tick()
    img = sensor.snapshot()
    blobs = img.find_blobs([red_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10);      #红色物块
    blobs1 = img.find_blobs([green_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10); #绿色物块
    blobs2 = img.find_blobs([yello_threshold_01], pixels_threshold=100, area_threshold=100, merge=True, margin=10);   #黄色物块
    if blobs:
    #如果找到了目标颜色
        print("red")
        for b in blobs:
        #迭代找到的目标颜色区域
            # Draw a rect around the blob.
            img.draw_rectangle(b[0:4]) # rect
            #用矩形标记出目标颜色区域
            img.draw_cross(b[5], b[6]) # cx, cy
            #在目标颜色区域的中心画十字形标记
    elif blobs1:
    #如果找到了目标颜色
        print("green")
        for b in blobs1:
        #迭代找到的目标颜色区域
            # Draw a rect around the blob.
            img.draw_rectangle(b[0:4]) # rect
            #用矩形标记出目标颜色区域
            img.draw_cross(b[5], b[6]) # cx, cy
            #在目标颜色区域的中心画十字形标记
    elif blobs2:
    #如果找到了目标颜色
        print("yello")
        for b in blobs2:
        #迭代找到的目标颜色区域
            # Draw a rect around the blob.
            img.draw_rectangle(b[0:4]) # rect
            #用矩形标记出目标颜色区域
            img.draw_cross(b[5], b[6]) # cx, cy
            #在目标颜色区域的中心画十字形标记
  • 以上实现了对颜色识别的优先级跟踪,优先级是红色 > 绿色 >黄色,首先在红色,绿色,黄色三种颜色的物体放到一起时,只能对红色颜色进行跟踪,当红色被拿除后,再对绿色进行跟踪,当绿色再被拿除后,最后再对黄色物体进行跟踪。
  • 2
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值