diff --git a/EPII_CM55M_APP_S/app/main.c b/EPII_CM55M_APP_S/app/main.c index 33cbdcef..67d14cee 100644 --- a/EPII_CM55M_APP_S/app/main.c +++ b/EPII_CM55M_APP_S/app/main.c @@ -124,3 +124,15 @@ int main(void) return 0; } #endif + +#ifdef TFLM_2IN1_FD_FL_FR_ENROLL_YOLOV8 +#include "tflm_2in1_fd_fl_fr_enroll_yolov8.h" + +/** main entry */ +int main(void) +{ + board_init(); + app_main(); + return 0; +} +#endif diff --git a/EPII_CM55M_APP_S/app/scenario_app/allon_sensor_tflm_freertos/allon_sensor_tflm_freertos.mk b/EPII_CM55M_APP_S/app/scenario_app/allon_sensor_tflm_freertos/allon_sensor_tflm_freertos.mk index 17beca7b..7dabb081 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/allon_sensor_tflm_freertos/allon_sensor_tflm_freertos.mk +++ b/EPII_CM55M_APP_S/app/scenario_app/allon_sensor_tflm_freertos/allon_sensor_tflm_freertos.mk @@ -38,7 +38,7 @@ override EPII_USECASE_SEL := drv_onecore_cm55m_s CIS_SUPPORT_INAPP = cis_sensor #CIS_SUPPORT_INAPP_MODEL = cis_hm0360 CIS_SUPPORT_INAPP_MODEL = cis_ov5647 -#CIS_SUPPORT_INAPP_MODEL = cis_imx219 +# CIS_SUPPORT_INAPP_MODEL = cis_imx219 #CIS_SUPPORT_INAPP_MODEL = cis_imx477 ifeq ($(CIS_SUPPORT_INAPP_MODEL), cis_imx219) diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.c index 916e4391..7282924b 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.c @@ -667,6 +667,13 @@ uint32_t app_get_jpeg_addr() return g_wdma2_baseaddr; } +uint32_t app_get_jpeg_sz() +{ + //EPII_InvalidateDCache_by_Addr(g_jpegautofill_addr, 4); + hx_InvalidateDCache_by_Addr((volatile void *)g_jpegautofill_addr, 32); + return *((uint32_t*)g_jpegautofill_addr); +} + uint32_t app_get_raw_addr() { return g_wdma3_baseaddr; diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.h index 4b6b1790..fa302e31 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.h +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx219/cisdp_sensor.h @@ -42,6 +42,7 @@ void cisdp_mipi_reset(); void cisdp_get_jpginfo(uint32_t *jpeg_enc_filesize, uint32_t *jpeg_enc_addr); uint32_t app_get_jpeg_addr(); +uint32_t app_get_jpeg_sz(); uint32_t app_get_raw_addr(); uint32_t app_get_raw_sz(); uint32_t app_get_raw_width(); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.c index e2105604..0b66859d 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.c @@ -672,6 +672,13 @@ uint32_t app_get_jpeg_addr() return g_wdma2_baseaddr; } +uint32_t app_get_jpeg_sz() +{ + //EPII_InvalidateDCache_by_Addr(g_jpegautofill_addr, 4); + hx_InvalidateDCache_by_Addr((volatile void *)g_jpegautofill_addr, 32); + return *((uint32_t*)g_jpegautofill_addr); +} + uint32_t app_get_raw_addr() { return g_wdma3_baseaddr; diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.h index c7d2d59c..4660465c 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.h +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_imx477/cisdp_sensor.h @@ -45,6 +45,7 @@ void set_mipi_csirx_enable(); void cisdp_get_jpginfo(uint32_t *jpeg_enc_filesize, uint32_t *jpeg_enc_addr); uint32_t app_get_jpeg_addr(); +uint32_t app_get_jpeg_sz(); uint32_t app_get_raw_addr(); uint32_t app_get_raw_sz(); uint32_t app_get_raw_width(); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.c index 6d5162e0..24a84af5 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.c @@ -681,6 +681,13 @@ uint32_t app_get_jpeg_addr() return g_wdma2_baseaddr; } +uint32_t app_get_jpeg_sz() +{ + //EPII_InvalidateDCache_by_Addr(g_jpegautofill_addr, 4); + hx_InvalidateDCache_by_Addr((volatile void *)g_jpegautofill_addr, 32); + return *((uint32_t*)g_jpegautofill_addr); +} + uint32_t app_get_raw_addr() { //raw data area BBBBBB/GGGGGG/RRRRRR diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.h index 5b83ff3b..e4ebad39 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.h +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cis_sensor/cis_ov5647/cisdp_sensor.h @@ -41,6 +41,7 @@ void cisdp_sensor_stop(); void cisdp_get_jpginfo(uint32_t *jpeg_enc_filesize, uint32_t *jpeg_enc_addr); uint32_t app_get_jpeg_addr(); +uint32_t app_get_jpeg_sz(); uint32_t app_get_raw_addr(); uint32_t app_get_raw_sz(); uint32_t app_get_raw_width(); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.cpp index d523b3eb..5136dee4 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.cpp +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.cpp @@ -36,7 +36,7 @@ #include "cisdp_cfg.h" #include "memory_manage.h" #include "common_config.h" - +#include "send_result.h" #ifdef TRUSTZONE_SEC #define U55_BASE BASE_ADDR_APB_U55_CTRL_ALIAS @@ -88,6 +88,9 @@ #endif +#define TOTAL_STEP_TICK 1 +#define CPU_CLK 0xffffff+1 +static uint32_t capture_image_tick = 0; //left eyes indices #16 point int LEFT_EYE_mesh_index[16] ={ 362, 382, 381, 380, 374, 373, 390, 249, 263, 466, 388, 387, 386, 385,384, 398 }; @@ -376,7 +379,7 @@ float CaculateDistance(uint32_t x1,uint32_t y1,uint32_t x2,uint32_t y2) } #ifdef COMPUTE_ANGLE -void compute_ypr_face_mesh(struct_fm_algoResult *algoresult_fm) +void compute_ypr_face_mesh(struct_fm_algoResult_with_fps *algoresult_fm) { //MAX_FACE_LAND_MARK_TRACKED_POINT @@ -473,7 +476,7 @@ void compute_ypr_face_mesh(struct_fm_algoResult *algoresult_fm) return ; } -void compute_ANGLE_face_mesh(struct_fm_algoResult *algoresult_fm) +void compute_ANGLE_face_mesh(struct_fm_algoResult_with_fps *algoresult_fm) { /* MAR = (np.linalg.norm(marks[61, ] - marks[67, ]) + @@ -624,7 +627,7 @@ void crop_single_eye_IL(uint8_t* input_face_w_pad_image,uint8_t* crop_dist_image hx_lib_image_copy_helium((uint8_t*)input_face_w_pad_image, crop_dist_image, FM_INPUT_TENSOR_WIDTH, FM_INPUT_TENSOR_WIDTH, COLOR_CHANNEL, crop_eye_bbox.x, crop_eye_bbox.y, crop_eye_bbox.width, crop_eye_bbox.height); } -static void IL_post_proccessing(TfLiteTensor* outputTensor_1,TfLiteTensor* outputTensor_2, struct_fm_algoResult *algoresult_fm,struct_position* eye_center, int LR) +static void IL_post_proccessing(TfLiteTensor* outputTensor_1,TfLiteTensor* outputTensor_2, struct_fm_algoResult_with_fps *algoresult_fm,struct_position* eye_center, int LR) { int eye_shift_x,eye_shift_y; eye_shift_x= eye_center->x - 64/2; @@ -776,7 +779,7 @@ static void IL_post_proccessing(TfLiteTensor* outputTensor_1,TfLiteTensor* outpu } } -void cal_iris_angle(struct_fm_algoResult *algoresult_fm,int LR) +void cal_iris_angle(struct_fm_algoResult_with_fps *algoresult_fm,int LR) { if(LR==1)//right { @@ -857,10 +860,10 @@ void cal_iris_angle(struct_fm_algoResult *algoresult_fm,int LR) } #endif #ifdef APP_IRIS_LANDMARK -void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct_fm_algoResult *algoresult_fm, struct_position *fm_eye_r_wo_scale_R,struct_position *fm_eye_r_wo_scale_L) +void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct_fm_algoResult_with_fps *algoresult_fm, struct_position *fm_eye_r_wo_scale_R,struct_position *fm_eye_r_wo_scale_L) #else -//void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct__box *bbox, int org_img_w, int org_img_h,struct_fm_algoResult *algoresult_fm) -void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct_fm_algoResult *algoresult_fm) +//void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct__box *bbox, int org_img_w, int org_img_h,struct_fm_algoResult_with_fps *algoresult_fm) +void blazeface_mesh_post_procees(TfLiteTensor *outputTensor_1,TfLiteTensor *outputTensor_2,struct_fm_algoResult_with_fps *algoresult_fm) #endif { float outputTensor_1_scale = ((TfLiteAffineQuantization*)(outputTensor_1->quantization.params))->scale->data[0]; @@ -1133,8 +1136,16 @@ int cv_fd_fm_init(bool security_enable, bool privilege_enable, uint32_t fd_model return ercode; } -int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_result) { + +int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult_with_fps *alg_fm_result) { + +static uint32_t algo_tick = 0; +#if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); +#endif int ercode = 0; TfLiteStatus invoke_status=kTfLiteOk; @@ -1214,8 +1225,11 @@ int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_res #if FRAME_CHECK_DEBUG //hx_drv_spi_mst_protocol_write_wait_finish(); #endif - //recapture image - sensordplib_retrigger_capture(); +#ifdef UART_SEND_ALOGO_RESEULT +#else + //recapture image + sensordplib_retrigger_capture(); +#endif } else { @@ -1243,7 +1257,7 @@ int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_res } } - /**copy face detect result to struct_fm_algoResult - alg_fm_result*/ + /**copy face detect result to struct_fm_algoResult_with_fps - alg_fm_result*/ for(int i=0;iface_bbox[i].x = (uint16_t)alg_result->ht[i].upper_body_bbox.x; @@ -1259,8 +1273,11 @@ int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_res alg_fm_result->face_bbox[0].x, alg_fm_result->face_bbox[0].y, \ alg_fm_result->face_bbox[0].width, alg_fm_result->face_bbox[0].height); +#ifdef UART_SEND_ALOGO_RESEULT +#else //recapture image sensordplib_retrigger_capture(); +#endif if(alg_fm_result->face_bbox[0].height > alg_fm_result->face_bbox[0].width) { @@ -1409,7 +1426,101 @@ int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_res } //if (alg_result->num_tracked_human_targets == 0) else +#if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + alg_fm_result->algo_tick = algo_tick + capture_image_tick; +#endif + +#ifdef UART_SEND_ALOGO_RESEULT + uint32_t judge_case_data; + uint32_t g_trans_type; + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); +if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) +{ + el_img_t temp_el_jpg_img = el_img_t{}; + temp_el_jpg_img.data = (uint8_t *)app_get_jpeg_addr(); + temp_el_jpg_img.size = app_get_jpeg_sz(); + temp_el_jpg_img.width = app_get_raw_width(); + temp_el_jpg_img.height = app_get_raw_height(); + temp_el_jpg_img.format = EL_PIXEL_FORMAT_JPEG; + temp_el_jpg_img.rotate = EL_PIXEL_ROTATE_0; + + std::forward_list el_fm_point_algo; + + el_fm_point_t temp_el_fm_point_algo; + temp_el_fm_point_algo.el_box.x = alg_fm_result->face_bbox[0].x; + temp_el_fm_point_algo.el_box.y = alg_fm_result->face_bbox[0].y; + temp_el_fm_point_algo.el_box.w = alg_fm_result->face_bbox[0].width; + temp_el_fm_point_algo.el_box.h = alg_fm_result->face_bbox[0].height; + temp_el_fm_point_algo.el_box.score = alg_fm_result->face_bbox[0].face_score; + temp_el_fm_point_algo.el_box.target = 0; + for(int c=0;cfmr[c].x; + temp_el_fm_point_algo.el_fm_point[c].y = alg_fm_result->fmr[c].y; + temp_el_fm_point_algo.el_fm_point[c].score = temp_el_fm_point_algo.el_box.score; + temp_el_fm_point_algo.el_fm_point[c].target = 0; + } + + for(int c=0;cfmr_iris[c].x; + temp_el_fm_point_algo.el_fm_iris[c].y = alg_fm_result->fmr_iris[c].y; + temp_el_fm_point_algo.el_fm_iris[c].score = temp_el_fm_point_algo.el_box.score; + temp_el_fm_point_algo.el_fm_iris[c].target = 0; + } + + + temp_el_fm_point_algo.el_fm_angle.yaw = alg_fm_result->face_angle.yaw * 100.0; + temp_el_fm_point_algo.el_fm_angle.pitch = alg_fm_result->face_angle.pitch* 100.0; + temp_el_fm_point_algo.el_fm_angle.roll = alg_fm_result->face_angle.roll* 100.0; + temp_el_fm_point_algo.el_fm_angle.MAR = alg_fm_result->face_angle.MAR* 100.0; + temp_el_fm_point_algo.el_fm_angle.LEAR = alg_fm_result->face_angle.LEAR* 100.0; + temp_el_fm_point_algo.el_fm_angle.REAR = alg_fm_result->face_angle.REAR* 100.0; + + temp_el_fm_point_algo.el_fm_angle.left_iris_theta = alg_fm_result->left_iris_theta* 100.0; + temp_el_fm_point_algo.el_fm_angle.left_iris_phi = alg_fm_result->left_iris_phi* 100.0; + temp_el_fm_point_algo.el_fm_angle.right_iris_theta = alg_fm_result->right_iris_theta* 100.0; + temp_el_fm_point_algo.el_fm_angle.right_iris_phi = alg_fm_result->right_iris_phi* 100.0; + + el_fm_point_algo.emplace_front(temp_el_fm_point_algo); + + std::forward_list el_fm_face_bbox_algo; + + el_box_t temp_el_fm_face_bbox_algo; + for(int i = 0; i < MAX_TRACKED_ALGO_RES;i++) + { + temp_el_fm_face_bbox_algo.x = alg_fm_result->face_bbox[i].x; + temp_el_fm_face_bbox_algo.y = alg_fm_result->face_bbox[i].y; + temp_el_fm_face_bbox_algo.w = alg_fm_result->face_bbox[i].width; + temp_el_fm_face_bbox_algo.h = alg_fm_result->face_bbox[i].height; + temp_el_fm_face_bbox_algo.score = alg_fm_result->face_bbox[i].face_score; + temp_el_fm_face_bbox_algo.target = i; + + el_fm_face_bbox_algo.emplace_front(temp_el_fm_face_bbox_algo); + } + send_device_id(); + event_reply(concat_strings(", ", fm_face_bbox_results_2_json_str(el_fm_face_bbox_algo),", ", algo_tick_2_json_str(algo_tick),", ", fm_point_results_2_json_str(el_fm_point_algo), ", ", img_2_json_str(&temp_el_jpg_img))); +} +else if( g_trans_type == 1)// transfer type is (SPI) +{ + +} + set_model_change_by_uart(); +#endif + +#ifdef UART_SEND_ALOGO_RESEULT + SystemGetTick(&systick_1, &loop_cnt_1); + //recapture image + sensordplib_retrigger_capture(); + + SystemGetTick(&systick_2, &loop_cnt_2); + capture_image_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); +#endif return ercode; } diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.h index 9a08f583..3171a95e 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.h +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/cvapp_fd_fm.h @@ -16,7 +16,7 @@ extern "C" { int cv_fd_fm_init(bool security_enable, bool privilege_enable, uint32_t fd_model_addr, uint32_t fm_model_addr, uint32_t il_model_addr); -int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult *alg_fm_result); +int cv_fd_fm_run(struct_algoResult *alg_result, struct_fm_algoResult_with_fps *alg_fm_result); int cv_fd_fm_deinit(); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.cpp new file mode 100644 index 00000000..9e3c2067 --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.cpp @@ -0,0 +1,811 @@ +extern "C" { +#include +#include "hx_drv_swreg_aon.h" +#include "tflm_fd_fm.h" +} +#include + +#include +#include +#include +#include +#include +#include +#include +#include "WE2_core.h" +#include + +static char* img_2_json_str_buffer = nullptr; + +el_err_code_t send_bytes(const char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + size_t sent{0}; + size_t pos_of_bytes{0}; + + while (size) { + size_t bytes_to_send{size < 8 ? size : 8}; + + sent += console_uart->uart_write(buffer + pos_of_bytes, bytes_to_send); + pos_of_bytes += bytes_to_send; + size -= bytes_to_send; + } + + //0 is ok(success) + //1 is again (fail) + return sent == pos_of_bytes ? EL_OK : EL_AGAIN; +} + + +el_err_code_t read_bytes(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + read += console_uart->uart_read(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + +el_err_code_t read_bytes_nonblock(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + + read += console_uart->uart_read_nonblock(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + + +void set_model_change_by_uart() +{ + char c{'\0'}; + if(!read_bytes_nonblock((char *)(&c), 1))//if read ok + { + uint32_t data; + hx_drv_swreg_aon_get_appused1(&data); + //transfer type + uint16_t trans_type = (data>>16); + //model case + uint16_t model_case = (data&0xff); + + if( c == 255)// set using UART (trans_type == 0) + { + hx_drv_swreg_aon_set_appused1( (0x0<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 254)// set using SPI (trans_type == 1) + { + hx_drv_swreg_aon_set_appused1( (0x1<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 253)// set using SPI & UART (trans_type == 2) + { + hx_drv_swreg_aon_set_appused1( (0x2<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if(c == 0) + { + hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (0 & 0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + // if(c == 5) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (5 & 0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 6) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (6&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 9) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (9&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 10) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (10&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 11) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (11&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + } + +} + + + + + + + +static const char* BASE64_CHARS_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +void el_base64_encode(const unsigned char* in, int in_len, char* out) { + int i = 0; + int j = 0; + unsigned char char_array_3[3]; + unsigned char char_array_4[4]; + + while (in_len--) { + char_array_3[i++] = *(in++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (i = 0; i < 4; i++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + i = 0; + } + } + + if (i) { + for (j = i; j < 3; j++) char_array_3[j] = '\0'; + + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (j = 0; j < i + 1; j++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + while (i++ < 3) *out++ = '='; + } +} + +std::string img_2_json_str(el_img_t* img) { +if (!img || !img->data || !img->size) [[unlikely]] + return std::string("\"image\": \"\""); + + static std::size_t size = 0; + static std::size_t buffer_size = 0; + + + // only reallcate memory when buffer size is not enough + if (img->size > size) [[unlikely]] { + size = img->size; + buffer_size = (((size + 2u) / 3u) << 2u) + 1u; // base64 encoded size, +1 for terminating null character + printf("buffer_size: %d may be too small reallocating\r\n\n",buffer_size); + printf("if still fail, please modify linker script heap size\r\n\n"); + if (img_2_json_str_buffer) [[likely]] + delete[] img_2_json_str_buffer; + img_2_json_str_buffer = new char[buffer_size]{}; + } + + std::memset(img_2_json_str_buffer, 0, buffer_size); + el_base64_encode(img->data, img->size, img_2_json_str_buffer); + + return concat_strings("\"image\": \"", img_2_json_str_buffer, "\""); +} + + +std::string img_res_2_json_str(const el_img_t* img) { + return concat_strings("\"resolution\": [", std::to_string(img->width), ", ", std::to_string(img->height), "]"); +} + + + +template constexpr std::string results_2_json_str(const std::forward_list& results) { + std::string ss; + const char* delim = ""; + + if (std::is_same::value) { + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"points\": ["; + for (const auto& point : results) { + ss += concat_strings(delim, + "[", + std::to_string(point.x), + ", ", + std::to_string(point.y), + ", ", + std::to_string(point.score), + ", ", + std::to_string(point.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"classes\": ["; + for (const auto& cls : results) { + ss += concat_strings(delim, "[", std::to_string(cls.score), ", ", std::to_string(cls.target), "]"); + delim = ", "; + } + } + ss += "]"; + + return ss; +} + + +std::string box_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_face_bbox_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + ss = "\"fm_face_boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_point_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"fm_points\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < FM_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_point[i].x), + ", ", + std::to_string(it->el_fm_point[i].y), + ", ", + std::to_string(it->el_fm_point[i].score), + ", ", + std::to_string(it->el_fm_point[i].target), + "]"); + delim = ", "; + } + + delim = "] , ["; + for(int i = 0 ; i < FM_IRIS_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_iris[i].x), + ", ", + std::to_string(it->el_fm_iris[i].y), + ", ", + std::to_string(it->el_fm_iris[i].score), + ", ", + std::to_string(it->el_fm_iris[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_angle.yaw), + ", ", + std::to_string(it->el_fm_angle.pitch), + ", ", + std::to_string(it->el_fm_angle.roll), + ", ", + std::to_string(it->el_fm_angle.MAR), + ", ", + std::to_string(it->el_fm_angle.LEAR), + ", ", + std::to_string(it->el_fm_angle.REAR), + ", ", + std::to_string(it->el_fm_angle.left_iris_theta), + ", ", + std::to_string(it->el_fm_angle.left_iris_phi), + ", ", + std::to_string(it->el_fm_angle.right_iris_theta), + ", ", + std::to_string(it->el_fm_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; +} + + +std::string fd_fl_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl_el_9pt\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////left eye landmark + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->left_eye_landmark[i].x), + ", ", + std::to_string(it->left_eye_landmark[i].y), + ", ", + std::to_string(it->left_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////right eye landmark + + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->right_eye_landmark[i].x), + ", ", + std::to_string(it->right_eye_landmark[i].y), + ", ", + std::to_string(it->right_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + ", ", + std::to_string(it->el_fl_angle.left_iris_theta), + ", ", + std::to_string(it->el_fl_angle.left_iris_phi), + ", ", + std::to_string(it->el_fl_angle.right_iris_theta), + ", ", + std::to_string(it->el_fl_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + + +std::string keypoint_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"keypoints\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + for(int i = 0 ; i < KEYPOINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_keypoint[i].x), + ", ", + std::to_string(it->el_keypoint[i].y), + ", ", + std::to_string(it->el_keypoint[i].score), + ", ", + std::to_string(it->el_keypoint[i].target), + "]"); + delim = ", "; + } + ss += "]]"; + delim = ", "; + } + ss += "]"; + + return ss; +} + + +void event_reply(std::string data) { +std::string _cmd ; +std::size_t _n_times; +bool _results_only; + +std::size_t _task_id; +// el_sensor_info_t _sensor_info; +// el_model_info_t _model_info; +// el_algorithm_info_t _algorithm_info; + +std::size_t _times=0; +el_err_code_t _ret; +uint16_t _action_hash; + const auto& ss{concat_strings("\r{\"type\": 1, \"name\": \"", + "INVOKE", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"count\": ", + std::to_string(_times), + data, + "}}\n")}; + send_bytes(ss.c_str(), ss.size()); +} +inline std::string quoted(const std::string& str, const char delim = '"') { + std::size_t sz = 0; + for (char c : str) + if (c == delim) [[unlikely]] + ++sz; + std::string ss(1, delim); + ss.reserve(str.length() + (sz << 1)); + for (char c : str) { + if (c == delim) [[unlikely]] + ss += '\\'; + if (c != '\n') [[likely]] + ss += c; + } + ss += delim; + return ss; +} +const static uint16_t CRC16_MAXIM_TABLE[256] = { + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, + 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, + 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, + 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, + 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, + 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, + 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, + 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, + 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, + 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, + 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, + 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, + 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, + 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, + 0x4100, 0x81c1, 0x8081, 0x4040}; + +EL_ATTR_WEAK uint16_t el_crc16_maxim(const uint8_t* data, size_t length) { + uint16_t crc = 0x0000; + + for (size_t i = 0; i < length; ++i) { + uint8_t index = static_cast(crc ^ data[i]); + crc = (crc >> 8) ^ CRC16_MAXIM_TABLE[index]; + } + + return crc ^ 0xffff; +} + + +std::string model_info_2_json_str(el_model_info_t model_info) { + return concat_strings("{\"id\": ", + std::to_string(model_info.id), + ", \"type\": ", + std::to_string(model_info.type), + ", \"address\": ", + std::to_string(model_info.addr_flash), + ", \"size\": ", + std::to_string(model_info.size), + "}"); +} +void send_device_id() { + std::string cmd; + + const auto& ss{concat_strings("\r{\"type\": 0, \"name\": \"", + "NAME?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + quoted("kris Grove Vision AI (WE2)"), + "}\n")}; + send_bytes(ss.c_str(), ss.size()); + + const auto& ss_ver{concat_strings("\r{\"type\": 0, \"name\": \"", + "VER?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"software\": \"", + EL_VERSION, + "\", \"hardware\": \"", + "kris 2024", + "\"}}\n")}; + send_bytes(ss_ver.c_str(), ss_ver.size()); + + + + const auto& ss_id{concat_strings("\r{\"type\": 0, \"name\": \"", + "ID?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + "1", + "}\n")}; + send_bytes(ss_id.c_str(), ss_id.size()); + + char info[CONFIG_SSCMA_CMD_MAX_LENGTH]{}; + + const auto& ss_info{ + concat_strings("\r{\"type\": 0, \"name\": \"", + "INFO?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"crc16_maxim\": ", + std::to_string(el_crc16_maxim(reinterpret_cast(&info[0]), std::strlen(&info[0]))), + ", \"info\": ", + quoted(info), + "}}\n")}; + send_bytes(ss_info.c_str(), ss_info.size()); + el_model_info_t model_info; + model_info.id=0; + model_info.type=EL_ALGO_TYPE_UNDEFINED; + + const auto& ss_model_info{concat_strings("\r{\"type\": 0, \"name\": \"", + "MODEL?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + model_info_2_json_str(model_info), + "}\n")}; + send_bytes(ss_model_info.c_str(), ss_model_info.size()); + +} + +std::string algo_tick_2_json_str(uint32_t algo_tick) { + std::string ss; + const char* delim = ""; + + ss = "\"algo_tick\": ["; + + ss += concat_strings(delim, + "[", + std::to_string(algo_tick), + "]"); + delim = ", "; + ss += "]"; + + return ss; +} \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.h new file mode 100644 index 00000000..92a5e88c --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/send_result.h @@ -0,0 +1,183 @@ + +#ifdef __cplusplus +#include +#include +#include +#include +#include +#endif + + +#include +#include +extern "C" { +#include "hx_drv_swreg_aon.h" +} +#define CONSOLE_UART_ID 0 +#define EL_ATTR_WEAK __attribute__((weak)) +#define EL_VERSION __TIMESTAMP__ +#define CONFIG_SSCMA_CMD_MAX_LENGTH (4096) +#define KEYPOINT_NUM 17 +#define FM_POINT_NUM 468 +#define FM_IRIS_POINT_NUM 10 +#define MAX_FACE_LAND_MARK_TRACKED_POINT 68 +typedef enum { + EL_OK = 0, // success + EL_AGAIN = 1, // try again + EL_ELOG = 2, // logic error + EL_ETIMOUT = 3, // timeout + EL_EIO = 4, // IO error + EL_EINVAL = 5, // invalid argument + EL_ENOMEM = 6, // out of memory + EL_EBUSY = 7, // busy + EL_ENOTSUP = 8, // not supported + EL_EPERM = 9, // operation not permitted +} el_err_code_t; +typedef enum { + EL_PIXEL_FORMAT_RGB888 = 0, + EL_PIXEL_FORMAT_RGB565, + EL_PIXEL_FORMAT_YUV422, + EL_PIXEL_FORMAT_GRAYSCALE, + EL_PIXEL_FORMAT_JPEG, + EL_PIXEL_FORMAT_UNKNOWN, +} el_pixel_format_t; +typedef enum el_pixel_rotate_t { + EL_PIXEL_ROTATE_0 = 0, + EL_PIXEL_ROTATE_90, + EL_PIXEL_ROTATE_180, + EL_PIXEL_ROTATE_270, + EL_PIXEL_ROTATE_UNKNOWN, +} el_pixel_rotate_t; +typedef struct el_img_t { + uint8_t* data; + size_t size; + uint16_t width; + uint16_t height; + el_pixel_format_t format; + el_pixel_rotate_t rotate; +} el_img_t; +typedef struct el_box_t { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint8_t score; + uint8_t target; +} el_box_t; + +typedef struct el_point_t { + uint16_t x; + uint16_t y; + uint8_t score; + uint8_t target; +} el_point_t; + +typedef struct el_class_t { + uint16_t score; + uint16_t target; +} el_class_t; + +typedef struct el_keypoint_t { + el_box_t el_box; + el_point_t el_keypoint[KEYPOINT_NUM]; +} el_keypoint_t; + + +typedef struct { + int16_t yaw; + int16_t pitch; + int16_t roll; + int16_t MAR; + int16_t REAR; + int16_t LEAR; + int16_t left_iris_theta; + int16_t left_iris_phi; + int16_t right_iris_theta; + int16_t right_iris_phi; +}el_struct_angle; + +typedef struct el_fm_point_t { + el_box_t el_box; + el_point_t el_fm_point[FM_POINT_NUM]; + el_point_t el_fm_iris[FM_IRIS_POINT_NUM]; + el_struct_angle el_fm_angle; +} el_fm_point_t; + + +typedef struct el_fd_fl_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_struct_angle el_fl_angle; +} el_fd_fl_t; + +typedef struct el_fd_fl_el_9pt_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_point_t left_eye_landmark[9]; + el_point_t right_eye_landmark[9]; + el_struct_angle el_fl_angle; +} el_fd_fl_el_9pt_t; + +/** + * @brief Algorithm Types + */ +typedef enum { + EL_ALGO_TYPE_UNDEFINED = 0u, + EL_ALGO_TYPE_FOMO = 1u, + EL_ALGO_TYPE_PFLD = 2u, + EL_ALGO_TYPE_YOLO = 3u, + EL_ALGO_TYPE_IMCLS = 4u +} el_algorithm_type_t; +typedef struct el_model_info_t { + uint8_t id; + el_algorithm_type_t type; + uint32_t addr_flash; + uint32_t size; + const uint8_t* addr_memory; +} el_model_info_t; + +constexpr inline std::size_t lengthof(const char* s) { + std::size_t size = 0; + while (*(s + size) != '\0') ++size; + return size; +} + +template constexpr inline std::size_t lengthof(const T (&)[N]) noexcept { return N; } + +inline std::size_t lengthof(const std::string& s) { return s.length(); } + +// template constexpr inline decltype(auto) concat_strings(Args&&... args) { +// std::size_t length{(lengthof(args) + ...)}; // try calculate total length at compile time +// std::string result; +// result.reserve(length + 1); // preallocate memory, avoid repeatly allocate memory while appendings +// (result.append(std::forward(args)), ...); +// return result; +// } + +template constexpr inline decltype(auto) concat_strings(Args&&... args) { + std::size_t length{(lengthof(args) + ...)}; + std::string result; + result.reserve(length); + (result.append(std::forward(args)), ...); + return result; +} + + + +el_err_code_t send_bytes(const char* buffer, size_t size) ; +el_err_code_t read_bytes(char* buffer, size_t size); +el_err_code_t read_bytes_nonblock(char* buffer, size_t size); +void set_model_change_by_uart(); +std::string img_2_json_str(el_img_t* img); +void event_reply(std::string data); +void send_device_id(); +template constexpr std::string results_2_json_str(const std::forward_list& results); + +std::string box_results_2_json_str(std::forward_list& results); +std::string fm_point_results_2_json_str(std::forward_list& results); +std::string keypoint_results_2_json_str(std::forward_list& results); +std::string img_res_2_json_str(const el_img_t* img); +std::string algo_tick_2_json_str(uint32_t algo_tick); +std::string fd_fl_results_2_json_str(std::forward_list& results); +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results); +std::string fm_face_bbox_results_2_json_str(std::forward_list& results); \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.c index 8e8924ad..c5af5460 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.c @@ -97,12 +97,26 @@ static uint32_t g_use_case; /*volatile*/ uint32_t jpeg_addr, jpeg_sz; struct_algoResult algoresult; struct_hp_algoResult algoresult_pl; -struct_fm_algoResult algoresult_fm; +struct_fm_algoResult_with_fps algoresult_fm; +static uint32_t g_trans_type; +static uint32_t judge_case_data; void app_start_state(APP_STATE_E state); void pinmux_init(); -/* Init SPI master pin mux */ +// /* Init SPI master pin mux */ +// void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) +// { +// pinmux_cfg->pin_pb2 = SCU_PB2_PINMUX_SPI_M_DO_1; /*!< pin PB2*/ +// pinmux_cfg->pin_pb3 = SCU_PB3_PINMUX_SPI_M_DI_1; /*!< pin PB3*/ +// pinmux_cfg->pin_pb4 = SCU_PB4_PINMUX_SPI_M_SCLK_1; /*!< pin PB4*/ +// pinmux_cfg->pin_pb11 = SCU_PB11_PINMUX_SPI_M_CS; /*!< pin PB11*/ +// } + +#define GROVE_VISION_AI_II + +#ifdef GROVE_VISION_AI_II +/* Init SPI master pin mux (share with SDIO) */ void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) { pinmux_cfg->pin_pb2 = SCU_PB2_PINMUX_SPI_M_DO_1; /*!< pin PB2*/ @@ -110,8 +124,16 @@ void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) pinmux_cfg->pin_pb4 = SCU_PB4_PINMUX_SPI_M_SCLK_1; /*!< pin PB4*/ pinmux_cfg->pin_pb11 = SCU_PB11_PINMUX_SPI_M_CS; /*!< pin PB11*/ } - - +#else +/* Init SPI master pin mux (share with SDIO) */ +void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) +{ + pinmux_cfg->pin_pb2 = SCU_PB2_PINMUX_SPI_M_DO_1; /*!< pin PB2*/ + pinmux_cfg->pin_pb3 = SCU_PB3_PINMUX_SPI_M_DI_1; /*!< pin PB3*/ + pinmux_cfg->pin_pb4 = SCU_PB4_PINMUX_SPI_M_SCLK_1; /*!< pin PB4*/ + pinmux_cfg->pin_pb5 = SCU_PB5_PINMUX_SPI_M_CS_1; /*!< pin PB5*/ +} +#endif /******************************************************************************* * Code ******************************************************************************/ @@ -153,6 +175,137 @@ void WDG_Reset_ISR_CB (uint32_t event) //hx_drv_watchdog_stop(); } + +void SetAlarmPMU() { + uint32_t id; + TIMER_CFG_T timer_cfg; + //TIMER_ERROR_E ret; + +#ifdef EPII_FPGA + timer_cfg.period = 1000;//30000; +#else + timer_cfg.period = 1000;//30000; +#endif + timer_cfg.mode = TIMER_MODE_ONESHOT; + timer_cfg.ctrl = TIMER_CTRL_PMU; + timer_cfg.state = TIMER_STATE_PMU; + id = 1; + + //ret = hx_drv_timer_hw_start(id, &timer_cfg, NULL); + hx_drv_timer_hw_start(id, &timer_cfg, NULL); +} + +void SetPSPDNoVid() +{ + PM_PD_NOVIDPRE_CFG_T cfg; + uint8_t speed,reset, precap, nframeend_ctrl, trigger, retention; + uint32_t pmu_pad_pa01_mask, pmu_rtc_mask, support_debugdump; + uint32_t pmu_pad_pa23_mask, pmu_i2cw_mask, pmu_timer_mask, pmu_cmp_mask, pmu_ts_mask; + uint32_t dcdcpin, freq, cm55mdiv, cm55sdiv, pmu_anti_mask; + SCU_LSC_CLK_CFG_T lsc_cfg; + SCU_PDHSC_HSCCLK_CFG_T hsc_cfg; + PM_CFG_PWR_MODE_E mode; + + + speed = SCU_PLL_FREQ_ENABLE; + + reset = 0; + nframeend_ctrl = 0; + + retention = 0; + + precap = 0; + pmu_pad_pa01_mask = 0; + pmu_rtc_mask = 0; + pmu_pad_pa23_mask = 0; + pmu_i2cw_mask = 0; + pmu_timer_mask = 0; + pmu_cmp_mask = 0; + pmu_ts_mask = 0; + trigger = 1; + support_debugdump = 0; + dcdcpin = 0; + + freq = 400000000; + cm55mdiv = SCU_HSCCLKDIV_1; + cm55sdiv = SCU_LSCCLKDIV_4; + + pmu_anti_mask = 0; + dbg_app_log("speed=%d,reset=%d,nframeend_ctrl=%d,retention=%d,precap=%d\n", speed,reset,nframeend_ctrl,retention,precap); + dbg_app_log("ag_mask=0x%x,rtc_mask=0x%x,sb_mask=0x%x,i2cw_mask=0x%x,timer_mask=0x%x,cmp_mask=0x%x,ts_mask=0x%x\n", pmu_pad_pa01_mask,pmu_rtc_mask,pmu_pad_pa23_mask,pmu_i2cw_mask,pmu_timer_mask,pmu_cmp_mask,pmu_ts_mask); + dbg_app_log("trigger=%d,debug=%d, reset=%d\n", trigger,support_debugdump, reset); + dbg_app_log("dcdcpin=%d, pmu_anti_mask=0x%x\n", dcdcpin, pmu_anti_mask); + dbg_app_log("freq=%d, cm55mdiv=%d,cm55sdiv=%d\n", freq, cm55mdiv, cm55sdiv); + + mode = PM_MODE_PS_NOVID_PREROLLING; + hx_lib_pm_get_defcfg_bymode(&cfg, mode); + + cfg.bootromspeed.bootromclkfreq = speed; + cfg.bootromspeed.pll_freq = freq; + cfg.bootromspeed.cm55m_div = cm55mdiv; + cfg.bootromspeed.cm55s_div = cm55sdiv; + + + cfg.cm55s_reset = reset; + cfg.pmu_pad_pa01_mask = pmu_pad_pa01_mask; + cfg.pmu_rtc_mask = pmu_rtc_mask; + cfg.pmu_pad_pa23_mask = pmu_pad_pa23_mask; /**< PMU SB GPIO Interrupt Mask **/ + cfg.pmu_i2cw_mask = pmu_i2cw_mask; /**< PMU I2C Wakeup Interrupt Mask **/ + cfg.pmu_timer_mask = pmu_timer_mask; /**< PMU Timer0~5 Wakeup Interrupt Mask **/ + cfg.pmu_cmp_mask = pmu_cmp_mask; /**< PMU CMP Wakeup Interrupt Mask **/ + cfg.pmu_ts_mask = pmu_ts_mask; /**< PMU TS Wakeup Interrupt Mask **/ + cfg.pmu_anti_mask = pmu_anti_mask; + cfg.support_debugdump = support_debugdump; + + cfg.nframeend_ctrl = nframeend_ctrl; /**< NFrame Control **/ + + cfg.tcm_retention = retention; /**< CM55M TCM Retention**/ + cfg.hscsram_retention[0] = retention; /**< HSC SRAM Retention**/ + cfg.hscsram_retention[1] = retention; /**< HSC SRAM Retention**/ + cfg.hscsram_retention[2] = retention; /**< HSC SRAM Retention**/ + cfg.hscsram_retention[3] = retention; /**< HSC SRAM Retention**/ + cfg.lscsram_retention = retention; /**< LSC SRAM Retention**/ + cfg.skip_bootflow.sec_mem_flag = retention; /**< Skip Boot Flow**/ + cfg.skip_bootflow.first_bl_flag = retention; /*!< First BL Retention */ + cfg.skip_bootflow.cm55m_s_app_flag = retention; /*!< cm55m_s_app Retention */ + cfg.skip_bootflow.cm55m_ns_app_flag = retention; /*!< cm55m_ns_app Retention */ + cfg.skip_bootflow.cm55s_s_app_flag = retention; /*!< cm55s_s_app Retention */ + cfg.skip_bootflow.cm55s_ns_app_flag = retention; /*!< cm55s_ns_app Retention */ + cfg.skip_bootflow.cm55m_model_flag = retention; /*!< cm55m model Retention */ + cfg.skip_bootflow.cm55s_model_flag = retention; /*!< cm55s model Retention */ + cfg.skip_bootflow.cm55m_appcfg_flag = retention; /*!< cm55m appcfg Retention */ + cfg.skip_bootflow.cm55s_appcfg_flag = retention; /*!< cm55s appcfg Retention */ + cfg.skip_bootflow.cm55m_s_app_rwdata_flag = retention;/*!< cm55m_s_app RW Data Retention */ + cfg.skip_bootflow.cm55m_ns_app_rwdata_flag = retention;/*!< cm55m_ns_app RW Data Retention */ + cfg.skip_bootflow.cm55s_s_app_rwdata_flag = retention;/*!< cm55s_s_app RW Data Retention */ + cfg.skip_bootflow.cm55s_ns_app_rwdata_flag = retention;/*!< cm55s_ns_app RW Data Retention */ + cfg.skip_bootflow.secure_debug_flag = retention; + cfg.support_bootwithcap = precap; /**< Support capture when boot up**/ + cfg.pmu_dcdc_outpin = dcdcpin; + cfg.ioret = PM_CFG_PD_IORET_ON; + cfg.mipi_lane_en = PMU_MIPI_LANE_ALL_DISABLE; + cfg.sensor_type = PM_SENSOR_TIMING_FVLDLVLD_SHIFT; + cfg.simo_pd_onoff = PM_SIMO_PD_ONOFF_ON; + + hx_lib_pm_cfg_set(&cfg, NULL, PM_MODE_PS_NOVID_PREROLLING); + + SetAlarmPMU(); + + hsc_cfg.hscclk.hscclksrc = SCU_HSCCLKSRC_XTAL24M; + hsc_cfg.hscclk.hscclkdiv = SCU_HSCCLKDIV_1; + hsc_cfg.hscd12clksrc = SCU_HSCD12CLKSRC_HSC; + hsc_cfg.i3chcdiv = SCU_HSCI3CHCLKDIV_1; + hsc_cfg.sdiodiv = SCU_HSCSDIOCLKDIV_1; + lsc_cfg.lscclksrc = SCU_LSCCLKSRC_XTAL24M; + lsc_cfg.lscclkdiv = SCU_LSCCLKDIV_1; + + if(trigger == 1) + { + hx_lib_pm_trigger(hsc_cfg, lsc_cfg, PM_CLK_PARA_CTRL_BYAPP); + } + +} + static void dp_app_cv_fd_fm_eventhdl_cb(EVT_INDEX_E event) { uint16_t err; @@ -262,16 +415,34 @@ static void dp_app_cv_fd_fm_eventhdl_cb(EVT_INDEX_E event) } g_spi_master_initial_status = 1; } - read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); - //read_status = hx_drv_spi_mst_protocol_write_sp_wait(jpeg_addr, jpeg_sz, DATA_TYPE_JPG, 0); + #ifdef UART_SEND_ALOGO_RESEULT + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { + + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + } + #else + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + #endif #if DBG_APP_LOG dbg_printf(DBG_LESS_INFO, "write frame result %d, data size=%d,addr=0x%x\n",read_status, jpeg_sz,jpeg_addr); #endif #endif - cv_fd_fm_run(&algoresult, &algoresult_fm); +#ifdef UART_SEND_ALOGO_RESEULT + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { + cv_fd_fm_run(&algoresult, &algoresult_fm); #ifdef CIS_IMX hx_drv_scu_get_version(&chipid, &version); if (chipid == WE2_CHIP_VERSION_C) // mipi workaround for WE2 chip version C @@ -280,13 +451,69 @@ static void dp_app_cv_fd_fm_eventhdl_cb(EVT_INDEX_E event) cisdp_stream_on(); } #endif + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + cv_fd_fm_run(&algoresult, &algoresult_fm); +#ifdef CIS_IMX + hx_drv_scu_get_version(&chipid, &version); + if (chipid == WE2_CHIP_VERSION_C) // mipi workaround for WE2 chip version C + { + set_mipi_csirx_enable(); + cisdp_stream_on(); + } +#endif -#if FRAME_CHECK_DEBUG - hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_fm, sizeof(struct_fm_algoResult), DATA_TYPE_META_FM_DATA); - #if DBG_APP_LOG - dbg_printf(DBG_LESS_INFO, "META write frame result %d, data size=%d,addr=0x%x\n",read_status, - sizeof(algoresult_fm),&algoresult_fm); + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL FD_FM:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + + #endif + + #endif + + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_fm, sizeof(struct_fm_algoResult_with_fps), DATA_TYPE_META_FM_WITH_FPS_DATA); #endif + } +#else + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + cv_fd_fm_run(&algoresult, &algoresult_fm); +#ifdef CIS_IMX + hx_drv_scu_get_version(&chipid, &version); + if (chipid == WE2_CHIP_VERSION_C) // mipi workaround for WE2 chip version C + { + set_mipi_csirx_enable(); + cisdp_stream_on(); + } +#endif + + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL FD_FM:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + + #endif + + #endif + + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_fm, sizeof(struct_fm_algoResult_with_fps), DATA_TYPE_META_FM_WITH_FPS_DATA); + #endif #endif //clear_alg_rsult for (int i = 0; i < MAX_TRACKED_ALGO_RES; ++i) { @@ -357,9 +584,45 @@ void app_start_state(APP_STATE_E state) } dp_var_int(); - - if (state == APP_STATE_ALLON_FD_FM) +#ifdef UART_SEND_ALOGO_RESEULT + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) { + if (state == APP_STATE_ALLON_FD_FM) + { + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_fd_fm_eventhdl_cb, 4, APP_DP_RES_YUV640x480_INP_SUBSAMPLE_2X) < 0)// YUV 640X480 + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + else + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + else if ( g_trans_type == 1 ) // only use SPI + { + if(state == APP_STATE_ALLON_FD_FM) { + //if wdma variable is zero when not init yet, then this step is a must be to retrieve wdma address + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_fd_fm_eventhdl_cb, 4, APP_DP_RES_YUV640x480_INP_SUBSAMPLE_1X) < 0)// YUV 640X480 + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + else + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } +#else//if no UART_SEND_ALOGO_RESEULT + if(state == APP_STATE_ALLON_FD_FM) { + //if wdma variable is zero when not init yet, then this step is a must be to retrieve wdma address if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_fd_fm_eventhdl_cb, 4, APP_DP_RES_YUV640x480_INP_SUBSAMPLE_1X) < 0)// YUV 640X480 { xprintf("\r\nDATAPATH Init fail\r\n"); @@ -368,9 +631,10 @@ void app_start_state(APP_STATE_E state) } else { - xprintf("\r\nDATAPATH Init fail\r\n"); - APP_BLOCK_FUNC(); - } + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } +#endif event_handler_init(); cisdp_sensor_start(); @@ -396,12 +660,25 @@ int app_main(void) { hx_drv_swreg_aon_get_pllfreq(&freq); xprintf("wakeup_event=0x%x,WakeupEvt1=0x%x, freq=%d\n", wakeup_event, wakeup_event1, freq); + if((wakeup_event == PMU_WAKEUP_NONE) && (wakeup_event1 == PMU_WAKEUPEVENT1_NONE)) { + } + else { + hx_lib_pm_ctrl_fromPMUtoCPU(NULL); + } + pinmux_init(); hx_lib_spi_eeprom_open(USE_DW_SPI_MST_Q); hx_lib_spi_eeprom_enable_XIP(USE_DW_SPI_MST_Q, true, FLASH_QUAD, true); + // //check current use case + //judge which case + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + //transfer type + g_trans_type = (judge_case_data>>16); + #ifdef WATCHDOG_VERSION //watch dog start WATCHDOG_CFG_T wdg_cfg; diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.h index 94905087..42419fb3 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.h +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.h @@ -21,5 +21,5 @@ typedef enum }APP_STATE_E; int app_main(void); - +void SetPSPDNoVid(); #endif /* SCENARIO_TFLM_FD_FM_ */ diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.ld b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.ld index 071a2fc2..7cdfdf2e 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.ld +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.ld @@ -9,8 +9,8 @@ MEMORY CM55M_S_SRAM (rwx) : ORIGIN = BOOT2NDLOADER_BASE, LENGTH = 0x00200000-(BOOT2NDLOADER_BASE-BASE_ADDR_SRAM0_ALIAS) /* 2M-0x1f000 bytes*/ } -__HEAP_SIZE = 0x10000; -__STACK_SIZE = 0x10000; +__HEAP_SIZE = 0x26000; +__STACK_SIZE = 0xA000; ENTRY(Reset_Handler) diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.mk b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.mk index 2c3c62fb..54d644a4 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.mk +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_fd_fm/tflm_fd_fm.mk @@ -4,6 +4,8 @@ APPL_DEFINES += -DTFLM_FD_FM APPL_DEFINES += -Daudvidpre_ret_pll400_timer1 -DIP_xdma APPL_DEFINES += -DEVT_DATAPATH +APPL_DEFINES += -DUART_SEND_ALOGO_RESEULT + #APPL_DEFINES += -DEVT_CM55MTIMER -DEVT_CM55MMB APPL_DEFINES += -DDBG_MORE @@ -34,8 +36,8 @@ override EPII_USECASE_SEL := drv_user_defined CIS_SUPPORT_INAPP = cis_sensor #CIS_SUPPORT_INAPP_MODEL = cis_hm0360 CIS_SUPPORT_INAPP_MODEL = cis_ov5647 -#CIS_SUPPORT_INAPP_MODEL = cis_imx219 -#CIS_SUPPORT_INAPP_MODEL = cis_imx477 +# CIS_SUPPORT_INAPP_MODEL = cis_imx219 +# CIS_SUPPORT_INAPP_MODEL = cis_imx477 ifeq ($(CIS_SUPPORT_INAPP_MODEL), cis_imx219) APPL_DEFINES += -DCIS_IMX diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/TFLM_yolov8_od_S_only.ld b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/TFLM_yolov8_od_S_only.ld index 4e8db9b2..dd825db2 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/TFLM_yolov8_od_S_only.ld +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/TFLM_yolov8_od_S_only.ld @@ -9,7 +9,7 @@ MEMORY CM55M_S_SRAM (rwx) : ORIGIN = BOOT2NDLOADER_BASE, LENGTH = 0x00200000-(BOOT2NDLOADER_BASE-BASE_ADDR_SRAM0_ALIAS) /* 2M-0x1f000 bytes*/ } -__HEAP_SIZE = 0x10000; +__HEAP_SIZE = 0x20000; __STACK_SIZE = 0x10000; ENTRY(Reset_Handler) diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/cvapp_yolov8n_ob.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/cvapp_yolov8n_ob.cpp index f4f69912..cf01f9d1 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/cvapp_yolov8n_ob.cpp +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/cvapp_yolov8n_ob.cpp @@ -34,7 +34,7 @@ #include "spi_master_protocol.h" #include "cisdp_cfg.h" #include "memory_manage.h" - +#include #define CHANGE_YOLOV8_OB_OUPUT_SHAPE 1 @@ -55,12 +55,12 @@ // #define EACH_STEP_TICK -// #define TOTAL_STEP_TICK +#define TOTAL_STEP_TICK #define YOLOV8_POST_EACH_STEP_TICK 0 uint32_t systick_1, systick_2; uint32_t loop_cnt_1, loop_cnt_2; #define CPU_CLK 0xffffff+1 - +static uint32_t capture_image_tick = 0; #ifdef TRUSTZONE_SEC #define U55_BASE BASE_ADDR_APB_U55_CTRL_ALIAS #else @@ -257,7 +257,7 @@ static void yolov8_NMSBoxes(std::vector &boxes,std::vector &confide #if CHANGE_YOLOV8_OB_OUPUT_SHAPE -static void yolov8_ob_post_processing(tflite::MicroInterpreter* static_interpreter,float modelScoreThreshold, float modelNMSThreshold, struct_yolov8_ob_algoResult *alg) +static void yolov8_ob_post_processing(tflite::MicroInterpreter* static_interpreter,float modelScoreThreshold, float modelNMSThreshold, struct_yolov8_ob_algoResult *alg, std::forward_list &el_algo) { uint32_t img_w = app_get_raw_width(); uint32_t img_h = app_get_raw_height(); @@ -387,6 +387,20 @@ static void yolov8_ob_post_processing(tflite::MicroInterpreter* static_interpret alg->obr[i].bbox.width = (uint32_t)(boxes[idx].w * scale_factor_w); alg->obr[i].bbox.height = (uint32_t)(boxes[idx].h * scale_factor_h); alg->obr[i].class_idx = class_idxs[idx]; + el_box_t temp_el_box; + temp_el_box.score = confidences[idx]*100; + temp_el_box.target = class_idxs[idx]; + temp_el_box.x = (uint32_t)(boxes[idx].x * scale_factor_w); + temp_el_box.y = (uint32_t)(boxes[idx].y * scale_factor_h); + temp_el_box.w = (uint32_t)(boxes[idx].w * scale_factor_w); + temp_el_box.h = (uint32_t)(boxes[idx].h * scale_factor_h); + + + // printf("temp_el_box.x %d,temp_el_box.y: %d\r\n",temp_el_box.x,temp_el_box.y); + el_algo.emplace_front(temp_el_box); + // for (auto box : el_algo) { + // printf("el_algo.box.x %d,el_algo.box.y%d\r\n",box.x,box.y); + // } #if YOLOV8N_OB_DBG_APP_LOG printf("detect object[%d]: %s confidences: %f\r\n",i, coco_classes[class_idxs[idx]].c_str(),confidences[idx]); @@ -526,7 +540,7 @@ int cv_yolov8n_ob_run(struct_yolov8_ob_algoResult *algoresult_yolov8n_ob) { uint32_t ch = app_get_raw_channels(); uint32_t raw_addr = app_get_raw_addr(); uint32_t expand = 0; - + std::forward_list el_algo; #if YOLOV8N_OB_DBG_APP_LOG xprintf("raw info: w[%d] h[%d] ch[%d] addr[%x]\n",img_w, img_h, ch, raw_addr); @@ -593,7 +607,7 @@ int cv_yolov8n_ob_run(struct_yolov8_ob_algoResult *algoresult_yolov8n_ob) { SystemGetTick(&systick_1, &loop_cnt_1); #endif //retrieve output data - yolov8_ob_post_processing(yolov8n_ob_int_ptr,0.25, 0.45, algoresult_yolov8n_ob); + yolov8_ob_post_processing(yolov8n_ob_int_ptr,0.25, 0.45, algoresult_yolov8n_ob,el_algo); #ifdef EACH_STEP_TICK SystemGetTick(&systick_2, &loop_cnt_2); dbg_printf(DBG_LESS_INFO,"Tick for Invoke for YOLOV8_OB_post_processing:[%d]\r\n\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); @@ -603,10 +617,42 @@ int cv_yolov8n_ob_run(struct_yolov8_ob_algoResult *algoresult_yolov8n_ob) { #endif #ifdef TOTAL_STEP_TICK SystemGetTick(&systick_2, &loop_cnt_2); - dbg_printf(DBG_LESS_INFO,"Tick for TOTAL YOLOV8 OB:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + // dbg_printf(DBG_LESS_INFO,"Tick for TOTAL YOLOV8 OB:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); #endif + } + + +#ifdef UART_SEND_ALOGO_RESEULT + algoresult_yolov8n_ob->algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2) + capture_image_tick; +uint32_t judge_case_data; +uint32_t g_trans_type; +hx_drv_swreg_aon_get_appused1(&judge_case_data); +g_trans_type = (judge_case_data>>16); +if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) +{ + el_img_t temp_el_jpg_img = el_img_t{}; + temp_el_jpg_img.data = (uint8_t *)app_get_jpeg_addr(); + temp_el_jpg_img.size = app_get_jpeg_sz(); + temp_el_jpg_img.width = app_get_raw_width(); + temp_el_jpg_img.height = app_get_raw_height(); + temp_el_jpg_img.format = EL_PIXEL_FORMAT_JPEG; + temp_el_jpg_img.rotate = EL_PIXEL_ROTATE_0; + + send_device_id(); + // event_reply(concat_strings(", ", box_results_2_json_str(el_algo), ", ", img_2_json_str(&temp_el_jpg_img))); + event_reply(concat_strings(", ", algo_tick_2_json_str(algoresult_yolov8n_ob->algo_tick),", ", box_results_2_json_str(el_algo), ", ", img_2_json_str(&temp_el_jpg_img))); +} + set_model_change_by_uart(); +#endif + + SystemGetTick(&systick_1, &loop_cnt_1); + //recapture image sensordplib_retrigger_capture(); + + + SystemGetTick(&systick_2, &loop_cnt_2); + capture_image_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); return ercode; } diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.cpp new file mode 100644 index 00000000..49fdd5f9 --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.cpp @@ -0,0 +1,811 @@ +extern "C" { +#include +#include "hx_drv_swreg_aon.h" +#include "tflm_yolov8_od.h" +} +#include + +#include +#include +#include +#include +#include +#include +#include +#include "WE2_core.h" +#include + +static char* img_2_json_str_buffer = nullptr; + +el_err_code_t send_bytes(const char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + size_t sent{0}; + size_t pos_of_bytes{0}; + + while (size) { + size_t bytes_to_send{size < 8 ? size : 8}; + + sent += console_uart->uart_write(buffer + pos_of_bytes, bytes_to_send); + pos_of_bytes += bytes_to_send; + size -= bytes_to_send; + } + + //0 is ok(success) + //1 is again (fail) + return sent == pos_of_bytes ? EL_OK : EL_AGAIN; +} + + +el_err_code_t read_bytes(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + read += console_uart->uart_read(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + +el_err_code_t read_bytes_nonblock(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + + read += console_uart->uart_read_nonblock(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + + +void set_model_change_by_uart() +{ + char c{'\0'}; + if(!read_bytes_nonblock((char *)(&c), 1))//if read ok + { + uint32_t data; + hx_drv_swreg_aon_get_appused1(&data); + //transfer type + uint16_t trans_type = (data>>16); + //model case + uint16_t model_case = (data&0xff); + + if( c == 255)// set using UART (trans_type == 0) + { + hx_drv_swreg_aon_set_appused1( (0x0<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 254)// set using SPI (trans_type == 1) + { + hx_drv_swreg_aon_set_appused1( (0x1<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 253)// set using SPI & UART (trans_type == 2) + { + hx_drv_swreg_aon_set_appused1( (0x2<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if(c == 0) + { + hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (0 & 0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + // if(c == 5) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (5 & 0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 6) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (6&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 9) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (9&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 10) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (10&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 11) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (11&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + } + +} + + + + + + + +static const char* BASE64_CHARS_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +void el_base64_encode(const unsigned char* in, int in_len, char* out) { + int i = 0; + int j = 0; + unsigned char char_array_3[3]; + unsigned char char_array_4[4]; + + while (in_len--) { + char_array_3[i++] = *(in++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (i = 0; i < 4; i++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + i = 0; + } + } + + if (i) { + for (j = i; j < 3; j++) char_array_3[j] = '\0'; + + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (j = 0; j < i + 1; j++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + while (i++ < 3) *out++ = '='; + } +} + +std::string img_2_json_str(el_img_t* img) { +if (!img || !img->data || !img->size) [[unlikely]] + return std::string("\"image\": \"\""); + + static std::size_t size = 0; + static std::size_t buffer_size = 0; + + + // only reallcate memory when buffer size is not enough + if (img->size > size) [[unlikely]] { + size = img->size; + buffer_size = (((size + 2u) / 3u) << 2u) + 1u; // base64 encoded size, +1 for terminating null character + printf("buffer_size: %d may be too small reallocating\r\n\n",buffer_size); + printf("if still fail, please modify linker script heap size\r\n\n"); + if (img_2_json_str_buffer) [[likely]] + delete[] img_2_json_str_buffer; + img_2_json_str_buffer = new char[buffer_size]{}; + } + + std::memset(img_2_json_str_buffer, 0, buffer_size); + el_base64_encode(img->data, img->size, img_2_json_str_buffer); + + return concat_strings("\"image\": \"", img_2_json_str_buffer, "\""); +} + + +std::string img_res_2_json_str(const el_img_t* img) { + return concat_strings("\"resolution\": [", std::to_string(img->width), ", ", std::to_string(img->height), "]"); +} + + + +template constexpr std::string results_2_json_str(const std::forward_list& results) { + std::string ss; + const char* delim = ""; + + if (std::is_same::value) { + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"points\": ["; + for (const auto& point : results) { + ss += concat_strings(delim, + "[", + std::to_string(point.x), + ", ", + std::to_string(point.y), + ", ", + std::to_string(point.score), + ", ", + std::to_string(point.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"classes\": ["; + for (const auto& cls : results) { + ss += concat_strings(delim, "[", std::to_string(cls.score), ", ", std::to_string(cls.target), "]"); + delim = ", "; + } + } + ss += "]"; + + return ss; +} + + +std::string box_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_face_bbox_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + ss = "\"fm_face_boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_point_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"fm_points\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < FM_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_point[i].x), + ", ", + std::to_string(it->el_fm_point[i].y), + ", ", + std::to_string(it->el_fm_point[i].score), + ", ", + std::to_string(it->el_fm_point[i].target), + "]"); + delim = ", "; + } + + delim = "] , ["; + for(int i = 0 ; i < FM_IRIS_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_iris[i].x), + ", ", + std::to_string(it->el_fm_iris[i].y), + ", ", + std::to_string(it->el_fm_iris[i].score), + ", ", + std::to_string(it->el_fm_iris[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_angle.yaw), + ", ", + std::to_string(it->el_fm_angle.pitch), + ", ", + std::to_string(it->el_fm_angle.roll), + ", ", + std::to_string(it->el_fm_angle.MAR), + ", ", + std::to_string(it->el_fm_angle.LEAR), + ", ", + std::to_string(it->el_fm_angle.REAR), + ", ", + std::to_string(it->el_fm_angle.left_iris_theta), + ", ", + std::to_string(it->el_fm_angle.left_iris_phi), + ", ", + std::to_string(it->el_fm_angle.right_iris_theta), + ", ", + std::to_string(it->el_fm_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; +} + + +std::string fd_fl_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl_el_9pt\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////left eye landmark + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->left_eye_landmark[i].x), + ", ", + std::to_string(it->left_eye_landmark[i].y), + ", ", + std::to_string(it->left_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////right eye landmark + + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->right_eye_landmark[i].x), + ", ", + std::to_string(it->right_eye_landmark[i].y), + ", ", + std::to_string(it->right_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + ", ", + std::to_string(it->el_fl_angle.left_iris_theta), + ", ", + std::to_string(it->el_fl_angle.left_iris_phi), + ", ", + std::to_string(it->el_fl_angle.right_iris_theta), + ", ", + std::to_string(it->el_fl_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + + +std::string keypoint_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"keypoints\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + for(int i = 0 ; i < KEYPOINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_keypoint[i].x), + ", ", + std::to_string(it->el_keypoint[i].y), + ", ", + std::to_string(it->el_keypoint[i].score), + ", ", + std::to_string(it->el_keypoint[i].target), + "]"); + delim = ", "; + } + ss += "]]"; + delim = ", "; + } + ss += "]"; + + return ss; +} + + +void event_reply(std::string data) { +std::string _cmd ; +std::size_t _n_times; +bool _results_only; + +std::size_t _task_id; +// el_sensor_info_t _sensor_info; +// el_model_info_t _model_info; +// el_algorithm_info_t _algorithm_info; + +std::size_t _times=0; +el_err_code_t _ret; +uint16_t _action_hash; + const auto& ss{concat_strings("\r{\"type\": 1, \"name\": \"", + "INVOKE", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"count\": ", + std::to_string(_times), + data, + "}}\n")}; + send_bytes(ss.c_str(), ss.size()); +} +inline std::string quoted(const std::string& str, const char delim = '"') { + std::size_t sz = 0; + for (char c : str) + if (c == delim) [[unlikely]] + ++sz; + std::string ss(1, delim); + ss.reserve(str.length() + (sz << 1)); + for (char c : str) { + if (c == delim) [[unlikely]] + ss += '\\'; + if (c != '\n') [[likely]] + ss += c; + } + ss += delim; + return ss; +} +const static uint16_t CRC16_MAXIM_TABLE[256] = { + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, + 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, + 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, + 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, + 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, + 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, + 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, + 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, + 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, + 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, + 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, + 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, + 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, + 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, + 0x4100, 0x81c1, 0x8081, 0x4040}; + +EL_ATTR_WEAK uint16_t el_crc16_maxim(const uint8_t* data, size_t length) { + uint16_t crc = 0x0000; + + for (size_t i = 0; i < length; ++i) { + uint8_t index = static_cast(crc ^ data[i]); + crc = (crc >> 8) ^ CRC16_MAXIM_TABLE[index]; + } + + return crc ^ 0xffff; +} + + +std::string model_info_2_json_str(el_model_info_t model_info) { + return concat_strings("{\"id\": ", + std::to_string(model_info.id), + ", \"type\": ", + std::to_string(model_info.type), + ", \"address\": ", + std::to_string(model_info.addr_flash), + ", \"size\": ", + std::to_string(model_info.size), + "}"); +} +void send_device_id() { + std::string cmd; + + const auto& ss{concat_strings("\r{\"type\": 0, \"name\": \"", + "NAME?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + quoted("kris Grove Vision AI (WE2)"), + "}\n")}; + send_bytes(ss.c_str(), ss.size()); + + const auto& ss_ver{concat_strings("\r{\"type\": 0, \"name\": \"", + "VER?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"software\": \"", + EL_VERSION, + "\", \"hardware\": \"", + "kris 2024", + "\"}}\n")}; + send_bytes(ss_ver.c_str(), ss_ver.size()); + + + + const auto& ss_id{concat_strings("\r{\"type\": 0, \"name\": \"", + "ID?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + "1", + "}\n")}; + send_bytes(ss_id.c_str(), ss_id.size()); + + char info[CONFIG_SSCMA_CMD_MAX_LENGTH]{}; + + const auto& ss_info{ + concat_strings("\r{\"type\": 0, \"name\": \"", + "INFO?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"crc16_maxim\": ", + std::to_string(el_crc16_maxim(reinterpret_cast(&info[0]), std::strlen(&info[0]))), + ", \"info\": ", + quoted(info), + "}}\n")}; + send_bytes(ss_info.c_str(), ss_info.size()); + el_model_info_t model_info; + model_info.id=0; + model_info.type=EL_ALGO_TYPE_UNDEFINED; + + const auto& ss_model_info{concat_strings("\r{\"type\": 0, \"name\": \"", + "MODEL?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + model_info_2_json_str(model_info), + "}\n")}; + send_bytes(ss_model_info.c_str(), ss_model_info.size()); + +} + +std::string algo_tick_2_json_str(uint32_t algo_tick) { + std::string ss; + const char* delim = ""; + + ss = "\"algo_tick\": ["; + + ss += concat_strings(delim, + "[", + std::to_string(algo_tick), + "]"); + delim = ", "; + ss += "]"; + + return ss; +} \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.h new file mode 100644 index 00000000..92a5e88c --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/send_result.h @@ -0,0 +1,183 @@ + +#ifdef __cplusplus +#include +#include +#include +#include +#include +#endif + + +#include +#include +extern "C" { +#include "hx_drv_swreg_aon.h" +} +#define CONSOLE_UART_ID 0 +#define EL_ATTR_WEAK __attribute__((weak)) +#define EL_VERSION __TIMESTAMP__ +#define CONFIG_SSCMA_CMD_MAX_LENGTH (4096) +#define KEYPOINT_NUM 17 +#define FM_POINT_NUM 468 +#define FM_IRIS_POINT_NUM 10 +#define MAX_FACE_LAND_MARK_TRACKED_POINT 68 +typedef enum { + EL_OK = 0, // success + EL_AGAIN = 1, // try again + EL_ELOG = 2, // logic error + EL_ETIMOUT = 3, // timeout + EL_EIO = 4, // IO error + EL_EINVAL = 5, // invalid argument + EL_ENOMEM = 6, // out of memory + EL_EBUSY = 7, // busy + EL_ENOTSUP = 8, // not supported + EL_EPERM = 9, // operation not permitted +} el_err_code_t; +typedef enum { + EL_PIXEL_FORMAT_RGB888 = 0, + EL_PIXEL_FORMAT_RGB565, + EL_PIXEL_FORMAT_YUV422, + EL_PIXEL_FORMAT_GRAYSCALE, + EL_PIXEL_FORMAT_JPEG, + EL_PIXEL_FORMAT_UNKNOWN, +} el_pixel_format_t; +typedef enum el_pixel_rotate_t { + EL_PIXEL_ROTATE_0 = 0, + EL_PIXEL_ROTATE_90, + EL_PIXEL_ROTATE_180, + EL_PIXEL_ROTATE_270, + EL_PIXEL_ROTATE_UNKNOWN, +} el_pixel_rotate_t; +typedef struct el_img_t { + uint8_t* data; + size_t size; + uint16_t width; + uint16_t height; + el_pixel_format_t format; + el_pixel_rotate_t rotate; +} el_img_t; +typedef struct el_box_t { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint8_t score; + uint8_t target; +} el_box_t; + +typedef struct el_point_t { + uint16_t x; + uint16_t y; + uint8_t score; + uint8_t target; +} el_point_t; + +typedef struct el_class_t { + uint16_t score; + uint16_t target; +} el_class_t; + +typedef struct el_keypoint_t { + el_box_t el_box; + el_point_t el_keypoint[KEYPOINT_NUM]; +} el_keypoint_t; + + +typedef struct { + int16_t yaw; + int16_t pitch; + int16_t roll; + int16_t MAR; + int16_t REAR; + int16_t LEAR; + int16_t left_iris_theta; + int16_t left_iris_phi; + int16_t right_iris_theta; + int16_t right_iris_phi; +}el_struct_angle; + +typedef struct el_fm_point_t { + el_box_t el_box; + el_point_t el_fm_point[FM_POINT_NUM]; + el_point_t el_fm_iris[FM_IRIS_POINT_NUM]; + el_struct_angle el_fm_angle; +} el_fm_point_t; + + +typedef struct el_fd_fl_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_struct_angle el_fl_angle; +} el_fd_fl_t; + +typedef struct el_fd_fl_el_9pt_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_point_t left_eye_landmark[9]; + el_point_t right_eye_landmark[9]; + el_struct_angle el_fl_angle; +} el_fd_fl_el_9pt_t; + +/** + * @brief Algorithm Types + */ +typedef enum { + EL_ALGO_TYPE_UNDEFINED = 0u, + EL_ALGO_TYPE_FOMO = 1u, + EL_ALGO_TYPE_PFLD = 2u, + EL_ALGO_TYPE_YOLO = 3u, + EL_ALGO_TYPE_IMCLS = 4u +} el_algorithm_type_t; +typedef struct el_model_info_t { + uint8_t id; + el_algorithm_type_t type; + uint32_t addr_flash; + uint32_t size; + const uint8_t* addr_memory; +} el_model_info_t; + +constexpr inline std::size_t lengthof(const char* s) { + std::size_t size = 0; + while (*(s + size) != '\0') ++size; + return size; +} + +template constexpr inline std::size_t lengthof(const T (&)[N]) noexcept { return N; } + +inline std::size_t lengthof(const std::string& s) { return s.length(); } + +// template constexpr inline decltype(auto) concat_strings(Args&&... args) { +// std::size_t length{(lengthof(args) + ...)}; // try calculate total length at compile time +// std::string result; +// result.reserve(length + 1); // preallocate memory, avoid repeatly allocate memory while appendings +// (result.append(std::forward(args)), ...); +// return result; +// } + +template constexpr inline decltype(auto) concat_strings(Args&&... args) { + std::size_t length{(lengthof(args) + ...)}; + std::string result; + result.reserve(length); + (result.append(std::forward(args)), ...); + return result; +} + + + +el_err_code_t send_bytes(const char* buffer, size_t size) ; +el_err_code_t read_bytes(char* buffer, size_t size); +el_err_code_t read_bytes_nonblock(char* buffer, size_t size); +void set_model_change_by_uart(); +std::string img_2_json_str(el_img_t* img); +void event_reply(std::string data); +void send_device_id(); +template constexpr std::string results_2_json_str(const std::forward_list& results); + +std::string box_results_2_json_str(std::forward_list& results); +std::string fm_point_results_2_json_str(std::forward_list& results); +std::string keypoint_results_2_json_str(std::forward_list& results); +std::string img_res_2_json_str(const el_img_t* img); +std::string algo_tick_2_json_str(uint32_t algo_tick); +std::string fd_fl_results_2_json_str(std::forward_list& results); +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results); +std::string fm_face_bbox_results_2_json_str(std::forward_list& results); \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.c index 14bb34c0..c3998849 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.c @@ -68,6 +68,7 @@ #include "memory_manage.h" #include "hx_drv_watchdog.h" + #ifdef EPII_FPGA #define DBG_APP_LOG (1) #else @@ -105,6 +106,8 @@ struct_fl_fr_algoResult algoresult_fl_fr_infer; struct_yolov8_ob_algoResult algoresult_yolov8n_ob; struct_yolov8_ob_algoResult algoresult_yolofastest_ob; struct_yolov8_pose_algoResult algoresult_yolov8_pose; +static uint32_t g_trans_type; +static uint32_t judge_case_data; void app_start_state(APP_STATE_E state); void model_change(void); void pinmux_init(); @@ -712,11 +715,13 @@ static void dp_app_cv_yolov8n_ob_eventhdl_cb(EVT_INDEX_E event) if(g_frame_ready == 1) { g_frame_ready = 0; + + hx_drv_swreg_aon_get_appused1(&judge_case_data); // #ifdef WATCHDOG_VERSION // if(EPII_get_memory(0x5610F02c)==g_use_case) // hx_drv_watchdog_update(WATCHDOG_ID_0, WATCH_DOG_TIMEOUT_TH); // #endif - if(EPII_get_memory(0x5610F02c)!=g_use_case) { + if( ((judge_case_data&0xff) !=g_use_case) || ( (judge_case_data>>16) != g_trans_type ) ) { //cisdp_sensor_stop(); model_change(); #ifdef CPU_24MHZ_VERSION @@ -742,32 +747,80 @@ static void dp_app_cv_yolov8n_ob_eventhdl_cb(EVT_INDEX_E event) } g_spi_master_initial_status = 1; } - read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); - //read_status = hx_drv_spi_mst_protocol_write_sp_wait(jpeg_addr, jpeg_sz, DATA_TYPE_JPG, 0); + #ifdef UART_SEND_ALOGO_RESEULT + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { + + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + } + #else + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + #endif #if DBG_APP_LOG dbg_printf(DBG_LESS_INFO, "write frame result %d, data size=%d,addr=0x%x\n",read_status, jpeg_sz,jpeg_addr); #endif #endif #ifdef EN_ALGO +#ifdef UART_SEND_ALOGO_RESEULT -#if TOTAL_STEP_TICK - uint32_t systick_1, systick_2; - uint32_t loop_cnt_1, loop_cnt_2; - SystemGetTick(&systick_1, &loop_cnt_1); -#endif - + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { cv_yolov8n_ob_run(&algoresult_yolov8n_ob); -#if TOTAL_STEP_TICK - SystemGetTick(&systick_2, &loop_cnt_2); - #if TOTAL_STEP_TICK_DBG_LOG - xprintf("Tick for TOTAL YOLOV8N OB:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); - #endif - algoresult_yolov8n_ob.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); -#endif + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + cv_yolov8n_ob_run(&algoresult_yolov8n_ob); + + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL YOLOV8N OB:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + #endif + + if(g_trans_type == 1)//USE SPI + { + algoresult_yolov8n_ob.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + } + #endif + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8n_ob, sizeof(struct_yolov8_ob_algoResult), DATA_TYPE_META_YOLOV8_OB_DATA); + #endif + } +#else + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + + cv_yolov8n_ob_run(&algoresult_yolov8n_ob); + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL YOLOV8N OB:[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + #endif + algoresult_yolov8n_ob.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + #endif + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8n_ob, sizeof(struct_yolov8_ob_algoResult), DATA_TYPE_META_YOLOV8_OB_DATA); + #endif -#if FRAME_CHECK_DEBUG - hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8n_ob, sizeof(struct_yolov8_ob_algoResult), DATA_TYPE_META_YOLOV8_OB_DATA); #endif //clear_alg_hp_rsult for (int i = 0; i < MAX_TRACKED_YOLOV8_ALGO_RES; ++i) @@ -806,6 +859,33 @@ void app_start_state(APP_STATE_E state) } dp_var_int(); +#ifdef UART_SEND_ALOGO_RESEULT + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) + { + if(state == APP_STATE_ALLON_YOLOV8N_OB) + { + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8n_ob_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + } + else if ( g_trans_type == 1 ) // only use SPI + { + if(state == APP_STATE_ALLON_YOLOV8N_OB) + { + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8n_ob_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + } +#else if(state == APP_STATE_ALLON_YOLOV8N_OB) { if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8n_ob_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) @@ -814,6 +894,7 @@ void app_start_state(APP_STATE_E state) APP_BLOCK_FUNC(); } } +#endif event_handler_init(); cisdp_sensor_start(); @@ -909,7 +990,15 @@ int tflm_yolov8_od_app(void) { // #endif //check current use case - g_use_case = EPII_get_memory(0x5610F02c); + // //check current use case + //judge which case + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + //transfer type + g_trans_type = (judge_case_data>>16); + //model case + g_use_case = (judge_case_data&0xff); + #ifndef CPU_24MHZ_VERSION xprintf("ori_clk src info, 0x56100030=%x\n",EPII_get_memory(0x56100030)); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.mk b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.mk index 71983aab..ace904b8 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.mk +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_od/tflm_yolov8_od.mk @@ -4,6 +4,7 @@ APPL_DEFINES += -DTFLM_YOLOV8_OD APPL_DEFINES += -Daudvidpre_ret_pll400_timer1 -DIP_xdma APPL_DEFINES += -DEVT_DATAPATH +APPL_DEFINES += -DUART_SEND_ALOGO_RESEULT #APPL_DEFINES += -DEVT_CM55MTIMER -DEVT_CM55MMB APPL_DEFINES += -DDBG_MORE diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/TFLM_yolov8_pose_S_only.ld b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/TFLM_yolov8_pose_S_only.ld index dec82a07..309d5e9f 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/TFLM_yolov8_pose_S_only.ld +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/TFLM_yolov8_pose_S_only.ld @@ -10,9 +10,8 @@ MEMORY CM55M_S_SRAM (rwx) : ORIGIN = BOOT2NDLOADER_BASE, LENGTH = 0x00200000-(BOOT2NDLOADER_BASE-BASE_ADDR_SRAM0_ALIAS) /* 2M-0x1f000 bytes*/ } -__HEAP_SIZE = 0x10000; -__STACK_SIZE = 0x10000; - +__HEAP_SIZE = 0x2D000; +__STACK_SIZE = 0x3000; ENTRY(Reset_Handler) SECTIONS diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/cvapp_yolov8_pose.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/cvapp_yolov8_pose.cpp index 48a81faf..55024c3a 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/cvapp_yolov8_pose.cpp +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/cvapp_yolov8_pose.cpp @@ -34,7 +34,7 @@ #include "cisdp_cfg.h" #include "memory_manage.h" #include "yolo_postprocessing.h" - +#include "send_result.h" #define YOLOV8_POSE_INPUT_224 0 #define YOLOV8_POSE_INPUT_256 1 @@ -56,6 +56,7 @@ #define EACH_STEP_TICK 0 +#define TOTAL_STEP_TICK 1 #ifdef TRUSTZONE_SEC #define U55_BASE BASE_ADDR_APB_U55_CTRL_ALIAS @@ -97,7 +98,7 @@ static float** anchor_756_2; #define CPU_CLK 0xffffff+1 uint32_t systick_1, systick_2; uint32_t loop_cnt_1, loop_cnt_2; - +static uint32_t capture_image_tick = 0; // #endif @@ -535,7 +536,8 @@ void yolov8_pose_cal_xywh(int j,TfLiteTensor* output[7], box *bbox, float** anch return ; } -static void yolov8_pose_post_processing(tflite::MicroInterpreter* static_interpreter,float modelScoreThreshold, float modelNMSThreshold, struct_yolov8_pose_algoResult *alg) +// static void yolov8_pose_post_processing(tflite::MicroInterpreter* static_interpreter,float modelScoreThreshold, float modelNMSThreshold, struct_yolov8_pose_algoResult *alg) +static void yolov8_pose_post_processing(tflite::MicroInterpreter* static_interpreter,float modelScoreThreshold, float modelNMSThreshold, struct_yolov8_pose_algoResult *alg, std::forward_list &el_keypoint_algo) { uint32_t img_w = app_get_raw_width(); uint32_t img_h = app_get_raw_height(); @@ -656,7 +658,9 @@ static void yolov8_pose_post_processing(tflite::MicroInterpreter* static_interpr alg->dypr[i].confidence = confidences[idx]; - for(int k = 0 ; k < 17 ; k++) + + el_keypoint_t temp_el_keypoint; + for(int k = 0 ; k < KEYPOINT_NUM ; k++) { alg->dypr[i].hpr[k].x = kpts_vector[idx].hpr[k].x; alg->dypr[i].hpr[k].y = kpts_vector[idx].hpr[k].y; @@ -671,10 +675,29 @@ static void yolov8_pose_post_processing(tflite::MicroInterpreter* static_interpr alg->dypr[i].hpr[k].x = (float)alg->dypr[i].hpr[k].x / (float)YOLOV8_POSE_INPUT_TENSOR_WIDTH *(float)img_w; alg->dypr[i].hpr[k].y = (float)alg->dypr[i].hpr[k].y / (float)YOLOV8_POSE_INPUT_TENSOR_HEIGHT * (float)img_h; ///resize to original image size + + /***set uart ouput format***/ + temp_el_keypoint.el_keypoint[k].score = alg->dypr[i].hpr[k].score*100; + temp_el_keypoint.el_keypoint[k].target = k; + temp_el_keypoint.el_keypoint[k].x = alg->dypr[i].hpr[k].x; + temp_el_keypoint.el_keypoint[k].y = alg->dypr[i].hpr[k].y; } #if DBG_APP_LOG printf("id: %d,confidence: %f x: %d, y: %d, w: %d, h: %d\r\n",i,alg->dypr[i].confidence, alg->dypr[i].bbox.x,alg->dypr[i].bbox.y,alg->dypr[i].bbox.width,alg->dypr[i].bbox.height); #endif + + + temp_el_keypoint.el_box.score = alg->dypr[i].confidence*100; + temp_el_keypoint.el_box.target = i; + temp_el_keypoint.el_box.x = alg->dypr[i].bbox.x; + temp_el_keypoint.el_box.y = alg->dypr[i].bbox.y; + temp_el_keypoint.el_box.w = alg->dypr[i].bbox.width; + temp_el_keypoint.el_box.h = alg->dypr[i].bbox.height; + + + // printf("temp_el_box.x %d,temp_el_box.y: %d\r\n",temp_el_box.x,temp_el_box.y); + el_keypoint_algo.emplace_front(temp_el_keypoint); + } } @@ -689,12 +712,17 @@ int cv_yolov8_pose_run(struct_yolov8_pose_algoResult *algoresult_yolov8_pose) { uint32_t ch = app_get_raw_channels(); uint32_t raw_addr = app_get_raw_addr(); uint32_t expand = 0; - + std::forward_list el_keypoint_algo; + #if DBG_APP_LOG xprintf("raw info: w[%d] h[%d] ch[%d] addr[%x]\n",img_w, img_h, ch, raw_addr); #endif + #if TOTAL_STEP_TICK + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + if(yolov8_pose_int_ptr!= nullptr) { //get image from sensor and resize w_scale = (float)(img_w - 1) / (YOLOV8_POSE_INPUT_TENSOR_WIDTH - 1); @@ -752,8 +780,11 @@ int cv_yolov8_pose_run(struct_yolov8_pose_algoResult *algoresult_yolov8_pose) { SystemGetTick(&systick_1, &loop_cnt_1); #endif //retrieve output data - yolov8_pose_post_processing(yolov8_pose_int_ptr,0.25, 0.45, algoresult_yolov8_pose ); - #if EACH_STEP_TICK + + + yolov8_pose_post_processing(yolov8_pose_int_ptr,0.25, 0.45, algoresult_yolov8_pose,el_keypoint_algo ); + + #if EACH_STEP_TICK SystemGetTick(&systick_2, &loop_cnt_2); xprintf("Tick for Invoke for YOLOV8_POSE_post_processing:[%d]\r\n\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); #endif @@ -762,7 +793,41 @@ int cv_yolov8_pose_run(struct_yolov8_pose_algoResult *algoresult_yolov8_pose) { xprintf("yolov8 pose done\r\n"); #endif } + + +#ifdef UART_SEND_ALOGO_RESEULT + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + algoresult_yolov8_pose->algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2) + capture_image_tick; + #endif +uint32_t judge_case_data; +uint32_t g_trans_type; +hx_drv_swreg_aon_get_appused1(&judge_case_data); +g_trans_type = (judge_case_data>>16); +if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) +{ + el_img_t temp_el_jpg_img = el_img_t{}; + temp_el_jpg_img.data = (uint8_t *)app_get_jpeg_addr(); + temp_el_jpg_img.size = app_get_jpeg_sz(); + temp_el_jpg_img.width = app_get_raw_width(); + temp_el_jpg_img.height = app_get_raw_height(); + temp_el_jpg_img.format = EL_PIXEL_FORMAT_JPEG; + temp_el_jpg_img.rotate = EL_PIXEL_ROTATE_0; + + send_device_id(); + // event_reply(concat_strings(", ", keypoint_results_2_json_str(el_keypoint_algo), ", ", img_2_json_str(&temp_el_jpg_img))); + event_reply(concat_strings(", ", algo_tick_2_json_str(algoresult_yolov8_pose->algo_tick),", ", keypoint_results_2_json_str(el_keypoint_algo), ", ", img_2_json_str(&temp_el_jpg_img))); +} + set_model_change_by_uart(); +#endif + + SystemGetTick(&systick_1, &loop_cnt_1); + //recapture image sensordplib_retrigger_capture(); + + SystemGetTick(&systick_2, &loop_cnt_2); + capture_image_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + return ercode; } diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.cpp b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.cpp new file mode 100644 index 00000000..4f610d52 --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.cpp @@ -0,0 +1,811 @@ +extern "C" { +#include +#include "hx_drv_swreg_aon.h" +#include "tflm_yolov8_pose.h" +} +#include + +#include +#include +#include +#include +#include +#include +#include +#include "WE2_core.h" +#include + +static char* img_2_json_str_buffer = nullptr; + +el_err_code_t send_bytes(const char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + size_t sent{0}; + size_t pos_of_bytes{0}; + + while (size) { + size_t bytes_to_send{size < 8 ? size : 8}; + + sent += console_uart->uart_write(buffer + pos_of_bytes, bytes_to_send); + pos_of_bytes += bytes_to_send; + size -= bytes_to_send; + } + + //0 is ok(success) + //1 is again (fail) + return sent == pos_of_bytes ? EL_OK : EL_AGAIN; +} + + +el_err_code_t read_bytes(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + read += console_uart->uart_read(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + +el_err_code_t read_bytes_nonblock(char* buffer, size_t size) { + DEV_UART* console_uart; + console_uart = hx_drv_uart_get_dev((USE_DW_UART_E)CONSOLE_UART_ID); + console_uart->uart_open(UART_BAUDRATE_921600); + + size_t read{0}; + size_t pos_of_bytes{0}; + while (size) { + size_t bytes_to_read{size < 8 ? size : 8}; + + read += console_uart->uart_read_nonblock(buffer + pos_of_bytes, bytes_to_read); + + pos_of_bytes += bytes_to_read; + size -= bytes_to_read; + + } + + return read > 0 ? EL_OK : EL_AGAIN; +} + + +void set_model_change_by_uart() +{ + char c{'\0'}; + if(!read_bytes_nonblock((char *)(&c), 1))//if read ok + { + uint32_t data; + hx_drv_swreg_aon_get_appused1(&data); + //transfer type + uint16_t trans_type = (data>>16); + //model case + uint16_t model_case = (data&0xff); + + if( c == 255)// set using UART (trans_type == 0) + { + hx_drv_swreg_aon_set_appused1( (0x0<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 254)// set using SPI (trans_type == 1) + { + hx_drv_swreg_aon_set_appused1( (0x1<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if( c == 253)// set using SPI & UART (trans_type == 2) + { + hx_drv_swreg_aon_set_appused1( (0x2<<16) | (model_case&0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + if(c == 0) + { + hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (0 & 0xff)); + delete[] img_2_json_str_buffer; + SetPSPDNoVid(); + } + // if(c == 5) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (5 & 0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 6) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (6&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 9) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (9&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 10) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (10&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + // if(c == 11) + // { + // hx_drv_swreg_aon_set_appused1( (trans_type<<16) | (11&0xff)); + // delete[] img_2_json_str_buffer; + // SetPSPDNoVid(); + // } + } + +} + + + + + + + +static const char* BASE64_CHARS_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +void el_base64_encode(const unsigned char* in, int in_len, char* out) { + int i = 0; + int j = 0; + unsigned char char_array_3[3]; + unsigned char char_array_4[4]; + + while (in_len--) { + char_array_3[i++] = *(in++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (i = 0; i < 4; i++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + i = 0; + } + } + + if (i) { + for (j = i; j < 3; j++) char_array_3[j] = '\0'; + + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (j = 0; j < i + 1; j++) *out++ = BASE64_CHARS_TABLE[char_array_4[i]]; + + while (i++ < 3) *out++ = '='; + } +} + +std::string img_2_json_str(el_img_t* img) { +if (!img || !img->data || !img->size) [[unlikely]] + return std::string("\"image\": \"\""); + + static std::size_t size = 0; + static std::size_t buffer_size = 0; + + + // only reallcate memory when buffer size is not enough + if (img->size > size) [[unlikely]] { + size = img->size; + buffer_size = (((size + 2u) / 3u) << 2u) + 1u; // base64 encoded size, +1 for terminating null character + printf("buffer_size: %d may be too small reallocating\r\n\n",buffer_size); + printf("if still fail, please modify linker script heap size\r\n\n"); + if (img_2_json_str_buffer) [[likely]] + delete[] img_2_json_str_buffer; + img_2_json_str_buffer = new char[buffer_size]{}; + } + + std::memset(img_2_json_str_buffer, 0, buffer_size); + el_base64_encode(img->data, img->size, img_2_json_str_buffer); + + return concat_strings("\"image\": \"", img_2_json_str_buffer, "\""); +} + + +std::string img_res_2_json_str(const el_img_t* img) { + return concat_strings("\"resolution\": [", std::to_string(img->width), ", ", std::to_string(img->height), "]"); +} + + + +template constexpr std::string results_2_json_str(const std::forward_list& results) { + std::string ss; + const char* delim = ""; + + if (std::is_same::value) { + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"points\": ["; + for (const auto& point : results) { + ss += concat_strings(delim, + "[", + std::to_string(point.x), + ", ", + std::to_string(point.y), + ", ", + std::to_string(point.score), + ", ", + std::to_string(point.target), + "]"); + delim = ", "; + } + } else if (std::is_same::value) { + ss = "\"classes\": ["; + for (const auto& cls : results) { + ss += concat_strings(delim, "[", std::to_string(cls.score), ", ", std::to_string(cls.target), "]"); + delim = ", "; + } + } + ss += "]"; + + return ss; +} + + +std::string box_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + ss = "\"boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_face_bbox_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + ss = "\"fm_face_boxes\": ["; + for (const auto& box : results) { + ss += concat_strings(delim, + "[", + std::to_string(box.x), + ", ", + std::to_string(box.y), + ", ", + std::to_string(box.w), + ", ", + std::to_string(box.h), + ", ", + std::to_string(box.score), + ", ", + std::to_string(box.target), + "]"); + delim = ", "; + } + ss += "]"; + + return ss; +} + + +std::string fm_point_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"fm_points\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < FM_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_point[i].x), + ", ", + std::to_string(it->el_fm_point[i].y), + ", ", + std::to_string(it->el_fm_point[i].score), + ", ", + std::to_string(it->el_fm_point[i].target), + "]"); + delim = ", "; + } + + delim = "] , ["; + for(int i = 0 ; i < FM_IRIS_POINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_iris[i].x), + ", ", + std::to_string(it->el_fm_iris[i].y), + ", ", + std::to_string(it->el_fm_iris[i].score), + ", ", + std::to_string(it->el_fm_iris[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fm_angle.yaw), + ", ", + std::to_string(it->el_fm_angle.pitch), + ", ", + std::to_string(it->el_fm_angle.roll), + ", ", + std::to_string(it->el_fm_angle.MAR), + ", ", + std::to_string(it->el_fm_angle.LEAR), + ", ", + std::to_string(it->el_fm_angle.REAR), + ", ", + std::to_string(it->el_fm_angle.left_iris_theta), + ", ", + std::to_string(it->el_fm_angle.left_iris_phi), + ", ", + std::to_string(it->el_fm_angle.right_iris_theta), + ", ", + std::to_string(it->el_fm_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; +} + + +std::string fd_fl_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results) +{ + std::string ss; + const char* delim = ""; + + + + ss = "\"fd_fl_el_9pt\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + + for(int i = 0 ; i < MAX_FACE_LAND_MARK_TRACKED_POINT ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl[i].x), + ", ", + std::to_string(it->el_fl[i].y), + ", ", + std::to_string(it->el_fl[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////left eye landmark + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->left_eye_landmark[i].x), + ", ", + std::to_string(it->left_eye_landmark[i].y), + ", ", + std::to_string(it->left_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ////////////////////////////////right eye landmark + + delim = "] , ["; + for(int i = 0 ; i < 9 ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->right_eye_landmark[i].x), + ", ", + std::to_string(it->right_eye_landmark[i].y), + ", ", + std::to_string(it->right_eye_landmark[i].target), + "]"); + delim = ", "; + } + + ///////////////////////////////////////// + ////yaw pitch roll + delim = "] , ["; + + ss += concat_strings(delim, + "[", + std::to_string(it->el_fl_angle.yaw), + ", ", + std::to_string(it->el_fl_angle.pitch), + ", ", + std::to_string(it->el_fl_angle.roll), + ", ", + std::to_string(it->el_fl_angle.MAR), + ", ", + std::to_string(it->el_fl_angle.LEAR), + ", ", + std::to_string(it->el_fl_angle.REAR), + ", ", + std::to_string(it->el_fl_angle.left_iris_theta), + ", ", + std::to_string(it->el_fl_angle.left_iris_phi), + ", ", + std::to_string(it->el_fl_angle.right_iris_theta), + ", ", + std::to_string(it->el_fl_angle.right_iris_phi), + "]"); + + ///////////////////////////////////////// + ss += "]]"; + delim = ", "; + } + ss += "]"; + return ss; + +} + + + + +std::string keypoint_results_2_json_str(std::forward_list& results) { + std::string ss; + const char* delim = ""; + + + + ss = "\"keypoints\": ["; + std::forward_list::iterator it; + for ( it = results.begin(); it != results.end(); ++it ) + { + ss += concat_strings(delim, + "[[", + std::to_string(it->el_box.x), + ", ", + std::to_string(it->el_box.y), + ", ", + std::to_string(it->el_box.w), + ", ", + std::to_string(it->el_box.h), + ", ", + std::to_string(it->el_box.score), + ", ", + std::to_string(it->el_box.target), + "]"); + delim = ", ["; + for(int i = 0 ; i < KEYPOINT_NUM ; i++) + { + ss += concat_strings(delim, + "[", + std::to_string(it->el_keypoint[i].x), + ", ", + std::to_string(it->el_keypoint[i].y), + ", ", + std::to_string(it->el_keypoint[i].score), + ", ", + std::to_string(it->el_keypoint[i].target), + "]"); + delim = ", "; + } + ss += "]]"; + delim = ", "; + } + ss += "]"; + + return ss; +} + + +void event_reply(std::string data) { +std::string _cmd ; +std::size_t _n_times; +bool _results_only; + +std::size_t _task_id; +// el_sensor_info_t _sensor_info; +// el_model_info_t _model_info; +// el_algorithm_info_t _algorithm_info; + +std::size_t _times=0; +el_err_code_t _ret; +uint16_t _action_hash; + const auto& ss{concat_strings("\r{\"type\": 1, \"name\": \"", + "INVOKE", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"count\": ", + std::to_string(_times), + data, + "}}\n")}; + send_bytes(ss.c_str(), ss.size()); +} +inline std::string quoted(const std::string& str, const char delim = '"') { + std::size_t sz = 0; + for (char c : str) + if (c == delim) [[unlikely]] + ++sz; + std::string ss(1, delim); + ss.reserve(str.length() + (sz << 1)); + for (char c : str) { + if (c == delim) [[unlikely]] + ss += '\\'; + if (c != '\n') [[likely]] + ss += c; + } + ss += delim; + return ss; +} +const static uint16_t CRC16_MAXIM_TABLE[256] = { + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, + 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, + 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, + 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, + 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, + 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, + 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, + 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, + 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, + 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, + 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, + 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, + 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, + 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, + 0x4100, 0x81c1, 0x8081, 0x4040}; + +EL_ATTR_WEAK uint16_t el_crc16_maxim(const uint8_t* data, size_t length) { + uint16_t crc = 0x0000; + + for (size_t i = 0; i < length; ++i) { + uint8_t index = static_cast(crc ^ data[i]); + crc = (crc >> 8) ^ CRC16_MAXIM_TABLE[index]; + } + + return crc ^ 0xffff; +} + + +std::string model_info_2_json_str(el_model_info_t model_info) { + return concat_strings("{\"id\": ", + std::to_string(model_info.id), + ", \"type\": ", + std::to_string(model_info.type), + ", \"address\": ", + std::to_string(model_info.addr_flash), + ", \"size\": ", + std::to_string(model_info.size), + "}"); +} +void send_device_id() { + std::string cmd; + + const auto& ss{concat_strings("\r{\"type\": 0, \"name\": \"", + "NAME?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + quoted("kris Grove Vision AI (WE2)"), + "}\n")}; + send_bytes(ss.c_str(), ss.size()); + + const auto& ss_ver{concat_strings("\r{\"type\": 0, \"name\": \"", + "VER?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"software\": \"", + EL_VERSION, + "\", \"hardware\": \"", + "kris 2024", + "\"}}\n")}; + send_bytes(ss_ver.c_str(), ss_ver.size()); + + + + const auto& ss_id{concat_strings("\r{\"type\": 0, \"name\": \"", + "ID?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + "1", + "}\n")}; + send_bytes(ss_id.c_str(), ss_id.size()); + + char info[CONFIG_SSCMA_CMD_MAX_LENGTH]{}; + + const auto& ss_info{ + concat_strings("\r{\"type\": 0, \"name\": \"", + "INFO?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": {\"crc16_maxim\": ", + std::to_string(el_crc16_maxim(reinterpret_cast(&info[0]), std::strlen(&info[0]))), + ", \"info\": ", + quoted(info), + "}}\n")}; + send_bytes(ss_info.c_str(), ss_info.size()); + el_model_info_t model_info; + model_info.id=0; + model_info.type=EL_ALGO_TYPE_UNDEFINED; + + const auto& ss_model_info{concat_strings("\r{\"type\": 0, \"name\": \"", + "MODEL?", + "\", \"code\": ", + std::to_string(EL_OK), + ", \"data\": ", + model_info_2_json_str(model_info), + "}\n")}; + send_bytes(ss_model_info.c_str(), ss_model_info.size()); + +} + +std::string algo_tick_2_json_str(uint32_t algo_tick) { + std::string ss; + const char* delim = ""; + + ss = "\"algo_tick\": ["; + + ss += concat_strings(delim, + "[", + std::to_string(algo_tick), + "]"); + delim = ", "; + ss += "]"; + + return ss; +} \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.h b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.h new file mode 100644 index 00000000..92a5e88c --- /dev/null +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/send_result.h @@ -0,0 +1,183 @@ + +#ifdef __cplusplus +#include +#include +#include +#include +#include +#endif + + +#include +#include +extern "C" { +#include "hx_drv_swreg_aon.h" +} +#define CONSOLE_UART_ID 0 +#define EL_ATTR_WEAK __attribute__((weak)) +#define EL_VERSION __TIMESTAMP__ +#define CONFIG_SSCMA_CMD_MAX_LENGTH (4096) +#define KEYPOINT_NUM 17 +#define FM_POINT_NUM 468 +#define FM_IRIS_POINT_NUM 10 +#define MAX_FACE_LAND_MARK_TRACKED_POINT 68 +typedef enum { + EL_OK = 0, // success + EL_AGAIN = 1, // try again + EL_ELOG = 2, // logic error + EL_ETIMOUT = 3, // timeout + EL_EIO = 4, // IO error + EL_EINVAL = 5, // invalid argument + EL_ENOMEM = 6, // out of memory + EL_EBUSY = 7, // busy + EL_ENOTSUP = 8, // not supported + EL_EPERM = 9, // operation not permitted +} el_err_code_t; +typedef enum { + EL_PIXEL_FORMAT_RGB888 = 0, + EL_PIXEL_FORMAT_RGB565, + EL_PIXEL_FORMAT_YUV422, + EL_PIXEL_FORMAT_GRAYSCALE, + EL_PIXEL_FORMAT_JPEG, + EL_PIXEL_FORMAT_UNKNOWN, +} el_pixel_format_t; +typedef enum el_pixel_rotate_t { + EL_PIXEL_ROTATE_0 = 0, + EL_PIXEL_ROTATE_90, + EL_PIXEL_ROTATE_180, + EL_PIXEL_ROTATE_270, + EL_PIXEL_ROTATE_UNKNOWN, +} el_pixel_rotate_t; +typedef struct el_img_t { + uint8_t* data; + size_t size; + uint16_t width; + uint16_t height; + el_pixel_format_t format; + el_pixel_rotate_t rotate; +} el_img_t; +typedef struct el_box_t { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint8_t score; + uint8_t target; +} el_box_t; + +typedef struct el_point_t { + uint16_t x; + uint16_t y; + uint8_t score; + uint8_t target; +} el_point_t; + +typedef struct el_class_t { + uint16_t score; + uint16_t target; +} el_class_t; + +typedef struct el_keypoint_t { + el_box_t el_box; + el_point_t el_keypoint[KEYPOINT_NUM]; +} el_keypoint_t; + + +typedef struct { + int16_t yaw; + int16_t pitch; + int16_t roll; + int16_t MAR; + int16_t REAR; + int16_t LEAR; + int16_t left_iris_theta; + int16_t left_iris_phi; + int16_t right_iris_theta; + int16_t right_iris_phi; +}el_struct_angle; + +typedef struct el_fm_point_t { + el_box_t el_box; + el_point_t el_fm_point[FM_POINT_NUM]; + el_point_t el_fm_iris[FM_IRIS_POINT_NUM]; + el_struct_angle el_fm_angle; +} el_fm_point_t; + + +typedef struct el_fd_fl_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_struct_angle el_fl_angle; +} el_fd_fl_t; + +typedef struct el_fd_fl_el_9pt_t { + el_box_t el_box; + el_point_t el_fl[MAX_FACE_LAND_MARK_TRACKED_POINT]; + el_point_t left_eye_landmark[9]; + el_point_t right_eye_landmark[9]; + el_struct_angle el_fl_angle; +} el_fd_fl_el_9pt_t; + +/** + * @brief Algorithm Types + */ +typedef enum { + EL_ALGO_TYPE_UNDEFINED = 0u, + EL_ALGO_TYPE_FOMO = 1u, + EL_ALGO_TYPE_PFLD = 2u, + EL_ALGO_TYPE_YOLO = 3u, + EL_ALGO_TYPE_IMCLS = 4u +} el_algorithm_type_t; +typedef struct el_model_info_t { + uint8_t id; + el_algorithm_type_t type; + uint32_t addr_flash; + uint32_t size; + const uint8_t* addr_memory; +} el_model_info_t; + +constexpr inline std::size_t lengthof(const char* s) { + std::size_t size = 0; + while (*(s + size) != '\0') ++size; + return size; +} + +template constexpr inline std::size_t lengthof(const T (&)[N]) noexcept { return N; } + +inline std::size_t lengthof(const std::string& s) { return s.length(); } + +// template constexpr inline decltype(auto) concat_strings(Args&&... args) { +// std::size_t length{(lengthof(args) + ...)}; // try calculate total length at compile time +// std::string result; +// result.reserve(length + 1); // preallocate memory, avoid repeatly allocate memory while appendings +// (result.append(std::forward(args)), ...); +// return result; +// } + +template constexpr inline decltype(auto) concat_strings(Args&&... args) { + std::size_t length{(lengthof(args) + ...)}; + std::string result; + result.reserve(length); + (result.append(std::forward(args)), ...); + return result; +} + + + +el_err_code_t send_bytes(const char* buffer, size_t size) ; +el_err_code_t read_bytes(char* buffer, size_t size); +el_err_code_t read_bytes_nonblock(char* buffer, size_t size); +void set_model_change_by_uart(); +std::string img_2_json_str(el_img_t* img); +void event_reply(std::string data); +void send_device_id(); +template constexpr std::string results_2_json_str(const std::forward_list& results); + +std::string box_results_2_json_str(std::forward_list& results); +std::string fm_point_results_2_json_str(std::forward_list& results); +std::string keypoint_results_2_json_str(std::forward_list& results); +std::string img_res_2_json_str(const el_img_t* img); +std::string algo_tick_2_json_str(uint32_t algo_tick); +std::string fd_fl_results_2_json_str(std::forward_list& results); +std::string fd_fl_el_9t_results_2_json_str(std::forward_list& results); +std::string fm_face_bbox_results_2_json_str(std::forward_list& results); \ No newline at end of file diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.c b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.c index 6a421263..d9336872 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.c +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.c @@ -86,6 +86,7 @@ #define CPU_CLK 0xffffff+1 #endif +#define GROVE_VISION_AI_II static uint8_t g_xdma_abnormal, g_md_detect, g_cdm_fifoerror, g_wdt1_timeout, g_wdt2_timeout,g_wdt3_timeout; static uint8_t g_hxautoi2c_error, g_inp1bitparer_abnormal; @@ -97,8 +98,46 @@ static uint8_t g_spi_master_initial_status; static uint32_t g_use_case; /*volatile*/ uint32_t jpeg_addr, jpeg_sz; struct_yolov8_pose_algoResult algoresult_yolov8_pose; +static uint32_t g_trans_type; +static uint32_t judge_case_data; void app_start_state(APP_STATE_E state); void model_change(void); +void pinmux_init(); + +#ifdef GROVE_VISION_AI_II +/* Init SPI master pin mux (share with SDIO) */ +void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) +{ + pinmux_cfg->pin_pb2 = SCU_PB2_PINMUX_SPI_M_DO_1; /*!< pin PB2*/ + pinmux_cfg->pin_pb3 = SCU_PB3_PINMUX_SPI_M_DI_1; /*!< pin PB3*/ + pinmux_cfg->pin_pb4 = SCU_PB4_PINMUX_SPI_M_SCLK_1; /*!< pin PB4*/ + pinmux_cfg->pin_pb11 = SCU_PB11_PINMUX_SPI_M_CS; /*!< pin PB11*/ +} +#else +/* Init SPI master pin mux (share with SDIO) */ +void spi_m_pinmux_cfg(SCU_PINMUX_CFG_T *pinmux_cfg) +{ + pinmux_cfg->pin_pb2 = SCU_PB2_PINMUX_SPI_M_DO_1; /*!< pin PB2*/ + pinmux_cfg->pin_pb3 = SCU_PB3_PINMUX_SPI_M_DI_1; /*!< pin PB3*/ + pinmux_cfg->pin_pb4 = SCU_PB4_PINMUX_SPI_M_SCLK_1; /*!< pin PB4*/ + pinmux_cfg->pin_pb5 = SCU_PB5_PINMUX_SPI_M_CS_1; /*!< pin PB5*/ +} +#endif + +/******************************************************************************* + * Code + ******************************************************************************/ +void pinmux_init() +{ + SCU_PINMUX_CFG_T pinmux_cfg; + + hx_drv_scu_get_all_pinmux_cfg(&pinmux_cfg); + + /* Init SPI master pin mux (share with SDIO) */ + spi_m_pinmux_cfg(&pinmux_cfg); + + hx_drv_scu_set_all_pinmux_cfg(&pinmux_cfg, 1); +} static void dp_var_int() @@ -667,11 +706,13 @@ static void dp_app_cv_yolov8_pose_eventhdl_cb(EVT_INDEX_E event) if(g_frame_ready == 1) { g_frame_ready = 0; + hx_drv_swreg_aon_get_appused1(&judge_case_data); + //TODO: check if register changed by pc tool // #ifdef WATCHDOG_VERSION -// if(EPII_get_memory(0x5610F02c)==g_use_case) +// if( (judge_case_data&0xff) ==g_use_case) // hx_drv_watchdog_update(WATCHDOG_ID_0, WATCH_DOG_TIMEOUT_TH); // #endif - if(EPII_get_memory(0x5610F02c)!=g_use_case) { + if( ((judge_case_data&0xff) !=g_use_case) || ( (judge_case_data>>16) != g_trans_type ) ) { //cisdp_sensor_stop(); model_change(); #ifdef CPU_24MHZ_VERSION @@ -689,7 +730,7 @@ static void dp_app_cv_yolov8_pose_eventhdl_cb(EVT_INDEX_E event) #if FRAME_CHECK_DEBUG if(g_spi_master_initial_status == 0) { - EPII_set_memory(0x42001110, 0x01010101); + // EPII_set_memory(0x42001110, 0x01010101); if(hx_drv_spi_mst_open_speed(SPI_SEN_PIC_CLK) != 0) { dbg_printf(DBG_LESS_INFO, "DEBUG SPI master init fail\r\n"); @@ -698,32 +739,79 @@ static void dp_app_cv_yolov8_pose_eventhdl_cb(EVT_INDEX_E event) } g_spi_master_initial_status = 1; } - read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); - //read_status = hx_drv_spi_mst_protocol_write_sp_wait(jpeg_addr, jpeg_sz, DATA_TYPE_JPG, 0); + #ifdef UART_SEND_ALOGO_RESEULT + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { + + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + } + #else + read_status = hx_drv_spi_mst_protocol_write_sp(jpeg_addr, jpeg_sz, DATA_TYPE_JPG); + #endif #if DBG_APP_LOG dbg_printf(DBG_LESS_INFO, "write frame result %d, data size=%d,addr=0x%x\n",read_status, jpeg_sz,jpeg_addr); #endif #endif #ifdef EN_ALGO +#ifdef UART_SEND_ALOGO_RESEULT -#if TOTAL_STEP_TICK - uint32_t systick_1, systick_2; - uint32_t loop_cnt_1, loop_cnt_2; - SystemGetTick(&systick_1, &loop_cnt_1); -#endif - + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 )// transfer type is (UART) + { cv_yolov8_pose_run(&algoresult_yolov8_pose); -#if TOTAL_STEP_TICK - SystemGetTick(&systick_2, &loop_cnt_2); - #if TOTAL_STEP_TICK_DBG_LOG - xprintf("Tick for TOTAL yolov8_pose :[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); - #endif - algoresult_yolov8_pose.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); -#endif + } + else if( g_trans_type == 1 || g_trans_type == 2)// transfer type is (SPI) or (UART & SPI) + { + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + + cv_yolov8_pose_run(&algoresult_yolov8_pose); + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL yolov8_pose :[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + #endif -#if FRAME_CHECK_DEBUG - hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8_pose, sizeof(struct_yolov8_pose_algoResult), DATA_TYPE_META_YOLOV8_POSE_DATA); + if(g_trans_type == 1)//USE SPI + { + algoresult_yolov8_pose.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + } + #endif + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8_pose, sizeof(struct_yolov8_pose_algoResult), DATA_TYPE_META_YOLOV8_POSE_DATA); + #endif + } +#else + #if TOTAL_STEP_TICK + uint32_t systick_1, systick_2; + uint32_t loop_cnt_1, loop_cnt_2; + SystemGetTick(&systick_1, &loop_cnt_1); + #endif + + cv_yolov8_pose_run(&algoresult_yolov8_pose); + #if TOTAL_STEP_TICK + SystemGetTick(&systick_2, &loop_cnt_2); + #if TOTAL_STEP_TICK_DBG_LOG + xprintf("Tick for TOTAL yolov8_pose :[%d]\r\n",(loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2)); + #endif + algoresult_yolov8_pose.algo_tick = (loop_cnt_2-loop_cnt_1)*CPU_CLK+(systick_1-systick_2); + #endif + + #if FRAME_CHECK_DEBUG + hx_drv_spi_mst_protocol_write_sp((uint32_t)&algoresult_yolov8_pose, sizeof(struct_yolov8_pose_algoResult), DATA_TYPE_META_YOLOV8_POSE_DATA); + #endif #endif //algoresult_yolov8_pose for (int i = 0; i < MAX_TRACKED_YOLOV8_ALGO_RES; i++) { @@ -767,16 +855,50 @@ void app_start_state(APP_STATE_E state) } dp_var_int(); + +#ifdef UART_SEND_ALOGO_RESEULT + + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + g_trans_type = (judge_case_data>>16); + if( g_trans_type == 0 || g_trans_type == 2)// transfer type is (UART) or (UART & SPI) + { + if(state == APP_STATE_YOLOV8_POSE) + { + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8_pose_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + + } + else if ( g_trans_type == 1 ) // only use SPI + { + if(state == APP_STATE_YOLOV8_POSE) + { + + // if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8_pose_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8_pose_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_1X) < 0) + { + xprintf("\r\nDATAPATH Init fail\r\n"); + APP_BLOCK_FUNC(); + } + } + + } +#else if(state == APP_STATE_YOLOV8_POSE) { - // if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8_pose_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_2X) < 0) + if(cisdp_dp_init(true, SENSORDPLIB_PATH_INT_INP_HW5X5_JPEG, dp_app_cv_yolov8_pose_eventhdl_cb, 4, APP_DP_RES_RGB640x480_INP_SUBSAMPLE_1X) < 0) - { + { xprintf("\r\nDATAPATH Init fail\r\n"); APP_BLOCK_FUNC(); } } +#endif event_handler_init(); cisdp_sensor_start(); @@ -815,6 +937,7 @@ int tflm_yolov8_pose_app(void) { hx_drv_swreg_aon_get_pllfreq(&freq); xprintf("wakeup_event=0x%x,WakeupEvt1=0x%x, freq=%d\n", wakeup_event, wakeup_event1, freq); + pinmux_init(); //SCB_DisableICache(); //SCB_DisableDCache(); @@ -844,7 +967,15 @@ int tflm_yolov8_pose_app(void) { // #endif //check current use case - g_use_case = EPII_get_memory(0x5610F02c); + // //check current use case + //judge which case + + hx_drv_swreg_aon_get_appused1(&judge_case_data); + //transfer type + g_trans_type = (judge_case_data>>16); + //model case + g_use_case = (judge_case_data&0xff); + #ifndef CPU_24MHZ_VERSION xprintf("ori_clk src info, 0x56100030=%x\n",EPII_get_memory(0x56100030)); diff --git a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.mk b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.mk index 18546c72..0ad16b61 100644 --- a/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.mk +++ b/EPII_CM55M_APP_S/app/scenario_app/tflm_yolov8_pose/tflm_yolov8_pose.mk @@ -5,6 +5,7 @@ APPL_DEFINES += -DTF_LITE_STATIC_MEMORY APPL_DEFINES += -Daudvidpre_ret_pll400_timer1 -DIP_xdma APPL_DEFINES += -DEVT_DATAPATH +APPL_DEFINES += -DUART_SEND_ALOGO_RESEULT #APPL_DEFINES += -DEVT_CM55MTIMER -DEVT_CM55MMB APPL_DEFINES += -DDBG_MORE diff --git a/EPII_CM55M_APP_S/library/inference/tflmtag2209_u55tag2205/tensorflow/lite/c/common.c.backup b/EPII_CM55M_APP_S/library/inference/tflmtag2209_u55tag2205/tensorflow/lite/c/common.c.backup deleted file mode 100644 index ef4d3ffd..00000000 --- a/EPII_CM55M_APP_S/library/inference/tflmtag2209_u55tag2205/tensorflow/lite/c/common.c.backup +++ /dev/null @@ -1,276 +0,0 @@ -/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#include "tensorflow/lite/c/common.h" -#include "tensorflow/lite/c/c_api_types.h" - -#ifndef TF_LITE_STATIC_MEMORY -#include -#include -#endif // TF_LITE_STATIC_MEMORY - -int TfLiteIntArrayGetSizeInBytes(int size) { - static TfLiteIntArray dummy; - - int computed_size = sizeof(dummy) + sizeof(dummy.data[0]) * size; -#if defined(_MSC_VER) - // Context for why this is needed is in http://b/189926408#comment21 - computed_size -= sizeof(dummy.data[0]); -#endif - return computed_size; -} - -int TfLiteIntArrayEqual(const TfLiteIntArray* a, const TfLiteIntArray* b) { - if (a == b) return 1; - if (a == NULL || b == NULL) return 0; - return TfLiteIntArrayEqualsArray(a, b->size, b->data); -} - -int TfLiteIntArrayEqualsArray(const TfLiteIntArray* a, int b_size, - const int b_data[]) { - if (a == NULL) return (b_size == 0); - if (a->size != b_size) return 0; - int i = 0; - for (; i < a->size; i++) - if (a->data[i] != b_data[i]) return 0; - return 1; -} - -#ifndef TF_LITE_STATIC_MEMORY - -TfLiteIntArray* TfLiteIntArrayCreate(int size) { - int alloc_size = TfLiteIntArrayGetSizeInBytes(size); - if (alloc_size <= 0) return NULL; - TfLiteIntArray* ret = (TfLiteIntArray*)malloc(alloc_size); - if (!ret) return ret; - ret->size = size; - return ret; -} - -TfLiteIntArray* TfLiteIntArrayCopy(const TfLiteIntArray* src) { - if (!src) return NULL; - TfLiteIntArray* ret = TfLiteIntArrayCreate(src->size); - if (ret) { - memcpy(ret->data, src->data, src->size * sizeof(int)); - } - return ret; -} - -void TfLiteIntArrayFree(TfLiteIntArray* a) { free(a); } - -#endif // TF_LITE_STATIC_MEMORY - -int TfLiteFloatArrayGetSizeInBytes(int size) { - static TfLiteFloatArray dummy; - - int computed_size = sizeof(dummy) + sizeof(dummy.data[0]) * size; -#if defined(_MSC_VER) - // Context for why this is needed is in http://b/189926408#comment21 - computed_size -= sizeof(dummy.data[0]); -#endif - return computed_size; -} - -#ifndef TF_LITE_STATIC_MEMORY - -TfLiteFloatArray* TfLiteFloatArrayCreate(int size) { - TfLiteFloatArray* ret = - (TfLiteFloatArray*)malloc(TfLiteFloatArrayGetSizeInBytes(size)); - ret->size = size; - return ret; -} - -void TfLiteFloatArrayFree(TfLiteFloatArray* a) { free(a); } - -void TfLiteTensorDataFree(TfLiteTensor* t) { - if (t->allocation_type == kTfLiteDynamic || - t->allocation_type == kTfLitePersistentRo) { - free(t->data.raw); - } - t->data.raw = NULL; -} - -void TfLiteQuantizationFree(TfLiteQuantization* quantization) { - if (quantization->type == kTfLiteAffineQuantization) { - TfLiteAffineQuantization* q_params = - (TfLiteAffineQuantization*)(quantization->params); - if (q_params->scale) { - TfLiteFloatArrayFree(q_params->scale); - q_params->scale = NULL; - } - if (q_params->zero_point) { - TfLiteIntArrayFree(q_params->zero_point); - q_params->zero_point = NULL; - } - free(q_params); - } - quantization->params = NULL; - quantization->type = kTfLiteNoQuantization; -} - -void TfLiteSparsityFree(TfLiteSparsity* sparsity) { - if (sparsity == NULL) { - return; - } - - if (sparsity->traversal_order) { - TfLiteIntArrayFree(sparsity->traversal_order); - sparsity->traversal_order = NULL; - } - - if (sparsity->block_map) { - TfLiteIntArrayFree(sparsity->block_map); - sparsity->block_map = NULL; - } - - if (sparsity->dim_metadata) { - int i = 0; - for (; i < sparsity->dim_metadata_size; i++) { - TfLiteDimensionMetadata metadata = sparsity->dim_metadata[i]; - if (metadata.format == kTfLiteDimSparseCSR) { - TfLiteIntArrayFree(metadata.array_segments); - metadata.array_segments = NULL; - TfLiteIntArrayFree(metadata.array_indices); - metadata.array_indices = NULL; - } - } - free(sparsity->dim_metadata); - sparsity->dim_metadata = NULL; - } - - free(sparsity); -} - -void TfLiteTensorFree(TfLiteTensor* t) { - TfLiteTensorDataFree(t); - if (t->dims) TfLiteIntArrayFree(t->dims); - t->dims = NULL; - - if (t->dims_signature) { - TfLiteIntArrayFree((TfLiteIntArray *) t->dims_signature); - } - t->dims_signature = NULL; - - TfLiteQuantizationFree(&t->quantization); - TfLiteSparsityFree(t->sparsity); - t->sparsity = NULL; -} - -void TfLiteTensorReset(TfLiteType type, const char* name, TfLiteIntArray* dims, - TfLiteQuantizationParams quantization, char* buffer, - size_t size, TfLiteAllocationType allocation_type, - const void* allocation, bool is_variable, - TfLiteTensor* tensor) { - TfLiteTensorFree(tensor); - tensor->type = type; - tensor->name = name; - tensor->dims = dims; - tensor->params = quantization; - tensor->data.raw = buffer; - tensor->bytes = size; - tensor->allocation_type = allocation_type; - tensor->allocation = allocation; - tensor->is_variable = is_variable; - - tensor->quantization.type = kTfLiteNoQuantization; - tensor->quantization.params = NULL; -} - -TfLiteStatus TfLiteTensorCopy(const TfLiteTensor* src, TfLiteTensor* dst) { - if (!src || !dst) - return kTfLiteOk; - if (src->bytes != dst->bytes) - return kTfLiteError; - if (src == dst) - return kTfLiteOk; - - dst->type = src->type; - if (dst->dims) - TfLiteIntArrayFree(dst->dims); - dst->dims = TfLiteIntArrayCopy(src->dims); - memcpy(dst->data.raw, src->data.raw, src->bytes); - dst->buffer_handle = src->buffer_handle; - dst->data_is_stale = src->data_is_stale; - dst->delegate = src->delegate; - - return kTfLiteOk; -} - -void TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor* tensor) { - if (tensor->allocation_type != kTfLiteDynamic && - tensor->allocation_type != kTfLitePersistentRo) { - return; - } - // TODO(b/145340303): Tensor data should be aligned. - if (!tensor->data.raw) { - tensor->data.raw = (char*)malloc(num_bytes); - } else if (num_bytes > tensor->bytes) { - tensor->data.raw = (char*)realloc(tensor->data.raw, num_bytes); - } - tensor->bytes = num_bytes; -} -#endif // TF_LITE_STATIC_MEMORY - -const char* TfLiteTypeGetName(TfLiteType type) { - switch (type) { - case kTfLiteNoType: - return "NOTYPE"; - case kTfLiteFloat32: - return "FLOAT32"; - case kTfLiteInt16: - return "INT16"; - case kTfLiteInt32: - return "INT32"; - case kTfLiteUInt32: - return "UINT32"; - case kTfLiteUInt8: - return "UINT8"; - case kTfLiteInt8: - return "INT8"; - case kTfLiteInt64: - return "INT64"; - case kTfLiteUInt64: - return "UINT64"; - case kTfLiteBool: - return "BOOL"; - case kTfLiteComplex64: - return "COMPLEX64"; - case kTfLiteComplex128: - return "COMPLEX128"; - case kTfLiteString: - return "STRING"; - case kTfLiteFloat16: - return "FLOAT16"; - case kTfLiteFloat64: - return "FLOAT64"; - case kTfLiteResource: - return "RESOURCE"; - case kTfLiteVariant: - return "VARIANT"; - } - return "Unknown type"; -} - -TfLiteDelegate TfLiteDelegateCreate(void) { - TfLiteDelegate d = { - .data_ = NULL, - .Prepare = NULL, - .CopyFromBufferHandle = NULL, - .CopyToBufferHandle = NULL, - .FreeBufferHandle = NULL, - .flags = kTfLiteDelegateFlagsNone, - }; - return d; -} diff --git a/EPII_CM55M_APP_S/library/spi_ptl/spi_protocol.h b/EPII_CM55M_APP_S/library/spi_ptl/spi_protocol.h index e6b8f030..cabaf962 100644 --- a/EPII_CM55M_APP_S/library/spi_ptl/spi_protocol.h +++ b/EPII_CM55M_APP_S/library/spi_ptl/spi_protocol.h @@ -49,6 +49,7 @@ typedef enum DATA_TYPE_JPG_R = 0x15, DATA_TYPE_RAW_IMG = 0x16, DATA_TYPE_BIN_DATA = 0x20, + DATA_TYPE_PREROLL_INFO = 0x21, DATA_TYPE_INCORRECT_DATA = 0x3F, DATA_TYPE_TV_STANDBY = 0x40, @@ -108,6 +109,10 @@ typedef enum DATA_TYPE_META_YOLOV8_POSE_DATA = 0X9C, /*YOLOV8 pose*/ + DATA_TYPE_META_FM_WITH_FPS_DATA = 0X9D, /*face mesh POINT with fps*/ + + DATA_TYPE_META_FL_WITH_FPS_DATA = 0X9E, /*FACE LANDMARK POINT with fps*/ + DATA_TYPE_END_OF_PACKET = 0XF0, /*represent end of data*/ }SPI_CMD_DATA_TYPE; @@ -183,6 +188,7 @@ typedef struct }struct_algoResult; + /**for human pose inference**/ typedef struct struct_human_pose{ uint32_t x; @@ -331,4 +337,36 @@ typedef struct uint32_t algo_tick; }struct_yolov8_pose_algoResult; + +typedef struct +{ + short num_tracked_face_targets ; + struct_face_box face_bbox[MAX_TRACKED_ALGO_RES]; + float score; + struct_face_mesh fmr[FACE_MESH_POINT_NUM]; + //struct_face_mesh fmr_eye_update[FACE_MESH_EYE_UPDATE_POINT_NUM]; + struct_face_mesh fmr_iris[FACE_MESH_IRIS_POINT_NUM]; + float left_iris_theta; + float left_iris_phi; + float right_iris_theta; + float right_iris_phi; + struct_angle face_angle; + uint32_t algo_tick; +}struct_fm_algoResult_with_fps; + + +typedef struct +{ + int num_hot_pixels ; + struct_MotionTarget Emt[MAX_TRACKED_ALGO_RES]; //ecv::motion::Target* *tracked_moving_targets; + int frame_count ; + short num_tracked_moving_targets; + short num_tracked_human_targets ; + bool humanPresence ; + struct_Human ht[MAX_TRACKED_ALGO_RES]; //TrackedHumanTarget* *tracked_human_targets; + int num_reliable_moving_targets; + int verifiedHumansExist; + uint32_t algo_fps; +}struct_algoResult_with_fps; + #endif /* INC_SPI_PROTOCOL_H_ */ diff --git a/EPII_CM55M_APP_S/makefile b/EPII_CM55M_APP_S/makefile index e1a39ec8..83ea064e 100644 --- a/EPII_CM55M_APP_S/makefile +++ b/EPII_CM55M_APP_S/makefile @@ -136,7 +136,6 @@ CUSTOMER ?= seeed # tflm_yolov8_pose ## APP_TYPE = allon_sensor_tflm_freertos - ### Options above must be added before include options.mk ### override EPII_ROOT := $(strip $(subst \,/,$(EPII_ROOT))) diff --git a/EPII_CM55M_APP_S/options/toolchain/toolchain_gnu.mk b/EPII_CM55M_APP_S/options/toolchain/toolchain_gnu.mk index 9cb7e501..83230e97 100644 --- a/EPII_CM55M_APP_S/options/toolchain/toolchain_gnu.mk +++ b/EPII_CM55M_APP_S/options/toolchain/toolchain_gnu.mk @@ -206,13 +206,18 @@ endif MKDEP_OPT = -fmacro-prefix-map="../$(@D)/"=. -MMD -MP -MF"$(@:$(OUT_DIR)/%.o=$(OUT_DIR)/%.d)" -MT"$(@:$(OUT_DIR)/%.o=$(OUT_DIR)/%.o)" -MT"$(@:$(OUT_DIR)/%.o=$(OUT_DIR)/%.d)" COMMON_COMPILE_OPT = $(OPT_OLEVEL) $(CDEBUG_OPTION) $(ALL_DEFINES) $(ALL_INCLUDES) $(MKDEP_OPT) - ## C/CPP/ASM/LINK Options - COMPILE_OPT += $(CCORE_OPT_GNU) $(ADT_COPT) $(COMMON_COMPILE_OPT) -std=gnu99 - ifdef OS_SEL - CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) -std=c++11 -fno-rtti -fno-exceptions - else - CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) -std=c++11 -fno-rtti -fno-exceptions -fno-threadsafe-statics - endif +# ## C/CPP/ASM/LINK Options +# COMPILE_OPT += $(CCORE_OPT_GNU) $(ADT_COPT) $(COMMON_COMPILE_OPT) -std=gnu99 +# ifdef OS_SEL +# CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) -std=c++11 -fno-rtti -fno-exceptions +# else +# CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) -std=c++11 -fno-rtti -fno-exceptions -fno-threadsafe-statics +# endif + COMPILE_OPT += $(CCORE_OPT_GNU) $(ADT_COPT) $(COMMON_COMPILE_OPT) -std=gnu11 + CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) -std=c++17 -fno-rtti -fno-exceptions -fno-threadsafe-statics -nostdlib + + + ASM_OPT += $(ACORE_OPT_GNU) $(ADT_AOPT) $(COMMON_COMPILE_OPT) -x assembler-with-cpp PRE_LINKER_SCRIPT_FILE = $(OUT_DIR)/$(APPL_NAME).ld ifeq ($(firstword $(sort $(GCC_VERSION) 12.0.0)),12.0.0) diff --git a/EPII_CM55M_APP_S/prebuilt_libs/gnu/lib_spi_ptl.a b/EPII_CM55M_APP_S/prebuilt_libs/gnu/lib_spi_ptl.a index 5ee25731..39af1535 100644 Binary files a/EPII_CM55M_APP_S/prebuilt_libs/gnu/lib_spi_ptl.a and b/EPII_CM55M_APP_S/prebuilt_libs/gnu/lib_spi_ptl.a differ diff --git a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libcommon.a b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libcommon.a index 564deb99..92cc8672 100644 Binary files a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libcommon.a and b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libcommon.a differ diff --git a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtflmtag2209_u55tag2205_gnu.a b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtflmtag2209_u55tag2205_gnu.a index 122c0f55..0847d1d0 100644 Binary files a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtflmtag2209_u55tag2205_gnu.a and b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtflmtag2209_u55tag2205_gnu.a differ diff --git a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtrustzone_cfg.a b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtrustzone_cfg.a index 972059a6..ee4dda5e 100644 Binary files a/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtrustzone_cfg.a and b/EPII_CM55M_APP_S/prebuilt_libs/gnu/libtrustzone_cfg.a differ diff --git a/README.md b/README.md index f5c98300..f927368e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Finally, teach you how to restore to the original factory settings and run [Sens - How to build face mesh scenario app exmple and run on WE2? - [Linux Environment](https://github.com/HimaxWiseEyePlus/Seeed_Grove_Vision_AI_Module_V2?tab=readme-ov-file#linux-environment-1) - [Windows Environment](https://github.com/HimaxWiseEyePlus/Seeed_Grove_Vision_AI_Module_V2?tab=readme-ov-file#windows-environment-1) + - [Send image and meta data by UART](https://github.com/HimaxWiseEyePlus/Seeed_Grove_Vision_AI_Module_V2?tab=readme-ov-file#send-image-and-meta-data-by-uart) - [Model source link](https://github.com/HimaxWiseEyePlus/Seeed_Grove_Vision_AI_Module_V2?tab=readme-ov-file#model-source-link) - [How to add support for raspberry pi camera?](https://github.com/HimaxWiseEyePlus/Seeed_Grove_Vision_AI_Module_V2?tab=readme-ov-file#how-to-add-support-for-raspberry-pi-camera) ## How to build the firmware? @@ -283,6 +284,25 @@ Following steps update application in the flash. ![alt text](images/flash_image_model_2.PNG) ![alt text](images/flash_image_model_3.png) +### Send image and meta data by UART +You can use the web toolkit which we provide, download it and unzip it to local PC, and double click `index.html`. +- Please check you select `Grove Vision AI(V2)` and press `connect` button + ![alt text](images/uart_show_1.png) +- Select your own COM. + ![alt text](images/uart_show_2.png) +- You will see the preview result on website. + ![alt text](images/uart_show_3.png) +- Tip + - Windows: + - Please use "Microsoft Edge" browser + - Linux: + - Open the permissions to acceess the deivce + ``` + sudo setfacl -m u:[USERNAME]:rw /dev/ttyUSB0 + # in my case + # sudo setfacl -m u:kris:rw /dev/ttyACM0 + ``` + - Please use "Google Chrome" browser ### Model source link - [Face detection](https://github.com/dog-qiuqiu/Yolo-Fastest) - [Face mesh from google (468 point)](https://github.com/google/mediapipe/blob/master/docs/solutions/models.md#face-mesh) diff --git a/images/uart_show_1.png b/images/uart_show_1.png new file mode 100644 index 00000000..f74b1e69 Binary files /dev/null and b/images/uart_show_1.png differ diff --git a/images/uart_show_2.png b/images/uart_show_2.png new file mode 100644 index 00000000..9c02585e Binary files /dev/null and b/images/uart_show_2.png differ diff --git a/images/uart_show_3.png b/images/uart_show_3.png new file mode 100644 index 00000000..e1fd9cee Binary files /dev/null and b/images/uart_show_3.png differ