找回密码
 立即注册

QQ登录

只需一步,快速开始

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

工程训练赛 用openmv识别二维码与颜色

[复制链接]
跳转到指定楼层
楼主
ID:524458 发表于 2019-10-21 18:15 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
import sensor, image, time,json
from pyb import UART

i= 1
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green things. You may wish to tune them...
thresholds = [(7, 41, 13, 37, -63, -21), #yellow generic_red_thresholds -> index is 0 so code == (1 << 0)
              (55, 79, -39, 0, 8, 27),
              (35, 55, 21, 84, 26, 69)] #blue generic_green_thresholds -> index is 1 so code == (1 << 1)
# 当“find_blobs”的“merge = True”时,code代码被组合在一起。

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
clock = time.clock()

# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = True”合并图像中所有重叠的色块。
uart =UART(3,115200)

while(True):
    clock.tick()
    img = sensor.snapshot()
    if i==1:
         img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
         for code in img.find_qrcodes():
            print(code)
            output_str="{%d}" code
            uart.write(output_str+'\r\n')
            print('send:',output_str)
            i=1
    else:
        for blob in img.find_blobs(thresholds,pixels_threshold =50):
            if blob.code() == 1: # r/g code == (1 << 1) | (1 << 0)
                img.draw_rectangle(blob.rect())
                img.draw_cross(blob.cx(), blob.cy())
                output_str="{1}"
                uart.write(output_str+'\r\n')
                print('send:',output_str)
            if blob.code() == 2: # r/g code == (1 << 1) | (1 << 0)
                img.draw_rectangle(blob.rect())
                img.draw_cross(blob.cx(), blob.cy())
                output_str="{2}"
                uart.write(output_str+'\r\n')
                print('send:',output_str)
                #print(2)
            if blob.code() == 4: # r/g code == (1 << 1) | (1 << 0)
                img.draw_rectangle(blob.rect())
                img.draw_cross(blob.cx(), blob.cy())
                output_str="{3}"
                uart.write(output_str+'\r\n')
                print('send:',output_str)
                #print(3)

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

使用道具 举报

沙发
ID:649415 发表于 2020-12-20 17:00 | 只看该作者
复制到open mv的IDE中为什么会有错误呢
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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