logo

请问为什么我一与stm32建立起连接并且找到目标就开始掉帧呢

2020-01-19 13:23
M
lmrz
image
555dbaf9-5d9c-49f0-82e9-f59fc692a50b.jpg
c sensor, image, time, math, struct,random
from pyb import UART

red = (49, 97, -31, 67, 52, 94)
red1 = (39, 100, 20, 127, -128, 127)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 10)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)

clock = time.clock()

# 串口初始化
uart = UART(4, 115200)
uart.init(115200, bits=8, parity=None, stop=1)


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 blob_sort(blobs):
    new_blobs = []
    for i in range(0,len(blobs)):
        max_blob = find_max(blobs)
        new_blobs.append(blobs.pop(blobs.index(max_blob)))
    return new_blobs

def send_message(blob):
    #for blob in blobs:
        x = int((blob.cx())*128/320)
        y = int((blob.cy())*60/240)
        z = int(blob.area()*(128*60)/(320*240))
        num = 1
        dateout = struct.pack("<bbhhhb",          # 打包数据
                                0xaa,             # 帧头1
                                0xae,             # 帧头2
                                x,                # 数据1
                                y,                # 数据2
                                num,              # 数据3
                                0xff)             # 帧尾
        uart.write(dateout + '\n')
        print(dateout)

#将获取到的色块的坐标变为json json.dumps([max_blob.cx(),max_blob.cy()])
while(True):
    Location = []
    clock.tick()
    img = sensor.snapshot()
    red_blobs = img.find_blobs([red1],area_threshold=10,pixels_threshold=20)
    if red_blobs:
        #new_blobs = blob_sort(red_blobs)              #对色块的大小进行排序
        #send_message(new_blobs)                       #获取排序后色块的信息并依次发送至muc
        max_blob = find_max(red_blobs)
        img.draw_rectangle(max_blob.rect())
        img.draw_cross(max_blob.cx(), max_blob.cy())
        send_message(max_blob)
2020-02-08 14:35
I
网红小智智 星瞳科技

什么叫做调帧?具体什么现象。