91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2023-12-27
  • 語言: Python
  • 標簽: openmv??

資源簡介

用于openmv對顏色進行識別,并且可以把識別物體的坐標發送給單片機處理。

資源截圖

代碼片段和文件信息

#?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

from?pyb?import?Pin

from?pyb?import?UART

import?struct


#?For?color?tracking?to?work?really?well?you?should?ideally?be?in?a?very?very
#?very?controlled?enviroment?where?the?lighting?is?constant...
#green_threshold???=?(???0???80??-70???-10???-0???30)
#green_threshold???=?(???70???100??-40???-20???15???35)
green_threshold???=?(???60???100??-75???-20???20???40)
#設置綠色的閾值,括號里面的數值分別是L?A?B?的最大值和最小值(minL?maxL?minA
#?maxA?minB?maxB),LAB的值在圖像左側三個坐標圖中選取。如果是灰度圖,則只需
#設置(min?max)兩個數字即可。
#red_threshold?=?(?15?50?40?80?20?60)
red_threshold?=?(?45?70?40?80?20?60)
#設置紅色閾值
yellow_threshold???=?(???65???100??-30???10???20???80)
blue_threshold???=?(???25??75??-10???40???-70???-40)
#black_threshold???=?(???10??20??-10???10???0???10)
black_threshold???=?(???5??25??-15???0???-5???15)

#?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?QQVGA?for?speed.
sensor.skip_frames(10)?#?Let?new?settings?take?affect.
sensor.set_auto_whitebal(False)?#?turn?this?off.
#關閉白平衡。白平衡是默認開啟的,在顏色識別中,需要關閉白平衡。
clock?=?time.clock()?#?Tracks?FPS.

uart?=?UART(3?115200)

time.sleep(100)



while(True):
????clock.tick()?#?Track?elapsed?milliseconds?between?snapshots().
????img?=?sensor.snapshot()?#?Take?a?picture?and?return?the?image.

????green_blobs?=?img.find_blobs([green_threshold])
????#find_blobs(thresholds?invert=False?roi=Auto)thresholds為顏色閾值,是一個元組,需要用括號[?]括起來。invert=1反轉顏色閾值,invert=False默認不反轉。roi設置顏色識別的視野區域,roi是一個元組,?roi?=?(x?y?w?h),代表從左上頂點(xy)開始的寬為w高為h的矩形區域,roi不設置的話默認為整個圖像視野。這個函數返回一個列表,[0]代表識別到的目標顏色區域左上頂點的x坐標,[1]代表左上頂點y坐標,[2]代表目標區域的寬,[3]代表目標區域的高,[4]代表目標區域像素點的個數,[5]代表目標區域的中心點x坐標,[6]代表目標區域中心點y坐標,[7]代表目標顏色區域的旋轉角度(是弧度值,浮點型,列表其他元素是整型),[8]代表與此目標區域交叉的目標個數,[9]代表顏色的編號(它可以用來分辨這個區域是用哪個顏色閾值threshold識別出來的)。
????if?green_blobs:
????#如果找到了目標顏色
????????for?b?in?green_blobs:
????????#迭代找到的目標顏色區域
????????????#?Draw?a?rect?around?the?blob.
????????????img.draw_rectangle(b[0:4]color=(02550))?#?rect
????????????#用綠色矩形標記出目標顏色區域
????????????img.draw_cross(b[5]?b[6])?#?cx?cy
????????

評論

共有 條評論