資源簡介
OpenMV形狀識別And顏色識別!
代碼片段和文件信息
#?Blob?Detection?Example
#
#?This?example?shows?off?how?to?use?the?find_blobs?function?to?find?color
#?blobs?in?the?image.?This?example?in?particular?looks?for?dark?green?objects.
import?sensor?image?time
#?For?color?tracking?to?work?really?well?you?should?ideally?be?in?a?very?very
#?very?controlled?enviroment?where?the?lighting?is?constant...
red_threshold_01?=?(120?160?0?40?0?40)
#設置紅色的閾值,括號里面的數(shù)值分別是L?A?B?的最大值和最小值(minL?maxL?minA
#?maxA?minB?maxB),LAB的值在圖像左側三個坐標圖中選取。如果是灰度圖,則只需
#設置(min?max)兩個數(shù)字即可。
#?You?may?need?to?tweak?the?above?settings?for?tracking?green?things...
#?Select?an?area?in?the?framebuffer?to?copy?the?color?settings.
sensor.reset()?#?Initialize?the?camera?sensor.
sensor.set_pixformat(sensor.RGB565)?#?use?RGB565.
sensor.set_framesize(sensor.QQVGA)?#?use?QVGA?for?quailtiy?use?QQVGA?for?speed.
sensor.skip_frames(10)?#?Let?new?settings?take?affect.
sensor.set_auto_whitebal(False)
#關閉白平衡。白平衡是默認開啟的,在顏色識別中,需要關閉白平衡。
clock?=?time.clock()?#?Tracks?FPS.
‘‘‘
??擴寬roi
‘‘‘
def?expand_roi(roi):
????#?set?for?QQVGA?160*120
????extra?=?5
????win_size?=?(160?120)
????(x?y?width?height)?=?roi
????new_roi?=?[x-extra?y-extra?width+2*extra?height+2*extra]
????if?new_roi[0]?0:
????????new_roi[0]?=?0
????if?new_roi[1]?0:
????????new_roi[1]?=?0
????if?new_roi[2]?>?win_size[0]:
????????new_roi[2]?=?win_size[0]
????if?new_roi[3]?>?win_size[1]:
????????new_roi[3]?=?win_size[1]
????return?tuple(new_roi)
while(True):
????clo
- 上一篇:100個經(jīng)典Python
- 下一篇:復旦大學人工智能N-Queens答案
評論
共有 條評論