完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
问题:在使用 K210 时使用官方介绍使用的八位通信,发送的数据为中需要十六位的数据,因为数据可能百位。
解决方法:将数据打包后发送。 一下为打包函数: def sending_data(cx,cy,ch): global uart; #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B]; #data = bytearray(frame) data = ustruct.pack(" 0x12, #帧头2 int(cx), # up sample by 4 #数据1 int(cy), # up sample by 4 #数据2 int(ch), 0x5B) uart = UART(UART.UART1, 115200, 8, 1, 0, timeout=1000, read_buf_len=4096) uart.write(data); #必须要传入一个字节数组 MAIX BIT K210端完整代码 # object detector boot.py # generated by maixhub.com import sensor, image, lcd, time import KPU as kpu import gc, sys import ustruct #LED from fpioa_manager import fm from Maix import GPIO io_led_red = 13 io_led_bule = 14 io_led_green = 12 fm.register(io_led_red, fm.fpioa.GPIO0) fm.register(io_led_bule, fm.fpioa.GPIO1) fm.register(io_led_green, fm.fpioa.GPIO2) led_r=GPIO(GPIO.GPIO0, GPIO.OUT) led_b=GPIO(GPIO.GPIO1, GPIO.OUT) led_g=GPIO(GPIO.GPIO2, GPIO.OUT) #串口 from fpioa_manager import fm from machine import UART # need your connect hardware IO 10/11 to loopback fm.register(10, fm.fpioa.UART1_TX, force=True) fm.register(9, fm.fpioa.UART1_RX, force=True) def sending_data(cx,cy,ch): global uart; #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B]; #data = bytearray(frame) data = ustruct.pack(" 0x12, #帧头2 int(cx), # up sample by 4 #数据1 int(cy), # up sample by 4 #数据2 int(ch), 0x5B) uart = UART(UART.UART1, 115200, 8, 1, 0, timeout=1000, read_buf_len=4096) uart.write(data); #必须要传入一个字节数组 def lcd_show_except(e): import uio err_str = uio.StringIO() sys.print_exception(e, err_str) err_str = err_str.getvalue() img = image.Image(size=(224,224)) img.draw_string(0, 10, err_str, scale=1, color=(0xff,0x00,0x00)) lcd.display(img) def main(anchors, labels = None, model_addr="/sd/m.kmodel", sensor_window=(240, 240), lcd_rotation=0, sensor_hmirror=False, sensor_vflip=False): sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.set_windowing(sensor_window) sensor.set_hmirror(sensor_hmirror) sensor.set_vflip(sensor_vflip) sensor.run(1) lcd.init(type=1) lcd.rotation(lcd_rotation) lcd.clear(lcd.WHITE) #uart = UART(UART.UART1, 500000, 8, 1, 0, timeout=1000, read_buf_len=4096) #白灯开机指示 led_r.value(0) led_b.value(0) led_g.value(0) if not labels: with open('labels.txt','r') as f: exec(f.read()) if not labels: print("no labels.txt") img = image.Image(size=(320, 240)) img.draw_string(90, 110, "no labels.txt", color=(255, 0, 0), scale=2) lcd.display(img) return 1 try: img = image.Image("startup.jpg") lcd.display(img) except Exception: img = image.Image(size=(320, 240)) img.draw_string(90, 110, "loading model...", color=(255, 255, 255), scale=2) lcd.display(img) try: task = None task = kpu.load(model_addr) kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:[0,1], nms_value: [0, 1] while(True): img = sensor.snapshot() t = time.ticks_ms() objects = kpu.run_yolo2(task, img) t = time.ticks_ms() - t if objects: for obj in objects: pos = obj.rect() img.draw_rectangle(pos) img.draw_string(pos[0], pos[1], "%s : %.2f" %(labels[obj.classid()], obj.value()), scale=2, color=(255, 0, 0)) #串口发送数据 objx = (obj.x()+obj.w())/2 objy = (obj.y()+obj.h())/2 #uart.write("AB%sD%dE%dF" %(labels[obj.classid()], objx, objy)) #print("AB%sD%dE%dF" %(labels[obj.classid()], objx, objy)) if labels[obj.classid()] == "WWW": sending_data(1,objx,objy) led_r.value(0) if labels[obj.classid()] == "CAR": sending_data(2,objx,objy) led_b.value(0) if labels[obj.classid()] == "HHH": sending_data(3,objx,objy) led_g.value(0) else: sending_data(0,0,0) led_r.value(1) led_b.value(1) led_g.value(1) #print(00000) img.draw_string(0, 200, "t:%dms" %(t), scale=2, color=(255, 0, 0)) lcd.display(img) except Exception as e: raise e finally: if not task is None: kpu.deinit(task) if __name__ == "__main__": try: labels = ["CAR", "WWW", "HHH"] anchors = [5.5, 6.90625, 5.0, 5.0, 4.1875, 4.125, 6.875, 5.25, 10.5, 9.9375] # main(anchors = anchors, labels=labels, model_addr=0x300000, lcd_rotation=0) main(anchors = anchors, labels=labels, model_addr="/sd/m.kmodel") except Exception as e: sys.print_exception(e) lcd_show_except(e) finally: gc.collect() 单片机端的数据处理代码 //Maix字节处理 void Maix_Byte_Get(u8 bytedata){ static u8 rec_sta; //u8 check_val=0; maix_buf[rec_sta] = bytedata; if(rec_sta==0) { if(bytedata==0x2C) { rec_sta=1; } else { rec_sta=0; } } else if(rec_sta==1) { if(bytedata==0x12) { rec_sta=2; } else { rec_sta=0; } } else if(rec_sta==2) { rec_sta=3; } else if(rec_sta == 3) { maix.clas = maix_buf[3]<<8|maix_buf[2]; rec_sta=4; } else if(rec_sta ==4) { rec_sta=5; } else if(rec_sta == 5) { maix.pos_x = maix_buf[5]<<8|maix_buf[4]; rec_sta=6; } else if(rec_sta == 6) { rec_sta=7; } else if(rec_sta == 7) { maix.pos_y = maix_buf[7]<<8|maix_buf[6]; rec_sta = 8; } else if(rec_sta == 8) { rec_sta = 9; } else if(rec_sta ==9) { rec_sta = 0; } } |
|
|
|
只有小组成员才能发言,加入小组>>
3275 浏览 9 评论
2950 浏览 16 评论
3454 浏览 1 评论
8982 浏览 16 评论
4043 浏览 18 评论
1092浏览 3评论
564浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
561浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2297浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1854浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 05:24 , Processed in 0.992296 second(s), Total 79, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号