forked from xuos/xiuos
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.
This commit is contained in:
parent
43f19c4b55
commit
bea5eda2e0
|
@ -7,7 +7,7 @@
|
||||||
#define STACK_SIZE (128 * 1024)
|
#define STACK_SIZE (128 * 1024)
|
||||||
#define JSON_FILE_PATH "/kmodel/detect.json"
|
#define JSON_FILE_PATH "/kmodel/detect.json"
|
||||||
#define JSON_BUFFER_SIZE (4 * 1024)
|
#define JSON_BUFFER_SIZE (4 * 1024)
|
||||||
|
static dmac_channel_number_t dma_ch = DMAC_CHANNEL_MAX;
|
||||||
// params from json
|
// params from json
|
||||||
static float anchor[ANCHOR_NUM * 2] = {};
|
static float anchor[ANCHOR_NUM * 2] = {};
|
||||||
static int net_output_shape[3] = {};
|
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_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);
|
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) {
|
if (NULL == showbuffer) {
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
printf("showbuffer apply memory fail !!");
|
printf("showbuffer apply memory fail !!");
|
||||||
return;
|
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) {
|
if (NULL == kpurgbbuffer) {
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
free(showbuffer);
|
rt_free_align(showbuffer);
|
||||||
printf("kpurgbbuffer apply memory fail !!");
|
printf("kpurgbbuffer apply memory fail !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||||
if (NULL == model_data) {
|
if (NULL == model_data) {
|
||||||
free(showbuffer);
|
rt_free_align(showbuffer);
|
||||||
free(kpurgbbuffer);
|
rt_free_align(kpurgbbuffer);
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
printf("model_data apply memory fail !!");
|
printf("model_data apply memory fail !!");
|
||||||
return;
|
return;
|
||||||
|
@ -296,27 +296,33 @@ static void *thread_face_detcet_entry(void *parameter)
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return 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);
|
kpu_run_kmodel(&face_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||||
while (!g_ai_done_flag)
|
while (!g_ai_done_flag)
|
||||||
;
|
;
|
||||||
|
dmalock_release(dma_ch);
|
||||||
float *output;
|
float *output;
|
||||||
size_t output_size;
|
size_t output_size;
|
||||||
kpu_get_output(&face_detect_task, 0, (uint8_t **)&output, &output_size);
|
kpu_get_output(&face_detect_task, 0, (uint8_t **)&output, &output_size);
|
||||||
face_detect_rl.input = output;
|
face_detect_rl.input = output;
|
||||||
region_layer_run(&face_detect_rl, &face_detect_info);
|
region_layer_run(&face_detect_rl, &face_detect_info);
|
||||||
/* display result */
|
/* display result */
|
||||||
#ifdef BSP_USING_LCD
|
|
||||||
for (int face_cnt = 0; face_cnt < face_detect_info.obj_number; face_cnt++) {
|
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],
|
draw_edge((uint32_t *)showbuffer, &face_detect_info, face_cnt, 0xF800, (uint16_t)sensor_output_size[1],
|
||||||
(uint16_t)sensor_output_size[0]);
|
(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,
|
// 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,
|
// 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);
|
// 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");
|
#ifdef BSP_USING_LCD
|
||||||
lcd_draw_picture(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);
|
||||||
|
//lcd_show_image(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
|
||||||
#endif
|
#endif
|
||||||
usleep(1);
|
usleep(500);
|
||||||
if (1 == if_exit) {
|
if (1 == if_exit) {
|
||||||
if_exit = 0;
|
if_exit = 0;
|
||||||
printf("thread_face_detcet_entry exit");
|
printf("thread_face_detcet_entry exit");
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
"kmodel_path": "/kmodel/human.kmodel",
|
"kmodel_path": "/kmodel/human.kmodel",
|
||||||
"kmodel_size": 2713236,
|
"kmodel_size": 2713236,
|
||||||
"obj_thresh": [
|
"obj_thresh": [
|
||||||
0.55
|
0.7
|
||||||
],
|
],
|
||||||
"labels": [
|
"labels": [
|
||||||
"human"
|
"human"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <transform.h>
|
#include <transform.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef LIB_USING_CJSON
|
#ifdef LIB_USING_CJSON
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +8,9 @@
|
||||||
#define STACK_SIZE (128 * 1024)
|
#define STACK_SIZE (128 * 1024)
|
||||||
#define JSON_FILE_PATH "/kmodel/human.json"
|
#define JSON_FILE_PATH "/kmodel/human.json"
|
||||||
#define JSON_BUFFER_SIZE (4 * 1024)
|
#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
|
// params from json
|
||||||
static float anchor[ANCHOR_NUM * 2] = {};
|
static float anchor[ANCHOR_NUM * 2] = {};
|
||||||
static int net_output_shape[3] = {};
|
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_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);
|
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) {
|
if (NULL == showbuffer) {
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
printf("showbuffer apply memory fail !!");
|
printf("showbuffer apply memory fail !!");
|
||||||
return;
|
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) {
|
if (NULL == kpurgbbuffer) {
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
free(showbuffer);
|
rt_free_align(showbuffer);
|
||||||
printf("kpurgbbuffer apply memory fail !!");
|
printf("kpurgbbuffer apply memory fail !!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
model_data = (unsigned char *)malloc(kmodel_size + 255);
|
||||||
if (NULL == model_data) {
|
if (NULL == model_data) {
|
||||||
free(showbuffer);
|
rt_free_align(showbuffer);
|
||||||
free(kpurgbbuffer);
|
rt_free_align(kpurgbbuffer);
|
||||||
close(g_fd);
|
close(g_fd);
|
||||||
printf("model_data apply memory fail !!");
|
printf("model_data apply memory fail !!");
|
||||||
return;
|
return;
|
||||||
|
@ -281,10 +284,12 @@ void instrusion_detect()
|
||||||
#ifdef __RT_THREAD_H__
|
#ifdef __RT_THREAD_H__
|
||||||
MSH_CMD_EXPORT(instrusion_detect, instrusion detect task);
|
MSH_CMD_EXPORT(instrusion_detect, instrusion detect task);
|
||||||
#endif
|
#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)
|
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");
|
printf("thread_instrusion_detect_entry start!\n");
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
// sysctl_enable_irq();
|
// sysctl_enable_irq();
|
||||||
|
@ -299,31 +304,35 @@ static void *thread_instrusion_detect_entry(void *parameter)
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return 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);
|
kpu_run_kmodel(&instrusion_detect_task, kpurgbbuffer, DMAC_CHANNEL5, ai_done, NULL);
|
||||||
while (!g_ai_done_flag)
|
while (!g_ai_done_flag)
|
||||||
;
|
;
|
||||||
|
dmalock_release(dma_ch);
|
||||||
float *output;
|
float *output;
|
||||||
size_t output_size;
|
size_t output_size;
|
||||||
kpu_get_output(&instrusion_detect_task, 0, (uint8_t **)&output, &output_size);
|
kpu_get_output(&instrusion_detect_task, 0, (uint8_t **)&output, &output_size);
|
||||||
instrusion_detect_rl.input = output;
|
instrusion_detect_rl.input = output;
|
||||||
region_layer_run(&instrusion_detect_rl, &instrusion_detect_info);
|
region_layer_run(&instrusion_detect_rl, &instrusion_detect_info);
|
||||||
/* display result */
|
/* display result */
|
||||||
|
for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++)
|
||||||
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,
|
draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800,(uint16_t)sensor_output_size[1],(uint16_t)sensor_output_size[0]);
|
||||||
// (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,
|
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].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].y2, labels[instrusion_detect_info.obj[instrusion_cnt].class_id],
|
||||||
instrusion_detect_info.obj[instrusion_cnt].prob);
|
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) {
|
if (0 != instrusion_detect_info.obj_number) {
|
||||||
printf("\n");
|
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);
|
usleep(1);
|
||||||
if (1 == if_exit) {
|
if (1 == if_exit) {
|
||||||
if_exit = 0;
|
if_exit = 0;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <dfs_poll.h>
|
#include <dfs_poll.h>
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <dfs.h>
|
#include <dfs.h>
|
||||||
|
#include<sys/ioctl.h>
|
||||||
#ifdef RT_USING_POSIX_TERMIOS
|
#ifdef RT_USING_POSIX_TERMIOS
|
||||||
#include <posix_termios.h>
|
#include <posix_termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,6 +51,12 @@
|
||||||
#include <lwip/netdb.h>
|
#include <lwip/netdb.h>
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_SAL */
|
||||||
|
#ifdef BOARD_K210_EVB
|
||||||
|
#include <dmac.h>
|
||||||
|
#include <dmalock.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#define RT_ALIGN_SIZE 8
|
#define RT_ALIGN_SIZE 8
|
||||||
#define RT_THREAD_PRIORITY_32
|
#define RT_THREAD_PRIORITY_32
|
||||||
#define RT_THREAD_PRIORITY_MAX 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_OVERFLOW_CHECK
|
||||||
#define RT_USING_HOOK
|
#define RT_USING_HOOK
|
||||||
#define RT_USING_IDLE_HOOK
|
#define RT_USING_IDLE_HOOK
|
||||||
|
|
Loading…
Reference in New Issue