欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: open mv二維碼識別有時候識別不出來什么原因 [打印本頁]

作者: 1970420173    時間: 2021-12-22 19:09
標題: open mv二維碼識別有時候識別不出來什么原因
import sensor, image,time,lcd, math
from pyb import UART,Timer,LED

threshold_index = 0 # 0 for red, 1 for green, 2 for blue




thresholds1 = [(65, 94, -63, -29, -14, 27)] # 黑色閾值

thresholds = [(8, 66, 21, 79, 3, 62), # 紅色
              (30, 100, -64, -8, -32, 32), #
              (96, 100, -15, -3, -14, 43)] #
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock = time.clock()
data = []
uart = UART(3,115200,8,None,1)       #創建串口對象

while(True):
  img = sensor.snapshot()     #保持一張照片
  for blob1 in img.find_blobs(thresholds1,roi= [0,0,318,145], pixels_threshold=300, area_threshold=200):
     b=blob1.x()-150   
     d=blob1.x()+70
     e=blob1.y()+50
     print(d)      
     print(e) #通過坐標得到一塊識別區域
  if(uart.any()): #判斷是否有串口信息過來                                                                        
     data = uart.read(8)  #讀8位數據                                       
     if((data[0] == 0x55)&(data[1] == 0x02)&(data[7] == 0xBB)):
       print("4")  
       if(data[2] == 0x92 and data[3] == 0x01 ):  #紅綠燈                                
          for blob in img.find_blobs(thresholds,roi= [0,0,d,e], pixels_threshold=300, area_threshold=200):   
                print( blob.code())                                             
                if blob.code()==1 or blob.code()==4:   #因為紅色與黃色總是識別成一樣的所以用坐標判斷
                  print("5")                  
                  if blob.x()<b:  #紅色                 
                    uart.writechar(0x55)
                    uart.writechar(0x02)
                    uart.writechar(0x92)
                    uart.writechar(0x01)
                    uart.writechar(0x01)
                    uart.writechar(0x01)
                    uart.writechar(0x00)
                    uart.writechar(0xBB)
                    print("紅色")                                                                           
                  if blob.x()>b: #黃色
                    # qr_Tab = code.payload()
                     uart.writechar(0x55)
                     uart.writechar(0x02)
                     uart.writechar(0x92)
                     uart.writechar(0x01)
                     uart.writechar(0x01)
                     uart.writechar(0x03)
                     uart.writechar(0x00)
                     uart.writechar(0xBB)                                       
                     print("黃色")                                                         
                if blob.code()!=1 or blob.code()!=4:#綠色
                   # qr_Tab = code.payload()
                    uart.writechar(0x55)
                    uart.writechar(0x02)
                    uart.writechar(0x92)
                    uart.writechar(0x01)
                    uart.writechar(0x01)
                    uart.writechar(0x02)
                    uart.writechar(0x00)
                    uart.writechar(0xBB)
                    print("綠色")                     
        if(data[2] == 0x92 and data[3] == 0x02 ):  #二維碼                  
                  print("二維碼")               
                  for code in img.find_qrcodes():  #這是一個二維碼功能函數     uart.writechar是串口發送數據的
                      time.sleep(100)                                    
                      qr_Tab = code.payload()
                      uart.writechar(0x55)
                      uart.writechar(0x02)
                      uart.writechar(0x89)
                      uart.writechar(0x01)                     
                      uart.writechar(len(qr_Tab))
                      for qrdata in qr_Tab:
                           uart.writechar(ord(qrdata))
                      uart.writechar(0xBB)
                      print("6")                                          







歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1