找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1277|回复: 0
打印 上一主题 下一主题
收起左侧

open mv二维码识别有时候识别不出来什么原因

[复制链接]
跳转到指定楼层
楼主
ID:836780 发表于 2021-12-22 19:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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")                                          


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表