日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

openmv串口发送数据_关于arduino和openmv串口通信的问题

發(fā)布時(shí)間:2023/12/2 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 openmv串口发送数据_关于arduino和openmv串口通信的问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

#openmv的代碼

import sensor, image, time

import json

from pyb import UART

# For color tracking to work really well you should ideally be in a very, very,

# very, controlled enviroment where the lighting is constant...

blue_threshold? ?= ( 0, 60, -20, 64, -128, 0)

# You may need to tweak the above settings for tracking green things...

# Select an area in the Framebuffer to copy the color settings.

#p4_10,p5_11,gnd_gnd

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)

'''

擴(kuò)寬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)

K=680 #the value should be measured

while(True):

clock.tick() # Track elapsed milliseconds between snapshots().

img = sensor.snapshot() # Take a picture and return the image.

blobs = img.find_blobs([blue_threshold], area_threshold=150)

if blobs:

#如果找到了目標(biāo)顏色

data=[]

#print(blobs)

for blob in blobs:

#迭代找到的目標(biāo)顏色區(qū)域

b = blob[0]

is_circle = False

max_circle = None

max_radius = -1

new_roi = expand_roi(blob.rect())

Lm = (blob[2]+blob[3])/2

length = K/Lm

length = str(length)

length = float(length)

for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, roi=new_roi):

is_circle = True

# img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255))

if c.r() > max_radius:

max_radius = c.r()

max_circle = c

if is_circle:

# 如果有對(duì)應(yīng)顏色的圓形 標(biāo)記外框

# Draw a rect around the blob.

img.draw_rectangle(new_roi) # rect

img.draw_rectangle(blob.rect()) # rect

#用矩形標(biāo)記出目標(biāo)顏色區(qū)域

img.draw_cross(blob[5], blob[6]) # cx, cy

img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r(), color = (0, 255, 0))

img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r() + 1, color = (0, 255, 0))

data.append((max_circle.x(),max_circle.y(),length))

#data.append(length)

data_out = json.dumps(set(data))

uart.write(data_out +'\n')

print('you send:',data_out)

else:

print("not found!")

else:

print("not found!")

#print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while

# connected to your computer. The FPS should increase once disconnected.

總結(jié)

以上是生活随笔為你收集整理的openmv串口发送数据_关于arduino和openmv串口通信的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。