From bea5eda2e0adbfea8970c3fed45af170587d58f3 Mon Sep 17 00:00:00 2001 From: chunyexixiaoyu <834670833@qq.com> Date: Thu, 14 Oct 2021 11:21:23 +0800 Subject: [PATCH] APP_Framework/Applications:update face detect and instrusion detect ,the version had been tested for long time,and its's stable. At the same time,rt-thread and kendryte-sdk-source both sub module must be updated. --- .../knowing_app/face_detect/face_detect.c | 34 ++++++++++------- .../knowing_app/instrusion_detect/human.json | 2 +- .../instrusion_detect/instrusion_detect.c | 37 ++++++++++++------- .../transform_layer/rtthread/transform.h | 7 ++++ Ubiquitous/RT_Thread/bsp/k210/rtconfig.h | 2 +- 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/APP_Framework/Applications/knowing_app/face_detect/face_detect.c b/APP_Framework/Applications/knowing_app/face_detect/face_detect.c index 6eca10910..77e4e3efa 100644 --- a/APP_Framework/Applications/knowing_app/face_detect/face_detect.c +++ b/APP_Framework/Applications/knowing_app/face_detect/face_detect.c @@ -7,7 +7,7 @@ #define STACK_SIZE (128 * 1024) #define JSON_FILE_PATH "/kmodel/detect.json" #define JSON_BUFFER_SIZE (4 * 1024) - +static dmac_channel_number_t dma_ch = DMAC_CHANNEL_MAX; // params from json static float anchor[ANCHOR_NUM * 2] = {}; static int net_output_shape[3] = {}; @@ -184,23 +184,23 @@ void face_detect() } _ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]}; ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso); - showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2); + showbuffer = (unsigned char *)rt_malloc_align(sensor_output_size[0] * sensor_output_size[1] * 2,64); if (NULL == showbuffer) { close(g_fd); printf("showbuffer apply memory fail !!"); return; } - kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3); + kpurgbbuffer = (unsigned char *)rt_malloc_align(net_input_size[0] * net_input_size[1] * 3,64); if (NULL == kpurgbbuffer) { close(g_fd); - free(showbuffer); + rt_free_align(showbuffer); printf("kpurgbbuffer apply memory fail !!"); return; } model_data = (unsigned char *)malloc(kmodel_size + 255); if (NULL == model_data) { - free(showbuffer); - free(kpurgbbuffer); + rt_free_align(showbuffer); + rt_free_align(kpurgbbuffer); close(g_fd); printf("model_data apply memory fail !!"); return; @@ -296,27 +296,33 @@ static void *thread_face_detcet_entry(void *parameter) pthread_exit(NULL); return NULL; } + if (dmalock_sync_take(&dma_ch, 2000)) + { + printf("Fail to take DMA channel"); + } kpu_run_kmodel(&face_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL); while (!g_ai_done_flag) ; + dmalock_release(dma_ch); float *output; size_t output_size; kpu_get_output(&face_detect_task, 0, (uint8_t **)&output, &output_size); face_detect_rl.input = output; region_layer_run(&face_detect_rl, &face_detect_info); /* display result */ -#ifdef BSP_USING_LCD + for (int face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) { draw_edge((uint32_t *)showbuffer, &face_detect_info, face_cnt, 0xF800, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0]); - printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", face_cnt, face_detect_info.obj[face_cnt].x1, - face_detect_info.obj[face_cnt].y1, face_detect_info.obj[face_cnt].x2, face_detect_info.obj[face_cnt].y2, - labels[face_detect_info.obj[face_cnt].class_id], face_detect_info.obj[face_cnt].prob); - } - if (0 != face_detect_info.obj_number) printf("\n"); - lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer); + // printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", face_cnt, face_detect_info.obj[face_cnt].x1, + // face_detect_info.obj[face_cnt].y1, face_detect_info.obj[face_cnt].x2, face_detect_info.obj[face_cnt].y2, + // labels[face_detect_info.obj[face_cnt].class_id], face_detect_info.obj[face_cnt].prob); + } +#ifdef BSP_USING_LCD + lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (uint32_t *)showbuffer); + //lcd_show_image(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer); #endif - usleep(1); + usleep(500); if (1 == if_exit) { if_exit = 0; printf("thread_face_detcet_entry exit"); diff --git a/APP_Framework/Applications/knowing_app/instrusion_detect/human.json b/APP_Framework/Applications/knowing_app/instrusion_detect/human.json index 9ef268f5a..feab75aeb 100644 --- a/APP_Framework/Applications/knowing_app/instrusion_detect/human.json +++ b/APP_Framework/Applications/knowing_app/instrusion_detect/human.json @@ -27,7 +27,7 @@ "kmodel_path": "/kmodel/human.kmodel", "kmodel_size": 2713236, "obj_thresh": [ - 0.55 + 0.7 ], "labels": [ "human" diff --git a/APP_Framework/Applications/knowing_app/instrusion_detect/instrusion_detect.c b/APP_Framework/Applications/knowing_app/instrusion_detect/instrusion_detect.c index 5683ec02d..0a48a1841 100644 --- a/APP_Framework/Applications/knowing_app/instrusion_detect/instrusion_detect.c +++ b/APP_Framework/Applications/knowing_app/instrusion_detect/instrusion_detect.c @@ -1,4 +1,5 @@ #include +#include #ifdef LIB_USING_CJSON #include #endif @@ -7,7 +8,9 @@ #define STACK_SIZE (128 * 1024) #define JSON_FILE_PATH "/kmodel/human.json" #define JSON_BUFFER_SIZE (4 * 1024) +static dmac_channel_number_t dma_ch = DMAC_CHANNEL_MAX; +extern void lcd_show_image(int x, int y, int wide, int height,const rt_uint8_t *buf); // params from json static float anchor[ANCHOR_NUM * 2] = {}; static int net_output_shape[3] = {}; @@ -184,23 +187,23 @@ void instrusion_detect() } _ioctl_set_dvp_reso set_dvp_reso = {sensor_output_size[1], sensor_output_size[0]}; ioctl(g_fd, IOCTRL_CAMERA_SET_DVP_RESO, &set_dvp_reso); - showbuffer = (unsigned char *)malloc(sensor_output_size[0] * sensor_output_size[1] * 2); + showbuffer = (unsigned char *)rt_malloc_align(sensor_output_size[0] * sensor_output_size[1] * 2,64); if (NULL == showbuffer) { close(g_fd); printf("showbuffer apply memory fail !!"); return; } - kpurgbbuffer = (unsigned char *)malloc(net_input_size[0] * net_input_size[1] * 3); + kpurgbbuffer = (unsigned char *)rt_malloc_align(net_input_size[0] * net_input_size[1] * 3,64); if (NULL == kpurgbbuffer) { close(g_fd); - free(showbuffer); + rt_free_align(showbuffer); printf("kpurgbbuffer apply memory fail !!"); return; } model_data = (unsigned char *)malloc(kmodel_size + 255); if (NULL == model_data) { - free(showbuffer); - free(kpurgbbuffer); + rt_free_align(showbuffer); + rt_free_align(kpurgbbuffer); close(g_fd); printf("model_data apply memory fail !!"); return; @@ -281,10 +284,12 @@ void instrusion_detect() #ifdef __RT_THREAD_H__ MSH_CMD_EXPORT(instrusion_detect, instrusion detect task); #endif + extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr); + extern void lcd_show_image(int x, int y, int wide, int height,const rt_uint8_t *buf); + extern void lcd_draw_16_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr); static void *thread_instrusion_detect_entry(void *parameter) { - extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t * ptr); printf("thread_instrusion_detect_entry start!\n"); int ret = 0; // sysctl_enable_irq(); @@ -299,31 +304,35 @@ static void *thread_instrusion_detect_entry(void *parameter) pthread_exit(NULL); return NULL; } + if (dmalock_sync_take(&dma_ch, 2000)) + { + printf("Fail to take DMA channel"); + } kpu_run_kmodel(&instrusion_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL); while (!g_ai_done_flag) ; + dmalock_release(dma_ch); float *output; size_t output_size; kpu_get_output(&instrusion_detect_task, 0, (uint8_t **)&output, &output_size); instrusion_detect_rl.input = output; region_layer_run(&instrusion_detect_rl, &instrusion_detect_info); /* display result */ - - for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++) { - // draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800, - // (uint16_t)sensor_output_size[1], - // (uint16_t)sensor_output_size[0]); + for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++) + { + draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800,(uint16_t)sensor_output_size[1],(uint16_t)sensor_output_size[0]); printf("%d: (%d, %d, %d, %d) cls: %s conf: %f\t", instrusion_cnt, instrusion_detect_info.obj[instrusion_cnt].x1, instrusion_detect_info.obj[instrusion_cnt].y1, instrusion_detect_info.obj[instrusion_cnt].x2, instrusion_detect_info.obj[instrusion_cnt].y2, labels[instrusion_detect_info.obj[instrusion_cnt].class_id], instrusion_detect_info.obj[instrusion_cnt].prob); } +#ifdef BSP_USING_LCD + //lcd_show_image(0, 0,(uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0],(unsigned int *)showbuffer); + lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (uint32_t *)showbuffer); +#endif if (0 != instrusion_detect_info.obj_number) { printf("\n"); } -#ifdef BSP_USING_LCD - lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer); -#endif usleep(1); if (1 == if_exit) { if_exit = 0; diff --git a/APP_Framework/Framework/transform_layer/rtthread/transform.h b/APP_Framework/Framework/transform_layer/rtthread/transform.h index 7fa00bcbe..a6db34732 100644 --- a/APP_Framework/Framework/transform_layer/rtthread/transform.h +++ b/APP_Framework/Framework/transform_layer/rtthread/transform.h @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef RT_USING_POSIX_TERMIOS #include #endif @@ -50,6 +51,12 @@ #include #include #endif /* RT_USING_SAL */ +#ifdef BOARD_K210_EVB +#include +#include +#endif + + #ifdef __cplusplus extern "C" { #endif diff --git a/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h b/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h index fb106bb78..c0c6bb3cf 100644 --- a/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h +++ b/Ubiquitous/RT_Thread/bsp/k210/rtconfig.h @@ -18,7 +18,7 @@ #define RT_ALIGN_SIZE 8 #define RT_THREAD_PRIORITY_32 #define RT_THREAD_PRIORITY_MAX 32 -#define RT_TICK_PER_SECOND 80 +#define RT_TICK_PER_SECOND 100 #define RT_USING_OVERFLOW_CHECK #define RT_USING_HOOK #define RT_USING_IDLE_HOOK