Lvpizz
发表于 2023-10-9 15:10:22
图片如下
Lvpizz
发表于 2023-10-9 15:10:49
接上文
Lvpizz
发表于 2023-10-9 15:11:16
再接上文
Lvpizz
发表于 2023-10-9 15:11:58
YOLO2训练代码
# generated by maixhub, tested on maixpy3 v0.4.8
# copy files to TF card and plug into board and power on
import sensor, image, lcd, time
import KPU as kpu
import gc, sys
input_size = (224, 224)
labels = ['FlightPark']
anchors =
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=input_size)
img.draw_string(0, 10, err_str, scale=1, color=(0xff,0x00,0x00))
lcd.display(img)
def main(anchors, labels = None, model_addr="/sd/Models/m.kmodel", sensor_window=input_size, 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)
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
kpu.init_yolo2(task, 0.5, 0.3, 5, anchors) # threshold:, nms_value:
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, pos, "%s : %.2f" %(labels, obj.value()), scale=2, color=(255, 0, 0))
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:
# main(anchors = anchors, labels=labels, model_addr=0x300000, lcd_rotation=0)
main(anchors = anchors, labels=labels, model_addr="/sd/Models/Parking.kmodel")
except Exception as e:
sys.print_exception(e)
lcd_show_except(e)
finally:
gc.collect()
Lvpizz
发表于 2023-10-9 15:13:27
飞控代码主函数(来自匿名凌霄)
/******************** (C) COPYRIGHT 2017 ANO Tech ********************************
* 作者 :匿名科创
* 官网 :www.anotc.com
* 淘宝 :anotc.taobao.com
* 技术Q群 :190169595
* 描述 :主循环
**********************************************************************************/
#include "SysConfig.h"
#include "Ano_Scheduler.h"
#include "Drv_Uart.h"
#include "My_main.h"
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
while (1)
{
//当系统出错后,会进入这个死循环
}
}
#endif
//=======================================================================================
//=======================================================================================
int main(void)
{
//进行所有设备的初始化,并将初始化结果保存
All_Init();
//调度器初始化,系统为裸奔,这里人工做了一个时分调度器
Scheduler_Setup();
Process_Init();
//用户初始化
UWBMapInit(); //UWB地图初始化
IMU_KalmanInit(); //IMU卡尔曼滤波器初始化
PTZ.Angle1 =0x69;PTZ.Angle2 =0x30;
UWB_ENABLE;
while (1)
{
//运行任务调度器,所有系统功能,除了中断服务函数,都在任务调度器内完成
Scheduler_Run();
}
}
/******************* (C) COPYRIGHT 2014 ANO TECH *****END OF FILE************/
sqj
发表于 2024-7-7 23:14:34
{:5_300:}感谢