OpenMV多色塊識別

2021-10-19 08:33:30 字數 2089 閱讀 2312

在螢幕上放的測試,實物可能需要更改一下閾值
import sensor, image, time ,pyb

sensor.

reset()

sensor.

set_pixformat

(sensor.

rgb565

)sensor.

set_framesize

(sensor.

qvga

)sensor.

skip_frames

(100

)#初始化指示燈

led = pyb.

led(2)

led.on(

)time.

sleep

(150

)led.

off(

)red_threshold =(23

,77,18

,101,-

16,96)

green_threshold =(9

,87,-

67,-11

,-2,

66)blue_threshold =(12

,69,2

,86,-

128,-23

)red_blobs = none #本幀捕捉到的色塊列表

green_blobs = none

blue_blobs = none

target_threshold =

[red_threshold,green_threshold,blue_threshold] #目標色塊閾值列表

target_blobs =

[red_blobs,green_blobs,blue_blobs] #注意!

: 這是巢狀列表 , 成員為色塊列表

name_list =

['red'

,'green'

,'blue'

]target_proportion =

(1.05,2

) #色塊長寬比例係數 w/h

clock = time.

clock()

def targetblobs_find()

: temp =

0while temp <3:

target_blobs[temp]

= img.

find_blobs

([target_threshold[temp]

],merge = true,area_threshold =

600)

iflen

(target_blobs[temp]

)>0:

for blob in target_blobs[temp]

: proportion = blob.h(

)/blob.w(

)if proportion > target_proportion[

0] and proportion < target_proportion[1]

: img.

draw_rectangle

(blob.

rect()

) img.

draw_string

(blob.x(

),blob.y(

),name_list[temp]

) temp +=

1while

(true)

: clock.

tick()

img = sensor.

snapshot()

img.

lens_corr

(strength=

1.6) #矯正畫面

targetblobs_find()

print

(clock.

fps(

))

OpenMV 檢測色塊

設定綠色的閾值,括號裡面的數值分別是l a b 的最大值和最小值 minl,maxl,mina,maxa,minb,maxb green threshold 0 80,70,10 0,30 初始化 sensor.reset 初始化攝像頭 sensor.set pixformat sensor.rgb...

OPEN MV捕捉最大色塊

open mv捕捉最大色塊 import image,sensor,time sensor.reset sensor.set pixformat sensor.rgb565 sensor.set framesize sensor.qvga sensor.skip frames 100 red 8 6...

OpenMV學習 顏色識別(一)python

python語法補充 在openmv中實際應用的應該稱為 mircopython 1 匯入模組 第一種 import 模組名 第二種 from 模組名 import 方法名 使用方法如下 import math 匯入math模組 math.floor 呼叫math模組中的floor函式 from m...