基本信息
源码名称:MaixPy之识别颜色-动态识别色块
源码大小:3.41KB
文件格式:.py
开发语言:Python
更新时间:2020-10-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

学MaixPy之机器视觉,在MaixPy IDE开发环境,用Maix Dock K210开发板,实现动态识别色块,包括红、蓝、绿、黄四个色。


red_threshold  =  (60, 68,  50,  62,  28,  42)    #(55, 70, 42, 65, 52, 8)
green_threshold=  (85, 95, -80, -49,  55,  70)    #(0, 88, -42, -6, -9, 13)
blue_threshold =  (79, 85, -24, -11, -27, -15)    #(0, 80, -128, 35, -128, -18)
yellow_threshold =(69, 80,   5,  21,  55,  73)       # (88, 95, 0, -44, 93, 48)
printfinish_Y = 0
printfinish_R = 0
printfinish_G = 0
printfinish_B = 0

while True:
    img=sensor.snapshot() #使用摄像头拍摄一张照片
    blobs_R = img.find_blobs([red_threshold])
    blobs_G = img.find_blobs([green_threshold])
    blobs_B = img.find_blobs([blue_threshold])
    blobs_Y = img.find_blobs([yellow_threshold])
    if blobs_R:
        img.draw_string(60, 100, "color is : Red!", scale=2)
        if printfinish_R == 0:
          print("color is : Red!")
          print("blobs: ",blobs_R)
          printfinish_R = 1
        led_r.value(0)
        for b in blobs_R:
            tmp=img.draw_rectangle(b[0:4],225)
            tmp=img.draw_cross(b[5], b[6])
            c=img.get_pixel(b[5], b[6])
    else:
        led_r.value(1)
        printfinish_R = 0