資源簡介
openMV串口通訊_(2).zip

代碼片段和文件信息
import?sensor?image?time?math
from?pyb?import?UART
import?json
import?ustruct
#white_threshold_01?=?((95?100?-18?3?-8?4));??#白色閾值
red_threshold_01?=?((35?100?41?77?24?59));
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()
uart?=?UART(3115200)???#定義串口3變量
uart.init(115200?bits=8?parity=None?stop=1)?#?init?with?given?parameters
def?find_max(blobs):????#定義尋找色塊面積最大的函數(shù)
????max_size=0
????for?blob?in?blobs:
????????if?blob.pixels()?>?max_size:
????????????max_blob=blob
????????????max_size?=?blob.pixels()
????return?max_blob
def?sending_data(cxcy):
????global?uart;
????#frame=[0x2C18cx%0xffint(cx/0xff)cy%0xffint(cy/0xff)0x5B];
????#data?=?bytearray(frame)
????data?=?ustruct.pack(“ ???????????????????0x2C???????????????????????#幀頭1
???????????????????0x12???????????????????????#幀頭2
???????????????????int(cx)?#?up?sample?by?4????#數(shù)據(jù)1
???????????????????int(cy)?#?up?sample?by?4????#數(shù)據(jù)2
???????????????????0x5B)
????uart.write(data);???#必須要傳入一個(gè)字節(jié)數(shù)組
def?recive_data():
????global?uart
????if?uart.any():
????????tmp_data?=?uart.readline();
????????print(tmp_data)
#mainloop
while(True):
????clock.tick()?#?Track?elapsed?milliseconds?between?snapshots().
????img?=?sensor.snapshot()?#?Take?a?picture?and?return?the?image.
????#??pixels_threshold=100?area_threshold=100
????blobs?=?img.find_blobs([red_threshold_01]?area_threshold=150);
????cx=0;cy=0;
????if?blobs:
????????#如果找到了目標(biāo)顏色
????????max_b?=?find_max(blobs);
????????#?Draw?a?rect?around?the?blob.
????????img.draw_rectangle(max_b[0:4])?#?rect
????????#用矩形標(biāo)記出目標(biāo)顏色區(qū)域
????????img.draw_cross(max_b[5]?max_b[6])?#?cx?cy
????????img.draw_cross(160?120)?#?在中心點(diǎn)畫標(biāo)記
????????#在目標(biāo)顏色區(qū)域的中心畫十字形標(biāo)記
????????cx=max_b[5];
????????cy=max_b[6];
????????img.draw_line((160120cxcy)?color=(127));
????????#img.draw_string(160120?“(%d?%d)“%(160120)?color=(127));
????????img.draw_string(cx?cy?“(%d?%d)“%(cxcy)?color=(127));
????sending_data(cxcy);?#發(fā)送點(diǎn)位坐標(biāo)
????recive_data();
????#time.sleep(1000)
#pack各字母對(duì)應(yīng)類型
#x???pad?byte????????no?value????????????1
#c???char????????????string?of?length?1??1
#b???signed?char?????integer?????????????1
#B???unsigned?char???integer?????????????1
#????_Bool???????????bool????????????????1
#h???short???????????integer?????????????2
#H???unsigned?short??integer?????????????2
#i???int?????????????integer?????????????4
#I???unsigned?int????integer?or?long?????4
#l???long????????????integer?????????????4
#L???unsigned?long???long????????????????4
#q???long?long???????long????????????????8
#Q???unsilong?long???long????????????????8
#f???float???????????float???????????????4
#d???double??????????float?????????????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????3352??2019-04-21?20:45??串口與STM32通訊.py
?????目錄???????????0??2019-08-06?12:34??可見光定位\
?????目錄???????????0??2019-08-06?12:34??可見光定位\HARDWARE\
?????文件????????3382??2012-09-04?11:32??可見光定位\HARDWARE\i2c.c
?????文件?????????316??2019-03-21?14:16??可見光定位\HARDWARE\i2c.h
?????文件???????16921??2019-04-21?20:14??可見光定位\HARDWARE\system.c
?????文件????????1520??2019-08-06?13:26??可見光定位\HARDWARE\system.h
?????目錄???????????0??2019-08-06?12:34??可見光定位\Inc\
?????文件???????24057??2012-06-06?21:27??可見光定位\Inc\fonts.H
?????文件????????6166??2012-06-06?21:27??可見光定位\Inc\lcd.h
?????文件????????3288??2012-06-06?13:27??可見光定位\Inc\stm32f10x_conf.h
?????文件????????1989??2012-06-06?13:27??可見光定位\Inc\stm32f10x_it.h
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\CoreSupport\
?????文件???????17273??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\CoreSupport\core_cm3.c
?????文件???????85714??2019-03-23?18:54??可見光定位\Libraries\CMSIS\CM3\CoreSupport\core_cm3.h
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\
?????文件???????26297??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\Release_Notes.html
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\
?????目錄???????????0??2019-08-06?12:34??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\
?????文件???????15766??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_cl.s
?????文件???????15503??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_hd.s
?????文件???????15692??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_hd_vl.s
?????文件???????12376??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_ld.s
?????文件???????13656??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_ld_vl.s
?????文件???????12765??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_md.s
?????文件???????14073??2012-06-06?13:27??可見光定位\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_md_vl.s
............此處省略240個(gè)文件信息
評(píng)論
共有 條評(píng)論