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

  • 大小: 36.08M
    文件類型: .7z
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2023-07-28
  • 語言: 其他
  • 標(biāo)簽: 其他??

資源簡介

基于OpenMV與STM32的尋球小車.7z

資源截圖

代碼片段和文件信息

#2018.8.2
import?sensor?image?time??pyb
from?pyb?import?UART
from?pyb?import?Timer
from?pyb?import?LED
import?json

led?=?pyb.LED(3)?#?Red?LED?=?1?Green?LED?=?2?Blue?LED?=?3?IR?LEDs?=?4.
thresholds?=?[(27?67?19?91?45?76)?#?紅色
??????????????#(21?75?3?-38?34?68)?#?綠色
??????????????(27?90?-3?-28?31?125)
??????????????(0?30?0?64?-128?0)]??#?generic_blue_thresholds
threshold_index?=?1?#?0?for?red?1?for?gre9en?2?for?blue


sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)???#320*240
sensor.skip_frames(time?=?100)
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()
uart?=?UART(3?115200)
uart.init(115200?bits=8?parity=None?stop=1?timeout_char=1000)?#?使用給定參數(shù)初始化

def?tick(timer):????????????#?we?will?receive?the?timer?object?when?being?called
????global?data
????if?blobs:
????????print(“Find“)
????????print(‘you?send:‘output_str)
????????uart.write(data)


tim?=?Timer(4?freq=10)??????#?create?a?timer?object?using?timer?4?-?trigger?at?1Hz
tim.callback(tick)??????????#?set?the?callback?to?our?tick?function


def?find_max(blobs):
????max_size=0
????for?blob?in?blobs:
????????if?blob[2]*blob[3]?>?max_size:
????????????max_blob=blob
????????????max_size?=?blob[2]*blob[3]
????return?max_blob

def?Uart_Receive():???#UART接收?改變框小球的顏色閾值
????global?threshold_index
????if?uart.any():
????????temp_data?=?uart.readchar()
????????if?temp_data==0:???#紅色
???????????threshold_index=0

???????????print(temp_datathreshold_index)
????????elif?temp_data==1:
???????????threshold_index=1
???????????print(temp_datathreshold_index)


while(True):
????clock.tick()
????img?=?sensor.snapshot()
????Uart_Receive()
????blobs?=?img.find_blobs([thresholds[threshold_index]])
????if?blobs:

????????max_blob?=?find_max(blobs)
????????b?=?max_blob[0]?#方框元組
????????L?=?(max_blob[2]+max_blob[3])/2
????????l=int(1000/L)
????????#x_error?=?max_blob[5]-img.width()/2???#求橫向偏差
????????x_error?=?max_blob[5]-img.width()/2

????????img.draw_rectangle(max_blob[0:4])????????#?畫矩形
????????img.draw_cross(max_blob[5]?max_blob[6])?#?畫十字

????????#發(fā)送?小球的(xyln)
????????#x為橫坐標(biāo),y為縱坐標(biāo),l為粗略的距離,n為小球顏色(0:紅?1:綠)
????????output_str=“%d%d%d%d“?%?(max_blob.cx()max_blob.cy()lthreshold_index)?#10進(jìn)制字符包
????????checkout=0xAA+0x55+0x07+int(max_blob.cx()/2)+max_blob.cy()+l+threshold_index
????????data?=?bytearray([0xAA0x550x07int(max_blob.cx()/2)max_blob.cy()lthreshold_index0x000x00checkout])#轉(zhuǎn)成16進(jìn)制
????????#uart.write(data)
????????time.sleep(1)
????????led.on()
????else:
????????print(“NO?FIND“)
????????data?=?bytearray([0xAA0x550x070x000x000x000x000x000x000x06])
????????uart.write(data)
????????led.off()




評論

共有 條評論