OpenMV多色块识别

OpenMV多色块识别

实现效果

在这里插入图片描述

具体代码

在屏幕上放的测试图片,实物可能需要更改一下阈值
import sensor, image, time ,pyb

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(100)
#初始化指示灯
led = pyb.LED(2)
led.on()
time.sleep(150)
led.off()

Red_threshold = (23, 77, 18, 101, -16, 96)
Green_threshold = (9, 87, -67, -11, -2, 66)
Blue_threshold = (12, 69, 2, 86, -128, -23)

Red_Blobs = None    #本帧捕捉到的色块列表
Green_Blobs = None
Blue_Blobs = None
Target_threshold = [Red_threshold,Green_threshold,Blue_threshold]   #目标色块阈值列表
Target_Blobs = [Red_Blobs,Green_Blobs,Blue_Blobs]   #注意!: 这是嵌套列表 , 成员为色块列表
Name_List = ['Red','Green','Blue']
Target_proportion = (1.05,2)      #色块长宽比例系数  W/H

clock = time.clock()

def TargetBlobs_Find():
    temp = 0
    while temp < 3:
        Target_Blobs[temp] = img.find_blobs([Target_threshold[temp]],merge = True,area_threshold = 600)
        if len(Target_Blobs[temp]) > 0:
            for Blob in Target_Blobs[temp]:
                proportion = Blob.h()/Blob.w()
                if proportion > Target_proportion[0] and proportion < Target_proportion[1]:
                    img.draw_rectangle(Blob.rect())
                    img.draw_string(Blob.x(),Blob.y(),Name_List[temp])
        temp += 1

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.lens_corr(strength=1.6)    #矫正画面
    TargetBlobs_Find()
    print(clock.fps())
  • 17
    点赞
  • 81
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值