我的设计是用迪文串口屏实现与K210的互动,实现人脸识别,今天拆腾一天,终于把图像稳定传输到迪文屏了:
【要点】迪文屏需要jpeg的文件流发送,网上搜了一天,最后还是在官方资料上面找到了:
最后的测试程序:
# Hello World Example
#
# Welcome to the MaixPy IDE!
# 1. Conenct board to computer
# 2. Select board at the top of MaixPy IDE: `tools->Select Board`
# 3. Click the connect buttion below to connect board
# 4. Click on the green run arrow button below to run the script!
import sensor, image, time, lcd
from machine import UART, Timer
from fpioa_manager import fm
fm.register(6,fm.fpioa.UART1_RX, force=True)
fm.register(7,fm.fpioa.UART1_TX, force=True)
import os
import gc, sys
import uio
line_len = 240
add_len = 120
# 数据头地址
# 数据地址
show = [[0x5A, 0xA5, 0x07, 0x82, 0x10, 0x11, 0x00, 0x50, 0x00, 0x70],
[0x5A, 0xA5, 0x07, 0x82, 0x10, 0x51, 0x00, 0x50, 0x00, 0x70]]
hide = [[0x5A, 0xA5, 0x07, 0x82, 0x10, 0x11, 0x0A, 0x10, 0xA0, 0x70],
[0x5A, 0xA5, 0x07, 0x82, 0x10, 0x51, 0x0A, 0x10, 0xA0, 0x70]]
foot = [[0x5A, 0xA5, 0x07, 0x82, 0x7F, 0xFE, 0x5A, 0xA5, 0x80, 0x00],
[0x5A, 0xA5, 0x07, 0x82, 0xBF, 0xFE, 0x5A, 0xA5, 0xC0, 0x00]]
var_index = 0
count = 0
debug = 0
uart = UART(UART.UART1, 460800, read_buf_len=4096)
#uart.write('start...')
lcd.init(freq=15000000)
sensor.reset() # Reset and initialize the sensor. It will
# run automatically, call sensor.run(0) to stop
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
sensor.set_vflip(0) #重直
sensor.set_hmirror(0)
def send_data(uart, str_hex_send):
result = uart.write(str_hex_send)
# time.sleep(0.01)
def send_img(img,var_index):
img = img.compressed(quality=50)
hex_data = img.to_bytes()
len_hex = len(hex_data)
if len_hex % line_len > 0:
for i in range(0, line_len - len_hex % line_len):
hex_data += b'\x00'
len_hex = len(hex_data)
send_data(uart, bytes(foot[var_index]))
if var_index == 0:
addr_data = 0x8000
send_data(uart, bytes(hide[0]))
else:
addr_data = 0xC000
send_data(uart, bytes(hide[1]))
for i in range(0, len_hex // line_len):
if debug:
print("chunk %d:" % (i + 1), end="")
str_hex = [0x5A, 0xA5, 0xF3, 0x82]
addr_hexVal = addr_data + i * add_len
addr_hexVal_l = addr_hexVal % 0x100
addr_hexVal_h = addr_hexVal // 0x100
str_hex.append(addr_hexVal_h)
str_hex.append(addr_hexVal_l)
str_hex_send = bytes(str_hex) + hex_data[(i * line_len):((i + 1) * line_len)]
#print(str_hex_send)
send_data(uart, str_hex_send)
#time.sleep(0.3)
if var_index == 0:
send_data(uart, bytes(foot[0]))
send_data(uart, bytes(show[0]))
send_data(uart, bytes(hide[1]))
else:
send_data(uart, bytes(foot[1]))
send_data(uart, bytes(show[1]))
send_data(uart, bytes(hide[0]))
while(True):
var_index = count % 2
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
lcd.display(img) # Display on LCD
send_img(img,var_index)
print(clock.fps()) # Note: MaixPy's Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.
if uart.any():
read_data = uart.read()
if read_data:
uart.write(read_data)
#print(read_data)
count = count + 1
这效果还不错,帧率能达到多少?
引用: lugl4313820 发表于 2022-7-11 11:10 人脸不识别时可以跑30帧
是在芯片上进行人脸识别,然后将图像数据传输到迪文屏上?
引用: wangerxian 发表于 2022-7-11 11:27 是在芯片上进行人脸识别,然后将图像数据传输到迪文屏上?
是在k210上识别的,迪文屏作为展示,信息的输入输出。但是K210联网有点小麻烦,还有就是内存是硬伤!
引用: lugl4313820 发表于 2022-7-11 17:34 是在k210上识别的,迪文屏作为展示,信息的输入输出。但是K210联网有点小麻烦,还有就是内存是硬伤!
这种带图片流视频流的内存一定要大,它这个内存多大?
引用: wangerxian 发表于 2022-7-11 17:37 这种带图片流视频流的内存一定要大,它这个内存多大?
可用内存6Mbit
迪文屏的最多支持32KB的图片,图片大了就会死机,重启。
引用: lugl4313820 发表于 2022-7-11 17:42 可用内存6Mbit
6Mbit RAM?
应该是的,一共有8M,2M分给了机器算法,好象也可以分给CPU。