找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2693|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

工程訓(xùn)練賽 用openmv識(shí)別二維碼與顏色

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:524458 發(fā)表于 2019-10-21 18:15 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
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)
# 當(dāng)“find_blobs”的“merge = True”時(shí),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”的區(qū)域才被
# 下面的“find_blobs”返回。 如果更改相機(jī)分辨率,
# 請(qǐng)更改“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 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:649415 發(fā)表于 2020-12-20 17:00 | 只看該作者
復(fù)制到open mv的IDE中為什么會(huì)有錯(cuò)誤呢
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表