资源简介

国赛运行最终程序

资源截图

代码片段和文件信息

# Untitled - By: hp - 周日 2月 17 2019
# open mv主代码
# 必须先扫描二维码,再识别颜色,返回抓取顺序
# uart 通讯
import sensor image time pyb
ROI = (20 120 280 100)

red_threshold = (47 68 55 103 25 63) # red_thresholds
green_threshold  = (45 65 -50 -30 0 40)# green_thresholds
blue_threshold  = (28 81 -52 81 -29 -87)# blue_thresholds

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking

red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)

uart = pyb.UART(39600)
uart.init(9600 bits=8 parity=0 stop=2 timeout_char = 500)
clock = time.clock()

qrcode1=0
RGB_Order=[‘0‘‘0‘‘0‘] #物块的排列顺序
qr_code=[‘0‘‘0‘‘0‘] #二维码要求抓取的顺序默认为RGB
sehuan_order=[‘0‘‘0‘‘0‘]#色环顺序
Put_Order=0

r=0
g=0
b=0

flag=0
i=j=0

first_one=0
second_one=0
third_one=0


flag_w=1

first_one1=0
second_one1=0
third_one1=0

flag_find_r=0
flag_find_g=0
flag_find_b=0

flag_sehuan_r=0
flag_sehuan_g=0
flag_sehuan_b=0

order=2 #寻找色块的顺序
sehuan=0#色环顺序
time.sleep(500)
while (flag_w==1):
            img = sensor.snapshot().lens_corr(1.8)
            for blob in img.find_blobs([red_threshold] pixels_threshold=800 area_threshold=800):
                if flag_find_r==0:
                    img.draw_rectangle(blob.rect())
                    img.draw_cross(blob.cx() blob.cy())
                    #r=blob.cx()
                    RGB_Order[order]=‘R‘
                    order=order-1
                    flag_find_r=1
                    red_led.on()
                    green_led.off()
                    blue_led.off()
                else:
                    #pass
                    print(“i have already find the r“)
            #print(“1111111111111“);
            #print(r);
            for blob in img.find_blobs([green_threshold] pixels_threshold=200 area_threshold=200):
                if flag_find_g==0:
                    img.draw_rectangle(blob.rect())
                    img.draw_cross(blob.cx() blob.cy())
                    #g=blob.cx()
                    RGB_Order[order]=‘G‘
                    order=order-1
                    flag_find_g=1
                    red_led.off()
                    green_led.on()
                    blue_led.off()
                else:
                    #pass
                    print(“i have already find the g“)
            #print(“222222222222()“);

            #print(g);
            for blob in img.find_blobs([blue_threshold] pixels_threshold=200 area_threshold=200):
                if flag_find_b==0:
                    img.draw_rectangle(blob.rect())
                    img.draw_cross(blob.cx() blob.cy())
                    #b=blob.cx()
                    RGB_Order[order]=‘B‘
                    order=order-1
                    f

评论

共有 条评论