diff --git a/gynet b/gynet index 6464c36..c3daf13 100644 Binary files a/gynet and b/gynet differ diff --git a/libdarknet.a b/libdarknet.a index 8bc0255..aee10cd 100644 Binary files a/libdarknet.a and b/libdarknet.a differ diff --git a/obj/block_to_send.o b/obj/block_to_send.o index 40d39c9..eb35fca 100644 Binary files a/obj/block_to_send.o and b/obj/block_to_send.o differ diff --git a/obj/dbscan.o b/obj/dbscan.o index 50cc0ea..9fd812c 100644 Binary files a/obj/dbscan.o and b/obj/dbscan.o differ diff --git a/obj/detector.o b/obj/detector.o index 83ede71..91ff699 100644 Binary files a/obj/detector.o and b/obj/detector.o differ diff --git a/obj/fflpr_plate_db.o b/obj/fflpr_plate_db.o index a475dac..ff3637f 100644 Binary files a/obj/fflpr_plate_db.o and b/obj/fflpr_plate_db.o differ diff --git a/obj/ivs.o b/obj/ivs.o index ff9b27f..3695c65 100644 Binary files a/obj/ivs.o and b/obj/ivs.o differ diff --git a/obj/network.o b/obj/network.o index 7b0a32b..8116bd9 100644 Binary files a/obj/network.o and b/obj/network.o differ diff --git a/obj/nweb.o b/obj/nweb.o index 7d71c66..7ca6fe4 100644 Binary files a/obj/nweb.o and b/obj/nweb.o differ diff --git a/obj/parser.o b/obj/parser.o index fb0c354..534b6f3 100644 Binary files a/obj/parser.o and b/obj/parser.o differ diff --git a/obj/pns.o b/obj/pns.o index 8650620..8a405f7 100644 Binary files a/obj/pns.o and b/obj/pns.o differ diff --git a/obj/ptz.o b/obj/ptz.o index cb8c618..976c7b6 100644 Binary files a/obj/ptz.o and b/obj/ptz.o differ diff --git a/obj/pythonR.o b/obj/pythonR.o index 4b5cc01..70c64b8 100644 Binary files a/obj/pythonR.o and b/obj/pythonR.o differ diff --git a/obj/test_nnctrl_live.o b/obj/test_nnctrl_live.o index 8bbd6f4..f682e74 100644 Binary files a/obj/test_nnctrl_live.o and b/obj/test_nnctrl_live.o differ diff --git a/obj/test_yuv_rgb.o b/obj/test_yuv_rgb.o index 648a031..d7d0be6 100644 Binary files a/obj/test_yuv_rgb.o and b/obj/test_yuv_rgb.o differ diff --git a/obj/utility.o b/obj/utility.o index a169813..d35949b 100644 Binary files a/obj/utility.o and b/obj/utility.o differ diff --git a/obj/utils.o b/obj/utils.o index 8c7fb6a..c599263 100644 Binary files a/obj/utils.o and b/obj/utils.o differ diff --git a/obj/websocket.o b/obj/websocket.o index ed3cf59..3719191 100644 Binary files a/obj/websocket.o and b/obj/websocket.o differ diff --git a/src/art.c b/src/art.c index 5d62550..b50061b 100644 --- a/src/art.c +++ b/src/art.c @@ -15,7 +15,7 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index) void * cap = open_video_stream(0, cam_index, 0,0,0); char *window = "ArtJudgementBot9000!!!"; - if(!cap) error("Couldn't connect to webcam.\n"); + if(!cap) printf("Couldn't connect to webcam.\n"); int i; int idx[] = {37, 401, 434}; int n = sizeof(idx)/sizeof(idx[0]); diff --git a/src/cuda.c b/src/cuda.c index 265df2e..3717021 100644 --- a/src/cuda.c +++ b/src/cuda.c @@ -35,7 +35,7 @@ void check_error(cudaError_t status) printf("CUDA Error: %s\n", s); assert(0); snprintf(buffer, 256, "CUDA Error: %s", s); - error(buffer); + printf("%s\n",buffer); } if (status2 != cudaSuccess) { @@ -44,7 +44,7 @@ void check_error(cudaError_t status) printf("CUDA Error Prev: %s\n", s); assert(0); snprintf(buffer, 256, "CUDA Error Prev: %s", s); - error(buffer); + printf("%s\n",buffer); } } @@ -99,7 +99,7 @@ float *cuda_make_array(float *x, size_t n) } else { fill_gpu(n, 0, x_gpu, 1); } - if(!x_gpu) error("Cuda malloc failed\n"); + if(!x_gpu) printf("Cuda malloc failed\n"); return x_gpu; } @@ -143,7 +143,7 @@ int *cuda_make_int_array(int *x, size_t n) status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice); check_error(status); } - if(!x_gpu) error("Cuda malloc failed\n"); + if(!x_gpu) printf("Cuda malloc failed\n"); return x_gpu; } diff --git a/src/darknet.c b/src/darknet.c index fe2f30b..335fb35 100644 --- a/src/darknet.c +++ b/src/darknet.c @@ -151,7 +151,6 @@ int main(int argc, char **argv) //sophia add 2020/10/08 if (chdir("/emmc/plugin") != 0) { - //perror("chdir() to /emmc/plugin fail"); printf("\nchdir() to /emmc/plugin fail\n"); return 0; } diff --git a/src/dbscan.c b/src/dbscan.c index 1452b63..2fad16d 100644 --- a/src/dbscan.c +++ b/src/dbscan.c @@ -83,7 +83,7 @@ node_t *create_node(unsigned int index) { node_t *n = (node_t *) calloc(1, sizeof(node_t)); if (n == NULL) - perror("Failed to allocate node."); + printf("Failed to allocate node.\n"); else { n->index = index; n->next = NULL; @@ -121,7 +121,7 @@ epsilon_neighbours_t *get_epsilon_neighbours( epsilon_neighbours_t *en = (epsilon_neighbours_t *) calloc(1, sizeof(epsilon_neighbours_t)); if (en == NULL) { - perror("Failed to allocate epsilon neighbours."); + printf("Failed to allocate epsilon neighbours.\n"); return en; } for (int i = 0; i < (int)num_points; ++i) { @@ -296,7 +296,7 @@ unsigned int parse_input( point_t *p = (point_t *) calloc(num_points, sizeof(point_t)); if (p == NULL) { - perror("Failed to allocate points array"); + printf("Failed to allocate points array\n"); return 0; } while (i < num_points) { diff --git a/src/demo.c b/src/demo.c index b89efb8..9c8a027 100644 --- a/src/demo.c +++ b/src/demo.c @@ -216,7 +216,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch cap = open_video_stream(0, cam_index, w, h, frames); } - if(!cap) error("Couldn't connect to webcam.\n"); + if(!cap) printf("Couldn't connect to webcam.\n"); buff[0] = get_image_from_stream(cap); buff[1] = copy_image(buff[0]); @@ -234,8 +234,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch while(!demo_done){ buff_index = (buff_index + 1) %3; - if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); - if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); + if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) printf("Thread creation failed\n"); + if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n"); if(!prefix){ fps = 1./(what_time_is_it_now() - demo_time); demo_time = what_time_is_it_now(); @@ -287,7 +287,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch } } - if(!cap) error("Couldn't connect to webcam.\n"); + if(!cap) printf("Couldn't connect to webcam.\n"); layer l = net->layers[net->n-1]; demo_detections = l.n*l.w*l.h; @@ -323,8 +323,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch while(!demo_done){ buff_index = (buff_index + 1) %3; -if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); -if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); +if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) printf("Thread creation failed\n"); +if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n"); if(!prefix){ fps = 1./(what_time_is_it_now() - demo_time); demo_time = what_time_is_it_now(); diff --git a/src/detector.c b/src/detector.c index 1407ac6..51a4675 100644 --- a/src/detector.c +++ b/src/detector.c @@ -32,7 +32,9 @@ #include #include #include "net_curl.h" +#ifdef GY_OS_AMBA #include +#endif #include "structures.h" #if defined GY_OS_AMBA @@ -156,11 +158,12 @@ pthread_mutex_t mutex_write_pcd_data_L; pthread_mutex_t mutex_write_pcd_data_M; pthread_mutex_t mutex_write_pcd_data_S; +pthread_mutex_t buffer_mutex; pthread_mutex_t mutex_remotesnap_image; // Ken 2022-09-26 pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 pthread_mutex_t mutex_tof_json; // Ken 2022-12-13 -pthread_mutex_t mutex_buffer; // Ming 2022-08-28 + pthread_mutex_t mutex_run_osd; #endif @@ -298,7 +301,7 @@ int g_check_current_resolution = 1; #if defined GY_OS_AMBA || defined GY_OS_NOVA cJSON *g_config_root = NULL; -char* get_enable_python_file_value(const char *filename); + #endif /*typedef struct { @@ -383,7 +386,9 @@ pthread_t http_thread_parse_json_data; pthread_t http_thread_pre_image_receive; #endif pthread_t post_notification_thread; +#ifdef GY_OS_AMBA pthread_t runpython_thread; +#endif pthread_t getalarmmotion_thread; pthread_t delete_jpg_in_seven_days_detector_thread_id; @@ -984,6 +989,8 @@ void *run_event_counter_thread(void *ptr) set_counter_zone(); + loadCounters(); + while (bHttpServerThreadStart) { //printf("\n-----run event counter thread start\n"); @@ -1191,6 +1198,9 @@ void *run_post_notification_thread(void *ptr) int count_ptz = 0; #endif + struct timeval currtime_pns_check; + long last_s_pns_check = 0; + while (bHttpServerThreadStart) { //printf("\n-----run post notification start\n"); @@ -1309,6 +1319,54 @@ void *run_post_notification_thread(void *ptr) #endif } + if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0){ + if (strlen(SystemSetting.cloud_account) >= 1 && strlen(SystemSetting.cloud_password) >= 1 && strcmp(SystemSetting.cloud_account, "myaccount@mail.com") != 0) { + if (g_check_ping_OK == 1) { + gettimeofday(&currtime_pns_check, NULL); + long current_s_pns_check = currtime_pns_check.tv_sec; + + if (last_s_pns_check == 0 || + ((current_s_pns_check - last_s_pns_check) >= 3600 && get_g_check_wrong_pass_or_email() == 0) || + ((current_s_pns_check - last_s_pns_check) >= 900 && get_g_check_wrong_pass_or_email() == 1)) { + + char returned_msg_temp[MEMORY_SIZE] = { 0 }; + PNS_check_if_to_post_image(SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg_temp, "https://cloud.ddnsipcam.com/pns/"); + + if (strstr(returned_msg_temp, "\"msg\":\"oaA=\"") != NULL) { + set_g_pns_account_OK(1); + + if (strstr(returned_msg_temp, "\"eid\":\"Yg==\"") != NULL) { + set_g_pns_access_level(0); + } + else if (strstr(returned_msg_temp, "\"eid\":\"Yw==\"") != NULL) { + set_g_pns_access_level(1); + set_g_check_invalidpass(0); + set_g_check_emailnotvalid(0); + } + else if (strstr(returned_msg_temp, "\"eid\":\"ZQ==\"") != NULL) { + set_g_pns_access_level(3); + set_g_check_invalidpass(0); + set_g_check_emailnotvalid(0); + } + else if (strstr(returned_msg_temp, "\"eid\":{\"err\":\"Yw==\",\"msg\":\"p6PFmpaZoZqU\"}") != NULL) { + set_g_pns_access_level(-2); + } + } + + last_s_pns_check = current_s_pns_check; + } + } + } + else { + set_g_pns_account_OK(1); + set_g_pns_access_level(0); + last_s_pns_check = 0; + } + } + else { + last_s_pns_check = 0; + } + #ifdef GY_OS_AMBA if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) { if (IsTracking() == 1) { @@ -5492,7 +5550,7 @@ void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, i g_PostRecorderList[k].box_h = 0; g_PostRecorderList[k].object_id = 0; - g_PostRecorderList[k].zone_idx = 0; + g_PostRecorderList[k].zone_idx = -1; strcpy(g_PostRecorderList[k].sPlateNumber, ""); g_PostRecorderList[k].count_trigger = 0; @@ -5525,7 +5583,7 @@ void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, i g_longterm_PostRecorderList[k].box_h = 0; g_longterm_PostRecorderList[k].object_id = 0; - g_longterm_PostRecorderList[k].zone_idx = 0; + g_longterm_PostRecorderList[k].zone_idx = -1; strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); g_longterm_PostRecorderList[k].count_trigger = 0; @@ -11223,7 +11281,7 @@ void initial_g_PostRecorderList() { g_PostRecorderList[i].box_h = 0.0; g_PostRecorderList[i].object_id = 0.0; - g_PostRecorderList[i].zone_idx = 0.0; + g_PostRecorderList[i].zone_idx = -1; strcpy(g_PostRecorderList[i].sPlateNumber, ""); strcpy(g_PostRecorderList[i].name, ""); @@ -11253,7 +11311,7 @@ void initial_g_PostRecorderList() { g_longterm_PostRecorderList[i].box_h = 0.0; g_longterm_PostRecorderList[i].object_id = 0.0; - g_longterm_PostRecorderList[i].zone_idx = 0.0; + g_longterm_PostRecorderList[i].zone_idx = -1; strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[i].name, ""); @@ -11342,11 +11400,17 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int temp_A.height = g_PostRecorderList[i].box_h; strcpy(temp_A.name, g_PostRecorderList[i].name); - float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) @@ -11391,14 +11455,16 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ { if (strcmp(g_PostRecorderList[i].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -11419,7 +11485,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -11454,11 +11520,17 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int temp_A.height = g_longterm_PostRecorderList[i].box_h; strcpy(temp_A.name, g_longterm_PostRecorderList[i].name); - float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); + float temp_A_iou = detection_overlap_ratio(&temp_A, pNext); //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) @@ -11493,14 +11565,16 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ { if (strcmp(g_longterm_PostRecorderList[i].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; @@ -11516,7 +11590,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; @@ -11537,7 +11611,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } -#if 1 +#if 0 if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { if (iFindMatchPost_longterm == 0) { @@ -11618,10 +11692,18 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int g_PostRecorderList[i].check_if_ftp = 0; g_PostRecorderList[i].check_if_getalarmmotion = 0; - g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; - g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; - g_PostRecorderList[i].box_w = pNext->width / 3.0; - g_PostRecorderList[i].box_h = pNext->height / 3.0; + if (strcmp(pNext->name, "car") == 0) { + g_PostRecorderList[i].box_x = pNext->left_x + pNext->width * 2.0 / 5.0; + g_PostRecorderList[i].box_y = pNext->top_y + pNext->height * 2.0 / 5.0; + g_PostRecorderList[i].box_w = pNext->width / 5.0; + g_PostRecorderList[i].box_h = pNext->height / 5.0; + } + else { + g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; + g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; + g_PostRecorderList[i].box_w = pNext->width / 3.0; + g_PostRecorderList[i].box_h = pNext->height / 3.0; + } g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; @@ -12576,13 +12658,11 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_email == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_email == 0)))) { - if (last_ms_CheckPostEventCondition_email == 0 || - (Get_mail_post_interval() == -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && - (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) || - (Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && - (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000) || - force_to_push == 1) { - if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) + if (Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && + (last_ms_CheckPostEventCondition_email == 0 || + (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000)) + { + if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) { QueueInfo q_info = { 0 }; @@ -13338,7 +13418,8 @@ void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_chan //printf("\n----------count_four_points_touch:%d\n", count_four_points_touch); //printf("\n----------count_touch:%d\n", count_touch); - int threahold_div = g_sensors_type == 0 ? 1 : 7; + //int threahold_div = g_sensors_type == 0 ? 1 : 5; + int threahold_div = 2; if (count_four_points_touch >= 45/threahold_div) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 1; @@ -13772,7 +13853,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki int last_count_touch = 0; float threshold_for_count_touch = 0.77; int threshold_for_last_count_touch = 55; - int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + int threahold_div = g_sensors_type == 0 ? 1 : 5;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; @@ -13870,7 +13951,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - if(strcmp(pNext->name,"person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + if(strcmp(pNext->name,"person") != 0 || fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { int m = 0; int array_zone_count[4] = { 0 }; @@ -14009,7 +14090,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if (strcmp(pNext->name, "person") != 0 || fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { @@ -14670,7 +14751,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki int last_count_touch = 0; float threshold_for_count_touch = 0.77; int threshold_for_last_count_touch = 55; - int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 + int threahold_div = g_sensors_type == 0 ? 1 : 5;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; @@ -14768,7 +14849,8 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) + if ((strcmp(pNext->name, "person") != 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 1.5) || + (strcmp(pNext->name, "person") == 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5)) { int m = 0; int array_zone_count[4] = { 0 }; @@ -14908,7 +14990,8 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { + if ((strcmp(pNext->name, "person") != 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 1.5) || + (strcmp(pNext->name, "person") == 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5)) { if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { @@ -17396,7 +17479,7 @@ void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_tem if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && pNext->obj_dwell_time >= 1 && strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && pNext->height >= 1 && pNext->width >= 1) { - int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width * 1.5, pNext->height * 1.5, g_ori_yuv_width, g_ori_yuv_height, 0); + int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width + pNext->height, pNext->width + pNext->height, g_ori_yuv_width, g_ori_yuv_height, 0); if (checkisInside == 1 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.2 && pNext->width / (float)g_ori_yuv_width < 0.2 && pNext->height / (float)g_ori_yuv_height < 0.2) { @@ -20886,6 +20969,7 @@ int reload_dataset_from_jsonfile(void) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); write_to_logs_html(temp_msg, "reload dataset", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "reload dataset", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -21225,11 +21309,10 @@ int reload_dataset_from_jsonfile(void) strcpy(SystemSetting.enable_python, enable_python->valuestring); enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - if (enable_python_file) + if (enable_python_file) { strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); } - enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); @@ -21884,7 +21967,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 //329個Memory not freed 正常背景值洩漏 if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) - error("HTTP server thread creation failed\n"); + printf("HTTP server thread creation failed\n"); #endif @@ -21899,7 +21982,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa long data_size = sizeof(frameimage) + sizeof(rbuf_t); tof_depth_shmid = Initial_ShareMemory(data_size, 888); if (tof_depth_shmid == -1) { - perror("Create shared memory failed !\n"); + printf("Create shared memory failed !\n"); } else { // 初始化緩衝區 @@ -21908,7 +21991,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa bTofDataStart = 1; if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0)) - error("thread gettofdata creation failed\n"); + printf("thread gettofdata creation failed\n"); } } #endif @@ -21981,17 +22064,17 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa bHttpServerThreadStart = 1; if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL)) - error("Post notification thread creation failed\n"); + printf("Post notification thread creation failed\n"); #endif #ifdef GY_OS_NOVA if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) - error("resolution changed thread failed\n"); + printf("resolution changed thread failed\n"); #else if (get_run_check_current_resolution() == -1) { set_run_check_current_resolution(0); if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) - error("check current resolution thread failed\n"); + printf("check current resolution thread failed\n"); } #endif @@ -22010,10 +22093,10 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa { printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n"); if (pthread_create(&getimage_thread, 0, thread_getimage, 0)) - error("thread getimage creation failed\n"); + printf("thread getimage creation failed\n"); #ifdef GY_OS_AMBA if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) - error("thread getimage creation failed\n"); + printf("thread getimage creation failed\n"); #endif } @@ -22023,20 +22106,20 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa if (g_IsRadarDevice == 1) { if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0)) - error("thread render_radar creation failed\n"); + printf("thread render_radar creation failed\n"); if (g_IsRadarFake == 1) { if (pthread_create(&radar_reciever_id, NULL, RADAR_recieve, (void *)&radar_json_data) < 0) - error("RADAR_recieve creation failed\n"); + printf("RADAR_recieve creation failed\n"); } else { if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) - error("thread getimage creation failed\n"); + printf("thread getimage creation failed\n"); if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) - error("thread radar parser creation failed\n"); + printf("thread radar parser creation failed\n"); } } #endif @@ -22054,9 +22137,9 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa if(unlockingKeyInnoFR_success == 1){ #ifdef GY_OS_AMBA if (pthread_create(&get_face_websocket_thread, 0, thread_get_face_websocket, 0)) - error("thread get_face_websocket creation failed\n"); + printf("thread get_face_websocket creation failed\n"); if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) - error("thread parse_face creation failed\n"); + printf("thread parse_face creation failed\n"); #endif } #endif @@ -22068,7 +22151,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 //test_nn_main & run_send_udp_thread & run_getalarmmotion_thread output.log 8,532,480byte -> 產生1167個記憶體洩漏 大約1167-1072=95個記憶體洩漏是run_getalarmmotion_thread造成的 if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) - error("Getalarmmotion thread creation failed\n"); + printf("Getalarmmotion thread creation failed\n"); #endif #ifdef GY_OS_V_SERIES @@ -22087,7 +22170,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 ////原本名稱是check_http_socket_thread,現在改成run_event_counter_thread if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) - error("check http socket thread creation failed\n"); + printf("check http socket thread creation failed\n"); #endif } #endif @@ -22108,7 +22191,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 //test_nn_main & run_send_udp_thread output.log 8,579,969byte -> 產生1072個記憶體洩漏 大約1072-875=197個記憶體洩漏是run_send_udp_thread造成的 if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) - error("check http socket thread creation failed\n"); + printf("check http socket thread creation failed\n"); #endif #ifdef GY_OS_AMBA @@ -22120,21 +22203,21 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa { #if 1 if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent)) - error("Test nnctrl live thread creation failed\n"); + printf("Test nnctrl live thread creation failed\n"); #endif } #endif #ifdef GY_OS_NOVA if (pthread_create(&test_nnctrl_live_thread, 0, nnctrl_main, &stAMBAcontent)) - error("Test nnctrl live thread creation failed\n"); + printf("Test nnctrl live thread creation failed\n"); #endif #if 1 //329個Memory not freed 正常背景值洩漏 //Get CPU/VPU loading & AI FPS if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) - error("fps loading thread creation failed\n"); + printf("fps loading thread creation failed\n"); #endif #ifdef GY_OS_AMBA #if 1 @@ -22147,13 +22230,23 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #ifdef GY_OS_NOVA if (pthread_create(&thread_id_get_nova_driver, 0, thread_get_nova_driver, 0)) - error("thread get nova driver creation failed\n"); + printf("thread get nova driver creation failed\n"); #endif //System time sync //if (pthread_create(&thread_id_run_system_time_sync, 0, run_osd_time_sync_thread, NULL)) { //printf("\nrun osd server thread creation failed\n"); //} + +#ifdef GY_OS_AMBA + if (strcmp(SystemSetting.enable_cloud, "Yes") == 0 && strstr(SystemSetting.enable_python_file, ".py") != NULL) + { + if (pthread_create(&runpython_thread, NULL, start_run_python_thread, NULL)) + { + printf("thread start run python failed\n"); + } + } +#endif } else bHttpServerThreadStart = 1; @@ -22349,7 +22442,6 @@ void stop_server() pthread_mutex_destroy(&mutex_remotesnap_image); // Ken 2022-09-26 pthread_mutex_destroy(&mutex_radar_json); pthread_mutex_destroy(&mutex_tof_json); - pthread_mutex_destroy(&mutex_buffer); #endif pthread_mutex_destroy(&mutex_get_image); pthread_mutex_destroy(&mutex_get_image_HD); @@ -22406,6 +22498,8 @@ void stop_server() pthread_mutex_destroy(&mutex_write_pcd_data_L); pthread_mutex_destroy(&mutex_write_pcd_data_M); pthread_mutex_destroy(&mutex_write_pcd_data_S); + + pthread_mutex_destroy(&buffer_mutex); #endif #ifdef GY_OS_NOVA pthread_mutex_destroy(&mutex_pre_bbox_receive); @@ -22473,6 +22567,7 @@ void write_to_enable_tracking(char *enable_tracking) { cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); + char* JsonString = cJSON_Print(root); FILE *fp; @@ -22640,88 +22735,35 @@ void move_file() { } } +#ifdef GY_OS_AMBA void *start_run_python_thread(void* pythonpath) { pthread_detach(pthread_self()); setPthreadName("run_python"); - char *value = get_enable_python_file_value((const char*)pythonpath); - while (python_check_webstatus == 0) - { - // python_check_webstatus = 0 Web close - // python_check_webstatus = 1 Web open - printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); - continue; - } - // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); - sleep(15); // sleep 15 sec,wait Web thread open - if (value == NULL) { - printf("Failed to retrieve enable_python_file value\n"); - pthread_exit(NULL); - } - // 抓取 python 檔案 - if (strstr(value, ".py") != NULL) { - // printf("enable_python_file is a Python file: %s\n", value); - const char *prefix = "lifile_liname="; - char pythonfile[256]; - snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); - runPython(pythonfile); - } else { - printf("enable_python_file is not a Python file: %s\n", value); - } - pthread_exit(NULL); -} -char* get_enable_python_file_value(const char *filename) { - FILE *file = fopen(filename, "r"); - if (file == NULL) { - printf("Could not open file %s\n", filename); - return NULL; - } - - // 獲取文件大小 - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - // 讀取文件內容到內存中 - char *file_content = (char *)malloc(file_size + 1); - if (file_content == NULL) { - printf("Memory allocation failed\n"); - fclose(file); - return NULL; - } - fread(file_content, 1, file_size, file); - file_content[file_size] = '\0'; - fclose(file); - - // 解析 JSON - cJSON *json = cJSON_Parse(file_content); - free(file_content); - if (json == NULL) { - printf("Error parsing JSON file\n"); - return NULL; - } - - // 獲取 system_setting 的值 - cJSON *system_setting = cJSON_GetObjectItem(json, "system_setting"); - if (system_setting == NULL) { - printf("system_setting not found in JSON\n"); - cJSON_Delete(json); - return NULL; - } - - // 獲取 enable_python_file 的值 - cJSON *enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - char *result = NULL; - if (enable_python_file != NULL && cJSON_IsString(enable_python_file)) { - result = strdup(enable_python_file->valuestring); // 複製字符串值 - } - - // 清理 cJSON 對象 - cJSON_Delete(json); - printf("[get_enable_python_file_value] result : %s \n",result); - // 返回結果 - return result; + while (1) + { + if (AI_fps >= 1) + { + // 抓取 python 檔案 + if (strstr(SystemSetting.enable_python_file, ".py") != NULL) + { + const char *prefix = "lifile_liname="; + char pythonfile[256] = { 0 }; + snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, SystemSetting.enable_python_file); + runPython(pythonfile); + break; + } + } + else + { + printf("Wait AI_fps..."); + sleep(1); + } + } + pthread_exit(NULL); } + +#endif void run_server(int argc, char **argv) { //以下沒有記憶體洩漏------------------------20210803 @@ -22914,9 +22956,7 @@ void run_server(int argc, char **argv) #ifdef GY_OS_AMBA pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 pthread_mutex_init(&mutex_radar_json, NULL); - pthread_mutex_init(&mutex_tof_json, NULL); - pthread_mutex_init(&mutex_buffer, NULL); - + pthread_mutex_init(&mutex_tof_json, NULL); #endif pthread_mutex_init(&mutex_get_image, NULL); pthread_mutex_init(&mutex_get_image_HD, NULL); @@ -22969,6 +23009,8 @@ void run_server(int argc, char **argv) pthread_mutex_init(&mutex_write_pcd_data_L, NULL); pthread_mutex_init(&mutex_write_pcd_data_M, NULL); pthread_mutex_init(&mutex_write_pcd_data_S, NULL); + + pthread_mutex_init(&buffer_mutex, NULL); #endif #ifdef GY_OS_NOVA pthread_mutex_init(&mutex_pre_bbox_receive, NULL); @@ -23024,7 +23066,7 @@ void run_server(int argc, char **argv) pthread_t preload_http_thread; if (pthread_create(&preload_http_thread, 0, run_preload_http_server_thread, 0)) - error("preload http server thread creation failed\n"); + printf("preload http server thread creation failed\n"); } @@ -25929,22 +25971,17 @@ void run_server(int argc, char **argv) strcpy(SystemSetting.enable_python, "No"); new_data_write_to_config_file_flag = 1; } - if (enable_python_file) + if (enable_python_file) { - // check python file if (strstr(enable_python_file->valuestring, ".py") == enable_python_file->valuestring + strlen(enable_python_file->valuestring) - 3) { strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - - if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { - printf("check current runpython thread failed\n"); - } + pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH); } else { printf("File is not a Python file.\n"); } } - else { strcpy(SystemSetting.enable_python_file, "No python running."); new_data_write_to_config_file_flag = 1; @@ -27383,7 +27420,7 @@ void run_server(int argc, char **argv) else { cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString("No")); } - + if (enable_python_file) { cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString(enable_python_file->valuestring)); } @@ -31775,6 +31812,104 @@ void file_management() { #endif } +#define COUNTER_FILE "/emmc/plugin/Aida_data/counters.dat" +int protected_counters = 0; +int g_last_counters[MAX_EVENT_COUNTERS] = { 0 }; +void loadCounters() { +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) + { + if (protected_counters == 0) { + protected_counters = 1; + FILE *file = fopen(COUNTER_FILE, "r+"); // 以二進位讀取方式開啟檔案 + int counters[MAX_EVENT_COUNTERS] = { 0 }; + + if (file) { + fread(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 從檔案中讀取計數器值 + fclose(file); + + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + eventCounterList[index_counter].counter_count = counters[index_counter]; + g_last_counters[index_counter] = counters[index_counter]; + } + } + else { + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + counters[index_counter] = eventCounterList[index_counter].counter_count; + g_last_counters[index_counter] = counters[index_counter]; + } + + file = fopen(COUNTER_FILE, "w+"); // 以二進位寫入方式開啟檔案 + if (file) { + fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 將計數器值寫入檔案 + fclose(file); + } + else { + printf("\nCOUNTER FILE error.#2\n"); + } + } + protected_counters = 0; + } + } +#endif +} + +void saveCounters() { +#ifdef GY_OS_V_SERIES + +#else + if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || + ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || + ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || +#ifdef GY_OS_NOVA + IsANPRCategory(featureType) || +#endif + g_IsCustomWeight == 1) + { + if (protected_counters == 0) { + protected_counters = 1; + int counters[MAX_EVENT_COUNTERS] = { 0 }; + int check_if_difference = 0; + + for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) + { + counters[index_counter] = eventCounterList[index_counter].counter_count; + if (counters[index_counter] != g_last_counters[index_counter]) { + check_if_difference = 1; + } + g_last_counters[index_counter] = counters[index_counter]; + } + + if (check_if_difference == 1) { + FILE *file = fopen(COUNTER_FILE, "wb"); // 以二進位寫入方式開啟檔案 + if (file) { + fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 將計數器值寫入檔案 + fclose(file); + } + else { + printf("\nCOUNTER FILE error.\n"); + } + } + protected_counters = 0; + } + } +#endif +} + #ifdef GY_OS_NOVA int get_pid_nova_driver() { char *temp = NULL; @@ -31829,6 +31964,7 @@ void *RUN_NOVA_DETECTION(void *ptr) { //A11en snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "get_pid_nova_driver() == -1"); write_to_logs_html(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) diff --git a/src/face_parser.cpp b/src/face_parser.cpp index c536142..2057ce2 100644 --- a/src/face_parser.cpp +++ b/src/face_parser.cpp @@ -313,7 +313,7 @@ void check_directory_exists(const char* path) { if (stat(directory_path, &st) == -1) { if (mkdir(directory_path, 0700) == -1) { - perror("mkdir error"); + printf("mkdir error\n"); } } } @@ -362,7 +362,7 @@ void save_base64_image(char* base64_data, const char* output_filename) { #endif if (errno != 0) { // 潛航炊嚗寞撖阡瘜航炊嚗臭誑雿輻 perror 賢圈航炊閮 - perror("fwrite error"); + printf("fwrite error\n"); // Fail } } else { @@ -652,7 +652,7 @@ void base64_to_tpl(char* base64_data, char* output_filename) { #endif if (errno != 0) { // 潛航炊嚗寞撖阡瘜航炊嚗臭誑雿輻 perror 賢圈航炊閮 - perror("fwrite error"); + printf("fwrite error\n"); // Fail } } else { @@ -678,7 +678,7 @@ void base64_to_tpl(char* base64_data, char* output_filename) { char *readJsonFile(const char *filePath) { FILE *file = fopen(filePath, "r"); if (file == NULL) { - perror("Error opening file"); + printf("Error opening file\n"); return NULL; } @@ -698,7 +698,7 @@ char *readJsonFile(const char *filePath) { void writeJsonToFile(const char *filePath, const char *jsonData) { FILE *file = fopen(filePath, "w"); if (file == NULL) { - perror("Error opening file"); + printf("Error opening file\n"); return; } diff --git a/src/ivs.cpp b/src/ivs.cpp index c14b102..2d3ca69 100644 --- a/src/ivs.cpp +++ b/src/ivs.cpp @@ -516,29 +516,17 @@ int get_store_img_background_array_length_test() { void release_img_background() { - //if (g_pMOG2 != nullptr) { - //g_pMOG2.release(); - //} - - //if (g_pMOG2_2 != nullptr) { - //g_pMOG2_2.release(); - //} - - // 清理記憶體 - g_multiLayerMOG2.clearMemory(); - g_multiLayerMOG2_2.clearMemory(); - for (int i = 0; i < store_img_background_array_length; i++) { if (!img_background_array[i].empty()) { img_background_array[i].release(); } } - for (int i = 0; i < store_img_background_array_length_test; i++) { - if (!img_background_array_test[i].empty()) { - img_background_array_test[i].release(); - } - } + //for (int i = 0; i < store_img_background_array_length_test; i++) { + //if (!img_background_array_test[i].empty()) { + //img_background_array_test[i].release(); + //} + //} if (!img_background_short_term.empty()) { img_background_short_term.release(); @@ -560,6 +548,17 @@ void release_img_background() { if (!img_background_long_term_yuv.empty()) img_background_long_term_yuv.release(); + + //if (g_pMOG2 != nullptr) { + //g_pMOG2.release(); + //} + + //if (g_pMOG2_2 != nullptr) { + //g_pMOG2_2.release(); + //} + // 清理記憶體 + g_multiLayerMOG2.clearMemory(); + g_multiLayerMOG2_2.clearMemory(); } void run_compute_median() { @@ -2282,7 +2281,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, //printf("\n-------tempering_ready:%d\n", tempering_ready); //printf("\n-------switch_happened:%d\n", get_check_if_existing_any_switch_happened()); - if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0)) + if (not_to_show_tempering == 1 || (area_scale <= 0.45 && tempering_ready == 0)) { check_if_tempering_many_times = (temp_AI_fps - 1) * 4; @@ -2742,7 +2741,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, } } } - else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1))//(area_scale >= 0.83 && imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) || + else if (not_to_show_tempering == 0 && ((area_scale >= 0.6 && check_if_tempering_many_times <= 0) || tempering_ready == 1))//(area_scale >= 0.83 && imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) || { current_store_object_size = 0; @@ -2764,9 +2763,9 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, tempering_ready = 0; } } -#if 0 - else if ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) || - record_change_state == 1) { +#if 1 + else if (not_to_show_tempering == 0 && ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) || + record_change_state == 1)) { current_store_object_size = 0; last_store_object_size = current_store_object_size; @@ -2787,7 +2786,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, } } #endif - else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) { + else if (not_to_show_tempering == 0 && (area_scale >= 0.6 && check_if_tempering_many_times >= 1)) { current_store_object_size = 0; last_store_object_size = current_store_object_size; /* @@ -2931,15 +2930,13 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, uint32_t valid_bbox_idx = 0; - int ivs_width = 240;//320 - int ivs_height = 135;//180 + int ivs_width = 320;//320 + int ivs_height = 180;//180 float ratio_width = (float)i_InSourceOri_w / (float)ivs_width; float ratio_height = (float)i_InSourceOri_h / (float)ivs_height; if (not_to_show_tempering == 0 && check_if_tempering_happened <= 0) { - *no_tempering = 0; - check_if_tempering_many_times = (temp_AI_fps - 1) * 2; - g_progress_bar = 100.0; + } else if (not_to_show_tempering == 0 && check_if_tempering_happened >= 1) { g_progress_bar = 1.0; @@ -2985,6 +2982,10 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, g_multiLayerMOG2_2.initialize(); g_count_mog2_2 = 0; + + check_if_tempering_many_times = (temp_AI_fps - 1) * 2; + *no_tempering = 0; + g_progress_bar = 100.0; } check_if_tempering_happened--; @@ -3659,10 +3660,11 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, double area_scale = ((double)sum_area) / ((double)ivs_width * (double)ivs_height); - //printf("\n-------area scale:%lf\n", area_scale); + //printf("\n-------area scale:%lf,switch:%d,times:%d,not_to_show:%d,no_tempering:%d,record_change_state:%d\n", area_scale, get_check_if_existing_any_switch_happened(), check_if_tempering_many_times, not_to_show_tempering, *no_tempering, record_change_state); - if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0)) + if (not_to_show_tempering == 1 || (area_scale <= 0.45 && tempering_ready == 0)) { + //printf("\nAAAAAAAA 1:not_to_show:%d,area_scale:%lf,tempering_ready:%d\n", not_to_show_tempering, area_scale, tempering_ready); check_if_tempering_many_times = (temp_AI_fps - 1) * 2; current_store_object_size = 0; @@ -4011,8 +4013,10 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, } } } - else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1)) + else if (not_to_show_tempering == 0 && ((area_scale >= 0.6 && check_if_tempering_many_times <= 0) || tempering_ready == 1)) { + //printf("\nAAAAAAAA 2:not_to_show:%d,area_scale:%lf,tempering_ready:%d,times:%d\n", not_to_show_tempering, area_scale, tempering_ready, check_if_tempering_many_times); + current_store_object_size = 0; last_store_object_size = current_store_object_size; @@ -4023,8 +4027,24 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, *no_tempering = 0; tempering_ready = 0; } - else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) + else if (not_to_show_tempering == 0 && ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) || + record_change_state == 1)) + { + //printf("\nAAAAAAAA 3:not_to_show:%d,area_scale:%lf,record_change_state:%d\n", not_to_show_tempering, area_scale, record_change_state); + + current_store_object_size = 0; + last_store_object_size = current_store_object_size; + + record_change_state = 1; + + check_if_tempering_happened = 0; + record_change_state = 0; + *no_tempering = 0; + tempering_ready = 0; + } + else if (not_to_show_tempering == 0 && (area_scale >= 0.6 && check_if_tempering_many_times >= 1)) { + //printf("\nAAAAAAAA 4:not_to_show:%d,area_scale:%lf,times:%d\n", not_to_show_tempering, area_scale, check_if_tempering_many_times); current_store_object_size = 0; last_store_object_size = current_store_object_size; diff --git a/src/network.c b/src/network.c index 6822ffd..beea093 100644 --- a/src/network.c +++ b/src/network.c @@ -396,7 +396,7 @@ int resize_network(network *net, int w, int h) }else if(l.type == COST){ resize_cost_layer(&l, inputs); }else{ - error("Cannot resize this type of layer"); + printf("Cannot resize this type of layer\n"); } if(l.workspace_size > workspace_size) workspace_size = l.workspace_size; if(l.workspace_size > 2000000000) assert(0); @@ -899,7 +899,7 @@ pthread_t train_network_in_thread(network *net, data d, float *err) ptr->net = net; ptr->d = d; ptr->err = err; - if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed"); + if(pthread_create(&thread, 0, train_thread, ptr)) printf("Thread creation failed\n"); return thread; } @@ -1097,7 +1097,7 @@ pthread_t sync_layer_in_thread(network **nets, int n, int j) ptr->nets = nets; ptr->n = n; ptr->j = j; - if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed"); + if(pthread_create(&thread, 0, sync_layer_thread, ptr)) printf("Thread creation failed\n"); return thread; } diff --git a/src/nweb.c b/src/nweb.c index d3856d0..8ed4d39 100644 --- a/src/nweb.c +++ b/src/nweb.c @@ -143,7 +143,6 @@ extern pthread_mutex_t mutex_web; extern pthread_mutex_t mutex_base64; //extern pthread_mutex_t mutex_get_canvas; extern pthread_mutex_t mutex_get_network_input; -extern pthread_mutex_t mutex_buffer; extern pthread_mutex_t mutex_set_http_request; extern pthread_mutex_t mutex_reset_counter; @@ -257,7 +256,7 @@ static char *http_strLicenseType; extern double http_license_fps; extern int http_sleep_interval; -unsigned int python_check_webstatus = 0; + float confidence_limit; extern CPoint trafficLightPoint; @@ -421,13 +420,13 @@ int g_control_alarm_gpio = 0; int g_is_check_credential = 0; -char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; +char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE] = { 0 }; unsigned int g_uiWebPythonCurrentBufferIndex = 0; unsigned int g_uiWebPythonLastBufferIndex = 0; unsigned int g_cWebPythonBufferSignal = 0; unsigned int g_cWebPythonDeleteStatus = 0; unsigned int g_cWebPythonStatus = 0; -char g_cWebPythonName[50]; +//char g_cWebPythonName[50] = { 0 }; struct MemoryStruct { char memory[MEMORY_SIZE];//256KB @@ -2476,6 +2475,7 @@ void *net_curl_https_post_push_info(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); write_to_logs_html(temp_msg, "curl to post", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "curl to post", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -2748,6 +2748,7 @@ void *net_curl_https_get_other_lpr_db(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); write_to_logs_html(temp_msg, "curl to post to get lpr db", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "curl to post to get lpr db", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -6530,6 +6531,7 @@ void* auto_resolution_changed(void * ptr) { snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "different width or height"); write_to_logs_html(temp_msg, "auto resolution changed", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "auto resolution changed", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -8798,6 +8800,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); write_to_logs_html(temp_msg, "exit gynet", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "exit gynet", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -9764,6 +9767,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand."); write_to_logs_html(temp_msg, "set no brand", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "set no brand", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -9885,6 +9889,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand."); write_to_logs_html(temp_msg, "set lilin", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "set lilin", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -10006,6 +10011,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the old port. Please restart gynet.exe with the new port."); write_to_logs_html(temp_msg, "set new port", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "set new port", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -10774,7 +10780,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - // perror("send error #1999"); + // printf("send error #1999\n"); } else #endif @@ -10838,7 +10844,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - // perror("send error #1999"); + // printf("send error #1999\n"); } else #endif @@ -11198,11 +11204,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snapshot_size = (size_t)get_bg_radar_image(snapshot_addr_radar); sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - perror("send error #199916"); + printf("send error #199916\n"); if ((int)snapshot_size >= 1) { if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1) - perror("send error #19999998"); + printf("send error #19999998\n"); } else { @@ -11221,11 +11227,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch speed_snapshot_size = (size_t)get_speed_bg_image(radar_speed_snapshot_addr); sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - perror("send error #199917"); + printf("send error #199917\n"); if ((int)speed_snapshot_size >= 1) { if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1) - perror("send error #19999999"); + printf("send error #19999999\n"); } else { @@ -11971,6 +11977,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot my service"); write_to_logs_html(temp_msg, "reboot my service", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "reboot my service", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -12119,7 +12126,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) - perror("send error #28"); + printf("send error #28\n"); if (JsonString != NULL) { free(JsonString); @@ -13080,6 +13087,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot to release memory"); write_to_logs_html(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -14116,7 +14124,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch readFolderList(sFileList); strcpy(beforeSendBuffer_xtra, sFileList); - printf("sFileList: %s\n", sFileList); + //printf("sFileList: %s\n", sFileList); } else { strcpy(beforeSendBuffer_xtra, ""); @@ -14130,12 +14138,13 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch else if (strncmp(urlBuffer, "/pythonget?file=", strlen("/pythonget?file=")) == 0) { char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { + if (strcmp(SystemSetting.enable_python, "Yes") == 0 && g_cWebPythonBufferSignal == 0){ + g_cWebPythonBufferSignal = 1; char Cmd[512] = { 0 }; char sOutput[10240]; strcpy(Cmd, urlBuffer + 16); - printf("get file name = %s \n", Cmd); + //printf("get file name = %s \n", Cmd); readPythonFile(Cmd, sOutput); // printf("\nfile!!!\n"); @@ -14150,6 +14159,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch g_uiWebPythonLastBufferIndex = 0; strcpy(beforeSendBuffer_xtra, sOutput); + g_cWebPythonBufferSignal = 0; } else { @@ -14170,7 +14180,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch strcpy(Cmd, urlBuffer + strlen("/pythonupload?")); // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 - printf("Uploading...\n"); + //printf("Uploading...\n"); char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); strcpy(beforeSendBuffer_xtra, uploadPython(decodeCMD)); @@ -14196,7 +14206,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch strcpy(Cmd, urlBuffer + strlen("/pythonsave?")); // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 - printf("Saving...\n"); + //printf("Saving...\n"); char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); strcpy(beforeSendBuffer_xtra, SavePython(decodeCMD)); @@ -14222,11 +14232,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char Cmd[512] = { 0 }; strcpy(Cmd, urlBuffer + 14); - printf("cmd = %s \n", Cmd); + //printf("cmd = %s \n", Cmd); strcpy(Cmd, urlBuffer + 19); - printf("get file name = %s \n", Cmd); + //printf("get file name = %s \n", Cmd); deletePythonFile(Cmd); if (g_cWebPythonDeleteStatus == 1) @@ -14240,7 +14250,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } else { - sprintf(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); + strcpy(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); } int sendBufferSize = SetHttpResponse(DeleteMessage_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendDeleteStatus), SendDeleteStatus); if (send(cli_socket, DeleteMessage_xtra, sendBufferSize, MSG_MORE) == -1) @@ -14257,7 +14267,8 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char Cmd[512] = { 0 }; strcpy(Cmd, urlBuffer + 17); - printf("cmd = %s \n", Cmd); + //printf("cmd = %s \n", Cmd); + strcpy(beforeSendBuffer_xtra,""); } else { strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB"); @@ -15621,7 +15632,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char sendBuffer_xtra[BUFSIZE * 8] = {0}; int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) - perror("send error radar.json"); + printf("send error radar.json\n"); // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE if (root) { @@ -16028,7 +16039,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) - perror("[CGI:/gettof] send json string error"); + printf("[CGI:/gettof] send json string error\n"); if (JsonString != NULL) { free(JsonString); @@ -16379,7 +16390,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char sendBuffer_xtra[BUFSIZE * 8] = {0}; int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) - perror("send error tof.json"); + printf("send error tof.json\n"); // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE if (root) { @@ -16425,7 +16436,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch size_t bufferContentSize = 0; char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 單行 512,最多拿 8 行,最大尺寸即為 4096 char SendBufferStatus[BUFSIZE * 8] = {0}; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { char *buffersize_ptr = strstr(urlBuffer, "buffersize="); if (buffersize_ptr != NULL) @@ -16439,7 +16450,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch { g_cWebPythonStatus = 3; } - printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + //printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); // 每次拿取 Buffer N 個 Row 的資料 for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) @@ -16457,7 +16468,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch else { g_cWebPythonStatus = 4; // 寫入和讀取在同一 Row - printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); + //printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); continue; } } @@ -16479,7 +16490,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch sprintf(SendBufferStatus, "{\"status\":\"%d\",\"bufferSignal\":\"%d\"}", g_cWebPythonStatus, g_cWebPythonBufferSignal); // printf("[/pythongetstatus] Send Data To Web : %s\n\n\n",SendBufferStatus); - printf("!!! [/pythongetstatus] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + //printf("!!! [/pythongetstatus] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendBufferStatus), SendBufferStatus); if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) @@ -16498,7 +16509,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 單行 512,最多拿 8 行,最大尺寸即為 4096 char beforeSendBuffer[BUFSIZE * 8] = {0}; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { char *buffersize_ptr = strstr(urlBuffer, "buffersize="); if (buffersize_ptr != NULL) @@ -16522,7 +16533,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch if (g_uiWebPythonLastBufferIndex >= (WEBPYTHONBUFFER_LENSIZE-1)) { - printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n"); + //printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n"); g_uiWebPythonLastBufferIndex = 0; } if (bufferContentSize > 0) @@ -16531,21 +16542,22 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch { // 不讀正在寫的行數 // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - pthread_mutex_lock(&mutex_buffer); + pthread_mutex_lock(&buffer_mutex); // 拿 python 輸出 - printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); + //printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); // 清空拿過的 row memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); - pthread_mutex_unlock(&mutex_buffer); // 解鎖 + pthread_mutex_unlock(&buffer_mutex); // 解鎖 // 更新讀取位置 g_uiWebPythonLastBufferIndex++; + usSleep(1000); } else { - printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n"); + //printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n"); continue; } @@ -16558,15 +16570,18 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } } + + g_cWebPythonBufferSignal = 0; } else { - strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + //strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); + strcpy(sPythonBufferTemp, ""); } - printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp); + //printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp); sprintf(beforeSendBuffer , sPythonBufferTemp); // printf("[/pythongetbuffer] Send Data To Web : %s\n\n\n",beforeSendBuffer); - printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); + //printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer), beforeSendBuffer); if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) @@ -19730,7 +19745,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch #endif } - + else { + //strcpy(beforeSendBuffer, "Fail---4:"); + //strcat(beforeSendBuffer, file_Content); + } + if (root) { cJSON_Delete(root); root = NULL; @@ -19763,18 +19782,33 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } #endif printf("\nFail to read config_import.json or config.json\n"); + //strcpy(beforeSendBuffer, "Fail---3"); } } + else { + //strcpy(beforeSendBuffer, "Fail---2"); + } + } + else { + //strcpy(beforeSendBuffer, "Fail---1"); + } + + if (check_if_setfile_OK == 1) + { + strcpy(beforeSendBuffer, "OK"); + } + else { + strcpy(beforeSendBuffer, "Fail"); } - strcpy(beforeSendBuffer, ""); if (strlen(contentDescription) > 0) { strcat(beforeSendBuffer, " "); strcat(beforeSendBuffer, contentDescription); } - if (check_if_setfile_OK == 1) { + if (check_if_setfile_OK == 1) + { int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) printf("\nsend(Not setconfigfile)\n"); @@ -20631,7 +20665,14 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } - strcpy(beforeSendBuffer, ""); + if (check_if_setfile_OK == 1) + { + strcpy(beforeSendBuffer, "OK"); + } + else { + strcpy(beforeSendBuffer, "Fail"); + } + if (strlen(contentDescription) > 0) { strcat(beforeSendBuffer, " "); @@ -23115,6 +23156,19 @@ void *http_connection_handler(void *socket_desc) //memset(temp_buffer, 0x00, header_len+ nbytes_sec); //memcpy(temp_buffer, buffer, header_len+ nbytes_sec); + if (strstr(buffer, "setconfigfile") != NULL && strstr(buffer, "camera01") != NULL) + { + if (strstr(buffer, "}}}") != NULL) { + + } + else if (strstr(buffer, "system_setting") != NULL && strstr(buffer, "}}") != NULL) { + + } + else { + header_len += nbytes_sec; + continue; + } + } } else if ((strstr(buffer, "Connection: Upgrade") != NULL || strstr(buffer, "Upgrade: websocket") != NULL ) && strstr(buffer, "\r\n\r\n") != NULL) //非socket的會去檢查到\r\n\r\n,才往下執行。 @@ -23141,6 +23195,20 @@ void *http_connection_handler(void *socket_desc) //printf("\n---------[NVR#1]buffer:%s\n", buffer); //memset(temp_buffer, 0x00, header_len + nbytes_sec); //memcpy(temp_buffer, buffer, header_len + nbytes_sec); + + if (strstr(buffer, "setconfigfile") != NULL && strstr(buffer, "camera01") != NULL) + { + if (strstr(buffer, "}}}") != NULL) { + + } + else if (strstr(buffer, "system_setting") != NULL && strstr(buffer, "}}") != NULL) { + + } + else { + header_len += nbytes_sec; + continue; + } + } } else if (strstr(buffer, "\r\n\r\n") != NULL) //如果不是上述兩個,則[NVR]直接做"\r\n\r\n"的判斷。 { @@ -23718,11 +23786,11 @@ void *http_connection_handler(void *socket_desc) { char* file_Content = recvbuffer + i; - printf("file content = %s \n", file_Content); + //printf("file content = %s \n", file_Content); //printf("\nfile!!!\n"); //runPython(file_Content, sock); // strcpy(sendBuffer_xtra, "Send python file OK!!"); - printf("##################### file_Content : %s /n", file_Content); + //printf("##################### file_Content : %s /n", file_Content); runPython(file_Content); strcpy(SendPython, "Web Buffer Run OK !!"); } @@ -23731,7 +23799,6 @@ void *http_connection_handler(void *socket_desc) strcpy(SendPython, "Send python file fail !!"); } } - } } else { @@ -24521,7 +24588,6 @@ void *http_connection_handler(void *socket_desc) while (bHttpServerMainStart) { - python_check_webstatus = 1; // Ming add if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) { //printf("\n------------websocket break 1\n"); break; diff --git a/src/nweb.h b/src/nweb.h index 921d957..6a32285 100644 --- a/src/nweb.h +++ b/src/nweb.h @@ -814,15 +814,6 @@ extern "C" { float y; } SpeedInfo; - extern char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; - extern unsigned int g_uiWebPythonCurrentBufferIndex; - extern unsigned int g_uiWebPythonLastBufferIndex; - extern unsigned int g_cWebPythonBufferSignal; - extern unsigned int g_cWebPythonDeleteStatus; - extern char g_cWebPythonName[50]; - extern unsigned int g_cWebPythonStatus; - extern unsigned int python_check_webstatus; // 給開關 plugin 時用的 - extern bool isGYNetReady; //===================== diff --git a/src/parser.c b/src/parser.c index 0c49218..e4466e2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -242,7 +242,7 @@ local_layer parse_local(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before local layer must output image."); + if(!(h && w && c)) printf("Layer before local layer must output image.\n"); local_layer layer = make_local_layer(batch,h,w,c,n,size,stride,pad,activation); @@ -263,7 +263,7 @@ layer parse_deconvolutional(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before deconvolutional layer must output image."); + if(!(h && w && c)) printf("Layer before deconvolutional layer must output image.\n"); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); int pad = option_find_int_quiet(options, "pad",0); int padding = option_find_int_quiet(options, "padding",0); @@ -293,7 +293,7 @@ convolutional_layer parse_convolutional(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before convolutional layer must output image."); + if(!(h && w && c)) printf("Layer before convolutional layer must output image.\n"); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); int binary = option_find_int_quiet(options, "binary", 0); int xnor = option_find_int_quiet(options, "xnor", 0); @@ -557,7 +557,7 @@ crop_layer parse_crop(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before crop layer must output image."); + if(!(h && w && c)) printf("Layer before crop layer must output image.\n"); int noadjust = option_find_int_quiet(options, "noadjust",0); @@ -579,7 +579,7 @@ layer parse_reorg(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before reorg layer must output image."); + if(!(h && w && c)) printf("Layer before reorg layer must output image.\n"); layer layer = make_reorg_layer(batch,w,h,c,stride,reverse, flatten, extra); return layer; @@ -596,7 +596,7 @@ maxpool_layer parse_maxpool(list *options, size_params params) w = params.w; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before maxpool layer must output image."); + if(!(h && w && c)) printf("Layer before maxpool layer must output image.\n"); maxpool_layer layer = make_maxpool_layer(batch,h,w,c,size,stride,padding); return layer; @@ -609,7 +609,7 @@ avgpool_layer parse_avgpool(list *options, size_params params) h = params.h; c = params.c; batch=params.batch; - if(!(h && w && c)) error("Layer before avgpool layer must output image."); + if(!(h && w && c)) printf("Layer before avgpool layer must output image.\n"); avgpool_layer layer = make_avgpool_layer(batch,w,h,c); return layer; @@ -707,7 +707,7 @@ route_layer parse_route(list *options, size_params params, network *net) { char *l = option_find(options, "layers"); int len = strlen(l); - if(!l) error("Route Layer must specify input layers"); + if(!l) printf("Route Layer must specify input layers\n"); int n = 1; int i; for(i = 0; i < len; ++i){ @@ -795,7 +795,7 @@ void parse_net_options(list *options, network *net) net->exposure = option_find_float_quiet(options, "exposure", 1); net->hue = option_find_float_quiet(options, "hue", 0); - if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied"); + if(!net->inputs && !(net->h && net->w && net->c)) printf("No input parameters supplied\n"); char *policy_s = option_find_str(options, "policy", "constant"); net->policy = get_policy(policy_s); @@ -807,7 +807,7 @@ void parse_net_options(list *options, network *net) } else if (net->policy == STEPS){ char *l = option_find(options, "steps"); char *p = option_find(options, "scales"); - if(!l || !p) error("STEPS policy must have steps and scales in cfg file"); + if(!l || !p) printf("STEPS policy must have steps and scales in cfg file\n"); int len = strlen(l); int n = 1; @@ -848,14 +848,14 @@ network *parse_network_cfg(char *filename) { list *sections = read_cfg(filename); node *n = sections->front; - if(!n) error("Config file has no sections"); + if(!n) printf("Config file has no sections\n"); network *net = make_network(sections->size - 1); net->gpu_index = gpu_index; size_params params; section *s = (section *)n->val; list *options = s->options; - if(!is_network(s)) error("First section must be [net] or [network]"); + if(!is_network(s)) printf("First section must be [net] or [network]\n"); parse_net_options(options, net); params.h = net->h; @@ -1685,7 +1685,7 @@ convolutional_layer parse_convolutional_mem(list *options, size_params params) w = params.w; c = params.c; batch = params.batch; - if (!(h && w && c)) error("Layer before convolutional layer must output image."); + if (!(h && w && c)) printf("Layer before convolutional layer must output image.\n"); int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0); int binary = option_find_int_quiet(options, "binary", 0); int xnor = option_find_int_quiet(options, "xnor", 0); @@ -1765,7 +1765,7 @@ maxpool_layer parse_maxpool_mem(list *options, size_params params) w = params.w; c = params.c; batch = params.batch; - if (!(h && w && c)) error("Layer before maxpool layer must output image."); + if (!(h && w && c)) printf("Layer before maxpool layer must output image.\n"); maxpool_layer layer = make_maxpool_layer_mem(batch, h, w, c, size, stride, padding); return layer; diff --git a/src/pns.c b/src/pns.c index 36e8b6c..e1fc357 100644 --- a/src/pns.c +++ b/src/pns.c @@ -856,6 +856,7 @@ size_t PNS_Get_Snapshot_From_IPCam(char* file_name, char* img_addr, int enable_t snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); write_to_logs_html(temp_msg, "PNS Get Snapshot", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "PNS Get Snapshot", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -1005,6 +1006,7 @@ size_t PNS_Get_Snapshot_From_Remote_IPCam(char* file_name, char* img_addr, int e snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); write_to_logs_html(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -1121,10 +1123,38 @@ void stop_canvas_live_mode_flag() { int g_pns_account_OK = 0; int g_pns_access_level = -1; int g_check_noapplink = 0; -char g_last_cloud_account[256] = { 0 }; -char g_last_cloud_password[256] = { 0 }; +int g_check_invalidpass = 0; +int g_check_emailnotvalid = 0; +//char g_last_cloud_account[256] = { 0 }; +//char g_last_cloud_password[256] = { 0 }; struct timeval g_currtime_pns_post; long g_last_s_pns_post = 0; + +void set_g_pns_account_OK(int temp_g_pns_account_OK) { + g_pns_account_OK = temp_g_pns_account_OK; +} + +void set_g_pns_access_level(int temp_g_pns_access_level) { + g_pns_access_level = temp_g_pns_access_level; +} + +void set_g_check_invalidpass(int temp_g_check_invalidpass) { + g_check_invalidpass = temp_g_check_invalidpass; +} + +void set_g_check_emailnotvalid(int temp_g_check_emailnotvalid) { + g_check_emailnotvalid = temp_g_check_emailnotvalid; +} + +int get_g_check_wrong_pass_or_email() { + if (g_check_emailnotvalid == 1 || g_check_invalidpass == 1) { + return 1; + } + else { + return 0; + } +} + void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr, char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime) { //printf("\n---------------[PNS Send Multipart POST]:%d\n",1); @@ -1138,12 +1168,10 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, if (g_check_ping_OK == 1) { if (g_pns_access_level <= 0 && (current_s_pns_post - g_last_s_pns_post) >= 3600) { g_check_noapplink = 0; - g_pns_account_OK = 0; g_last_s_pns_post = current_s_pns_post; } else if (g_pns_access_level >= 1 && (current_s_pns_post - g_last_s_pns_post) >= 600) { g_check_noapplink = 0; - g_pns_account_OK = 0; g_last_s_pns_post = current_s_pns_post; } } @@ -1151,48 +1179,7 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, int check_reboot = 0; - if (g_check_ping_OK == 1 && g_check_noapplink == 0) { - if (strlen(user_account) >= 1 && strlen(user_password) >= 1 && strcmp(user_account,"myaccount@mail.com") != 0){ - - if (strlen(g_last_cloud_account) >= 1 && strlen(g_last_cloud_password) >= 1) { - if (strcmp(user_account, g_last_cloud_account) != 0 || - strcmp(user_password, g_last_cloud_password) != 0) { - g_pns_account_OK = 0; - } - } - - if (g_pns_account_OK == 0) { - memset(g_last_cloud_account, 0x00, sizeof(g_last_cloud_account)); - memset(g_last_cloud_password, 0x00, sizeof(g_last_cloud_password)); - strcpy(g_last_cloud_account, user_account); - strcpy(g_last_cloud_password, user_password); - char returned_msg_temp[MEMORY_SIZE] = { 0 }; - PNS_check_if_to_post_image(user_account, user_password, returned_msg_temp, region_cloud_addr); - - if (strstr(returned_msg_temp, "\"msg\":\"oaA=\"") != NULL) { - g_pns_account_OK = 1; - } - - if (g_pns_account_OK == 1) { - if (strstr(returned_msg_temp, "\"eid\":\"Yg==\"") != NULL) { - g_pns_access_level = 0; - } - else if (strstr(returned_msg_temp, "\"eid\":\"Yw==\"") != NULL) { - g_pns_access_level = 1; - } - else if (strstr(returned_msg_temp, "\"eid\":\"ZQ==\"") != NULL) { - g_pns_access_level = 3; - } - else if (strstr(returned_msg_temp, "\"eid\":{\"err\":\"Yw==\",\"msg\":\"p6PFmpaZoZqU\"}") != NULL) { - g_pns_access_level = -2; - } - } - } - } - else { - g_pns_account_OK = 1; - g_pns_access_level = 0; - } + if (g_check_ping_OK == 1 && g_check_noapplink == 0 && g_pns_access_level >= 0) { //CURL* curl = curl_easy_init(); curl_mime* form = NULL; @@ -1737,6 +1724,16 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, if (strcmp(temp_msg,"noAppLink")==0 || strstr(temp_msg, "\"msg\":\"oKSipaB8nKOb\"") != NULL) { g_check_noapplink = 1; } + + if (strcmp(temp_msg, "invalidPass") == 0 || strstr(temp_msg, "\"msg\":\"m6PXlpyZl4WR1qs=\"") != NULL) { + g_check_invalidpass = 1; + g_pns_access_level = 0; + } + + if (strcmp(temp_msg, "emailNotValid") == 0 || strstr(temp_msg, "\"msg\":\"l6LCnpx+oqmGxKSdyg==\"") != NULL) { + g_check_emailnotvalid = 1; + g_pns_access_level = 0; + } } else { char c_access_level[50] = { 0 }; @@ -1754,6 +1751,16 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, if (strstr(ptr_responded_msg->memory, "\"msg\":\"oKSipaB8nKOb\"") != NULL) { g_check_noapplink = 1; } + + if (strstr(ptr_responded_msg->memory, "\"msg\":\"m6PXlpyZl4WR1qs=\"") != NULL) { + g_check_invalidpass = 1; + g_pns_access_level = 0; + } + + if (strstr(ptr_responded_msg->memory, "\"msg\":\"l6LCnpx+oqmGxKSdyg==\"") != NULL) { + g_check_emailnotvalid = 1; + g_pns_access_level = 0; + } } //printf("\n---------------[PNS Send Multipart POST]:%d\n", 12); @@ -1862,6 +1869,8 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, }*/ if (check_reboot == 1) { + saveCounters(); + pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { diff --git a/src/pns.h b/src/pns.h index f40972c..52e3db8 100644 --- a/src/pns.h +++ b/src/pns.h @@ -43,6 +43,12 @@ extern int g_check_ping_OK; extern int g_sdk_version; +void set_g_pns_access_level(int temp_g_pns_access_level); +void set_g_pns_account_OK(int temp_g_pns_account_OK); +void set_g_check_invalidpass(int temp_g_check_invalidpass); +void set_g_check_emailnotvalid(int temp_g_check_emailnotvalid); +int get_g_check_wrong_pass_or_email(); + void PNS_Query_Service_Status(char* returned_msg); void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr,char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime); int PNS_Get_Device_Name(int arg_url_encoded_or_not, char *returned_msg); diff --git a/src/ptz.c b/src/ptz.c index cdaae7d..60a24a9 100644 --- a/src/ptz.c +++ b/src/ptz.c @@ -896,7 +896,7 @@ void UpdatePTZConfigSetting() } }*/ - printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne); + //printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne); diff --git a/src/pythonR.c b/src/pythonR.c index 8e555fd..c4e6a74 100644 --- a/src/pythonR.c +++ b/src/pythonR.c @@ -1,43 +1,52 @@ #include "pythonR.h" #include -#define MAX_BUFFER_LINES 1024 -char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; -char sFileName[PTYHON_FILE_NAME] = { 0 }; + +//char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; +//char sFileName[PTYHON_FILE_NAME] = { 0 }; //char sPythonFilename[PTYHON_FILE_NAME]; -pthread_mutex_t buffer_mutex = PTHREAD_MUTEX_INITIALIZER; -int check_count = 0; +//int check_count = 0; void IfFolderExist() { - if (access(PYTHON_FOLDER, 0) == 0) - { - printf("FOLDER EXISTS. \n"); - } - else - { - printf("FOLDER DOESN'T EXISTS! \n"); - //int ret; - /*ret = */mkdir(PYTHON_FOLDER, S_IRWXU | S_IRWXG | S_IRWXO); + int check_count = 0; + int check_if_ok = 0; + + while (check_count < 10) { + if (access(PYTHON_FOLDER, F_OK) == 0) { + //printf("FOLDER EXISTS.\n"); + check_if_ok = 1; + break; + } + else { + //printf("FOLDER DOESN'T EXIST! Attempting to create it...\n"); - check_count++; - if (check_count < 10) - { - IfFolderExist(); + if (mkdir(PYTHON_FOLDER, S_IRWXU | S_IRWXG | S_IRWXO) == 0) { + //printf("FOLDER CREATED SUCCESSFULLY.\n"); + } + else { + //printf("Failed to create python folder\n"); + } } + + check_count++; + usSleep(100); } + + if(check_if_ok == 0) + printf("FAILED TO CREATE FOLDER AFTER %d ATTEMPTS.\n", check_count); } void readPythonFile(char *sINFileName, char *sOutput) { - memset(sPythonCode, 0, PYTHON_CODE_SIZE); - memset(sFileName, 0, PTYHON_FILE_NAME); + //char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; + char sFileName[PTYHON_FILE_NAME] = { 0 }; int lSize = 0; //check folder exist - check_count = 0; + //check_count = 0; IfFolderExist(); //python file name @@ -60,37 +69,49 @@ void readPythonFile(char *sINFileName, char *sOutput) fclose(f); } - else { - } } // 確認資料夾存在 int ensureFolderExists(const char *folderPath) { struct stat st = { 0 }; - if (stat(folderPath, &st) == -1) { - mkdir(folderPath, 0777); - if (stat(folderPath, &st) == -1) { - return -1; // 無法創建資料夾 + int ret = 0; + + // 檢查資料夾是否已存在 + if (stat(folderPath, &st) == -1) { + // 嘗試創建資料夾 + if (mkdir(folderPath, 0777) == -1) { + // 如果創建失敗,記錄原因 + printf("\nFailed to create directory\n"); + ret = -1; // 創建失敗 } } + else if (!S_ISDIR(st.st_mode)) { + // 如果同名的檔案存在但不是資料夾 + printf("\nError: A file with the same name as the folder exists.\n"); + ret = -1; + } - return 0; // + return ret; } int saveFile(char *pythonData, char *filename) { + int ret = 0; if (ensureFolderExists(PYTHON_FOLDER) == -1) { - return -1; // 資料夾不存在 - } - chmod(filename, 0777); - printf("[pythonR.html saveFile()] filename = %s\n", filename); - FILE *f = fopen(filename, "w"); - if (f != NULL) { - fprintf(f, "%s\n", pythonData); - fclose(f); - return 0; // 成功 - } else { - return -2; // 無法寫入 + ret = -1; // 資料夾不存在 } + else { + chmod(filename, 0777); + //printf("[pythonR.html saveFile()] filename = %s\n", filename); + FILE *f = fopen(filename, "w"); + if (f != NULL) { + fprintf(f, "%s\n", pythonData); + fclose(f); + } + else { + ret = -2; // 無法寫入 + } + } + return ret; } #if 1 @@ -100,19 +121,19 @@ void deletePythonFile(char *sINFileName) // g_cWebPythonDeleteStatus = 0 deleted successfully // g_cWebPythonDeleteStatus = 1 deleted failed g_cWebPythonDeleteStatus = 0; - memset(sFileName, 0, PTYHON_FILE_NAME); + char sFileName[PTYHON_FILE_NAME] = { 0 }; //check folder exist - check_count = 0; + //check_count = 0; IfFolderExist(); //python file name //sprintf(sFileName, "%s/%s.py", PYTHON_FOLDER, sINFileName); sprintf(sFileName, "%s/%s", PYTHON_FOLDER, sINFileName); - printf("[pythonR.html deletePythonFile()] filename = %s\n", sFileName); + //printf("[pythonR.html deletePythonFile()] filename = %s\n", sFileName); if (remove(sFileName) == 0) { - printf("The file is deleted successfully. \n"); + //printf("The file is deleted successfully. \n"); g_cWebPythonDeleteStatus = 1; } else { @@ -124,15 +145,21 @@ void deletePythonFile(char *sINFileName) #endif int checkDuplicateFile(const char *filename) { // check file name duplicate - char fullPath[1024]; - snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename); + int ret = 0; + char fullPath[1024]; + snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename); + if (access(fullPath, F_OK) != -1) { // file exists - return 1; + ret = 1; } - // file not exists - return 0; + else { + // file not exists + ret = 0; + } + + return ret; } const char* SavePython(char *urlData) { @@ -140,7 +167,8 @@ const char* SavePython(char *urlData) { char *substr2 = "&code="; char *result_1 = strstr(urlData, substr1); char *result_2 = strstr(urlData, substr2); - + int ret = 0; + if (result_1 != NULL && result_2 != NULL) { char sPythonFileName[1024] = {0}; char sPythonFilePath[1024] = {0}; @@ -151,14 +179,26 @@ const char* SavePython(char *urlData) { sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName); int saveResult = saveFile(sPythonCode, sPythonFilePath); - if(saveResult==0){ - return "File save successfully"; - }else{ - return "File save failed"; - } - + if(saveResult == 0){ + ret = 1; + } + else{ + ret = 2; + } + } + else { + ret = 0; + } + + if (ret == 1) { + return "File save successfully"; + } + else if (ret == 2) { + return "File save failed"; + } + else {//ret = 0 + return "Invalid URL parameters"; } - return "Invalid URL parameters"; } const char* uploadPython(char *urlData) { @@ -166,7 +206,8 @@ const char* uploadPython(char *urlData) { char *substr2 = "&code="; char *result_1 = strstr(urlData, substr1); char *result_2 = strstr(urlData, substr2); - + int ret = 0; + if (result_1 != NULL && result_2 != NULL) { char sPythonFileName[1024] = {0}; char sPythonFilePath[1024] = {0}; @@ -175,243 +216,268 @@ const char* uploadPython(char *urlData) { memcpy(sPythonFileName, result_1 + strlen(substr1) , (result_2)-(result_1 + strlen(substr1))); memcpy(sPythonCode, result_2 + strlen(substr2), (strlen(urlData) - ((result_2 + strlen(substr2)) - urlData))); sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName); - printf("[uploadPython] sPythonFileName = %s : ", sPythonFileName); + //printf("[uploadPython] sPythonFileName = %s : ", sPythonFileName); if (strlen(sPythonFileName) == 0) { - printf("######################## No File name \n "); - return "Invalid file name"; + //printf("######################## No File name \n "); + ret = 1; } else if (checkDuplicateFile(sPythonFileName) == 1) { - return "File already exists, please choose a different file name"; + ret = 2; } - int saveResult = saveFile(sPythonCode, sPythonFilePath); - if(saveResult==0){ - return "File uploaded successfully"; - }else{ - return "File upload failed"; - } - + else { + int saveResult = saveFile(sPythonCode, sPythonFilePath); + if (saveResult == 0) { + ret = 3; + } + else { + ret = 4; + } + } + } + else { + ret = 0; + } + + if (ret == 1) { + return "Invalid file name"; + } + else if (ret == 2) { + return "File already exists, please choose a different file name"; + } + else if (ret == 3) { + return "File uploaded successfully"; + } + else if (ret == 4) { + return "File upload failed"; + } + else {//ret = 0 + return "Invalid URL parameters"; } - return "Invalid URL parameters"; } +int g_stop_python = 0; void stopPython() { - g_cWebPythonBufferSignal = 0; - for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) - { - memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); // 2024-09-09 sure buffer clear + g_stop_python = 1; + if (g_cWebPythonBufferSignal == 0) { + g_cWebPythonBufferSignal = 0; + for (int i = 0; i <= WEBPYTHONBUFFER_LENSIZE; i++) + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); // 2024-09-09 sure buffer clear + } + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + g_cWebPythonStatus = 0; + //printf("\n\n\n\n\n\n\nPython has been signaled to stop.\n\n\n\n\n\n\n"); } - g_uiWebPythonCurrentBufferIndex = 0; - g_uiWebPythonLastBufferIndex = 0; - g_cWebPythonStatus = 0; - printf("\n\n\n\n\n\n\nPython has been signaled to stop.\n\n\n\n\n\n\n"); } - void runPython(char *pythonData) //2024/02/27 run button action { - // ------------------------------------------------- - // 處理 ajax 傳來的字串,拆解成檔名與檔案內容 - char *substr1 = "lifile_liname="; - char *result_1 = NULL; - char sPythonFileName[1024] = {0}; - result_1 = strstr(pythonData, substr1); //2024/02/27, search str and return str pointer position - memset(sPythonFileName, 0, PTYHON_FILE_NAME); //2024/02/27 name limit 1024 (use set mem value) - memset(sPythonCode, 0, PYTHON_CODE_SIZE); //2024/02/27 code size limit 20KB (use set mem value) - for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) // 2024-09-13 sure buffer clear - { - memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); - } - memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); - // if (g_cWebPythonName != NULL) { - - // memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); - - // } else { - // // 如果 json 檔抓到 g_cWebPythonName 有值 - // strncpy(sPythonFileName, g_cWebPythonName, sizeof(sPythonFileName) - 1); - // memset(g_cWebPythonName, 0, sizeof(g_cWebPythonName)); - // } - - // if need read python content, use cat command - // char result_3[PYTHON_CODE_SIZE] = {0}; - // char cat_cmd[1024] = {0}; - // FILE *fp; - // snprintf(cat_cmd, sizeof(cat_cmd), "cat %s/%s", PYTHON_FOLDER, sPythonFileName); - // fp = popen(cat_cmd, "r"); - // if (fp == NULL) { - // printf("can't use cat command \n"); - // } else { - // size_t bytes_read = fread(result_3, 1, sizeof(result_3) - 1, fp); - // if (bytes_read > 0) { - // result_3[bytes_read] = '\0'; // 確保字串結尾 - // } else { - // printf("read file content failed \n"); - // } - // pclose(fp); - // } - // ------------------------------------------------- - // 建立 virtual pipeline 取得 python 輸出 - int size_psBuffer = BUFSIZE_V3; - char psBuffer[WEBPYTHONBUFFER_ROWSIZE] = {0}; - char sendBuffer_xtra[BUFSIZE * 8] = {0}; - //char psRunPythonStatusMessage[80] = {0}; - char psBufferTemp[WEBPYTHONBUFFER_ROWSIZE] = { 0 }; - FILE *pPipe; - char cmd[256] = {0}; - memset(cmd, 0x00, sizeof(cmd)); - size_t psbufferContentSize = 0; - size_t psBufferTempSize = 0; - g_uiWebPythonCurrentBufferIndex = 0; - g_uiWebPythonLastBufferIndex = 0; - // sprintf(cmd, "python3 %s", sPythonFilePath); - sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // 新增 2>&1 - printf("run python cmd = \n%s \n", cmd); - pPipe = vpopen(cmd, "r"); - if (pPipe == NULL) - { - // virtual pipeline 建立失敗,回傳給 Web 錯誤訊息 - printf("\n-------------------------------------\n"); - printf("Failed to run command\n"); - printf("pPipe is None!!\n"); - printf("\n-------------------------------------\n"); - // sprintf(psRunPythonStatusMessage, "Failed to run command. pPipe is None!!"); - } - else - { - // sprintf(psRunPythonStatusMessage, "Web Buffer Run OK"); - // 成功開啟 virtual pipeline 才去讀 python 輸出 + g_stop_python = 0; + if (g_cWebPythonBufferSignal == 0) { g_cWebPythonBufferSignal = 1; // Signal to start reading - // g_uiWebPythonCurrentBufferIndex = 0; - while ((fgets(psBuffer, sizeof(psBuffer), pPipe) != NULL) && (g_cWebPythonBufferSignal != 0)) { //Ming 2024-09-01 - - printf("[runPython] PYTHON OUTPUT: %s", psBuffer); - // printf("[runPython] Before writing: g_uiWebPythonCurrentBufferIndex[%d]\n", g_uiWebPythonCurrentBufferIndex); - - psbufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); - // printf("\npsbufferContentSize len : %zu\n", psbufferContentSize); - if (psbufferContentSize == 0) { - printf("\n\n\n\n Writing !!!!!\n\n\n\n"); - pthread_mutex_lock(&buffer_mutex); - - size_t len = strlen(psBuffer); - - if (psBufferTempSize + len < sizeof(psBufferTemp)) { - strcat(psBufferTemp, psBuffer); // 添加內容到 psBufferTemp - psBufferTempSize += len; // 更新計數器 - } else { - // psBufferTemp 滿時,移到 g_aWebPythonBuffer2D 中並重置 + + // ------------------------------------------------- + // 處理 ajax 傳來的字串,拆解成檔名與檔案內容 + char *substr1 = "lifile_liname="; + char *result_1 = strstr(pythonData, substr1); //2024/02/27, search str and return str pointer position + if (result_1 != NULL) { + char sPythonFileName[PTYHON_FILE_NAME] = { 0 }; + char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; + for (int i = 0; i <= WEBPYTHONBUFFER_LENSIZE; i++) // 2024-09-13 sure buffer clear + { + memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); + } + + memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); + + // if (g_cWebPythonName != NULL) { + + // memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData)); + + // } else { + // // 如果 json 檔抓到 g_cWebPythonName 有值 + // strncpy(sPythonFileName, g_cWebPythonName, sizeof(sPythonFileName) - 1); + // memset(g_cWebPythonName, 0, sizeof(g_cWebPythonName)); + // } + + // if need read python content, use cat command + // char result_3[PYTHON_CODE_SIZE] = {0}; + // char cat_cmd[1024] = {0}; + // FILE *fp; + // snprintf(cat_cmd, sizeof(cat_cmd), "cat %s/%s", PYTHON_FOLDER, sPythonFileName); + // fp = popen(cat_cmd, "r"); + // if (fp == NULL) { + // printf("can't use cat command \n"); + // } else { + // size_t bytes_read = fread(result_3, 1, sizeof(result_3) - 1, fp); + // if (bytes_read > 0) { + // result_3[bytes_read] = '\0'; // 確保字串結尾 + // } else { + // printf("read file content failed \n"); + // } + // pclose(fp); + // } + + // ------------------------------------------------- + // 建立 virtual pipeline 取得 python 輸出 + char cmd[256] = { 0 }; + // sprintf(cmd, "python3 %s", sPythonFilePath); + sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // 新增 2>&1 + //printf("run python cmd = \n%s \n", cmd); + + FILE *pPipe; + pPipe = vpopen(cmd, "r"); + if (pPipe == NULL) + { + // virtual pipeline 建立失敗,回傳給 Web 錯誤訊息 + printf("\n-------------------------------------\n"); + printf("Failed to run command\n"); + printf("pPipe is None!!\n"); + printf("\n-------------------------------------\n"); + // sprintf(psRunPythonStatusMessage, "Failed to run command. pPipe is None!!"); + } + else + { + //int size_psBuffer = BUFSIZE_V3; + char psBuffer[WEBPYTHONBUFFER_ROWSIZE] = { 0 }; + //char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; + //char psRunPythonStatusMessage[80] = {0}; + char psBufferTemp[WEBPYTHONBUFFER_ROWSIZE] = { 0 }; + + size_t psbufferContentSize = 0; + size_t psBufferTempSize = 0; + g_uiWebPythonCurrentBufferIndex = 0; + g_uiWebPythonLastBufferIndex = 0; + + // sprintf(psRunPythonStatusMessage, "Web Buffer Run OK"); + // 成功開啟 virtual pipeline 才去讀 python 輸出 + + // g_uiWebPythonCurrentBufferIndex = 0; + while ((fgets(psBuffer, sizeof(psBuffer), pPipe) != NULL) && g_stop_python == 0) { //Ming 2024-09-01 + + // printf("[runPython] PYTHON OUTPUT: %s", psBuffer); + // printf("[runPython] Before writing: g_uiWebPythonCurrentBufferIndex[%d]\n", g_uiWebPythonCurrentBufferIndex); + + psbufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); + // printf("\npsbufferContentSize len : %zu\n", psbufferContentSize); + if (psbufferContentSize == 0) { + //printf("\n\n\n\n Writing !!!!!\n\n\n\n"); + pthread_mutex_lock(&buffer_mutex); + + size_t len = strlen(psBuffer); + + if (psBufferTempSize + len < sizeof(psBufferTemp)) { + strcat(psBufferTemp, psBuffer); // 添加內容到 psBufferTemp + psBufferTempSize += len; // 更新計數器 + } + else { + // psBufferTemp 滿時,移到 g_aWebPythonBuffer2D 中並重置 + strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); + memset(psBufferTemp, 0, sizeof(psBufferTemp)); // 清空 psBufferTemp + strcat(psBufferTemp, psBuffer); // 重置後繼續放入資料 + psBufferTempSize = 0; // 重置計數器 + psBufferTempSize += len; // 重置後繼續計數 + // printf("\n\n\n\n [runPython] Moved data to buffer : %s\n\n\n\n", g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); + g_uiWebPythonCurrentBufferIndex++; + + } + + pthread_mutex_unlock(&buffer_mutex); + + if (g_uiWebPythonCurrentBufferIndex >= (WEBPYTHONBUFFER_LENSIZE - 1)) { + //printf("!!! [runPython] Reset buffer index\n"); + g_uiWebPythonCurrentBufferIndex = 0; + } + usSleep(1000); + } + else { + //printf("[runPython] buffer is not empty, psbufferContentSize:%zu\n", psbufferContentSize); + continue; + } + } + vpclose(pPipe); // Close the pipe after reading all outputs + + // 未滿的 Row 要送入 Buffer + if (psBufferTempSize > 0) + { strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); memset(psBufferTemp, 0, sizeof(psBufferTemp)); // 清空 psBufferTemp - strcat(psBufferTemp, psBuffer); // 重置後繼續放入資料 - psBufferTempSize = 0; // 重置計數器 - psBufferTempSize += len; // 重置後繼續計數 - // printf("\n\n\n\n [runPython] Moved data to buffer : %s\n\n\n\n", g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]); g_uiWebPythonCurrentBufferIndex++; - - } - - pthread_mutex_unlock(&buffer_mutex); - if (g_uiWebPythonCurrentBufferIndex >= (WEBPYTHONBUFFER_LENSIZE - 1)) { - printf("!!! [runPython] Reset buffer index\n"); - g_uiWebPythonCurrentBufferIndex = 0; } - } else { - printf("[runPython] buffer is not empty, psbufferContentSize:%zu\n", psbufferContentSize); - continue; + // } + // int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(psRunPythonStatusMessage), psRunPythonStatusMessage); + // if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) + // { + // printf("\nsend error #32\n"); + // } } - // 未滿的 Row 要送入 Buffer - if (psBufferTempSize > 0 ) - { - strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); - memset(psBufferTemp, 0, sizeof(psBufferTemp)); // 清空 psBufferTemp - g_uiWebPythonCurrentBufferIndex++; - - } - - g_cWebPythonBufferSignal = 0; // 需在 python 跑完時,切回 0,pythongetbuffer CGI 才能確切知道 python 執行狀態 - // - pclose(pPipe); // Close the pipe after reading all outputs + g_cWebPythonBufferSignal = 0; // 需在 python 跑完時,切回 0,pythongetbuffer CGI 才能確切知道 python 執行狀態 } - // int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(psRunPythonStatusMessage), psRunPythonStatusMessage); - // if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - // { - // printf("\nsend error #32\n"); - // } - - } void readFolderList(char *output) { - DIR *d; - struct dirent *dir; - char sfileList[200][256] = { 0 }; - int file_number = 0; - char *testsarr[100] = { "a","b","c" }; - - //Create JSON - cJSON *s_root = cJSON_CreateObject(); - - cJSON *s_file_name; - cJSON *file_list = cJSON_CreateArray(); - + int ret = 0; if (ensureFolderExists(PYTHON_FOLDER) == -1) { - return -1; // 資料夾不存在 + ret = -1; // 資料夾不存在 } - - - d = opendir(PYTHON_FOLDER); - if (d) { - while ((dir = readdir(d)) != NULL) { - if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) - { - // do nothing (straight logic) + else { + DIR *folder_dir; + folder_dir = opendir(PYTHON_FOLDER); + if (folder_dir) { + //Create JSON + cJSON *s_root = cJSON_CreateObject(); + cJSON *file_list = cJSON_CreateArray(); + struct dirent *dir; + //int file_number = 0; + //char sfileList[200][256] = { 0 }; + + while ((dir = readdir(folder_dir)) != NULL) { + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + { + // do nothing (straight logic) + } + else { + //printf("%s\n", dir->d_name); + //sprintf(&sfileList[file_number], "%s", dir->d_name); + //printf("%s\n", sfileList[file_number]); + //file_number++; + cJSON_AddItemToArray(file_list, cJSON_CreateString(dir->d_name)); + } } - else { - //printf("%s\n", dir->d_name); - //sprintf(&sfileList[file_number], "%s", dir->d_name); - //printf("%s\n", sfileList[file_number]); - //file_number++; + closedir(folder_dir); - s_file_name = cJSON_CreateString(dir->d_name); + //printf("file num: %d \n", file_number); - cJSON_AddItemToArray(file_list, s_file_name); - } - } - //printf("file num: %d \n", file_number); - - for (int j = 0; j < file_number; j++) - { - printf("%s\n", sfileList[j]); - } + //for (int j = 0; j < file_number; j++) + //{ + //printf("%s\n", sfileList[j]); + //} - cJSON_AddItemToObject(s_root, "file_list", file_list); + cJSON_AddItemToObject(s_root, "file_list", file_list); - char* JsonString = cJSON_Print(s_root); + char* JsonString = cJSON_PrintUnformatted(s_root); - sprintf(output, "%s", JsonString); + sprintf(output, "%s", JsonString); - //printf("jstring = \n%s\n", JsonString); + //printf("jstring = \n%s\n", JsonString); - if (JsonString) { - free(JsonString); - JsonString = NULL; - } + if (JsonString) { + free(JsonString); + JsonString = NULL; + } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } } - - closedir(d); } - - - - return 0; + return ret; } diff --git a/src/pythonR.h b/src/pythonR.h index afdef51..7062019 100644 --- a/src/pythonR.h +++ b/src/pythonR.h @@ -22,18 +22,30 @@ #define PYTHON_LOG "python_log.txt" #define PYTHON_CODE_SIZE 1024*20 #define PTYHON_FILE_NAME 1024 +#define MAX_BUFFER_LINES 1024 #define DEBUG_COMPORT_PRINT_FGET 1 +extern char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; +extern unsigned int g_uiWebPythonCurrentBufferIndex; +extern unsigned int g_uiWebPythonLastBufferIndex; +extern unsigned int g_cWebPythonBufferSignal; +extern unsigned int g_cWebPythonDeleteStatus; +//extern char g_cWebPythonName[50]; +extern unsigned int g_cWebPythonStatus; + +#ifdef GY_OS_AMBA +extern pthread_mutex_t buffer_mutex; +#endif + void deletePythonFile(char *sINFileName); void readPythonFile(char *sINFileName, char *sOutput); void readFolderList(char *output); //int runPython(char *pythonData, int sock); //2024/03/08 void runPython(char *pythonData); // 2024-10-14 -//void runPython(char *pythonData); + //void uploadPython(char *urlData); const char* uploadPython(char *urlData); void parseContent(char *recvBuffer); - #endif \ No newline at end of file diff --git a/src/radar_receive.c b/src/radar_receive.c index b8c1341..e520e3e 100644 --- a/src/radar_receive.c +++ b/src/radar_receive.c @@ -105,13 +105,13 @@ void *RADAR_recieve(void *jsonstr) // a113n if (bind(sockfd, (const struct sockaddr *)&info, sizeof(info)) < 0) { - perror("error bind failed\n"); + printf("error bind failed\n"); close(sockfd); } /* if(listen(sockfd, 512) == -1){ - perror("error listen failed\n"); + printf("error listen failed\n"); close(sockfd); }*/ diff --git a/src/setting.h b/src/setting.h index 90ac2f9..1c85cb1 100644 --- a/src/setting.h +++ b/src/setting.h @@ -11,12 +11,11 @@ //general difinition #ifdef GY_OS_AMBA -#define APP_VERSION "2.0.7.60" //跟AMBA的LPKG.json要一致 +#define APP_VERSION "2.0.7.69" //跟AMBA的LPKG.json要一致 #else -#define APP_VERSION "1.4.3.2" //跟NOVA的LPKG.json要一致 +#define APP_VERSION "1.4.3.4" //跟NOVA的LPKG.json要一致 #endif - #ifdef GY_OS_AMBA #define MAX_IMG_BUFF_SIZE 1024*1024*20 //max image size is 20MB //#define MAX_IMG_BUFF_SIZE 8192*13 diff --git a/src/test_nnctrl_live.c b/src/test_nnctrl_live.c index ed42548..f4dcfbf 100644 --- a/src/test_nnctrl_live.c +++ b/src/test_nnctrl_live.c @@ -550,6 +550,7 @@ static int alloc_cv_mem(uint32_t *psize, uint32_t *pphys, uint8_t **pvirt) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_alloc err #1"); write_to_logs_html(temp_msg, "alloc cv mem", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "alloc cv mem", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -1052,7 +1053,7 @@ static int get_network_input(struct nnctrl_param *pctrl) // 對映記憶體共享區 tof_yuv_arr = Correspond_Memory_YUV(tof_shmid); if (tof_yuv_arr == (void *)-1) { - perror("Mapping shared memory failed!\n"); + printf("Mapping shared memory failed!\n"); } } } @@ -2598,7 +2599,7 @@ int load_no_padding_file(FILE *in, uint8_t *virt_addr, struct io_dim *dim, struc for (d = 0; d < dim->depth; d++) { for (h = 0; h < dim->height; h++) { if (fread(virt, 1, one_line, in) != one_line) { - perror("fread input file"); + printf("fread input file\n"); rval = -1; break; } @@ -2619,25 +2620,25 @@ int load_file(const char *file_name, uint8_t *virt_addr, uint32_t size,struct io do { if ((in = fopen(file_name, "rb")) == NULL) { - perror(file_name); + printf("%s\n",file_name); rval = -1; break; } if (fseek(in, 0, SEEK_END) < 0) { - perror("fseek input file"); + printf("fseek input file\n"); rval = -1; break; } file_size = ftell(in); if (fseek(in, 0, SEEK_SET) < 0) { - perror("fseek input file"); + printf("fseek input file\n"); rval = -1; break; } if (file_size == size) { if (fread(virt_addr, 1, size, in) != size) { - perror("fread input file"); + printf("fread input file\n"); rval = -1; break; } @@ -4017,155 +4018,6 @@ void cropped_roi_ivs(detection_pos *pNext_plate, struct net_match *net_pair_orc, //pthread_mutex_unlock(&mutex_cropped_roi); return; } - -#if 0 - if (AI_fps >= 1) { - if (IsANPRCategory(pNext_plate->engine_type) && - pNext_plate->obj_type == _PLATE) { - if (enable_downsized_cropped_roi == 1) { - pthread_mutex_lock(&mutex_enable_lpr_db); - if (strcmp(viewChannelData[0].enable_lpr_db, "Yes") == 0 && viewChannelData[0].enable_anpr > 0) - { - // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - Start - vect_desc_t downsized_cropped; - - memset(&downsized_cropped, 0, sizeof(downsized_cropped)); - - downsized_cropped.shape.p = 1; - downsized_cropped.shape.d = 3; - if (obj_h <= VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { - double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; - double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; - double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; - - downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); - downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; - downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); - downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; - } - else if (obj_h > VIEW_WEB_HEIGHT && obj_w <= VIEW_WEB_WIDTH) { - downsized_cropped.shape.h = VIEW_WEB_HEIGHT; - downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; - downsized_cropped.shape.w = obj_w * VIEW_WEB_HEIGHT / obj_h; - downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; - } - else if (obj_h <= VIEW_WEB_HEIGHT && obj_w > VIEW_WEB_WIDTH) { - downsized_cropped.shape.h = obj_h * VIEW_WEB_WIDTH / obj_w; - downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; - downsized_cropped.shape.w = VIEW_WEB_WIDTH; - downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; - } - else { - double temp_ratio_h = (double)VIEW_WEB_HEIGHT / (double)obj_h; - double temp_ratio_w = (double)VIEW_WEB_WIDTH / (double)obj_w; - double small_temp_ratio = temp_ratio_h <= temp_ratio_w ? temp_ratio_h : temp_ratio_w; - - downsized_cropped.shape.h = (int)(((double)obj_h) * small_temp_ratio); - downsized_cropped.shape.h -= downsized_cropped.shape.h % 2; - downsized_cropped.shape.w = (int)(((double)obj_w) * small_temp_ratio); - downsized_cropped.shape.w -= downsized_cropped.shape.w % 2; - } - - downsized_cropped.data_format.sign = cropped.data_format.sign; - downsized_cropped.data_format.datasize = cropped.data_format.datasize; - downsized_cropped.data_format.exp_offset = cropped.data_format.exp_offset; - downsized_cropped.data_format.exp_bits = cropped.data_format.exp_bits; - downsized_cropped.pitch = ROUND_UP(downsized_cropped.shape.w * (1 << downsized_cropped.data_format.datasize), 32); - downsized_cropped.color_space = cropped.color_space; - - downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; - - { - downsized_cropped.data_addr = downsized_cropped_mem.phys; - // vproc_memcpy(downsized_cropped.data_addr, cropped.data_addr, downsized_cropped_mem.size); - - downsized_cropped_mem.size = downsized_cropped.shape.p * downsized_cropped.shape.d * downsized_cropped.shape.h * downsized_cropped.pitch; - - if (vproc_resize(&cropped, &downsized_cropped) < 0) { - printf("[cropped roi ivs] vproc_resize(&cropped, &downsized_cropped) failed.\n"); - if (pNext_plate->image_id >= 0) { - pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); - g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; - g_downsized_cropped_pitch[pNext_plate->image_id] = 0; - g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; - pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); - } - } - else - { - pthread_mutex_lock(&mutex_if_enable_lpr_db_is_Yes); - //printf("[cropped roi] Copying resized cropped image from the memory...\n"); - //printf("\n-----------downsized_cropped_mem.size: %d\n", (int)downsized_cropped_mem.size); - - - //memset(g_img_buf[pNext_plate->image_id], 0x00, MAX_IMG_SIZE); - - if (downsized_cropped_mem.size != 0 && pNext_plate->image_id >= 0) { - memcpy(g_img_buf[pNext_plate->image_id], downsized_cropped_mem.virt, downsized_cropped_mem.size); - - g_downsized_cropped_shape_w[pNext_plate->image_id] = downsized_cropped.shape.w; - g_downsized_cropped_pitch[pNext_plate->image_id] = downsized_cropped.pitch; - g_downsized_cropped_shape_h[pNext_plate->image_id] = downsized_cropped.shape.h; - - if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && g_IsPTZDevice == 0) { - int color_size = -1; //convert_to_general_image_for_lpr不做memcpy。 - pNext_plate->color_id = convert_to_general_image_for_lpr(NULL, &color_size, g_img_buf[pNext_plate->image_id], g_downsized_cropped_shape_w[pNext_plate->image_id], g_downsized_cropped_pitch[pNext_plate->image_id], g_downsized_cropped_shape_h[pNext_plate->image_id], 0, &pNext_plate->sec_color_id); - } - else { - pNext_plate->color_id = 0; - pNext_plate->sec_color_id = 0; - } - - downsized_cropped_mem.size = cropped.shape.p * cropped.shape.d * cropped.shape.h * cropped.pitch; - check_first_downsized_cropped_roi = 1; - - } - else { - if (pNext_plate->image_id >= 0) { - g_downsized_cropped_shape_w[pNext_plate->image_id] = 0; - g_downsized_cropped_pitch[pNext_plate->image_id] = 0; - g_downsized_cropped_shape_h[pNext_plate->image_id] = 0; - } - } - - - pthread_mutex_unlock(&mutex_if_enable_lpr_db_is_Yes); - } - } - // Color Detection from 416x416 CNN size - Added by LILIN Cayman - 2021.4.15 - End - } - pthread_mutex_unlock(&mutex_enable_lpr_db); - } - } - else if (!IsANPRCategory(pNext_plate->engine_type) && - strcmp(SystemSetting.enable_display_properties, "Yes") == 0 && - //iFeature_logo_layer_index == -1 && - g_IsPTZDevice == 0) - { - - pthread_mutex_lock(&mutex_differ_image); - - if ((int)snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { - int color_size = -1; //crop_image_ivs不做memcpy。 - pNext_plate->color_id = crop_image_ivs(NULL, &color_size, snapshot_addr, (int)snapshot_size, pNext_plate, g_ori_yuv_width, g_ori_yuv_height); - pNext_plate->sec_color_id = 0; - } - else { - pNext_plate->color_id = 0; - pNext_plate->sec_color_id = 0; - } - - pthread_mutex_unlock(&mutex_differ_image); - - check_first_downsized_cropped_roi_for_object = 1; - } - else - { - pNext_plate->color_id = 0; - pNext_plate->sec_color_id = 0; - } - } -#endif //printf("\n--------cropped roi:----------7\n"); } } @@ -4467,10 +4319,10 @@ void *run_one_net_thread(void *ptr) { } } else { - pNext_ivs->left_x = g_ori_yuv_width * 0.025; - pNext_ivs->top_y = g_ori_yuv_height * 0.225; - pNext_ivs->width = g_ori_yuv_width * 0.95; - pNext_ivs->height = g_ori_yuv_height * 0.775; + pNext_ivs->left_x = g_ori_yuv_width * 0.05; + pNext_ivs->top_y = g_ori_yuv_height * 0.05; + pNext_ivs->width = g_ori_yuv_width * 0.9; + pNext_ivs->height = g_ori_yuv_height * 0.9; } //printf("\n--------%f\n", pNext_ivs->width * pNext_ivs->height / ((float)g_ori_yuv_width * (float)g_ori_yuv_height)); @@ -4607,10 +4459,10 @@ void *run_one_net_thread(void *ptr) { } } - if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { - memset(pNext_word, 0x00, sizeof(detection_pos)); - continue; - } + //if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { + //memset(pNext_word, 0x00, sizeof(detection_pos)); + //continue; + //} /*if (imageDnData.color_mode == 2 && strcmp(pNext_word->name, "person") == 0) { check_if_clear_spider_zone = 1; @@ -4965,230 +4817,400 @@ void *run_one_net_thread(void *ptr) { } else { - ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) + { + detection_pos temp_PosInfo_ivs = { 0 }; + pNext_ivs = &temp_PosInfo_ivs; + pNext_ivs->left_x = g_ori_yuv_width * 0.05; + pNext_ivs->top_y = g_ori_yuv_height * 0.05; + pNext_ivs->width = g_ori_yuv_width * 0.9; + pNext_ivs->height = g_ori_yuv_height * 0.9; + cropped_roi_ivs(pNext_ivs, &g_pctrl_run_one_net->net_pair[idx], 0, snapshot_addr, snapshot_size); - //gettimeofday(&currtime, NULL); - //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 - //double dw_FPS_time_delta = (double)(now_ms - last_ms); - //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); - //printf("\n-----run one net thread #3:%lf ms\n", dw_FPS_time_delta); + ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); - if (ret < 0) { - live_mode_flag = 0; - printf("serial run one net idx #3: %d err\n", idx); - break; - } - if (g_pctrl_run_one_net != NULL) - bbox_ret = parse_bbox_data(NULL,g_pctrl_run_one_net, idx, frame_id, 0.1); + //gettimeofday(&currtime, NULL); + //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 + //double dw_FPS_time_delta = (double)(now_ms - last_ms); + //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); + //printf("\n-----run one net thread #3:%lf ms\n", dw_FPS_time_delta); - if (bbox_ret < 0) - { - printf("parse bbox err idx #4: %d \n", idx); - continue; - } - g_element_size_traffic[idx][0] = g_pctrl_run_one_net->net_pair[idx].valid_result_num; - g_total_element_size_traffic += g_element_size_traffic[idx][0]; - - //printf("\n-----KK#2-------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); - //printf("\n-----#2---------g_pctrl_run_one_net->net_pair[idx].yolov3_result_num:%d\n", g_pctrl_run_one_net->net_pair[idx].yolov3_result_num); - - valid_bbox_idx = 0; - for (int i = 0; i < g_pctrl_run_one_net->net_pair[idx].yolov3_result_num; i++) { - if (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].valid && - (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min > 0 && - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min > 0 && - (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min) > 0 && - (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min) > 0 - - ) + if (ret < 0) { + live_mode_flag = 0; + printf("serial run one net idx #3: %d err\n", idx); + break; + } + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_ivs, g_pctrl_run_one_net, idx, frame_id, 0.1); + + if (bbox_ret < 0) { + printf("parse bbox err idx #4: %d \n", idx); + continue; + } + g_element_size_traffic[idx][0] = g_pctrl_run_one_net->net_pair[idx].valid_result_num; + g_total_element_size_traffic += g_element_size_traffic[idx][0]; + + //printf("\n-----KK#2-------g_element_size_traffic[idx][0]:%d\n", g_element_size_traffic[idx][0]); + //printf("\n-----#2---------g_pctrl_run_one_net->net_pair[idx].yolov3_result_num:%d\n", g_pctrl_run_one_net->net_pair[idx].yolov3_result_num); + + valid_bbox_idx = 0; + for (int i = 0; i < g_pctrl_run_one_net->net_pair[idx].yolov3_result_num; i++) { + if (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min) > 0 + + ) + { #ifdef GY_OS_AMBA - pNext_word = g_PosInfo_traffic + valid_bbox_idx + (g_total_element_size_traffic - g_element_size_traffic[idx][0]); - pNext_word->class_id = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].label; - label_name_idx = g_pctrl_run_one_net->net_pair[idx].objects_id[i]; + pNext_word = g_PosInfo_traffic + valid_bbox_idx + (g_total_element_size_traffic - g_element_size_traffic[idx][0]); + pNext_word->class_id = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].label; + label_name_idx = g_pctrl_run_one_net->net_pair[idx].objects_id[i]; #else - pNext_word = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx; - pNext_word->class_id = g_current_bbox_list[i].class_id; - label_name_idx = pNext_word->class_id; + pNext_word = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx; + pNext_word->class_id = g_current_bbox_list[i].class_id; + label_name_idx = pNext_word->class_id; #endif - memset(pNext_word->name, 0x00, sizeof(pNext_word->name)); + memset(pNext_word->name, 0x00, sizeof(pNext_word->name)); #ifdef GY_OS_AMBA - snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", g_pctrl_run_one_net->net_pair[idx].classNames[label_name_idx * 2]); - pNext_word->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0; + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", g_pctrl_run_one_net->net_pair[idx].classNames[label_name_idx * 2]); + pNext_word->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].score * (double)100)*10.0; - pNext_word->left_x = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min; - pNext_word->top_y = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min; - pNext_word->width = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min); - pNext_word->height = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min); + pNext_word->left_x = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min; + pNext_word->top_y = g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min; + pNext_word->width = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.x_min); + pNext_word->height = (g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_max - g_pctrl_run_one_net->net_pair[idx].amba_yolov3_result[i].bbox.y_min); - pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2; - pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2; + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2; #else - snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", G_nnctrl.net_pair[idx].classNames[(label_name_idx * 2)]); - pNext_word->confidence = g_current_bbox_list[i].confidence; - pNext_word->class_score = g_current_bbox_list[i].class_score; - pNext_word->object_score = g_current_bbox_list[i].object_score; - pNext_word->left_x = g_current_bbox_list[i].x; - pNext_word->top_y = g_current_bbox_list[i].y; - pNext_word->width = g_current_bbox_list[i].w; - pNext_word->height = g_current_bbox_list[i].h; - pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; - pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; + snprintf(pNext_word->name, sizeof(pNext_word->name), "%s", G_nnctrl.net_pair[idx].classNames[(label_name_idx * 2)]); + pNext_word->confidence = g_current_bbox_list[i].confidence; + pNext_word->class_score = g_current_bbox_list[i].class_score; + pNext_word->object_score = g_current_bbox_list[i].object_score; + pNext_word->left_x = g_current_bbox_list[i].x; + pNext_word->top_y = g_current_bbox_list[i].y; + pNext_word->width = g_current_bbox_list[i].w; + pNext_word->height = g_current_bbox_list[i].h; + pNext_word->center_x = pNext_word->left_x + pNext_word->width / 2.0; + pNext_word->center_y = pNext_word->top_y + pNext_word->height / 2.0; #endif - pNext_word->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[idx];//layerFeatureType[layer_idx]; - pNext_word->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[idx]; + pNext_word->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[idx];//layerFeatureType[layer_idx]; + pNext_word->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[idx]; - pNext_word->parent_idx = -1; - pNext_word->car_logo_idx = -1; - pNext_word->number_row = 1; + pNext_word->parent_idx = -1; + pNext_word->car_logo_idx = -1; + pNext_word->number_row = 1; - pNext_word->box_x = pNext_word->left_x; - pNext_word->box_y = pNext_word->top_y; - pNext_word->box_w = pNext_word->width; - pNext_word->box_h = pNext_word->height; - pNext_word->obj_type = _PLATE; - pNext_word->test_id = i; + pNext_word->box_x = pNext_word->left_x; + pNext_word->box_y = pNext_word->top_y; + pNext_word->box_w = pNext_word->width; + pNext_word->box_h = pNext_word->height; + pNext_word->obj_type = _PLATE; + pNext_word->test_id = i; #if 1 - if ((((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || - (((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || - (((pNext_word->width) / ((float)g_ori_yuv_width)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || - (((pNext_word->width) / ((float)g_ori_yuv_width)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || - (((pNext_word->height) / ((float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || - (((pNext_word->height) / ((float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || - strlen(pNext_word->name) == 0 || - strncmp(pNext_word->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_word->name, "_s", strlen("_s")) == 0 || - //pNext_word->center_y / (float)g_ori_yuv_height < 0.053 || - ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && strcmp(pNext_word->name, "person") != 0 && g_IsHelm_without_car == 1) || - strcmp(pNext_word->name, "male") == 0 || strcmp(pNext_word->name, "female") == 0 || strcmp(pNext_word->name, "third_gender") == 0 || - (strcmp(SystemSetting.enable_cloud, "No") == 0 && (strcmp(pNext_word->name, "camera") == 0 || strcmp(pNext_word->name, "nvr") == 0 || - strcmp(pNext_word->name, "smog") == 0 || strcmp(pNext_word->name, "robber_mask") == 0 - || strcmp(pNext_word->name, "coat_shirt") == 0 || strcmp(pNext_word->name, "shorts") == 0 || strcmp(pNext_word->name, "dress_skirt") == 0 || strcmp(pNext_word->name, "trousers") == 0 || strcmp(pNext_word->name, "golf_cart") == 0 - || strcmp(pNext_word->name, "stroller") == 0 || strcmp(pNext_word->name, "snow") == 0 || strcmp(pNext_word->name, "backpack") == 0 || strcmp(pNext_word->name, "handbag") == 0 - || strcmp(pNext_word->name, "suitcase") == 0 || strcmp(pNext_word->name, "knife") == 0 - || (strcmp(pNext_word->name, "glasses") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) - || strcmp(pNext_word->name, "gun") == 0)) || - (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "cat") == 0 || strcmp(pNext_word->name, "dog") == 0)) - ) - { - memset(pNext_word, 0x00, sizeof(detection_pos)); - continue; - } + if ((((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width * pNext_word->height) / ((float)g_ori_yuv_width *(float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->width) / ((float)g_ori_yuv_width)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) > ((float)atoi(viewChannelData[0].obj_max_proportion) / 100.0)) || + (((pNext_word->height) / ((float)g_ori_yuv_height)) < ((float)atoi(viewChannelData[0].obj_min_proportion) / 100.0)) || + strlen(pNext_word->name) == 0 || + strncmp(pNext_word->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_word->name, "_s", strlen("_s")) == 0 || + //pNext_word->center_y / (float)g_ori_yuv_height < 0.053 || + ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && strcmp(pNext_word->name, "person") != 0 && g_IsHelm_without_car == 1) || + strcmp(pNext_word->name, "male") == 0 || strcmp(pNext_word->name, "female") == 0 || strcmp(pNext_word->name, "third_gender") == 0 || + (strcmp(SystemSetting.enable_cloud, "No") == 0 && (strcmp(pNext_word->name, "camera") == 0 || strcmp(pNext_word->name, "nvr") == 0 || + strcmp(pNext_word->name, "smog") == 0 || strcmp(pNext_word->name, "robber_mask") == 0 + || strcmp(pNext_word->name, "coat_shirt") == 0 || strcmp(pNext_word->name, "shorts") == 0 || strcmp(pNext_word->name, "dress_skirt") == 0 || strcmp(pNext_word->name, "trousers") == 0 || strcmp(pNext_word->name, "golf_cart") == 0 + || strcmp(pNext_word->name, "stroller") == 0 || strcmp(pNext_word->name, "snow") == 0 || strcmp(pNext_word->name, "backpack") == 0 || strcmp(pNext_word->name, "handbag") == 0 + || strcmp(pNext_word->name, "suitcase") == 0 || strcmp(pNext_word->name, "knife") == 0 + || (strcmp(pNext_word->name, "glasses") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) + || strcmp(pNext_word->name, "gun") == 0)) || + (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "cat") == 0 || strcmp(pNext_word->name, "dog") == 0)) + ) + { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } #endif - if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bus") == 0 || strcmp(pNext_word->name, "train") == 0 || strcmp(pNext_word->name, "truck") == 0)) { - strcpy(pNext_word->name, "car"); - pNext_word->class_id = 2; - } - - if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bicycle") == 0 || strcmp(pNext_word->name, "motorbike") == 0)) { - if (g_check_if_OK_thermal == 1) { - strcpy(pNext_word->name, "person"); - pNext_word->class_id = 0; + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bus") == 0 || strcmp(pNext_word->name, "train") == 0 || strcmp(pNext_word->name, "truck") == 0)) { + strcpy(pNext_word->name, "car"); + pNext_word->class_id = 2; } - else { - if (strcmp(pNext_word->name, "motorbike") == 0) { - memset(pNext_word, 0x00, sizeof(detection_pos)); - continue; + + if (strcmp(heartbeatData.events_default_version, "4") == 0 && (strcmp(pNext_word->name, "bicycle") == 0 || strcmp(pNext_word->name, "motorbike") == 0)) { + if (g_check_if_OK_thermal == 1) { + strcpy(pNext_word->name, "person"); + pNext_word->class_id = 0; + } + else { + if (strcmp(pNext_word->name, "motorbike") == 0) { + memset(pNext_word, 0x00, sizeof(detection_pos)); + continue; + } } } - } - - if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { - memset(pNext_word, 0x00, sizeof(detection_pos)); - continue; - } - /*if (imageDnData.color_mode == 2 && strcmp(pNext_word->name, "person") == 0) { - check_if_clear_spider_zone = 1; + //if (pNext_word->height / pNext_word->width < 1.25 && strcmp(pNext_word->name, "person") == 0) { + //memset(pNext_word, 0x00, sizeof(detection_pos)); + //continue; + //} - int ratio_width = (int)((pNext_word->left_x + pNext_word->width / 2.0) * 4.0 / (float)g_ori_yuv_width); - int ratio_height = (int)((pNext_word->top_y + pNext_word->height / 2.0) * 4.0 / (float)g_ori_yuv_height); + /*if (imageDnData.color_mode == 2 && strcmp(pNext_word->name, "person") == 0) { + check_if_clear_spider_zone = 1; - if (ratio_width > 3) - ratio_width = 3; - if (ratio_height > 3) - ratio_height = 3; + int ratio_width = (int)((pNext_word->left_x + pNext_word->width / 2.0) * 4.0 / (float)g_ori_yuv_width); + int ratio_height = (int)((pNext_word->top_y + pNext_word->height / 2.0) * 4.0 / (float)g_ori_yuv_height); - int index_spider_zone = ratio_width + 4 * ratio_height; + if (ratio_width > 3) + ratio_width = 3; + if (ratio_height > 3) + ratio_height = 3; - float temp_record_avg_spider_zone = (record_avg_spider_zone[index_spider_zone] * count_num_spider_zone[index_spider_zone] + pNext_word->width * pNext_word->height) / (count_num_spider_zone[index_spider_zone] + 1); + int index_spider_zone = ratio_width + 4 * ratio_height; - record_avg_spider_zone[index_spider_zone] = temp_record_avg_spider_zone; - count_num_spider_zone[index_spider_zone]++; - if (count_num_spider_zone[index_spider_zone] > 33) { - count_num_spider_zone[index_spider_zone] = 33; - } - if (record_avg_spider_zone[index_spider_zone] > 0.0) { - float ratio_area_threshold = fabs((pNext_word->width * pNext_word->height) / record_avg_spider_zone[index_spider_zone] - 1.0); + float temp_record_avg_spider_zone = (record_avg_spider_zone[index_spider_zone] * count_num_spider_zone[index_spider_zone] + pNext_word->width * pNext_word->height) / (count_num_spider_zone[index_spider_zone] + 1); - if (ratio_area_threshold < 0.4 && ratio_area_threshold >= 0.1) { - pNext_word->confidence -= (ratio_area_threshold * 100.0); + record_avg_spider_zone[index_spider_zone] = temp_record_avg_spider_zone; + count_num_spider_zone[index_spider_zone]++; + if (count_num_spider_zone[index_spider_zone] > 33) { + count_num_spider_zone[index_spider_zone] = 33; } - else if (ratio_area_threshold >= 0.4) { - pNext_word->confidence -= 40.0; + if (record_avg_spider_zone[index_spider_zone] > 0.0) { + float ratio_area_threshold = fabs((pNext_word->width * pNext_word->height) / record_avg_spider_zone[index_spider_zone] - 1.0); + + if (ratio_area_threshold < 0.4 && ratio_area_threshold >= 0.1) { + pNext_word->confidence -= (ratio_area_threshold * 100.0); + } + else if (ratio_area_threshold >= 0.4) { + pNext_word->confidence -= 40.0; + } } } - } - else if (imageDnData.color_mode != 2) { - if (check_if_clear_spider_zone == 1) { - check_if_clear_spider_zone = 0; - for (int index_spider_zone = 0; index_spider_zone < MAX_SPIDER_ZONE; index_spider_zone++) { - count_num_spider_zone[index_spider_zone] = 0; - record_avg_spider_zone[index_spider_zone] = 0.0; + else if (imageDnData.color_mode != 2) { + if (check_if_clear_spider_zone == 1) { + check_if_clear_spider_zone = 0; + for (int index_spider_zone = 0; index_spider_zone < MAX_SPIDER_ZONE; index_spider_zone++) { + count_num_spider_zone[index_spider_zone] = 0; + record_avg_spider_zone[index_spider_zone] = 0.0; + } } + }*/ + + if (strcmp(pNext_word->name, "barcode") == 0 || strcmp(pNext_word->name, "qrcode") == 0) { + current_image_id_for_anpr++; + if (current_image_id_for_anpr >= MAX_PLATE_BUF_NUM) { + current_image_id_for_anpr = 0; + } + pNext_word->image_id = current_image_id_for_anpr; } - }*/ + else { - if (strcmp(pNext_word->name, "barcode") == 0 || strcmp(pNext_word->name, "qrcode") == 0) { - current_image_id_for_anpr++; - if (current_image_id_for_anpr >= MAX_PLATE_BUF_NUM) { - current_image_id_for_anpr = 0; + current_image_id_for_object++; + if (current_image_id_for_object >= MAX_OBJECT_NUM) { + current_image_id_for_object = 0; + } + pNext_word->image_id = current_image_id_for_object; } - pNext_word->image_id = current_image_id_for_anpr; - } - else { - current_image_id_for_object++; - if (current_image_id_for_object >= MAX_OBJECT_NUM) { - current_image_id_for_object = 0; +#if 0 + printf("\n[run one net thread]-------------pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f,pNext_word->box_w:%f,pNext_word->box_h:%f\n", pNext_word->name, pNext_word->box_x, pNext_word->box_y, pNext_word->box_w, pNext_word->box_h); +#endif + + /*if (idx == iFeature_tof_det_layer_index) { + float bbox_distance = 0.0; + float bbox_height = 0.0; + get_bbox_distance_and_height(pNext_word->left_x, pNext_word->top_y, pNext_word->width, pNext_word->height, &bbox_distance, &bbox_height); + + pNext_word->bbox_distance = bbox_distance; + pNext_word->bbox_height = bbox_height; + + //printf("\nTTTTTTTTTTTTTTTTT: %f,%f\n", pNext_word->bbox_distance, pNext_word->bbox_height); + } - pNext_word->image_id = current_image_id_for_object; - } + else */if (idx == iFeature_traf_det_layer_index && iFeature_logo_layer_index >= 0) { + if (IsVehicleCategory(pNext_word)) + { +#if 1 + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); - #if 0 - printf("\n[run one net thread]-------------pNext_word->name:%s,pNext_word->box_x:%f,pNext_word->box_y:%f,pNext_word->box_w:%f,pNext_word->box_h:%f\n", pNext_word->name, pNext_word->box_x, pNext_word->box_y, pNext_word->box_w, pNext_word->box_h); - #endif + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index]); - /*if (idx == iFeature_tof_det_layer_index) { - float bbox_distance = 0.0; - float bbox_height = 0.0; - get_bbox_distance_and_height(pNext_word->left_x, pNext_word->top_y, pNext_word->width, pNext_word->height, &bbox_distance, &bbox_height); + if (ret < 0) { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); - pNext_word->bbox_distance = bbox_distance; - pNext_word->bbox_height = bbox_height; + printf("serial run one net iFeature_logo_layer_index #2: %d err\n", iFeature_logo_layer_index); + memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); + g_total_element_size_traffic = 0; + //printf("-----------------------error ret: %d-----------------------\n", ret); + //g_rval = -1; - //printf("\nTTTTTTTTTTTTTTTTT: %f,%f\n", pNext_word->bbox_distance, pNext_word->bbox_height); + //stop_test_nn_cavalry(); + //stop_server(); - } - else */if (idx == iFeature_traf_det_layer_index && iFeature_logo_layer_index >= 0) { - if (IsVehicleCategory(pNext_word)) + //printf("=======>>>>> 33333 \n"); + //g_rval = -2; + + //live_mode_flag = 0; + break; + + //exit(EXIT_FAILURE); + } + + //printf("\n-----------------------------parse bbox data: #2\n"); + if (g_pctrl_run_one_net != NULL) + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_logo_layer_index, frame_id, 0.3); + //printf("\n-----------------------------parse bbox data end: #2\n"); + + if (bbox_ret < 0) + { + //pthread_mutex_unlock(&mutex_get_network_input); + //pthread_mutex_unlock(&mutex_run_one_net); + + printf("parse bbox err iFeature_logo_layer_index #222: %d \n", iFeature_logo_layer_index); + + continue; + } + + valid_bbox_idx_alphabet = 0; + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].yolov3_result_num; j++) + { + + if (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + + ) + { + pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].objects_id[j]; + memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_logo_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_logo_layer_index]; + + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min); + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min); + pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; + pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; + pNext_alphabet->car_logo_idx = valid_bbox_idx; + pNext_alphabet->parent_idx = -1; + pNext_alphabet->number_row = 1; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].label; + + pNext_alphabet->box_x = pNext_alphabet->left_x; + + pNext_alphabet->box_y = pNext_alphabet->top_y; + pNext_alphabet->box_w = pNext_alphabet->width; + pNext_alphabet->box_h = pNext_alphabet->height; + pNext_alphabet->obj_type = _PLATE; + + pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); + +#if 0 + printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); +#endif + + if ( + strlen(pNext_alphabet->name) == 0 || + strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 + ) + { + memset(pNext_alphabet, 0x00, sizeof(detection_pos)); + continue; + } + + valid_bbox_idx_alphabet++; + } + + } + + //g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + } +#endif + + } + } + else if (idx == iFeature_production_layer_index && IsProductionCategory(pNext_word)) { - #if 1 if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { - cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + // class_id : 1 , name : barcode + // class_id : 6 , name : qrcode + //printf("======================================\n"); + //printf("========== class_id: %d \n", pNext_word->class_id); + //printf("========== name: %s \n", pNext_word->name); + //joy + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_production_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); + + // 傳入 qrcode 跟 barcode 辨識 + unsigned char* imageDataPtr = (const unsigned char*)g_img_buf_for_barode[pNext_word->image_id]; + //printf("========== imageDataPtr: %p \n", imageDataPtr); + //printf("========== croppedImageWidth: %d \n", croppedImageWidth); + //printf("========== croppedImageHeight: %d \n", croppedImageHeight); + //printf("========== croppedImagePitch: %d \n", croppedImagePitch); + if (strcmp(pNext_word->name, "qrcode") == 0) { + char qrcodeResult[512] = { 0 }; + readQRCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, qrcodeResult); + //printf("========== qrcodeResult: %s \n", qrcodeResult); + if (strlen(qrcodeResult) >= 1) { + strcpy(pNext_word->code_content, qrcodeResult); + strcpy(pNext_word->properties.plate, qrcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + else if (strcmp(pNext_word->name, "barcode") == 0) { + char barcodeResult[512] = { 0 }; + readBarCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, barcodeResult); + //printf("========== barcodeResult: %s \n", barcodeResult); + if (strlen(barcodeResult) >= 1) { + strcpy(pNext_word->code_content, barcodeResult); + strcpy(pNext_word->properties.plate, barcodeResult); + } + else { + strcpy(pNext_word->code_content, ""); + strcpy(pNext_word->properties.plate, ""); + } + } + + } + } + else if (strcmp(WeightFileModeName, "mod003") == 0 && idx == iFeature_traf_det_layer_index && iFeature_mask_layer_index >= 0 && strcmp(pNext_word->name, "person") == 0) { + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); - ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index]); + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index]); if (ret < 0) { //pthread_mutex_unlock(&mutex_get_network_input); //pthread_mutex_unlock(&mutex_run_one_net); - printf("serial run one net iFeature_logo_layer_index #2: %d err\n", iFeature_logo_layer_index); + printf("serial run one net iFeature_mask_layer_index #2: %d err\n", iFeature_mask_layer_index); memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); g_total_element_size_traffic = 0; //printf("-----------------------error ret: %d-----------------------\n", ret); @@ -5208,7 +5230,7 @@ void *run_one_net_thread(void *ptr) { //printf("\n-----------------------------parse bbox data: #2\n"); if (g_pctrl_run_one_net != NULL) - bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_logo_layer_index, frame_id, 0.3); + bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_mask_layer_index, frame_id, 0.3); //printf("\n-----------------------------parse bbox data end: #2\n"); if (bbox_ret < 0) @@ -5216,45 +5238,45 @@ void *run_one_net_thread(void *ptr) { //pthread_mutex_unlock(&mutex_get_network_input); //pthread_mutex_unlock(&mutex_run_one_net); - printf("parse bbox err iFeature_logo_layer_index #222: %d \n", iFeature_logo_layer_index); + printf("parse bbox err iFeature_mask_layer_index #222: %d \n", iFeature_mask_layer_index); continue; } valid_bbox_idx_alphabet = 0; - for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].yolov3_result_num; j++) + for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].yolov3_result_num; j++) { - if (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].valid && - (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && - (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && - (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 + if (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].valid && + (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && + g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 ) { pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; - label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].objects_id[j]; + label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].objects_id[j]; memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); - snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark + snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark - pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; + pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; - pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_logo_layer_index];//layerFeatureType[layer_idx]; - pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_logo_layer_index]; + pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_mask_layer_index];//layerFeatureType[layer_idx]; + pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_mask_layer_index]; - pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; - pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; + pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; + pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; - pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.x_min); - pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].bbox.y_min); + pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) / g_ori_yuv_width * pNext_word->width; + pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) / g_ori_yuv_height * pNext_word->height; pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; pNext_alphabet->car_logo_idx = valid_bbox_idx; pNext_alphabet->parent_idx = -1; pNext_alphabet->number_row = 1; - pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].amba_yolov3_result[j].label; + pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].label; pNext_alphabet->box_x = pNext_alphabet->left_x; @@ -5265,9 +5287,9 @@ void *run_one_net_thread(void *ptr) { pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); - #if 0 +#if 0 printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); - #endif +#endif if ( strlen(pNext_alphabet->name) == 0 || @@ -5283,181 +5305,22 @@ void *run_one_net_thread(void *ptr) { } - //g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index].valid_result_num; - //g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; - g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; - g_total_element_size_traffic += g_element_size_traffic[iFeature_logo_layer_index][valid_bbox_idx]; + //g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].valid_result_num; + //g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; + g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; + g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; } - #endif - } - } - else if (idx == iFeature_production_layer_index && IsProductionCategory(pNext_word)) - { - if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { - // class_id : 1 , name : barcode - // class_id : 6 , name : qrcode - //printf("======================================\n"); - //printf("========== class_id: %d \n", pNext_word->class_id); - //printf("========== name: %s \n", pNext_word->name); - //joy - cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_production_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); - - // 傳入 qrcode 跟 barcode 辨識 - unsigned char* imageDataPtr = (const unsigned char*)g_img_buf_for_barode[pNext_word->image_id]; - //printf("========== imageDataPtr: %p \n", imageDataPtr); - //printf("========== croppedImageWidth: %d \n", croppedImageWidth); - //printf("========== croppedImageHeight: %d \n", croppedImageHeight); - //printf("========== croppedImagePitch: %d \n", croppedImagePitch); - if (strcmp(pNext_word->name, "qrcode") == 0) { - char qrcodeResult[512] = { 0 }; - readQRCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, qrcodeResult); - //printf("========== qrcodeResult: %s \n", qrcodeResult); - if (strlen(qrcodeResult)>=1) { - strcpy(pNext_word->code_content, qrcodeResult); - strcpy(pNext_word->properties.plate, qrcodeResult); - } - else { - strcpy(pNext_word->code_content, ""); - strcpy(pNext_word->properties.plate, ""); - } - } - else if (strcmp(pNext_word->name, "barcode") == 0) { - char barcodeResult[512] = { 0 }; - readBarCode(imageDataPtr, croppedImageWidth, croppedImageHeight, croppedImagePitch, barcodeResult); - //printf("========== barcodeResult: %s \n", barcodeResult); - if (strlen(barcodeResult)>=1) { - strcpy(pNext_word->code_content, barcodeResult); - strcpy(pNext_word->properties.plate, barcodeResult); - } - else { - strcpy(pNext_word->code_content, ""); - strcpy(pNext_word->properties.plate, ""); + else if ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && iFeature_logo_layer_index == -1) { + if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { + if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[idx], valid_bbox_idx, snapshot_addr, snapshot_size); } } - } - } - else if (strcmp(WeightFileModeName, "mod003") == 0 && idx == iFeature_traf_det_layer_index && iFeature_mask_layer_index >= 0 && strcmp(pNext_word->name, "person") == 0) { - if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { - cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); - - ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index]); - - if (ret < 0) { - //pthread_mutex_unlock(&mutex_get_network_input); - //pthread_mutex_unlock(&mutex_run_one_net); - - printf("serial run one net iFeature_mask_layer_index #2: %d err\n", iFeature_mask_layer_index); - memset(&g_PosInfo_traffic, 0x00, MAX_DETECT_OBJECTS * sizeof(detection_pos)); - g_total_element_size_traffic = 0; - //printf("-----------------------error ret: %d-----------------------\n", ret); - //g_rval = -1; - - //stop_test_nn_cavalry(); - //stop_server(); - - //printf("=======>>>>> 33333 \n"); - //g_rval = -2; - - //live_mode_flag = 0; - break; - - //exit(EXIT_FAILURE); - } - - //printf("\n-----------------------------parse bbox data: #2\n"); - if (g_pctrl_run_one_net != NULL) - bbox_ret = parse_bbox_data(pNext_word, g_pctrl_run_one_net, iFeature_mask_layer_index, frame_id, 0.3); - //printf("\n-----------------------------parse bbox data end: #2\n"); - - if (bbox_ret < 0) - { - //pthread_mutex_unlock(&mutex_get_network_input); - //pthread_mutex_unlock(&mutex_run_one_net); - - printf("parse bbox err iFeature_mask_layer_index #222: %d \n", iFeature_mask_layer_index); - - continue; - } - - valid_bbox_idx_alphabet = 0; - for (int j = 0; j < g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].yolov3_result_num; j++) - { - - if (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].valid && - (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0 > g_stAMBAcontent.confidence_traffic && - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min > 0 && - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min > 0 && - (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) > 0 && - (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) > 0 - - ) - { - pNext_alphabet = g_PosInfo_traffic + g_total_element_size_traffic + valid_bbox_idx_alphabet; - label_name_idx = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].objects_id[j]; - memset(pNext_alphabet->name, 0x00, sizeof(pNext_alphabet->name)); - snprintf(pNext_alphabet->name, sizeof(pNext_alphabet->name), "%s", g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].classNames[label_name_idx * 2]); //20201022 sophia mark - - pNext_alphabet->confidence = (float)sqrt((double)g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].score * (double)100)*10.0; - - pNext_alphabet->engine_type = g_stAMBAcontent.i_amba_LayerFeatureType[iFeature_mask_layer_index];//layerFeatureType[layer_idx]; - pNext_alphabet->engine_type2 = g_stAMBAcontent.i_amba_LayerFeatureType2[iFeature_mask_layer_index]; - - pNext_alphabet->left_x = pNext_word->left_x + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min / g_ori_yuv_width * pNext_word->width) - 10; - pNext_alphabet->top_y = pNext_word->top_y + (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min / g_ori_yuv_height * pNext_word->height) - 10; - - pNext_alphabet->width = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.x_min) / g_ori_yuv_width * pNext_word->width; - pNext_alphabet->height = (g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_max - g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].bbox.y_min) / g_ori_yuv_height * pNext_word->height; - pNext_alphabet->center_x = pNext_alphabet->left_x + pNext_alphabet->width / 2; - pNext_alphabet->center_y = pNext_alphabet->top_y + pNext_alphabet->height / 2; - pNext_alphabet->car_logo_idx = valid_bbox_idx; - pNext_alphabet->parent_idx = -1; - pNext_alphabet->number_row = 1; - pNext_alphabet->class_id = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].amba_yolov3_result[j].label; - - pNext_alphabet->box_x = pNext_alphabet->left_x; - - pNext_alphabet->box_y = pNext_alphabet->top_y; - pNext_alphabet->box_w = pNext_alphabet->width; - pNext_alphabet->box_h = pNext_alphabet->height; - pNext_alphabet->obj_type = _PLATE; - - pNext_word->car_logo_idx = (g_total_element_size_traffic + valid_bbox_idx_alphabet); - - #if 0 - printf("\npNext_alphabet->top_y:%f,pNext_alphabet->name:%s,pNext_alphabet->left_x:%f,pNext_alphabet->width:%f,pNext_alphabet->confidence:%f\n", pNext_alphabet->top_y, pNext_alphabet->name, pNext_alphabet->left_x, pNext_alphabet->width, pNext_alphabet->confidence); - #endif - - if ( - strlen(pNext_alphabet->name) == 0 || - strncmp(pNext_alphabet->name, NO_OUTPUT_PREFIX, strlen(NO_OUTPUT_PREFIX)) == 0 || strncmp(pNext_alphabet->name, "_s", strlen("_s")) == 0 - ) - { - memset(pNext_alphabet, 0x00, sizeof(detection_pos)); - continue; - } - - valid_bbox_idx_alphabet++; - } - - } - //g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index].valid_result_num; - //g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; - g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx] = valid_bbox_idx_alphabet; - g_total_element_size_traffic += g_element_size_traffic[iFeature_mask_layer_index][valid_bbox_idx]; - } - } - else if ((idx == iFeature_traf_det_layer_index || idx == iFeature_traf_det_layer_index_2) && iFeature_logo_layer_index == -1) { - if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { - if (snapshot_size >= 1 && g_ori_yuv_width >= 1 && g_ori_yuv_height >= 1) { - cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[idx], valid_bbox_idx, snapshot_addr, snapshot_size); - } - } + valid_bbox_idx++; } - - valid_bbox_idx++; } } } @@ -7312,10 +7175,18 @@ void clear_PostRecorderList() { int index_max_iDiffSec_not_zone = -1; int clear_count_long_not_zone = 0; + double max_iDiffSec_short[MAX_DETECTION_ZONE] = { 0 }; + int index_max_iDiffSec_short[MAX_DETECTION_ZONE] = { 0 }; + int clear_count_short[MAX_DETECTION_ZONE] = { 0 }; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { max_iDiffSec[index_zone] = 0.0; index_max_iDiffSec[index_zone] = -1; clear_count_long[index_zone] = 0; + + max_iDiffSec_short[index_zone] = 0.0; + index_max_iDiffSec_short[index_zone] = -1; + clear_count_short[index_zone] = 0; } for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) @@ -7332,6 +7203,11 @@ void clear_PostRecorderList() { } double thres_dwell_to_the_same_location = (double)atoi(heartbeatData.dwell_to_the_same_location); + + if (strcmp(g_PostRecorderList[index_post].name, "car") == 0) { + thres_dwell_to_the_same_location = thres_dwell_to_the_same_location + 15.0; + } + if (g_PostRecorderList[index_post].count_trigger <= 2) { thres_dwell_to_the_same_location = thres_dwell_to_the_same_location; } @@ -7365,6 +7241,24 @@ void clear_PostRecorderList() { //} double iDiffSec = difftime(now_time, g_PostRecorderList[index_post].t_UpdateTime); + + if (g_PostRecorderList[index_post].zone_idx >= 0) { + //if (strcmp(g_PostRecorderList[index_post].name, "car") == 0 && thres_dwell_to_the_same_location >= 10.0) { + //thres_dwell_to_the_same_location = thres_dwell_to_the_same_location / 2.5; + //} + //else if (thres_dwell_to_the_same_location >= 10.0) { + //thres_dwell_to_the_same_location = thres_dwell_to_the_same_location / 1.5; + //} + + int zone_idx = g_PostRecorderList[index_post].zone_idx; + clear_count_short[zone_idx]++; + if (iDiffSec > max_iDiffSec_short[zone_idx]) + { + max_iDiffSec_short[zone_idx] = iDiffSec; + index_max_iDiffSec_short[zone_idx] = index_post; + } + } + //printf("\n------------iDiffSec:%d\n", iDiffSec); if ((iDiffSec > thres_dwell_to_the_same_location && strlen(g_PostRecorderList[index_post].sPlateNumber) == 0) || (iDiffSec > 60.0 && strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1)) @@ -7391,7 +7285,7 @@ void clear_PostRecorderList() { g_PostRecorderList[index_post].box_h = 0; g_PostRecorderList[index_post].object_id = 0; - g_PostRecorderList[index_post].zone_idx = 0; + g_PostRecorderList[index_post].zone_idx = -1; strcpy(g_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_PostRecorderList[index_post].name, ""); @@ -7449,6 +7343,10 @@ void clear_PostRecorderList() { double iDiffSec = difftime(now_time, g_longterm_PostRecorderList[index_post].t_UpdateTime); if (g_longterm_PostRecorderList[index_post].zone_idx >= 0) { + //if (strcmp(g_PostRecorderList[index_post].name, "car") == 0 && thres_dwell_to_the_same_location >= 10.0) { + //thres_dwell_to_the_same_location = thres_dwell_to_the_same_location / 2.0; + //} + int zone_idx = g_longterm_PostRecorderList[index_post].zone_idx; clear_count_long[zone_idx]++; if (iDiffSec > max_iDiffSec[zone_idx]) @@ -7493,7 +7391,7 @@ void clear_PostRecorderList() { g_longterm_PostRecorderList[index_post].box_h = 0; g_longterm_PostRecorderList[index_post].object_id = 0; - g_longterm_PostRecorderList[index_post].zone_idx = 0; + g_longterm_PostRecorderList[index_post].zone_idx = -1; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7503,7 +7401,7 @@ void clear_PostRecorderList() { } } - if (clear_count_long_not_zone >= 50) { + if (clear_count_long_not_zone > 25) { if (index_max_iDiffSec_not_zone >= 0) { counter_index_long--; int index_post = index_max_iDiffSec_not_zone; @@ -7528,7 +7426,7 @@ void clear_PostRecorderList() { g_longterm_PostRecorderList[index_post].box_h = 0; g_longterm_PostRecorderList[index_post].object_id = 0; - g_longterm_PostRecorderList[index_post].zone_idx = 0; + g_longterm_PostRecorderList[index_post].zone_idx = -1; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7538,7 +7436,7 @@ void clear_PostRecorderList() { } for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { - if (clear_count_long[index_zone] >= 15) { + if (clear_count_long[index_zone] >= 8) { if (index_max_iDiffSec[index_zone] >= 0) { counter_index_long--; int index_post = index_max_iDiffSec[index_zone]; @@ -7563,7 +7461,7 @@ void clear_PostRecorderList() { g_longterm_PostRecorderList[index_post].box_h = 0; g_longterm_PostRecorderList[index_post].object_id = 0; - g_longterm_PostRecorderList[index_post].zone_idx = 0; + g_longterm_PostRecorderList[index_post].zone_idx = -1; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7571,6 +7469,40 @@ void clear_PostRecorderList() { //g_longterm_PostRecorderList[index_post].the_same_id = 0; } } + + if (clear_count_short[index_zone] >= 15) { + if (index_max_iDiffSec_short[index_zone] >= 0) { + counter_index_post--; + int index_post = index_max_iDiffSec[index_zone]; + g_PostRecorderList[index_post].iIfUse = 0; + g_PostRecorderList[index_post].t_FirstGetTime = 0; + g_PostRecorderList[index_post].t_FirstGetTime_total = 0; + g_PostRecorderList[index_post].t_UpdateTime = 0; + + for (int m = 0; m < MAX_DETECTION_ZONE; m++) { + g_PostRecorderList[index_post].check_if_post[m] = 0; + } + g_PostRecorderList[index_post].check_if_cloud = 0; + g_PostRecorderList[index_post].check_if_cloud_v2 = 0; + g_PostRecorderList[index_post].check_if_cloud_record_v2 = 0; + g_PostRecorderList[index_post].check_if_email = 0; + g_PostRecorderList[index_post].check_if_ftp = 0; + g_PostRecorderList[index_post].check_if_getalarmmotion = 0; + + g_PostRecorderList[index_post].box_x = 0; + g_PostRecorderList[index_post].box_y = 0; + g_PostRecorderList[index_post].box_w = 0; + g_PostRecorderList[index_post].box_h = 0; + + g_PostRecorderList[index_post].object_id = 0; + g_PostRecorderList[index_post].zone_idx = -1; + strcpy(g_PostRecorderList[index_post].sPlateNumber, ""); + strcpy(g_PostRecorderList[index_post].name, ""); + + g_PostRecorderList[index_post].count_trigger = 0; + //g_PostRecorderList[index_post].the_same_id = 0; + } + } } g_counter_index_post = counter_index_post; @@ -8995,45 +8927,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten #endif strcpy(pNext->name, pNext2->name); -#if 0 - if (pNext2->height > 0 && pNext2->width > 0 && pNext2->number_row != 2) { - for (int index_post = 0; index_post < MAX_POST_RECODER_SIZE; index_post++) - { - if (g_PostRecorderList[index_post].iIfUse == 0) { - break; - } - - if (g_PostRecorderList[index_post].iIfUse == 1 && strcmp(g_PostRecorderList[index_post].name, "person") == 0) - { - if (g_PostRecorderList[index_post].box_w > 0 && g_PostRecorderList[index_post].box_h > 0) { - detection_pos temp_A = { 0 }; - temp_A.left_x = g_PostRecorderList[index_post].box_x; - temp_A.top_y = g_PostRecorderList[index_post].box_y; - temp_A.width = g_PostRecorderList[index_post].box_w; - temp_A.height = g_PostRecorderList[index_post].box_h; - strcpy(temp_A.name, g_PostRecorderList[index_post].name); - - float temp_A_iou = detection_overlap_ratio(&temp_A, pNext2); - //float compare_ratio = (temp_A.height / temp_A.width) / (pNext2->height / pNext2->width); - float compare_height_ratio = pNext2->height / temp_A.height; - float compare_width_ratio = pNext2->width / temp_A.width; - if (pNext2->height / pNext2->width >= 1.25) { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { - if (temp_A_iou > 0.15) { - memset(pNext->name, 0x00, sizeof(pNext->name)); - strcpy(pNext->name, "person"); - pNext->confidence = 80; - pNext->confidence2 = 80; - } - } - } - } - } - } - } -#endif //printf("\n[start all nets]--------------5\n"); pNext->progress_bar = pNext2->progress_bar; @@ -9295,7 +9189,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten continue; if (strcmp(pNext->name, "object") == 0) { - if (pNext->center_y > g_ori_yuv_height * 3 / 4) { + if (pNext->center_y > g_ori_yuv_height * 2 / 3) { pNext->width = 0; pNext->height = 0; continue; @@ -9343,9 +9237,10 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } } -#if 0 else if (strcmp(pNext->name, "car") == 0 && strcmp(pNext_temp->name, "car") == 0) { - if (detection_overlap_ratio(pNext, pNext_temp) > 0.7){ + if (detection_overlap_ratio(pNext, pNext_temp) > 0.75 && + pNext->width / pNext_temp->width >= 0.85 && pNext->width / pNext_temp->width <= 1.15 && + pNext->height / pNext_temp->height >= 0.85 && pNext->height / pNext_temp->height <= 1.15){ if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { pNext->width = 0; pNext->height = 0; @@ -9356,7 +9251,6 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } } -#endif } } } @@ -9453,115 +9347,6 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten else { // 08-23 -#if 0 - if (check_if_combine == 1 && strcmp(pNext_temp->name, "object") != 0 && strcmp(pNext->name, "object") != 0) - { - // 再確認是否與歷史紀錄重疊到 - - int check_if_pNext_overlap_recorder = 0; - int check_if_pNext_temp_overlap_recorder = 0; - - for (int index_recoder = 0; index_recoder < MAX_POST_RECODER_SIZE; index_recoder++) - { - if (g_PostRecorderList[index_recoder].iIfUse == 0 && g_longterm_PostRecorderList[index_recoder].iIfUse == 0) { - break; - } - - if (g_longterm_PostRecorderList[index_recoder].iIfUse == 1) { - if (g_longterm_PostRecorderList[index_recoder].box_w > 0 && g_longterm_PostRecorderList[index_recoder].box_h > 0) - { - if (strcmp(pNext->name, g_longterm_PostRecorderList[index_recoder].name) == 0) - { - detection_pos PostRecoderTemp = { 0 }; - PostRecoderTemp.left_x = g_longterm_PostRecorderList[index_recoder].box_x; - PostRecoderTemp.top_y = g_longterm_PostRecorderList[index_recoder].box_y; - PostRecoderTemp.width = g_longterm_PostRecorderList[index_recoder].box_w; - PostRecoderTemp.height = g_longterm_PostRecorderList[index_recoder].box_h; - strcpy(PostRecoderTemp.name, g_longterm_PostRecorderList[index_recoder].name); - - float compare_height_ratio = pNext->height / PostRecoderTemp.height; - float compare_width_ratio = pNext->width / PostRecoderTemp.width; - - float fPostRecoderTempIou = detection_overlap_ratio(pNext, &PostRecoderTemp); - if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { - check_if_pNext_overlap_recorder = 1; - } - } - - if (strcmp(pNext_temp->name, g_longterm_PostRecorderList[index_recoder].name) == 0) - { - detection_pos PostRecoderTemp = { 0 }; - PostRecoderTemp.left_x = g_longterm_PostRecorderList[index_recoder].box_x; - PostRecoderTemp.top_y = g_longterm_PostRecorderList[index_recoder].box_y; - PostRecoderTemp.width = g_longterm_PostRecorderList[index_recoder].box_w; - PostRecoderTemp.height = g_longterm_PostRecorderList[index_recoder].box_h; - strcpy(PostRecoderTemp.name, g_longterm_PostRecorderList[index_recoder].name); - - float compare_height_ratio = pNext_temp->height / PostRecoderTemp.height; - float compare_width_ratio = pNext_temp->width / PostRecoderTemp.width; - - float fPostRecoderTempIou = detection_overlap_ratio(pNext_temp, &PostRecoderTemp); - if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { - check_if_pNext_temp_overlap_recorder = 1; - } - } - } - } - - if (g_PostRecorderList[index_recoder].iIfUse == 1) { - if (g_PostRecorderList[index_recoder].box_w > 0 && g_PostRecorderList[index_recoder].box_h > 0) - { - if (strcmp(pNext->name, g_PostRecorderList[index_recoder].name) == 0) - { - detection_pos PostRecoderTemp = { 0 }; - PostRecoderTemp.left_x = g_PostRecorderList[index_recoder].box_x; - PostRecoderTemp.top_y = g_PostRecorderList[index_recoder].box_y; - PostRecoderTemp.width = g_PostRecorderList[index_recoder].box_w; - PostRecoderTemp.height = g_PostRecorderList[index_recoder].box_h; - strcpy(PostRecoderTemp.name, g_PostRecorderList[index_recoder].name); - - float compare_height_ratio = pNext->height / PostRecoderTemp.height; - float compare_width_ratio = pNext->width / PostRecoderTemp.width; - - float fPostRecoderTempIou = detection_overlap_ratio(pNext, &PostRecoderTemp); - if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { - check_if_pNext_overlap_recorder = 1; - } - } - - if (strcmp(pNext_temp->name, g_PostRecorderList[index_recoder].name) == 0) - { - detection_pos PostRecoderTemp = { 0 }; - PostRecoderTemp.left_x = g_PostRecorderList[index_recoder].box_x; - PostRecoderTemp.top_y = g_PostRecorderList[index_recoder].box_y; - PostRecoderTemp.width = g_PostRecorderList[index_recoder].box_w; - PostRecoderTemp.height = g_PostRecorderList[index_recoder].box_h; - strcpy(PostRecoderTemp.name, g_PostRecorderList[index_recoder].name); - - float compare_height_ratio = pNext_temp->height / PostRecoderTemp.height; - float compare_width_ratio = pNext_temp->width / PostRecoderTemp.width; - - float fPostRecoderTempIou = detection_overlap_ratio(pNext_temp, &PostRecoderTemp); - if (fPostRecoderTempIou > 0.35 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { - check_if_pNext_temp_overlap_recorder = 1; - } - } - - } - } - - if (check_if_pNext_overlap_recorder == 1 && check_if_pNext_temp_overlap_recorder == 1) { - check_if_combine = 0; - break; - } - } - } -#endif - if (check_if_combine == 1) { float min_x_1 = pNext->left_x; float min_y_1 = pNext->top_y; @@ -9647,31 +9432,40 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten IsANPRCategory_L_Plate(pNext->name) == 1) continue; - if (strcmp(pNext->name, "person") == 0) { - - for (int j = 0; j < total_element_size; j++) - { - if (i != j) { - pNext_temp = PosInfo + j; - - if (pNext_temp->width == 0 || - pNext_temp->height == 0 || - IsANPRCategory(pNext_temp->engine_type) || - IsANPRCategory_L_Plate(pNext_temp->name) == 1) - continue; + for (int j = 0; j < total_element_size; j++) + { + if (i != j) { + pNext_temp = PosInfo + j; - if (strcmp(pNext->name, pNext_temp->name) == 0) { - if (pNext->engine_type == pNext_temp->engine_type && - pNext->engine_type2 == pNext_temp->engine_type2) { + if (pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext_temp->engine_type) || + IsANPRCategory_L_Plate(pNext_temp->name) == 1) + continue; - if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { - //check_if_combine = 1; - //if (strcmp(pNext->name, "person") == 0) - { - pNext_temp->width = 0; - pNext_temp->height = 0; - } - } + if (strcmp(pNext->name, "person") == 0 && strcmp(pNext_temp->name, "person") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.0) { + if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { + pNext->width = 0; + pNext->height = 0; + } + else { + pNext_temp->width = 0; + pNext_temp->height = 0; + } + } + } + else if (strcmp(pNext->name, "car") == 0 && strcmp(pNext_temp->name, "car") == 0) { + if (detection_overlap_ratio(pNext, pNext_temp) > 0.75 && + pNext->width / pNext_temp->width >= 0.85 && pNext->width / pNext_temp->width <= 1.15 && + pNext->height / pNext_temp->height >= 0.85 && pNext->height / pNext_temp->height <= 1.15) { + if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { + pNext->width = 0; + pNext->height = 0; + } + else { + pNext_temp->width = 0; + pNext_temp->height = 0; } } } @@ -10029,6 +9823,12 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { @@ -10092,14 +9892,17 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ + { if (strcmp(g_PostRecorderList[index_post].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10130,7 +9933,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10163,7 +9966,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten else { if (strcmp(pNext->name, "person") == 0) { //只做時間更新 - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10213,6 +10016,12 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { @@ -10276,13 +10085,16 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) { + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ + { if (strcmp(g_longterm_PostRecorderList[index_post].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10313,7 +10125,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10346,7 +10158,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten else { if (strcmp(pNext->name, "person") == 0) { //只做時間更新 - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10383,7 +10195,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } - if (pNext->width == 0 || (strcmp(pNext->name, "person") == 0 && pNext->height / pNext->width < 1.25)) + if (pNext->width == 0 || pNext->height == 0 /*|| (strcmp(pNext->name, "person") == 0 && pNext->height / pNext->width < 1.25)*/) { pNext->width = 0; pNext->height = 0; @@ -10401,6 +10213,10 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[index_trigger].detect_event_id); if (trigger_event_type == (unsigned int)TRIGGER_PARKING_VIOLATION || + trigger_event_type == (unsigned int)TRIGGER_GO_STRAIGHT || + trigger_event_type == (unsigned int)TRIGGER_GO_STRAIGHT_RED_LIGHT || + trigger_event_type == (unsigned int)TRIGGER_TURN_LEFT_RED_LIGHT || + trigger_event_type == (unsigned int)TRIGGER_TURN_RIGHT_RED_LIGHT || trigger_event_type == (unsigned int)TRIGGER_MISSING_UNATTENDED || trigger_event_type == (unsigned int)TRIGGER_TAMPERING || trigger_event_type == (unsigned int)TRIGGER_QUEUING_VIOLATION || @@ -10469,8 +10285,11 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten double thres_dwell_to_the_same_location = (double)atoi(heartbeatData.dwell_to_the_same_location); if (strcmp(SystemSetting.enable_dwell_bounding_box, "Yes") == 0) { + //if(temp_size_g_PostRecorderList >= 1 || temp_size_g_PostRecorderList_longterm >= 1) +#if 1 if (((/*((int)(pNext->center_stability) == DIRECTION_DEFAULT) ||*/ (dTime > 3.0/*&& count_trigger_post >= 3*/) || (dTime_long > 3.0 /*&& count_trigger_long >= 2*/)) && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext) || strcmp(pNext->name, "person") == 0) ) /*|| (strcmp(pNext->name, "person") == 0 && dTime > 300.0)*/) +#endif { pNext->width = 0; pNext->height = 0; @@ -10814,6 +10633,12 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { @@ -10890,14 +10715,16 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ { if (strcmp(g_PostRecorderList[index_post].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -10934,7 +10761,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -10989,6 +10816,12 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten float compare_height_ratio = pNext->height / temp_A.height; float compare_width_ratio = pNext->width / temp_A.width; + float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0; + float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0; + float p_center_x = pNext->left_x + pNext->width / 2.0; + float p_center_y = pNext->top_y + pNext->height / 2.0; + float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y); + if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) { if (strlen(g_longterm_PostRecorderList[index_post].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[index_post].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { @@ -11054,14 +10887,16 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) + /*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) || + (strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0 + && compare_width_ratio >= 5.0 && compare_width_ratio <= 9.0))*/ { if (strcmp(g_longterm_PostRecorderList[index_post].name, pNext->name) == 0) { if (strcmp(pNext->name, "person") == 0) { //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) { - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; @@ -11093,7 +10928,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; @@ -11140,7 +10975,16 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } - if (pNext->trigger_type >= 1 && temp_size_g_PostRecorderList_longterm == 0 && strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { + int check_if_in_zone = 0; + for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) + { + if (pNext->check_if_within_zone[index_zone]) { + check_if_in_zone = 1; + break; + } + } + + if ((pNext->trigger_type >= 1 || (temp_size_g_PostRecorderList >= 1 && check_if_in_zone == 0)) && temp_size_g_PostRecorderList_longterm == 0 && strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { for (int j = 0; j < MAX_POST_RECODER_SIZE; j++) { if (g_longterm_PostRecorderList[j].iIfUse == 0) @@ -11160,10 +11004,18 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten g_longterm_PostRecorderList[j].check_if_ftp = 0; g_longterm_PostRecorderList[j].check_if_getalarmmotion = 0; - g_longterm_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; - g_longterm_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; - g_longterm_PostRecorderList[j].box_w = pNext->width / 3.0; - g_longterm_PostRecorderList[j].box_h = pNext->height / 3.0; + if (strcmp(pNext->name, "car") == 0) { + g_longterm_PostRecorderList[j].box_x = pNext->left_x + pNext->width * 2.0 / 5.0; + g_longterm_PostRecorderList[j].box_y = pNext->top_y + pNext->height * 2.0 / 5.0; + g_longterm_PostRecorderList[j].box_w = pNext->width / 5.0; + g_longterm_PostRecorderList[j].box_h = pNext->height / 5.0; + } + else { + g_longterm_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; + g_longterm_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; + g_longterm_PostRecorderList[j].box_w = pNext->width / 3.0; + g_longterm_PostRecorderList[j].box_h = pNext->height / 3.0; + } g_longterm_PostRecorderList[j].object_id = pNext->obj_tracking_id; g_longterm_PostRecorderList[j].zone_idx = record_zone_id; @@ -11225,10 +11077,18 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten g_PostRecorderList[j].check_if_ftp = 0; g_PostRecorderList[j].check_if_getalarmmotion = 0; - g_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; - g_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; - g_PostRecorderList[j].box_w = pNext->width / 3.0; - g_PostRecorderList[j].box_h = pNext->height / 3.0; + if (strcmp(pNext->name, "car") == 0) { + g_PostRecorderList[j].box_x = pNext->left_x + pNext->width * 2.0 / 5.0; + g_PostRecorderList[j].box_y = pNext->top_y + pNext->height * 2.0 / 5.0; + g_PostRecorderList[j].box_w = pNext->width / 5.0; + g_PostRecorderList[j].box_h = pNext->height / 5.0; + } + else { + g_PostRecorderList[j].box_x = pNext->left_x + pNext->width / 3.0; + g_PostRecorderList[j].box_y = pNext->top_y + pNext->height / 3.0; + g_PostRecorderList[j].box_w = pNext->width / 3.0; + g_PostRecorderList[j].box_h = pNext->height / 3.0; + } g_PostRecorderList[j].object_id = pNext->obj_tracking_id; g_PostRecorderList[j].zone_idx = record_zone_id; @@ -14861,12 +14721,14 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten continue; } +#if 1 if (strcmp(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes") == 0) { if ((int)(pNext->center_stability) == DIRECTION_DEFAULT && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext))) { //printf("\n[start all nets]center_stability == DIRECTION_DEFAULT && IsVehicleCategory:%s\n", pNext->name); continue; } } +#endif for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { @@ -15390,6 +15252,9 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten void stop_test_nn_cavalry(char* note_stop) { + saveCounters(); + usSleep(1000); + check_if_start_run_server = 0; { @@ -15427,19 +15292,29 @@ void stop_test_nn_cavalry(char* note_stop) { //printf("\nstop test nn cavalry------01\n"); stop_canvas_live_mode_flag(); + usSleep(1000); + //printf("\nstop test nn cavalry------01-----1\n"); live_mode_flag = 0; - + usSleep(1000); + //printf("\nstop test nn cavalry------01-----2\n"); check_stop_test_nn_cavalry = 1; + usSleep(1000); + //printf("\nstop test nn cavalry------01-----3\n"); #ifdef GY_OS_AMBA close_udp_socket(); + usSleep(1000); #endif - + //printf("\nstop test nn cavalry------01-----4\n"); #if defined GY_OS_AMBA || defined GY_OS_V_SERIES release_img_background(); + usSleep(1000); #endif - + //printf("\nstop test nn cavalry------01-----5\n"); clear_g_ivs_hash_record(); + usSleep(1000); + //printf("\nstop test nn cavalry------01-----6\n"); clear_putting_vehicles(); + usSleep(1000); //printf("\nstop test nn cavalry------02\n"); for (int i = 0; i < MAX_DETECTION_ZONE; i++) { @@ -15490,7 +15365,7 @@ void stop_test_nn_cavalry(char* note_stop) { } } } - CATCH + CATCH { } @@ -15839,6 +15714,8 @@ void *run_fps_loading_thread(void *ptr) int g_try_times_device = 0; + int count_to_save = 0; + //unsigned int count_to_refresh_smtp_service = 0; //unsigned int count_to_refresh_lpr_db = 0; @@ -15849,7 +15726,7 @@ void *run_fps_loading_thread(void *ptr) set_record_process_note("run_fps_start"); //printf("\n-------run fps start\n"); g_osdSysTimeStamp++; -#if 1 +#if 0 if (count_post >= 28800) { count_post = 0; @@ -15863,6 +15740,8 @@ void *run_fps_loading_thread(void *ptr) write_to_logs_html(temp_msg, "run osd time sync thread", "CGI_REBOOT", "Yes"); //printf("\n-----------------------There is no post for 4 hours.: exit-----------------------\n"); write_to_log_if_error(temp_msg, "run osd time sync thread", "CGI_REBOOT"); + saveCounters(); + pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { @@ -15933,6 +15812,12 @@ void *run_fps_loading_thread(void *ptr) } count_to_refresh_check_license++; + if (count_to_save % 300 == 0) { + count_to_save = 0; + saveCounters(); + } + count_to_save++; + //count_to_refresh_smtp_service++; //if (count_to_refresh_smtp_service >= MAX_COUNT_TO_REFRESH_SMTP_SERVICE) { //count_to_refresh_smtp_service = 0; @@ -16085,6 +15970,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "init_param(ptr) < 0"); write_to_logs_html(temp_msg, "init_param", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "init_param", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16104,6 +15990,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "pctrl->fd_cav < 0"); write_to_logs_html(temp_msg, "pctrl->fd_cav", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "pctrl->fd_cav", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16127,6 +16014,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_init(pctrl->fd_cav, (uint8_t)pctrl->verbose) < 0"); write_to_logs_html(temp_msg, "cavalry_mem_init", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "cavalry_mem_init", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16145,6 +16033,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "vproc_get_version(&ver) < 0"); write_to_logs_html(temp_msg, "vproc_get_version", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "vproc_get_version", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16164,6 +16053,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "vproc_init(/usr/local/vproc/vproc.bin, &size) < 0"); write_to_logs_html(temp_msg, "vproc_init", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "vproc_init", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16182,6 +16072,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "cavalry_mem_alloc(&lib_mem.size, &lib_mem.phys, &lib_mem.virt, 1, 1) < 0"); write_to_logs_html(temp_msg, "cavalry_mem_alloc", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "cavalry_mem_alloc", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16208,6 +16099,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "(fd_iav = open(/dev/iav, O_RDWR, 0)) < 0"); write_to_logs_html(temp_msg, "/dev/iav", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "/dev/iav", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16227,6 +16119,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "state < 0"); write_to_logs_html(temp_msg, "state < 0", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "state < 0", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16242,6 +16135,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "map_dsp_buffer(state) < 0"); write_to_logs_html(temp_msg, "map dsp buffer", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "map dsp buffer", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16260,6 +16154,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "init_param(ptr) < 0"); write_to_logs_html(temp_msg, "nnctrl main", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "nnctrl main", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -16281,6 +16176,7 @@ void* test_nn_main(void *ptr) snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "start all nets err"); write_to_logs_html(temp_msg, "nnctrl main", "CGI_REBOOT", "Yes"); write_to_log_if_error(temp_msg, "nnctrl main", "CGI_REBOOT"); + saveCounters(); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) @@ -17885,9 +17781,8 @@ int check_dsp_state(void) { int state; if (ioctl(fd_iav, IAV_IOC_GET_IAV_STATE, &state) < 0) { - //perror("IAV_IOC_GET_IAV_STATE"); - printf("IAV_IOC_GET_IAV_STATE"); - exit(2); + printf("IAV_IOC_GET_IAV_STATE\n"); + return -1; } if ((state != IAV_STATE_PREVIEW) && (state != IAV_STATE_ENCODING) diff --git a/src/test_yuv_rgb.c b/src/test_yuv_rgb.c index 8601be2..47d0dc4 100644 --- a/src/test_yuv_rgb.c +++ b/src/test_yuv_rgb.c @@ -31,7 +31,7 @@ int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t ** FILE *fp = fopen(filename, "rb"); if(!fp) { - perror("Error opening yuv image for read"); + printf("Error opening yuv image for read\n"); return 1; } @@ -49,7 +49,7 @@ int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t ** *YUV = malloc(size); size_t result = fread(*YUV, 1, size, fp); if (result != size) { - perror("Error reading yuv image"); + printf("Error reading yuv image\n"); fclose(fp); return 3; } @@ -63,7 +63,7 @@ int saveRawYUV(const char *filename, uint32_t width, uint32_t height, const uint FILE *fp = fopen(filename, "wb"); if(!fp) { - perror("Error opening yuv image for write"); + printf("Error opening yuv image for write\n"); return 1; } @@ -112,7 +112,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R FILE *fp = fopen(filename, "rb"); if(!fp) { - perror("Error opening rgb image for read"); + printf("Error opening rgb image for read\n"); return 1; } @@ -121,7 +121,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R magic[2]='\0'; if(result!=2 || strcmp(magic,"P6")!=0) { - perror("Error reading rgb image header, or invalid format"); + printf("Error reading rgb image header, or invalid format\n"); fclose(fp); return 3; } @@ -130,7 +130,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R result = fscanf(fp, " %u %u %u ", width, height, &max); if(result!=3 || max>255) { - perror("Error reading rgb image header, or invalid values"); + printf("Error reading rgb image header, or invalid values\n"); fclose(fp); return 3; } @@ -139,7 +139,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R *RGB = malloc(size); if(!*RGB) { - perror("Error allocating rgb image memory"); + printf("Error allocating rgb image memory\n"); fclose(fp); return 2; } @@ -147,7 +147,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R result = fread(*RGB, 1, size, fp); if(result != size) { - perror("Error reading rgb image"); + printf("Error reading rgb image\n"); fclose(fp); return 3; } @@ -162,7 +162,7 @@ int savePPM(const char* filename, uint32_t width, uint32_t height, const uint8_t FILE *fp = fopen(filename, "wb"); if(!fp) { - perror("Error opening rgb image for write"); + printf("Error opening rgb image for write\n"); return 1; } diff --git a/src/tof.c b/src/tof.c index 16ce40f..cd8860f 100644 --- a/src/tof.c +++ b/src/tof.c @@ -626,13 +626,13 @@ void *thread_getTofData(void *ptr) { // 撠閮園曹澈 tof_raw_arr = Correspond_Memory(tof_depth_shmid); if (tof_raw_arr == (void *)-1) { - perror(" [tof.c] Mapping RAW shared memory failed !\n"); + printf(" [tof.c] Mapping RAW shared memory failed !\n"); break; } else { // tof_yuv_arr = Correspond_Memory_YUV(tof_yuv_shmid); // if (tof_yuv_arr == (void *)-1) { - // perror(" [tof.c] Mapping YUV shared memory failed !\n"); + // printf(" [tof.c] Mapping YUV shared memory failed !\n"); // } // 瑼X亦詨 frame 銋瘝脖 @@ -813,7 +813,7 @@ void Receive_Data_ShareMemory(frameimage_yuv *arr){ // 曇園曹澈(for depth values) char Free_ShareMemory(frameimage *arr){ if (shmdt((void *) arr) == -1) { - perror(" [tof.c] Free depth shared memory failed !\n"); + printf(" [tof.c] Free depth shared memory failed !\n"); return -1; } return 0; @@ -821,7 +821,7 @@ char Free_ShareMemory(frameimage *arr){ // 曇園曹澈(for YUV values) char Free_ShareMemory_YUV(frameimage_yuv *arr){ if (shmdt((void *) arr) == -1) { - perror(" [tof.c] Free YUV shared memory failed!\n"); + printf(" [tof.c] Free YUV shared memory failed!\n"); return -1; } return 0; @@ -829,7 +829,7 @@ char Free_ShareMemory_YUV(frameimage_yuv *arr){ // 蝘駁方園曹澈 char Delete_ShareMemory(int shmid){ if (shmctl(shmid, IPC_RMID, 0) == -1) { - perror(" [tof.c] Remove shared memory failed!\n"); + printf(" [tof.c] Remove shared memory failed!\n"); return -1; } return 0; diff --git a/src/utility.cpp b/src/utility.cpp index 628d2b9..625054a 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -173,34 +173,46 @@ char* ReadAllBytes(const char *fileName) //You must free the result float detection_overlap_ratio(detection_pos* det1, detection_pos* det2) { - if (det1->left_x > det2->left_x + det2->width) { return 0.0; } - if (det1->top_y > det2->top_y + det2->height) { return 0.0; } - if (det1->left_x + det1->width < det2->left_x) { return 0.0; } - if (det1->top_y + det1->height < det2->top_y) { return 0.0; } - float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x)); - float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y)); - float overlapArea = colInt * rowInt; //相交處面積 - float area1 = det1->width * det1->height; - float area2 = det2->width * det2->height; - float smallerArea = (area1 > area2) ? area2 : area1; - return overlapArea / smallerArea; //相交處面積占較小物件比例 - //return overlapArea / (area1 + area2 - overlapArea); //相交處面積比例占大小物件加總比例 + // 計算重疊區域的寬度和高度 + float colInt = std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x); + float rowInt = std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y); + + // 檢查是否完全不重疊 + if (colInt <= 0 || rowInt <= 0) { return 0.0; } + + // 計算重疊區域面積 + float overlapArea = colInt * rowInt; + + // 計算兩個偵測框的面積 + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + + // 使用較小的面積作為基準,計算重疊比例 + float smallerArea = (area1 < area2) ? area1 : area2; + return overlapArea / smallerArea; } float detection_overlap_ratio_union(detection_pos* det1, detection_pos* det2) { - if (det1->left_x > det2->left_x + det2->width) { return 0.0; } - if (det1->top_y > det2->top_y + det2->height) { return 0.0; } - if (det1->left_x + det1->width < det2->left_x) { return 0.0; } - if (det1->top_y + det1->height < det2->top_y) { return 0.0; } - float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x)); - float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y)); - float overlapArea = colInt * rowInt; //相交處面積 - float area1 = det1->width * det1->height; - float area2 = det2->width * det2->height; - //float smallerArea = (area1 > area2) ? area2 : area1; - //return overlapArea / smallerArea; //相交處面積占較小物件比例 - return overlapArea / (area1 + area2 - overlapArea); //相交處面積比例占大小物件加總比例 + // 檢查是否完全不重疊 + if (det1->left_x >= det2->left_x + det2->width) { return 0.0; } + if (det1->top_y >= det2->top_y + det2->height) { return 0.0; } + if (det1->left_x + det1->width <= det2->left_x) { return 0.0; } + if (det1->top_y + det1->height <= det2->top_y) { return 0.0; } + + // 計算重疊區域的寬度和高度 + float colInt = std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x); + float rowInt = std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y); + + // 計算重疊區域面積 + float overlapArea = colInt * rowInt; + + // 計算兩個偵測框的面積 + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + + // 計算重疊比例:重疊面積占聯集面積的比例 + return overlapArea / (area1 + area2 - overlapArea); } void PrintMACaddress(char* MACAddress, unsigned char MACData[]) @@ -2037,7 +2049,7 @@ void verify_directory_exists(const char* path) { if (stat(directory_path, &st) == -1) { if (mkdir(directory_path, 0700) == -1) { - perror("mkdir error"); + printf("mkdir error\n"); } } } diff --git a/src/utility.h b/src/utility.h index a2aa037..0d6825c 100644 --- a/src/utility.h +++ b/src/utility.h @@ -772,6 +772,12 @@ extern "C" { void set_record_process_note(char *process_note); void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size); + + void loadCounters(); + void saveCounters(); +#ifdef GY_OS_AMBA + void *start_run_python_thread(void* pythonpath); +#endif #ifdef GY_OS_V_SERIES #else diff --git a/src/utils.c b/src/utils.c index 97a1eac..5cc91cc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -360,7 +360,7 @@ int read_int(int fd) void write_int(int fd, int n) { int next = write(fd, &n, sizeof(int)); - if(next <= 0) error("read failed"); + if(next <= 0) printf("read failed\n"); } int read_all_fail(int fd, char *buffer, size_t bytes) @@ -390,7 +390,7 @@ void read_all(int fd, char *buffer, size_t bytes) size_t n = 0; while(n < bytes){ int next = read(fd, buffer + n, bytes-n); - if(next <= 0) error("read failed"); + if(next <= 0) printf("read failed\n"); n += next; } } @@ -400,7 +400,7 @@ void write_all(int fd, char *buffer, size_t bytes) size_t n = 0; while(n < bytes){ size_t next = write(fd, buffer + n, bytes-n); - if(next <= 0) error("write failed"); + if(next <= 0) printf("write failed\n"); n += next; } }