diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5090605 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "structures.h": "c" + } +} \ No newline at end of file diff --git a/README.md b/README.md index 09fdeee..e59cba0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ -![Darknet Logo](http://pjreddie.com/media/files/darknet-black-small.png) +同樣適用於 darknet_3 -# Darknet # -Darknet is an open source neural network framework written in C and CUDA. It is fast, easy to install, and supports CPU and GPU computation. +Ming 資料夾結構 /emmc_python/ Aida Aida_data -For more information see the [Darknet project website](http://pjreddie.com/darknet). +公司資料夾結構 /emmc_ori/ plugin/ Aida.. Aida_data + +主要修改以下 +- darknet_2_5 & darknet_3 + - /pythonR.c, /pythonR.h:直接替換成自己的版本 + - /nweb.c, /nweb.h, /detector.c:修改部分程式 -For questions or issues please use the [Google Group](https://groups.google.com/forum/#!forum/darknet). diff --git a/gynet b/gynet index 758a978..6464c36 100644 Binary files a/gynet and b/gynet differ diff --git a/libdarknet.a b/libdarknet.a index 65a0e5c..8bc0255 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 eb35fca..40d39c9 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 9fd812c..50cc0ea 100644 Binary files a/obj/dbscan.o and b/obj/dbscan.o differ diff --git a/obj/detector.o b/obj/detector.o index f9e034d..83ede71 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 ff3637f..a475dac 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 3695c65..ff9b27f 100644 Binary files a/obj/ivs.o and b/obj/ivs.o differ diff --git a/obj/network.o b/obj/network.o index 8116bd9..7b0a32b 100644 Binary files a/obj/network.o and b/obj/network.o differ diff --git a/obj/nweb.o b/obj/nweb.o index ed7eee6..7d71c66 100644 Binary files a/obj/nweb.o and b/obj/nweb.o differ diff --git a/obj/parser.o b/obj/parser.o index 534b6f3..fb0c354 100644 Binary files a/obj/parser.o and b/obj/parser.o differ diff --git a/obj/pns.o b/obj/pns.o index 8a405f7..8650620 100644 Binary files a/obj/pns.o and b/obj/pns.o differ diff --git a/obj/ptz.o b/obj/ptz.o index 976c7b6..cb8c618 100644 Binary files a/obj/ptz.o and b/obj/ptz.o differ diff --git a/obj/pythonR.o b/obj/pythonR.o index 70c64b8..4b5cc01 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 f682e74..8bbd6f4 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 d7d0be6..648a031 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 d35949b..a169813 100644 Binary files a/obj/utility.o and b/obj/utility.o differ diff --git a/obj/utils.o b/obj/utils.o index c599263..8c7fb6a 100644 Binary files a/obj/utils.o and b/obj/utils.o differ diff --git a/obj/websocket.o b/obj/websocket.o index 3719191..ed3cf59 100644 Binary files a/obj/websocket.o and b/obj/websocket.o differ diff --git a/src/art.c b/src/art.c index b50061b..5d62550 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) printf("Couldn't connect to webcam.\n"); + if(!cap) error("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 3717021..265df2e 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); - printf("%s\n",buffer); + error(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); - printf("%s\n",buffer); + error(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) printf("Cuda malloc failed\n"); + if(!x_gpu) error("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) printf("Cuda malloc failed\n"); + if(!x_gpu) error("Cuda malloc failed\n"); return x_gpu; } diff --git a/src/darknet.c b/src/darknet.c index 335fb35..fe2f30b 100644 --- a/src/darknet.c +++ b/src/darknet.c @@ -151,6 +151,7 @@ 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 2fad16d..1452b63 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) - printf("Failed to allocate node.\n"); + perror("Failed to allocate node."); 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) { - printf("Failed to allocate epsilon neighbours.\n"); + perror("Failed to allocate epsilon neighbours."); 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) { - printf("Failed to allocate points array\n"); + perror("Failed to allocate points array"); return 0; } while (i < num_points) { diff --git a/src/demo.c b/src/demo.c index 9c8a027..b89efb8 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) printf("Couldn't connect to webcam.\n"); + if(!cap) error("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)) printf("Thread creation failed\n"); - if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n"); + 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(!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) printf("Couldn't connect to webcam.\n"); + if(!cap) error("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)) printf("Thread creation failed\n"); -if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n"); +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(!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 459726d..1407ac6 100644 --- a/src/detector.c +++ b/src/detector.c @@ -32,9 +32,7 @@ #include #include #include "net_curl.h" -#ifdef GY_OS_AMBA #include -#endif #include "structures.h" #if defined GY_OS_AMBA @@ -158,12 +156,11 @@ 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 @@ -301,7 +298,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 { @@ -386,9 +383,7 @@ 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; @@ -989,8 +984,6 @@ void *run_event_counter_thread(void *ptr) set_counter_zone(); - loadCounters(); - while (bHttpServerThreadStart) { //printf("\n-----run event counter thread start\n"); @@ -1198,9 +1191,6 @@ 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"); @@ -1319,54 +1309,6 @@ 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) { @@ -5550,7 +5492,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 = -1; + g_PostRecorderList[k].zone_idx = 0; strcpy(g_PostRecorderList[k].sPlateNumber, ""); g_PostRecorderList[k].count_trigger = 0; @@ -5583,7 +5525,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 = -1; + g_longterm_PostRecorderList[k].zone_idx = 0; strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); g_longterm_PostRecorderList[k].count_trigger = 0; @@ -11281,7 +11223,7 @@ void initial_g_PostRecorderList() { g_PostRecorderList[i].box_h = 0.0; g_PostRecorderList[i].object_id = 0.0; - g_PostRecorderList[i].zone_idx = -1; + g_PostRecorderList[i].zone_idx = 0.0; strcpy(g_PostRecorderList[i].sPlateNumber, ""); strcpy(g_PostRecorderList[i].name, ""); @@ -11311,7 +11253,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 = -1; + g_longterm_PostRecorderList[i].zone_idx = 0.0; strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[i].name, ""); @@ -11400,17 +11342,11 @@ 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(&temp_A, pNext); + float temp_A_iou = detection_overlap_ratio_union(&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) @@ -11455,16 +11391,14 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -11485,7 +11419,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -11520,17 +11454,11 @@ 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(&temp_A, pNext); + float temp_A_iou = detection_overlap_ratio_union(&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) @@ -11565,16 +11493,14 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; @@ -11590,7 +11516,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; @@ -11611,7 +11537,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int } } -#if 0 +#if 1 if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { if (iFindMatchPost_longterm == 0) { @@ -11692,18 +11618,10 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int g_PostRecorderList[i].check_if_ftp = 0; g_PostRecorderList[i].check_if_getalarmmotion = 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].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; @@ -12658,11 +12576,13 @@ 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 (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) + 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) { QueueInfo q_info = { 0 }; @@ -13418,8 +13338,7 @@ 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 : 5; - int threahold_div = 2; + int threahold_div = g_sensors_type == 0 ? 1 : 7; 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; @@ -13853,7 +13772,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 : 5;//1 7 + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; @@ -13951,7 +13870,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - 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(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) { int m = 0; int array_zone_count[4] = { 0 }; @@ -14090,7 +14009,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } - 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 (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 ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { @@ -14751,7 +14670,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 : 5;//1 7 + int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; @@ -14849,8 +14768,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - 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 (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) { int m = 0; int array_zone_count[4] = { 0 }; @@ -14990,8 +14908,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki } } - 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 (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 ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { @@ -16228,10 +16145,10 @@ void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracki } else { if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { - int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); - int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); - int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height); int threshold_3 = 25; @@ -16255,10 +16172,10 @@ void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracki } else { if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { - int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); - int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height / 2)); - int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].width); int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].height); int threshold_3 = 25; @@ -16715,11 +16632,11 @@ void update_vote_table(detection_pos* PosInfo, int total_element_size, int track } if (det_count >= 1) { - int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)); - int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2)); - - //ˬdשMe׬O_b@wd - int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width); + int deltaX = abs((pNext->left_x + pNext->width / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)); + int deltaY = abs((pNext->top_y + pNext->height / 2) - (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y + g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2)); + + //ˬdשMe׬O_b@wd + int deltaWidth = abs(pNext->width - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width); int deltaHeight = abs(pNext->height - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height); int threshold = 5; @@ -17479,7 +17396,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 + pNext->height, pNext->width + pNext->height, g_ori_yuv_width, g_ori_yuv_height, 0); + 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); 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) { @@ -20969,7 +20886,6 @@ 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)) @@ -21309,9 +21225,11 @@ 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); @@ -21966,7 +21884,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 //329Memory not freed `IȬ| if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) - printf("HTTP server thread creation failed\n"); + error("HTTP server thread creation failed\n"); #endif @@ -21981,7 +21899,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) { - printf("Create shared memory failed !\n"); + perror("Create shared memory failed !\n"); } else { // lƽwİ @@ -21990,7 +21908,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)) - printf("thread gettofdata creation failed\n"); + error("thread gettofdata creation failed\n"); } } #endif @@ -22063,17 +21981,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)) - printf("Post notification thread creation failed\n"); + error("Post notification thread creation failed\n"); #endif #ifdef GY_OS_NOVA if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) - printf("resolution changed thread failed\n"); + error("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)) - printf("check current resolution thread failed\n"); + error("check current resolution thread failed\n"); } #endif @@ -22092,10 +22010,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)) - printf("thread getimage creation failed\n"); + error("thread getimage creation failed\n"); #ifdef GY_OS_AMBA if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) - printf("thread getimage creation failed\n"); + error("thread getimage creation failed\n"); #endif } @@ -22105,20 +22023,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)) - printf("thread render_radar creation failed\n"); + error("thread render_radar creation failed\n"); if (g_IsRadarFake == 1) { if (pthread_create(&radar_reciever_id, NULL, RADAR_recieve, (void *)&radar_json_data) < 0) - printf("RADAR_recieve creation failed\n"); + error("RADAR_recieve creation failed\n"); } else { if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) - printf("thread getimage creation failed\n"); + error("thread getimage creation failed\n"); if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) - printf("thread radar parser creation failed\n"); + error("thread radar parser creation failed\n"); } } #endif @@ -22136,9 +22054,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)) - printf("thread get_face_websocket creation failed\n"); + error("thread get_face_websocket creation failed\n"); if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) - printf("thread parse_face creation failed\n"); + error("thread parse_face creation failed\n"); #endif } #endif @@ -22150,7 +22068,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ӰO鬪| j1167-1072=95ӰO鬪|Orun_getalarmmotion_thready if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) - printf("Getalarmmotion thread creation failed\n"); + error("Getalarmmotion thread creation failed\n"); #endif #ifdef GY_OS_V_SERIES @@ -22169,7 +22087,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa #if 1 ////쥻W٬Ocheck_http_socket_threadA{b令run_event_counter_thread if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) - printf("check http socket thread creation failed\n"); + error("check http socket thread creation failed\n"); #endif } #endif @@ -22190,7 +22108,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ӰO鬪| j1072-875=197ӰO鬪|Orun_send_udp_thready if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) - printf("check http socket thread creation failed\n"); + error("check http socket thread creation failed\n"); #endif #ifdef GY_OS_AMBA @@ -22202,21 +22120,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)) - printf("Test nnctrl live thread creation failed\n"); + error("Test nnctrl live thread creation failed\n"); #endif } #endif #ifdef GY_OS_NOVA if (pthread_create(&test_nnctrl_live_thread, 0, nnctrl_main, &stAMBAcontent)) - printf("Test nnctrl live thread creation failed\n"); + error("Test nnctrl live thread creation failed\n"); #endif #if 1 //329Memory not freed `IȬ| //Get CPU/VPU loading & AI FPS if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) - printf("fps loading thread creation failed\n"); + error("fps loading thread creation failed\n"); #endif #ifdef GY_OS_AMBA #if 1 @@ -22229,23 +22147,13 @@ 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)) - printf("thread get nova driver creation failed\n"); + error("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; @@ -22441,6 +22349,7 @@ 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); @@ -22497,8 +22406,6 @@ 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); @@ -22566,7 +22473,6 @@ 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; @@ -22734,33 +22640,88 @@ void move_file() { } } -#ifdef GY_OS_AMBA void *start_run_python_thread(void* pythonpath) { pthread_detach(pthread_self()); setPthreadName("run_python"); - - while (bHttpServerThreadStart) - { - 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 if (strstr(SystemSetting.enable_python_file, ".py") == NULL) { - break; - } - usSleep(1000000); + 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 secAwait 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); } - -#endif +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; + } + + // jp + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + // Ū󤺮e줺s + 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); + + // ѪR 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); // ƻsrŦ + } + + // Mz cJSON H + cJSON_Delete(json); + printf("[get_enable_python_file_value] result : %s \n",result); + // ^G + return result; +} void run_server(int argc, char **argv) { //HUSO鬪|------------------------20210803 @@ -22953,7 +22914,9 @@ 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_tof_json, NULL); + pthread_mutex_init(&mutex_buffer, NULL); + #endif pthread_mutex_init(&mutex_get_image, NULL); pthread_mutex_init(&mutex_get_image_HD, NULL); @@ -23006,8 +22969,6 @@ 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); @@ -23063,7 +23024,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)) - printf("preload http server thread creation failed\n"); + error("preload http server thread creation failed\n"); } @@ -25968,11 +25929,22 @@ 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) { - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - + // 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"); + } + } 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; @@ -27411,7 +27383,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)); } @@ -31803,104 +31775,6 @@ 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+"); // HGiŪ覡}ɮ - int counters[MAX_EVENT_COUNTERS] = { 0 }; - - if (file) { - fread(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // qɮפŪpƾ - 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+"); // HGigJ覡}ɮ - if (file) { - fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // NpƾȼgJɮ - 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"); // HGigJ覡}ɮ - if (file) { - fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // NpƾȼgJɮ - fclose(file); - } - else { - printf("\nCOUNTER FILE error.\n"); - } - } - protected_counters = 0; - } - } -#endif -} - #ifdef GY_OS_NOVA int get_pid_nova_driver() { char *temp = NULL; @@ -31955,7 +31829,6 @@ 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 2057ce2..c536142 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) { - printf("mkdir error\n"); + perror("mkdir error"); } } } @@ -362,7 +362,7 @@ void save_base64_image(char* base64_data, const char* output_filename) { #endif if (errno != 0) { // 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息 - printf("fwrite error\n"); + perror("fwrite error"); // Fail } } else { @@ -652,7 +652,7 @@ void base64_to_tpl(char* base64_data, char* output_filename) { #endif if (errno != 0) { // 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息 - printf("fwrite error\n"); + perror("fwrite error"); // 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) { - printf("Error opening file\n"); + perror("Error opening file"); 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) { - printf("Error opening file\n"); + perror("Error opening file"); return; } diff --git a/src/ivs.cpp b/src/ivs.cpp index 2d3ca69..c14b102 100644 --- a/src/ivs.cpp +++ b/src/ivs.cpp @@ -516,17 +516,29 @@ 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(); + //} + + // MzO + 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(); @@ -548,17 +560,6 @@ 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(); - //} - // MzO - g_multiLayerMOG2.clearMemory(); - g_multiLayerMOG2_2.clearMemory(); } void run_compute_median() { @@ -2281,7 +2282,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.45 && tempering_ready == 0)) + if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0)) { check_if_tempering_many_times = (temp_AI_fps - 1) * 4; @@ -2741,7 +2742,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, } } } - 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) || + 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) || { current_store_object_size = 0; @@ -2763,9 +2764,9 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer, tempering_ready = 0; } } -#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)) { +#if 0 + else if ((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; @@ -2786,7 +2787,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.6 && check_if_tempering_many_times >= 1)) { + else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) { current_store_object_size = 0; last_store_object_size = current_store_object_size; /* @@ -2930,13 +2931,15 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, uint32_t valid_bbox_idx = 0; - int ivs_width = 320;//320 - int ivs_height = 180;//180 + int ivs_width = 240;//320 + int ivs_height = 135;//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; @@ -2982,10 +2985,6 @@ 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--; @@ -3660,11 +3659,10 @@ 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,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); + //printf("\n-------area scale:%lf\n", area_scale); - if (not_to_show_tempering == 1 || (area_scale <= 0.45 && tempering_ready == 0)) + if (not_to_show_tempering == 1 || (area_scale <= 0.95 && 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; @@ -4013,10 +4011,8 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer, } } } - else if (not_to_show_tempering == 0 && ((area_scale >= 0.6 && check_if_tempering_many_times <= 0) || tempering_ready == 1)) + else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && 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; @@ -4027,24 +4023,8 @@ 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.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)) + else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && 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 beea093..6822ffd 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{ - printf("Cannot resize this type of layer\n"); + error("Cannot resize this type of layer"); } 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)) printf("Thread creation failed\n"); + if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed"); 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)) printf("Thread creation failed\n"); + if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed"); return thread; } diff --git a/src/nweb.c b/src/nweb.c index 65ec9fa..d3856d0 100644 --- a/src/nweb.c +++ b/src/nweb.c @@ -143,6 +143,7 @@ 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; @@ -256,7 +257,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; @@ -420,13 +421,13 @@ int g_control_alarm_gpio = 0; int g_is_check_credential = 0; -char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE] = { 0 }; +char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; 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] = { 0 }; +char g_cWebPythonName[50]; struct MemoryStruct { char memory[MEMORY_SIZE];//256KB @@ -2475,7 +2476,6 @@ 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,7 +2748,6 @@ 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)) @@ -6531,7 +6530,6 @@ 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)) @@ -8800,7 +8798,6 @@ 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)) @@ -9767,7 +9764,6 @@ 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)) @@ -9889,7 +9885,6 @@ 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)) @@ -10011,7 +10006,6 @@ 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)) @@ -10780,7 +10774,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) - // printf("send error #1999\n"); + // perror("send error #1999"); } else #endif @@ -10844,7 +10838,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) - // printf("send error #1999\n"); + // perror("send error #1999"); } else #endif @@ -11204,11 +11198,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) - printf("send error #199916\n"); + perror("send error #199916"); if ((int)snapshot_size >= 1) { if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1) - printf("send error #19999998\n"); + perror("send error #19999998"); } else { @@ -11227,11 +11221,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) - printf("send error #199917\n"); + perror("send error #199917"); if ((int)speed_snapshot_size >= 1) { if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1) - printf("send error #19999999\n"); + perror("send error #19999999"); } else { @@ -11977,7 +11971,6 @@ 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)) @@ -12126,7 +12119,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) - printf("send error #28\n"); + perror("send error #28"); if (JsonString != NULL) { free(JsonString); @@ -13087,7 +13080,6 @@ 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)) @@ -14124,7 +14116,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, ""); @@ -14138,13 +14130,12 @@ 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 && g_cWebPythonBufferSignal == 0){ - g_cWebPythonBufferSignal = 1; + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { 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"); @@ -14159,7 +14150,6 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch g_uiWebPythonLastBufferIndex = 0; strcpy(beforeSendBuffer_xtra, sOutput); - g_cWebPythonBufferSignal = 0; } else { @@ -14180,7 +14170,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)); @@ -14206,7 +14196,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)); @@ -14232,11 +14222,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) @@ -14250,7 +14240,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } else { - strcpy(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); + sprintf(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) @@ -14267,8 +14257,7 @@ 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); - strcpy(beforeSendBuffer_xtra,""); + printf("cmd = %s \n", Cmd); } else { strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB"); @@ -15632,7 +15621,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) - printf("send error radar.json\n"); + perror("send error radar.json"); // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE if (root) { @@ -16039,7 +16028,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) - printf("[CGI:/gettof] send json string error\n"); + perror("[CGI:/gettof] send json string error"); if (JsonString != NULL) { free(JsonString); @@ -16390,7 +16379,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) - printf("send error tof.json\n"); + perror("send error tof.json"); // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE if (root) { @@ -16436,7 +16425,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 }; // 512A̦h 8 A̤jؤoY 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) @@ -16450,7 +16439,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); // C Buffer N Row for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) @@ -16468,7 +16457,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch else { g_cWebPythonStatus = 4; // gJMŪbP@ Row - //printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); + printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); continue; } } @@ -16490,7 +16479,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) @@ -16509,9 +16498,8 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 512A̦h 8 A̤jؤoY 4096 char beforeSendBuffer[BUFSIZE * 8] = {0}; - if (strcmp(SystemSetting.enable_python, "Yes") == 0 && g_cWebPythonBufferSignal == 0) + if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - g_cWebPythonBufferSignal = 1; char *buffersize_ptr = strstr(urlBuffer, "buffersize="); if (buffersize_ptr != NULL) { @@ -16534,7 +16522,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) @@ -16543,22 +16531,21 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch { // Ūbg // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - pthread_mutex_lock(&buffer_mutex); + pthread_mutex_lock(&mutex_buffer); // python X - //printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); + printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); // MŮL row memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); - pthread_mutex_unlock(&buffer_mutex); // + pthread_mutex_unlock(&mutex_buffer); // // sŪm 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; } @@ -16571,18 +16558,15 @@ 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, ""); + strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); } - //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) @@ -19746,11 +19730,7 @@ 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; @@ -19783,33 +19763,18 @@ 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"); @@ -20666,14 +20631,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch } - if (check_if_setfile_OK == 1) - { - strcpy(beforeSendBuffer, "OK"); - } - else { - strcpy(beforeSendBuffer, "Fail"); - } - + strcpy(beforeSendBuffer, ""); if (strlen(contentDescription) > 0) { strcat(beforeSendBuffer, " "); @@ -23157,19 +23115,6 @@ 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) //Dsocket|hˬd\r\n\r\nA~UC @@ -23196,20 +23141,6 @@ 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) //pGOWzӡAh[NVR]"\r\n\r\n"P_C { @@ -23787,11 +23718,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 !!"); } @@ -23800,6 +23731,7 @@ void *http_connection_handler(void *socket_desc) strcpy(SendPython, "Send python file fail !!"); } } + } } else { @@ -24589,6 +24521,7 @@ 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 6a32285..921d957 100644 --- a/src/nweb.h +++ b/src/nweb.h @@ -814,6 +814,15 @@ 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 e4466e2..0c49218 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)) printf("Layer before local layer must output image.\n"); + if(!(h && w && c)) error("Layer before local layer must output image."); 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)) printf("Layer before deconvolutional layer must output image.\n"); + if(!(h && w && c)) error("Layer before deconvolutional layer must output image."); 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)) printf("Layer before convolutional layer must output image.\n"); + if(!(h && w && c)) error("Layer before convolutional layer must output image."); 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)) printf("Layer before crop layer must output image.\n"); + if(!(h && w && c)) error("Layer before crop layer must output image."); 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)) printf("Layer before reorg layer must output image.\n"); + if(!(h && w && c)) error("Layer before reorg layer must output image."); 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)) printf("Layer before maxpool layer must output image.\n"); + if(!(h && w && c)) error("Layer before maxpool layer must output image."); 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)) printf("Layer before avgpool layer must output image.\n"); + if(!(h && w && c)) error("Layer before avgpool layer must output image."); 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) printf("Route Layer must specify input layers\n"); + if(!l) error("Route Layer must specify input layers"); 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)) printf("No input parameters supplied\n"); + if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied"); 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) printf("STEPS policy must have steps and scales in cfg file\n"); + if(!l || !p) error("STEPS policy must have steps and scales in cfg file"); 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) printf("Config file has no sections\n"); + if(!n) error("Config file has no sections"); 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)) printf("First section must be [net] or [network]\n"); + if(!is_network(s)) error("First section must be [net] or [network]"); 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)) printf("Layer before convolutional layer must output image.\n"); + if (!(h && w && c)) error("Layer before convolutional layer must output image."); 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)) printf("Layer before maxpool layer must output image.\n"); + if (!(h && w && c)) error("Layer before maxpool layer must output image."); 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 e1fc357..36e8b6c 100644 --- a/src/pns.c +++ b/src/pns.c @@ -856,7 +856,6 @@ 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)) @@ -1006,7 +1005,6 @@ 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)) @@ -1123,38 +1121,10 @@ void stop_canvas_live_mode_flag() { int g_pns_account_OK = 0; int g_pns_access_level = -1; int g_check_noapplink = 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 }; +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); @@ -1168,10 +1138,12 @@ 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; } } @@ -1179,7 +1151,48 @@ 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 && g_pns_access_level >= 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; + } //CURL* curl = curl_easy_init(); curl_mime* form = NULL; @@ -1724,16 +1737,6 @@ 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 }; @@ -1751,16 +1754,6 @@ 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); @@ -1869,8 +1862,6 @@ 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 52e3db8..f40972c 100644 --- a/src/pns.h +++ b/src/pns.h @@ -43,12 +43,6 @@ 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 60a24a9..cdaae7d 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 d1e5807..8e555fd 100644 --- a/src/pythonR.c +++ b/src/pythonR.c @@ -1,52 +1,43 @@ #include "pythonR.h" #include - -//char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; -//char sFileName[PTYHON_FILE_NAME] = { 0 }; +#define MAX_BUFFER_LINES 1024 +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() { - 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"); - - 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); + 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); + + check_count++; + if (check_count < 10) + { + IfFolderExist(); + } + } } void readPythonFile(char *sINFileName, char *sOutput) { - //char sPythonCode[PYTHON_CODE_SIZE] = { 0 }; - char sFileName[PTYHON_FILE_NAME] = { 0 }; + memset(sPythonCode, 0, PYTHON_CODE_SIZE); + memset(sFileName, 0, PTYHON_FILE_NAME); int lSize = 0; //check folder exist - //check_count = 0; + check_count = 0; IfFolderExist(); //python file name @@ -69,49 +60,37 @@ void readPythonFile(char *sINFileName, char *sOutput) fclose(f); } + else { + } } // T{Ƨsb int ensureFolderExists(const char *folderPath) { - struct stat st = { 0 }; - int ret = 0; - - // ˬdƧO_wsb - if (stat(folderPath, &st) == -1) { - // ճЫظƧ - if (mkdir(folderPath, 0777) == -1) { - // pGЫإѡAO] - printf("\nFailed to create directory\n"); - ret = -1; // Ыإ - } - } - else if (!S_ISDIR(st.st_mode)) { - // pGPWɮצsbOƧ - printf("\nError: A file with the same name as the folder exists.\n"); - ret = -1; - } - - return ret; + struct stat st = { 0 }; + if (stat(folderPath, &st) == -1) { + mkdir(folderPath, 0777); + if (stat(folderPath, &st) == -1) { + return -1; // LkЫظƧ + } + } + + return 0; // } int saveFile(char *pythonData, char *filename) { - int ret = 0; if (ensureFolderExists(PYTHON_FOLDER) == -1) { - ret = -1; // Ƨsb + return -1; // Ƨsb + } + 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; // LkgJ } - 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; // LkgJ - } - } - return ret; } #if 1 @@ -121,19 +100,19 @@ void deletePythonFile(char *sINFileName) // g_cWebPythonDeleteStatus = 0 deleted successfully // g_cWebPythonDeleteStatus = 1 deleted failed g_cWebPythonDeleteStatus = 0; - char sFileName[PTYHON_FILE_NAME] = { 0 }; + memset(sFileName, 0, PTYHON_FILE_NAME); //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 { @@ -145,21 +124,15 @@ void deletePythonFile(char *sINFileName) #endif int checkDuplicateFile(const char *filename) { // check file name duplicate - - int ret = 0; - char fullPath[1024]; + char fullPath[1024]; snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename); - + if (access(fullPath, F_OK) != -1) { // file exists - ret = 1; + return 1; } - else { - // file not exists - ret = 0; - } - - return ret; + // file not exists + return 0; } const char* SavePython(char *urlData) { @@ -167,8 +140,7 @@ 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}; @@ -179,26 +151,14 @@ const char* SavePython(char *urlData) { sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName); int saveResult = saveFile(sPythonCode, sPythonFilePath); - 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"; + if(saveResult==0){ + return "File save successfully"; + }else{ + return "File save failed"; + } + } + return "Invalid URL parameters"; } const char* uploadPython(char *urlData) { @@ -206,8 +166,7 @@ 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}; @@ -216,268 +175,243 @@ 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 "); - ret = 1; + printf("######################## No File name \n "); + return "Invalid file name"; } else if (checkDuplicateFile(sPythonFileName) == 1) { - ret = 2; - } - else { - int saveResult = saveFile(sPythonCode, sPythonFilePath); - if (saveResult == 0) { - ret = 3; - } - else { - ret = 4; - } + return "File already exists, please choose a different file name"; } + int saveResult = saveFile(sPythonCode, sPythonFilePath); + if(saveResult==0){ + return "File uploaded successfully"; + }else{ + return "File upload failed"; + } + } - 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_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_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"); } + void runPython(char *pythonData) //2024/02/27 run button action { - g_stop_python = 0; - if (g_cWebPythonBufferSignal == 0) { + // ------------------------------------------------- + // Bz ajax ǨӪrAѦɦWPɮפe + 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 { + // // pG 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'; // TOr굲 + // } else { + // printf("read file content failed \n"); + // } + // pclose(fp); + // } + // ------------------------------------------------- + // إ virtual pipeline o python X + 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); // sW 2>&1 + printf("run python cmd = \n%s \n", cmd); + pPipe = vpopen(cmd, "r"); + if (pPipe == NULL) + { + // virtual pipeline إߥѡA^ǵ Web ~T + 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 ~hŪ python X g_cWebPythonBufferSignal = 1; // Signal to start reading - - // ------------------------------------------------- - // Bz ajax ǨӪrAѦɦWPɮפe - 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 { - // // pG 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'; // TOr굲 - // } else { - // printf("read file content failed \n"); - // } - // pclose(fp); - // } - - // ------------------------------------------------- - // إ virtual pipeline o python X - char cmd[256] = { 0 }; - // sprintf(cmd, "python3 %s", sPythonFilePath); - sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // sW 2>&1 - //printf("run python cmd = \n%s \n", cmd); - - FILE *pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe == NULL) - { - // virtual pipeline إߥѡA^ǵ Web ~T - 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 ~hŪ python X - - // 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); // K[e psBufferTemp - psBufferTempSize += len; // spƾ - } - else { - // psBufferTemp ɡA g_aWebPythonBuffer2D ím - strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); - memset(psBufferTemp, 0, sizeof(psBufferTemp)); // M psBufferTemp - strcat(psBufferTemp, psBuffer); // m~J - psBufferTempSize = 0; // mpƾ - psBufferTempSize += len; // m~p - // 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 neJ Buffer - if (psBufferTempSize > 0) - { + // 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); // K[e psBufferTemp + psBufferTempSize += len; // spƾ + } else { + // psBufferTemp ɡA g_aWebPythonBuffer2D ím strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); memset(psBufferTemp, 0, sizeof(psBufferTemp)); // M psBufferTemp + strcat(psBufferTemp, psBuffer); // m~J + psBufferTempSize = 0; // mpƾ + psBufferTempSize += len; // m~p + // 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 neJ Buffer + if (psBufferTempSize > 0 ) + { + strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE); + memset(psBufferTemp, 0, sizeof(psBufferTemp)); // M psBufferTemp + g_uiWebPythonCurrentBufferIndex++; + + } + g_cWebPythonBufferSignal = 0; // ݦb python ]ɡA^ 0Apythongetbuffer CGI ~TD python 檬A + // + pclose(pPipe); // Close the pipe after reading all outputs + } + // 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) { - int ret = 0; + 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(); + if (ensureFolderExists(PYTHON_FOLDER) == -1) { - ret = -1; // Ƨsb + return -1; // Ƨsb } - 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)); - } + + + d = opendir(PYTHON_FOLDER); + if (d) { + while ((dir = readdir(d)) != NULL) { + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + { + // do nothing (straight logic) } - closedir(folder_dir); + else { + //printf("%s\n", dir->d_name); + //sprintf(&sfileList[file_number], "%s", dir->d_name); + //printf("%s\n", sfileList[file_number]); + //file_number++; - //printf("file num: %d \n", file_number); + s_file_name = cJSON_CreateString(dir->d_name); - //for (int j = 0; j < file_number; j++) - //{ - //printf("%s\n", sfileList[j]); - //} + cJSON_AddItemToArray(file_list, s_file_name); + } + } + //printf("file num: %d \n", file_number); - cJSON_AddItemToObject(s_root, "file_list", file_list); + for (int j = 0; j < file_number; j++) + { + printf("%s\n", sfileList[j]); + } - char* JsonString = cJSON_PrintUnformatted(s_root); + cJSON_AddItemToObject(s_root, "file_list", file_list); - sprintf(output, "%s", JsonString); + char* JsonString = cJSON_Print(s_root); - //printf("jstring = \n%s\n", JsonString); + sprintf(output, "%s", JsonString); - if (JsonString) { - free(JsonString); - JsonString = NULL; - } + //printf("jstring = \n%s\n", JsonString); - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } + if (JsonString) { + free(JsonString); + JsonString = NULL; } + + if (s_root) { + cJSON_Delete(s_root); + s_root = NULL; + } + + closedir(d); } - return ret; + + + + return 0; } diff --git a/src/pythonR.h b/src/pythonR.h index 7062019..afdef51 100644 --- a/src/pythonR.h +++ b/src/pythonR.h @@ -22,30 +22,18 @@ #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 e520e3e..b8c1341 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) { - printf("error bind failed\n"); + perror("error bind failed\n"); close(sockfd); } /* if(listen(sockfd, 512) == -1){ - printf("error listen failed\n"); + perror("error listen failed\n"); close(sockfd); }*/ diff --git a/src/setting.h b/src/setting.h index 1c85cb1..90ac2f9 100644 --- a/src/setting.h +++ b/src/setting.h @@ -11,11 +11,12 @@ //general difinition #ifdef GY_OS_AMBA -#define APP_VERSION "2.0.7.69" //AMBALPKG.jsonn@P +#define APP_VERSION "2.0.7.60" //AMBALPKG.jsonn@P #else -#define APP_VERSION "1.4.3.4" //NOVALPKG.jsonn@P +#define APP_VERSION "1.4.3.2" //NOVALPKG.jsonn@P #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 f4dcfbf..ed42548 100644 --- a/src/test_nnctrl_live.c +++ b/src/test_nnctrl_live.c @@ -550,7 +550,6 @@ 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)) @@ -1053,7 +1052,7 @@ static int get_network_input(struct nnctrl_param *pctrl) // MO@ɰ tof_yuv_arr = Correspond_Memory_YUV(tof_shmid); if (tof_yuv_arr == (void *)-1) { - printf("Mapping shared memory failed!\n"); + perror("Mapping shared memory failed!\n"); } } } @@ -2599,7 +2598,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) { - printf("fread input file\n"); + perror("fread input file"); rval = -1; break; } @@ -2620,25 +2619,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) { - printf("%s\n",file_name); + perror(file_name); rval = -1; break; } if (fseek(in, 0, SEEK_END) < 0) { - printf("fseek input file\n"); + perror("fseek input file"); rval = -1; break; } file_size = ftell(in); if (fseek(in, 0, SEEK_SET) < 0) { - printf("fseek input file\n"); + perror("fseek input file"); rval = -1; break; } if (file_size == size) { if (fread(virt_addr, 1, size, in) != size) { - printf("fread input file\n"); + perror("fread input file"); rval = -1; break; } @@ -4018,6 +4017,155 @@ 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_lprmemcpyC + 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_ivsmemcpyC + 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"); } } @@ -4319,10 +4467,10 @@ void *run_one_net_thread(void *ptr) { } } else { - 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; + 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; } //printf("\n--------%f\n", pNext_ivs->width * pNext_ivs->height / ((float)g_ori_yuv_width * (float)g_ori_yuv_height)); @@ -4459,10 +4607,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; @@ -4817,400 +4965,230 @@ void *run_one_net_thread(void *ptr) { } else { - 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); - - ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); + ret = run_one_net(&g_pctrl_run_one_net->net_pair[idx]); - //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); + //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 (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 (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); - if (bbox_ret < 0) + 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 + + ) { - 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, "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; - } - 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); - } - else if (ratio_area_threshold >= 0.4) { - pNext_word->confidence -= 40.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 (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 (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 (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; + 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; } - 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; + } + 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; } - pNext_word->image_id = current_image_id_for_object; } + }*/ -#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); - + 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; } - 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); - - ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_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); - 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_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); + pNext_word->image_id = current_image_id_for_anpr; + } + else { -#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 + 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; + } - 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; - } + #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 - valid_bbox_idx_alphabet++; - } + /*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; - //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 + //printf("\nTTTTTTTTTTTTTTTTT: %f,%f\n", pNext_word->bbox_distance, pNext_word->bbox_height); - } - } - else if (idx == iFeature_production_layer_index && IsProductionCategory(pNext_word)) + } + 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) { - // 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); - - // ǤJ 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); + cropped_roi(pNext_word, &g_pctrl_run_one_net->net_pair[iFeature_logo_layer_index], valid_bbox_idx, snapshot_addr, snapshot_size); - ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_mask_layer_index]); + ret = run_one_net(&g_pctrl_run_one_net->net_pair[iFeature_logo_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); + 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); @@ -5230,7 +5208,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_mask_layer_index, frame_id, 0.3); + 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) @@ -5238,45 +5216,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_mask_layer_index #222: %d \n", iFeature_mask_layer_index); + 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_mask_layer_index].yolov3_result_num; j++) + 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_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 + 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_mask_layer_index].objects_id[j]; + 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_mask_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_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_mask_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_logo_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->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_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->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_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->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_mask_layer_index].amba_yolov3_result[j].label; + 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; @@ -5287,9 +5265,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 || @@ -5305,22 +5283,181 @@ void *run_one_net_thread(void *ptr) { } - //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]; + //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_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 (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); + + // ǤJ 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); - valid_bbox_idx++; + 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++; } } } @@ -7175,18 +7312,10 @@ 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++) @@ -7203,11 +7332,6 @@ 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; } @@ -7241,24 +7365,6 @@ 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)) @@ -7285,7 +7391,7 @@ void clear_PostRecorderList() { g_PostRecorderList[index_post].box_h = 0; g_PostRecorderList[index_post].object_id = 0; - g_PostRecorderList[index_post].zone_idx = -1; + g_PostRecorderList[index_post].zone_idx = 0; strcpy(g_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_PostRecorderList[index_post].name, ""); @@ -7343,10 +7449,6 @@ 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]) @@ -7391,7 +7493,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 = -1; + g_longterm_PostRecorderList[index_post].zone_idx = 0; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7401,7 +7503,7 @@ void clear_PostRecorderList() { } } - if (clear_count_long_not_zone > 25) { + if (clear_count_long_not_zone >= 50) { if (index_max_iDiffSec_not_zone >= 0) { counter_index_long--; int index_post = index_max_iDiffSec_not_zone; @@ -7426,7 +7528,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 = -1; + g_longterm_PostRecorderList[index_post].zone_idx = 0; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7436,7 +7538,7 @@ void clear_PostRecorderList() { } for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { - if (clear_count_long[index_zone] >= 8) { + if (clear_count_long[index_zone] >= 15) { if (index_max_iDiffSec[index_zone] >= 0) { counter_index_long--; int index_post = index_max_iDiffSec[index_zone]; @@ -7461,7 +7563,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 = -1; + g_longterm_PostRecorderList[index_post].zone_idx = 0; strcpy(g_longterm_PostRecorderList[index_post].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[index_post].name, ""); @@ -7469,40 +7571,6 @@ 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; @@ -8927,7 +8995,45 @@ 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; @@ -9189,7 +9295,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 * 2 / 3) { + if (pNext->center_y > g_ori_yuv_height * 3 / 4) { pNext->width = 0; pNext->height = 0; continue; @@ -9237,10 +9343,9 @@ 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.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 (detection_overlap_ratio(pNext, pNext_temp) > 0.7){ if (pNext->width * pNext->height > pNext_temp->width * pNext_temp->height) { pNext->width = 0; pNext->height = 0; @@ -9251,6 +9356,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } } +#endif } } } @@ -9347,6 +9453,115 @@ 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) + { + // AT{O_Pv| + + 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; @@ -9432,40 +9647,31 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten IsANPRCategory_L_Plate(pNext->name) == 1) continue; - for (int j = 0; j < total_element_size; j++) - { - if (i != j) { - pNext_temp = PosInfo + j; + if (strcmp(pNext->name, "person") == 0) { - 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, "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; + if (pNext_temp->width == 0 || + pNext_temp->height == 0 || + IsANPRCategory(pNext_temp->engine_type) || + IsANPRCategory_L_Plate(pNext_temp->name) == 1) + continue; + + if (strcmp(pNext->name, pNext_temp->name) == 0) { + if (pNext->engine_type == pNext_temp->engine_type && + pNext->engine_type2 == pNext_temp->engine_type2) { + + 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; + } + } } } } @@ -9823,12 +10029,6 @@ 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) { @@ -9892,17 +10092,14 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -9933,7 +10130,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -9966,7 +10163,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten else { if (strcmp(pNext->name, "person") == 0) { //uɶs - if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10016,12 +10213,6 @@ 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) { @@ -10085,16 +10276,13 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10125,7 +10313,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10158,7 +10346,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten else { if (strcmp(pNext->name, "person") == 0) { //uɶs - if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; int check_if_existing_in_post = 0; @@ -10195,7 +10383,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } - if (pNext->width == 0 || pNext->height == 0 /*|| (strcmp(pNext->name, "person") == 0 && pNext->height / pNext->width < 1.25)*/) + if (pNext->width == 0 || (strcmp(pNext->name, "person") == 0 && pNext->height / pNext->width < 1.25)) { pNext->width = 0; pNext->height = 0; @@ -10213,10 +10401,6 @@ 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 || @@ -10285,11 +10469,8 @@ 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; @@ -10633,12 +10814,6 @@ 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) { @@ -10715,16 +10890,14 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -10761,7 +10934,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { double temp_dTime = difftime(now_time, g_PostRecorderList[index_post].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; @@ -10816,12 +10989,6 @@ 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) { @@ -10887,16 +11054,14 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } else { - /*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 (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 + && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.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.7) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; @@ -10928,7 +11093,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.7 /*|| temp_distance <= 225.0*/) { + if (/*g_longterm_PostRecorderList[index_post].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { g_longterm_PostRecorderList[index_post].t_UpdateTime = now_time; g_longterm_PostRecorderList[index_post].object_id = pNext->obj_tracking_id; @@ -10975,16 +11140,7 @@ int start_all_nets(struct nnctrl_param *pctrl, struct amba_content *stAMBAconten } } - 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) { + if (pNext->trigger_type >= 1 && 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) @@ -11004,18 +11160,10 @@ 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; - 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].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; @@ -11077,18 +11225,10 @@ 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; - 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].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; @@ -14721,14 +14861,12 @@ 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++) { @@ -15252,9 +15390,6 @@ 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; { @@ -15292,29 +15427,19 @@ 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++) { @@ -15365,7 +15490,7 @@ void stop_test_nn_cavalry(char* note_stop) { } } } - CATCH + CATCH { } @@ -15714,8 +15839,6 @@ 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; @@ -15726,7 +15849,7 @@ void *run_fps_loading_thread(void *ptr) set_record_process_note("run_fps_start"); //printf("\n-------run fps start\n"); g_osdSysTimeStamp++; -#if 0 +#if 1 if (count_post >= 28800) { count_post = 0; @@ -15740,8 +15863,6 @@ 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)) { @@ -15812,12 +15933,6 @@ 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; @@ -15970,7 +16085,6 @@ 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)) @@ -15990,7 +16104,6 @@ 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)) @@ -16014,7 +16127,6 @@ 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)) @@ -16033,7 +16145,6 @@ 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)) @@ -16053,7 +16164,6 @@ 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)) @@ -16072,7 +16182,6 @@ 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)) @@ -16099,7 +16208,6 @@ 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)) @@ -16119,7 +16227,6 @@ 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)) @@ -16135,7 +16242,6 @@ 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)) @@ -16154,7 +16260,6 @@ 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)) @@ -16176,7 +16281,6 @@ 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)) @@ -17781,8 +17885,9 @@ int check_dsp_state(void) { int state; if (ioctl(fd_iav, IAV_IOC_GET_IAV_STATE, &state) < 0) { - printf("IAV_IOC_GET_IAV_STATE\n"); - return -1; + //perror("IAV_IOC_GET_IAV_STATE"); + printf("IAV_IOC_GET_IAV_STATE"); + exit(2); } if ((state != IAV_STATE_PREVIEW) && (state != IAV_STATE_ENCODING) diff --git a/src/test_yuv_rgb.c b/src/test_yuv_rgb.c index 47d0dc4..8601be2 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) { - printf("Error opening yuv image for read\n"); + perror("Error opening yuv image for read"); 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) { - printf("Error reading yuv image\n"); + perror("Error reading yuv image"); 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) { - printf("Error opening yuv image for write\n"); + perror("Error opening yuv image for write"); 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) { - printf("Error opening rgb image for read\n"); + perror("Error opening rgb image for read"); 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) { - printf("Error reading rgb image header, or invalid format\n"); + perror("Error reading rgb image header, or invalid format"); 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) { - printf("Error reading rgb image header, or invalid values\n"); + perror("Error reading rgb image header, or invalid values"); 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) { - printf("Error allocating rgb image memory\n"); + perror("Error allocating rgb image memory"); 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) { - printf("Error reading rgb image\n"); + perror("Error reading rgb image"); 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) { - printf("Error opening rgb image for write\n"); + perror("Error opening rgb image for write"); return 1; } diff --git a/src/tof.c b/src/tof.c index cd8860f..16ce40f 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) { - printf(" [tof.c] Mapping RAW shared memory failed !\n"); + perror(" [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) { - // printf(" [tof.c] Mapping YUV shared memory failed !\n"); + // perror(" [tof.c] Mapping YUV shared memory failed !\n"); // } // 先檢查相同的 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) { - printf(" [tof.c] Free depth shared memory failed !\n"); + perror(" [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) { - printf(" [tof.c] Free YUV shared memory failed!\n"); + perror(" [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) { - printf(" [tof.c] Remove shared memory failed!\n"); + perror(" [tof.c] Remove shared memory failed!\n"); return -1; } return 0; diff --git a/src/utility.cpp b/src/utility.cpp index 625054a..628d2b9 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -173,46 +173,34 @@ char* ReadAllBytes(const char *fileName) //You must free the result float detection_overlap_ratio(detection_pos* det1, detection_pos* det2) { - // p⭫|ϰ쪺eשM - 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); - - // ˬdO_| - if (colInt <= 0 || rowInt <= 0) { return 0.0; } - - // p⭫|ϰ쭱n - float overlapArea = colInt * rowInt; - - // pӰتn - float area1 = det1->width * det1->height; - float area2 = det2->width * det2->height; - - // ϥθpn@ǡAp⭫| - float smallerArea = (area1 < area2) ? area1 : area2; - return overlapArea / smallerArea; + 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; //ۥBn + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + float smallerArea = (area1 > area2) ? area2 : area1; + return overlapArea / smallerArea; //ۥBnep + //return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` } float detection_overlap_ratio_union(detection_pos* det1, detection_pos* det2) { - // ˬdO_| - 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; } - - // p⭫|ϰ쪺eשM - 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); - - // p⭫|ϰ쭱n - float overlapArea = colInt * rowInt; - - // pӰتn - float area1 = det1->width * det1->height; - float area2 = det2->width * det2->height; - - // p⭫|ҡG|nepn - 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 = 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; //ۥBn + float area1 = det1->width * det1->height; + float area2 = det2->width * det2->height; + //float smallerArea = (area1 > area2) ? area2 : area1; + //return overlapArea / smallerArea; //ۥBnep + return overlapArea / (area1 + area2 - overlapArea); //ۥBnҥejp[` } void PrintMACaddress(char* MACAddress, unsigned char MACData[]) @@ -2049,7 +2037,7 @@ void verify_directory_exists(const char* path) { if (stat(directory_path, &st) == -1) { if (mkdir(directory_path, 0700) == -1) { - printf("mkdir error\n"); + perror("mkdir error"); } } } diff --git a/src/utility.h b/src/utility.h index 0d6825c..a2aa037 100644 --- a/src/utility.h +++ b/src/utility.h @@ -772,12 +772,6 @@ 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 5cc91cc..97a1eac 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) printf("read failed\n"); + if(next <= 0) error("read failed"); } 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) printf("read failed\n"); + if(next <= 0) error("read failed"); 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) printf("write failed\n"); + if(next <= 0) error("write failed"); n += next; } }