logo

在识别到红色时帧率太低,一卡一卡的

2022-10-19 17:39
I
yp5c
import sensor, image, time,lcd,math,pyb
import json
import gc
from image import SEARCH_EX, SEARCH_DS
import lcd
from pyb import UART
from pyb import Servo
from pyb import Pin
from pyb import LED
from fenghuang import QQQ
from fenghong import ppp
led = LED(4)
a=0
c=0
q=0
led.toggle()
blue_threshold   = (18, 38, 9, 58, -90, -33)
red_threshold   =  [(29, 53, 34, 74, 15, 55),(75, 50, 10, 68, 12, 67)]
yellow_threshold   = [(54, 67, -13, 4, 49, 71),(72, 95, -17, 9, 54, 82),(51, 77, -7, 24, 11, 55)]
fangkuai_thresholds =[(13, 38, 75, 61, 17, 52),(19, 57, 19, 87, 16, 58)]
thresholds = [(59, 63, 56, 64, 24, 41),(11, 33, -8, 58, 16, 44),
              (35, 53, 49, 74, 26, 63),(23, 50, 44, 79, 14, 63),
              (22, 53, 31, 74, 16, 51),(40, 56, 41, 84, 23, 65),
              (49, 65, 17, 75, 21, 64),(55, 76, 27, 55, 10, 64),
              (56, 71, 69, 52, 18, 49),(25, 70, 86, 19, -5, 65),
              (23, 84, 86, 19, -5, 65)]
erweima_threshold =[(90, 100, -28, 24, 35, -20) ]
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(20)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(False)
uart = UART(3, 115200)
clock = time.clock()
sensor.set_auto_exposure(True, exposure_us=5000) 
templates3 = ["/gaochangfangti1.pgm","/gaozhengfangti1.pgm",
              "/dichangfangti2.pgm","/dizhengfangti2.pgm",
              "/zhongzhengfangti1.pgm","/zhongchangfangti1.pgm"]
templates4 = ["/gaoyuanhuan1.pgm","/diyuanhuan2.pgm","/zhongyuanhuan1.pgm"]

s1=Servo(1)
s2=Servo(2)
s3=Servo(3)
s1.angle(15)
s2.angle(28)
s3.angle(-15)
while(True):
  clock.tick()
  lcd.display(sensor.snapshot())
  a=uart.readchar()
  #print(a)
  c=2
  led = LED(1)
  led = LED(4)
  led.off()
  if a==52 and c!=2:
     img = sensor.snapshot()
     sensor.set_framesize(sensor.QVGA)
     led = LED(1)
     led.off()
     s2.angle(60)
     sensor.set_windowing((70,1,80,170))
     led = LED(4)
     led.off()
     blobs0 = img.find_blobs([blue_threshold],pixels_threshold=180)
     blobs3 = img.find_blobs(red_threshold,pixels_threshold=80)
     if blobs0 :
        s3.angle(-75)
     if blobs3 :
        led.off()
        s3.angle(-75)
        pyb.delay(200)
        s3.angle(40)
        pyb.delay(200)
        s3.angle(-75)
        pyb.delay(200)
        c=c+1
  if a==50 and c!=2:
     s1=Servo(1)
     s2=Servo(2)
     s3=Servo(3)
     sensor.set_framesize(sensor.QVGA)
     sensor.set_windowing((165,20,148,100))
     led = LED(4)
     led.on()
     img = sensor.snapshot()
     blobs0 = img.find_blobs([blue_threshold],pixels_threshold=100)
     blobs3 = img.find_blobs(red_threshold,pixels_threshold=60)
     blobs2 = img.find_blobs(yellow_threshold,pixels_threshold=40)
     if blobs0 :
        s3.angle(-45)
     elif blobs2 :
        s3.angle(-45)
        s2.angle(-5)
        pyb.delay(200)
        s3.angle(40)
        pyb.delay(200)
        s3.angle(-45)
        pyb.delay(200)
     elif blobs3:
        s3.angle(-45)
        s2.angle(60)
        pyb.delay(200)
        s3.angle(40)
        pyb.delay(200)
        s3.angle(-45)
        pyb.delay(200)
  if  c==2 :
     sensor.set_framesize(sensor.QQVGA)
     img = sensor.snapshot()
     uart.write('0')
     #sensor.set_windowing((160,120))
     for code in img.find_qrcodes():
        img.draw_rectangle(code.rect(), color = (255, 0, 0))
        q=code.payload()
        if code.payload() =='R' :
           uart.write('1')
           print(q)
           pyb.delay(1800)
           ppp()
           pyb.delay(4500)
           QQQ()
        else :
           uart.write('0')
     for blob in img.find_blobs(thresholds, pixels_threshold=250, area_threshold=200):
        img = img.to_grayscale()
        for t in templates3:#高方块
            template = image.Image(t)
            r = img.find_template(template, 0.85, step=4, search=SEARCH_EX)
            if r and blob.cxf()<90 :
                uart.write('1')
                img.draw_rectangle(r, color=0)
                print(blob.code(), t,1)
                pyb.delay(1800)
                ppp()
                pyb.delay(4500)
                QQQ()
            else :
                 uart.write('0')
        for t in templates4:#高原换
            template = image.Image(t)
            r = img.find_template(template, 0.60, step=4, search=SEARCH_EX)
            if r  and blob.cxf()<70  :
                uart.write('2')
                img.draw_rectangle(r, color=0)
                print(blob.code(), t,2)
                pyb.delay(1800)
                ppp()
                pyb.delay(4500)
                QQQ()
            else :
                uart.write('0')
2022-10-19 23:08
I
网红小智智 星瞳科技

卡是因为有pyb.delay

2022-10-20 15:30
1
tvfa

没识别到图片没有进入到那个if里面,delay不起作用的,

现在只要看到红色就一卡一卡的

2022-10-22 12:45
I
网红小智智 星瞳科技

@tvfa 把代码精简,只留要测试的部分