logo

openmv接受数据 很慢

2018-06-03 16:20
5
_13531193294

openmv用UART read后速度变得很慢,如何解决

I
网红小智智 星瞳科技

你是想发送数据?还是接收数据?

2018-06-03 16:28
5
_13531193294

@kidswong999 接收数据,发送数据的时候没有这么慢

2018-06-03 16:50
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/pyb.UART.html#pyb.UART.read

read()里面要加入参数的,比如read(1)会读入一个byte,如果缓冲区没有这个数据,会等待大概1s。

2018-06-03 17:35
5
_13531193294

@kidswong999 试过改了很多参数了但是还是卡,就是出来的视频一卡一卡的

import sensor, image, time

from pyb import UART

from pyb import Servo

import json

#设置阈值

red_threshold_01 = (31, 54, 53, 81, 76, 48) #近阈值

red_threshold_02 = ( 8, 57, 23, 78, 16, 64) #远阈值

def dj(b):

step=0

x = b #将b[5]赋值给x

c=abs(80-b) #把cx与中心x值的差赋值给c

#下面为简单的识别舵机运动算法,具体根据实际调试修改参数,可以自行优化

if x > 81:

step=step-int(x-80)

if -800 > step:

step=step+int(x-80)

if x < 79:

step=step+int(80-x)

if step > 900:

step=step-int(80-x)

s1.pulse_width(1550-step) #舵机旋转角度

d=1550-step

print('偏转量 :',step)

#若偏离程度较小则小车加速

if c < 1:

if d == 1550:

uart.write('fast\r')

print('jia su')

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QQVGA)

sensor.set_auto_whitebal(False)

sensor.set_auto_gain(False) #关闭自动亮度增益,太暗了可以自行打开

sensor.set_contrast(3) #设置对比度为3

sensor.set_brightness(-3) #设置亮度最低

sensor.set_auto_exposure(False)

sensor.skip_frames(10)

clock = time.clock()

#用于灭灯时关闭图像识别(dj函数),1为开启,0为关闭

a=1 #默认为开启

s1 = Servo(1) #P7 舵机

s1.pulse_width(1100) #舵机初始化到中间位置

#设置感兴趣区域大小

ROI=(0,0,160,120)

uart = UART(3, 115200)

while(True):

img = sensor.snapshot()

#当读入ardiuo发送过来正在灭灯的信息时,dj函数关闭

if uart.readchar(1):

a=0

#读入ardiuo发送过来结束灭灯的信息时,dj函数开启

if uart.readchar(2):

a=1

#设置感兴趣区域

statistics=img.get_statistics(roi=ROI)

#分阈值查找色块,并返回数组

blobs1 = img.find_blobs([red_threshold_01],x_stride=8, y_stride=5,roi=ROI,area_threshold=40)

blobs2 = img.find_blobs([red_threshold_02],x_stride=1, y_stride=1,roi=ROI,area_threshold=1)

#色块在近处

if blobs1:

for b1 in blobs1:

if b1[2]<40 and b1[3]<30:

img.draw_rectangle(b1.rect(),color=(255,255,0)) #根据色块大小画黄色框

img.draw_cross(b1.cx(), b1.cy(),color=(255,255,0)) #根据色块中心点画黄色十字架

if a==1:

dj(b1.cx())

print('jin')

print('b1[5]=',b1[5])

#色块不在近处但在远处

else:

if blobs2:

for b2 in blobs2:

if b2[2]>1 and b2[3]>1:

img.draw_rectangle(b2.rect(),color=(255,255,255)) #根据色块大小画白色框

img.draw_cross(b2.cx(), b2.cy(),color=(255,255,255)) #根据色块中心点画白色十字架

if a==1:

dj(b2[5])

print('yuan')

print('b2[5]=',b2[5])

就这个代码,通过识别串口有没有信号来判断dj函数是否关闭开启,但是传到电脑视频画面一卡一卡的

2018-06-03 17:45
5
_13531193294

@13531193294 已经是有在里面加参数了,但不知道为什么还是很慢

2018-06-03 19:17
I
网红小智智 星瞳科技

你应该先判断串口是否有数据,比如

if uart.any():
    uart.read(1)