#include "darknet.h" #include "utils.h" #include "demo.h" #include "blas.h" #include "option_list.h" #include "setting.h" #include "utility.h" #include "libgen.h" #include "iniReader.h" #include "network.h" #include "cJSON.h" #include "cryptionPlus.h" #include "nweb.h" #include "gettest.h" #include "test_nnctrl_live.h" #include "fflpr_plate_db.h" #ifdef GY_OS_AMBA //#include "websocket_client.h" #endif #include "url_encode.h" #ifdef GY_OS_AMBA //#include "tof.h" #include "ptz.h" #endif #include "cold_zone.h" #include "cgicmd.h" #include #include "pns.h" #include #include "fork_pipe_lib.h" #include #include #include "net_curl.h" #include #include "structures.h" #if defined GY_OS_AMBA #include "ir_control.h" #endif #ifdef GY_OS_AMBA #include "send_osd_data.h" //#include "radar.h" //#include "radar_driver.h" //#include "radar_receive.h" //#include "radar_parser.h" #include "cv_point_transform.hpp" //#include "cv_point_transform.h" #include "cv.h" //#include "face_parser.h" #include "levenshtein.h" #endif ///Steven MARK TEMP //#include "zlog.h" //===================== //sophia add 2020/09/24 #if defined GY_OS_AMBA || defined GY_OS_NOVA #include "alm_queue.h" #endif //===================== #include #include #include #include #include #include #include #include #include #include #ifdef GY_OS_NOVA #include "bbox_receive.h" #endif #include "onvif_data.h" #include "anpr_rule.h" //pthread_mutex_t mutex_tcp_layer[MAX_LAYER_NUM]; //pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; //pthread_mutex_t mutex_post_notification; //pthread_mutex_t mutex_post_notification_push; pthread_mutex_t mutex_post_notification_pop; pthread_mutex_t mutex_getalarmmotion; pthread_mutex_t mutex_alm; pthread_mutex_t mutex_curl; pthread_mutex_t mutex_dn; pthread_mutex_t mutex_websocket; pthread_mutex_t mutex_enable_lpr_db; #ifdef GY_OS_AMBA pthread_mutex_t mutex_enable_face_db; #endif pthread_mutex_t mutex_username; pthread_mutex_t mutex_pns; pthread_mutex_t mutex_snap; //pthread_mutex_t mutex_get_canvas; //pthread_mutex_t mutex_cropped_roi; pthread_mutex_t mutex_config_json; #if defined GY_OS_AMBA //pthread_mutex_t mutex_jvc_config_json; #endif pthread_mutex_t mutex_events_json; pthread_mutex_t mutex_web; pthread_mutex_t mutex_http_connection_handler; pthread_mutex_t mutex_base64; pthread_mutex_t mutex_run_one_net; #ifdef GY_OS_NOVA //pthread_mutex_t mutex_run_parse_json; #endif pthread_mutex_t mutex_send_jpeg; pthread_mutex_t mutex_heatmap_jpeg; //pthread_mutex_t mutex_strsplit; #ifdef GY_OS_AMBA pthread_mutex_t mutex_perspective_transform; #endif //pthread_mutex_t mutex_snap_hd_image; pthread_mutex_t mutex_snap_image; pthread_mutex_t mutex_get_image; pthread_mutex_t mutex_get_image_HD; pthread_mutex_t mutex_if_enable_lpr_db_is_Yes; pthread_mutex_t mutex_get_network_input; pthread_mutex_t mutex_differ_image; pthread_mutex_t mutex_run_one_net_anpr; pthread_mutex_t mutex_check_license; pthread_mutex_t mutex_read_ipcam; pthread_mutex_t mutex_update_candidate; pthread_mutex_t mutex_send_cgi; //pthread_mutex_t mutex_parse_bbox; pthread_mutex_t mutex_compute_median; //pthread_mutex_t mutex_long_term; //pthread_mutex_t mutex_short_term; //pthread_mutex_t mutex_long_term_yuv; //pthread_mutex_t mutex_short_term_yuv; pthread_mutex_t mutex_set_http_request; pthread_mutex_t mutex_reset_counter; #ifdef GY_OS_AMBA pthread_mutex_t mutex_get_depth; //pthread_mutex_t mutex_tof_data; pthread_mutex_t mutex_write_pcd_data; 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 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 #ifdef GY_OS_NOVA pthread_mutex_t mutex_pre_bbox_receive; pthread_mutex_t mutex_pre_connection; pthread_mutex_t mutex_pre_image_receive; #endif //pthread_mutex_t mutex_color_detect; int g_match_mac = 0; char g_mac_address[256] = { 0 }; int g_sdk_version = -1; int g_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; int g_temp_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; float g_parking_space_recording_x[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; float g_parking_space_recording_y[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; time_t g_parking_space_update_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; time_t g_parking_space_status_change_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; long g_osdSysTimeStamp = 0; int check_if_run_post = -1; int check_if_correct_post = 0; int check_if_start_run_server = 0; char record_process_note[MAX_RECORD_PROCESS][MAX_PROCESS_LENGTH] = { 0 }; int current_index_record = 0; int size_record_process_note = 0; //http server parameters SocketInfo socketRecords[MAX_CLIENT_SOCKET] = { 0 }; ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW] = { 0 }; DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE] = { 0 }; SystemSettingInfo SystemSetting; PostEventInfo postEventList[MAX_POST_EVENTS] = { 0 }; #ifdef GY_OS_V_SERIES #else EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS] = { 0 }; ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS] = { 0 }; SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT] = { 0 }; #endif AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM] = { 0 }; //20201027 sophia add IPCAMServiceInfo IPCAMService; SnapHDInfo snapHDList[MAX_SNAP_HD_LIST] = { 0 }; EmailInfo emailData; WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST] = { 0 }; char WeightFileModeName[35] = { 0 }; HeartbeatInfo heartbeatData; #ifdef GY_OS_AMBA TofInfo tofData; #endif //int g_check_if_set_no_preset_no_autopan = 0; #if defined GY_OS_AMBA || defined GY_OS_NOVA PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER] = {0}; #endif ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER] = { 0 }; PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; //MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA] = { 0 }; #if defined GY_OS_AMBA || defined GY_OS_NOVA ImageDn imageDnData; #endif #ifdef GY_OS_AMBA OSDInfo OSDData[MAX_SIZE_OSD_ARRAY] = { 0 }; SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY] = { 0 }; #endif int g_PlateFilterTimes; //Times int g_PlateFilterTime; //Second int g_PlateRecorderFreeTime; //Second struct tm *cgi_reload_start_Time; struct tm *cgi_startTime_buff; struct tm *cgi_whenTime_buff; struct amba_content stAMBAcontent; static int protected_sqlite_fflpr_db_close = 0; int g_check_ping_OK = 1; int g_check_if_no_brand = 0; //static unsigned char g_snapshot_addr_to_post[MAX_IMG_SIZE] = { 0 }; int g_control_read_ipcam = 0; #ifdef GY_OS_AMBA int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 #endif #ifdef GY_OS_NOVA int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 #endif int g_max_sensor_size = MAX_SENSOR_TYPE0; int g_IsRadarDevice = 0; int g_IsPTZDevice = 0; int g_IsRadarFake = 0; int g_check_if_OK_thermal = 0; int unlockingKeyInnoFR = 0; int unlockingKeyInnoFR_success = 0; #ifdef GY_OS_AMBA char radar_json_data[4096]; #endif int g_check_if_OK_to_start_osd_server = 0; int g_IsSDK_3_0 = 0; int g_IsToFDevice = 0; int g_IsCustomWeight = 0; int g_IsHelm_without_car = 0; float g_thres_bbox_stability = 0.02;//0.02 0.1 float g_thres_bbox_stability_plate = 0.01; float g_thres_bbox_stability_predict = 0.32; float g_initial_background_learning_rate_x = 0.5; float g_initial_background_learning_rate_y = 0.5; float g_initial_background_learning_rate_error_x = 0.0; float g_initial_background_learning_rate_error_y = 0.0; float g_initial_background_mean_diff_x = 0.0; float g_initial_background_mean_diff_y = 0.0; float g_initial_background_error_diff_x = 0.0; float g_initial_background_error_diff_y = 0.0; 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 { network net; layer layer; char *datacfg; char *cfgfile; char *weightfile; float nms; float thresh; float hier_thresh; int dont_show; int ext_output; int save_labels; } NetworkInfo;*/ /*typedef struct { NetworkInfo networkLayer[2]; int layerCount; char **alphabet; ServerType serverType; LicenseType licenseType; AuthFailStatusCode afsCode; unsigned int featureType; } NetworkPool;*/ //static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90}; short td_weight_num = 0; ThirdPartyWeight td_weight_info[MAX_LAYER_NUM]; //CURLM* g_multi_handle; //int g_handle_count; CURL* g_http_handle = NULL; bool isGYNetReady; extern int reload_dataset_from_jsonfile(void); //extern int default_dataset_for_jsonfile(void); //#define DISAPPEAR_FRAME_MAX 8 static int DISAPPEAR_FRAME_MAX = 8; void set_DISAPPEAR_FRAME_MAX(int disappear_frame_max_temp) { DISAPPEAR_FRAME_MAX = disappear_frame_max_temp; } void setPthreadName(char *p_name) { if (p_name != NULL) { (void)prctl(PR_SET_NAME, (unsigned long)p_name);//lname 最多16?字符 } } //static NetworkPool networkPool[MAX_NETWORK_POOL_NUM]; //static int layer_count; static int dont_show; static int show; static int tcp_port; //static char *out_filename; //static char *outfile; //static char *prefix; static float thresh; static float hier_thresh; static int cam_index; static int frame_skip; static int num_of_clusters; static int yuv_width; static int yuv_height; static int ext_output; static int save_labels; static int http_port; //static char* unlocking_key; static int gpu_idx; //static char* c_cnn_type; pthread_t http_thread; #ifdef GY_OS_NOVA pthread_t http_thread_parse_json_data; pthread_t http_thread_pre_image_receive; #endif pthread_t post_notification_thread; pthread_t runpython_thread; pthread_t getalarmmotion_thread; pthread_t delete_jpg_in_seven_days_detector_thread_id; pthread_t send_udp_thread; pthread_t test_nnctrl_live_thread; pthread_t fps_loading_thread; pthread_t getimage_thread; pthread_t resolution_changed_thread; #ifdef GY_OS_V_SERIES #else pthread_t counter_thread; #endif #ifdef GY_OS_AMBA pthread_t getimage_hd_thread; pthread_t gettofdata_thread; pthread_t getstream_thread; pthread_t get_face_websocket_thread; pthread_t parse_face_thread; pthread_t radar_reciever_id; pthread_t render_radar_thread; pthread_t radar_parser_thread; pthread_t thread_id_run_osd_server; #endif #ifdef GY_OS_NOVA pthread_t thread_id_get_nova_driver; #endif //pthread_t thread_id_run_system_time_sync; static int check_if_is_existing_weight = 0; float overlap_ratio_limit; extern float confidence_limit; int input_resizable; char* custom_cpu_library; char* custom_cldnn; int performance_counter; static CNNType cnn_type; //static image **alphabet=NULL; //static network nets[MAX_LAYER_NUM]; //static layer layers[MAX_LAYER_NUM]; //static list *options[MAX_LAYER_NUM]; //static char *name_list[MAX_LAYER_NUM]; //static char **names[MAX_LAYER_NUM]; //static network net2; //static layer L2; //static list *options2; //static char *name_list2; //static char **names2; //static float nms[MAX_LAYER_NUM]; //static float nms2; //ini static char ppIniKeyValue[MAX_LAYER_NUM][MAX_SECTION_VARIABLE][50] = { 0 }; //http server parameters //static CNNType http_cnn_type; //static network http_nets[MAX_LAYER_NUM]; //static network http_net2; //static char **http_names[MAX_LAYER_NUM]; //static char **http_names2; //static image **http_alphabet; //static float http_nms[MAX_LAYER_NUM]; //static float http_nms2; //static float http_thresh; //static float http_hier_thresh; //static int http_dont_show; //static int http_ext_output; //static int http_save_labels; //static char *http_ip_address; //static char *http_mac_address; //static int http_http_port; //static int http_layer_count; //static char http_dataset_version; //static LicenseType http_licenseType; //static LicenseType http_advLicenseType; //static AuthFailStatusCode http_afsCode; //static size_t http_featureType; static size_t layerFeatureType[MAX_LAYER_NUM] = { 0 }; static size_t layerFeatureType2[MAX_LAYER_NUM] = { 0 }; //static char* layerUTF8Country[MAX_LAYER_NUM]; static char strLicenseType[MAX_MSG_LEN] = { 0 }; char strLicenseStatus[MAX_MSG_LEN] = { 0 }; char strUnlockingKey[MAX_MSG_LEN] = { 0 }; int bHttpServerThreadStart = 0; double http_license_fps; int http_sleep_interval = 2; int bPreloadHttpServerThreadStart = 0; //#ifdef GY_OS_WIN //static char msgText[MAX_MSG_LEN]; //#elif _DEBUG_AMBA //static char msgText[MAX_MSG_LEN]; //#endif int nIsCompatibleCPU = 0; int nIsCompatibleGPU = 0; int nIsCompatibleVPU = 0; int nIsHardwareOK = 1; size_t featureType; size_t featureType2; size_t advancedType; CPoint trafficLightPoint = { 0 }; int traffic_light_zone_width = 0; int traffic_light_zone_height = 0; LicenseType licenseType; AdvanceLicenseType advLicenseType; AuthFailStatusCode afsCode; HttpCode httpCode; MYBOOL activeDisplayDash; MYBOOL activeDisplayProperties; MYBOOL activePostNotification; MYBOOL activeSNMPPost; MYBOOL testPostNotification; char g_device_name[512] = { 0 }; int check_if_correct_mail = 0; int check_if_fe_fail = 0; int g_enable_person_for_metadata[MAX_DETECTION_ZONE] = { 0 }; //struct amba_content stAMBAcontent; int protect_set_record_process_note = 0; void set_record_process_note(char *process_note) { if (check_if_start_run_server == 1 && protect_set_record_process_note == 0) { protect_set_record_process_note = 1; memset(record_process_note[current_index_record], 0x00, sizeof(record_process_note[current_index_record])); snprintf(record_process_note[current_index_record], sizeof(record_process_note[current_index_record]), "%s", process_note); current_index_record++; if (current_index_record >= MAX_RECORD_PROCESS) { current_index_record = 0; } if (size_record_process_note < MAX_RECORD_PROCESS) { size_record_process_note++; } protect_set_record_process_note = 0; } } void record_process_note_write_to_log() { if (check_if_start_run_server == 0) { char temp_msg[8192] = { 0 }; for (int count_record = size_record_process_note - 1; count_record >= 0; count_record--) { int index_record = current_index_record - 1 - count_record; if (index_record < 0) { index_record += size_record_process_note; } if (count_record == 0) { char temp_temp_msg[8192] = { 0 }; snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s", record_process_note[index_record]); } else { if (count_record == size_record_process_note - 1) { char temp_temp_msg[8192] = { 0 }; snprintf(temp_temp_msg, sizeof(temp_temp_msg), "free:%d,%s,", get_free_mem_data(), record_process_note[index_record]); strcpy(temp_msg, temp_temp_msg); } else { char temp_temp_msg[8192] = { 0 }; snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s,", record_process_note[index_record]); strcat(temp_msg, temp_temp_msg); } } } write_to_logs_html(temp_msg, "record process", "ERROR", "Yes"); } } int get_check_if_correct_mail() { return check_if_correct_mail; } #ifdef GY_OS_NOVA void *thread_get_nova_driver(void *ptr) { pthread_detach(pthread_self()); setPthreadName("start nova driver"); usSleep(12000000); while (bHttpServerThreadStart) { start_nova_driver(); usSleep(3000000); } pthread_exit(NULL); } #endif void *thread_getimage(void *ptr) { pthread_detach(pthread_self()); setPthreadName("getimage"); while (bHttpServerThreadStart) { //printf("\n---------thread getimage start\n"); if (atoi(SystemSetting.getimage_encoder_id) - 1 >= 0) { get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id) - 1, 1); }else if(unlockingKeyInnoFR_success == 1){ get_snap_with_profile_id(0, 1); } //printf("\n---------thread getimage end\n"); usSleep(3000000); } pthread_exit(NULL); } void *thread_getimage_hd(void *ptr) { pthread_detach(pthread_self()); setPthreadName("getimage_hd"); while (bHttpServerThreadStart) { if (atoi(SystemSetting.getimage_encoder_id_HD) - 1 >= 0 && atoi(SystemSetting.getimage_encoder_id_HD) != atoi(SystemSetting.getimage_encoder_id)) { get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id_HD) - 1, 0); } usSleep(3000000); } pthread_exit(NULL); } void *run_http_server_thread(void *ptr) { //printf("[run http server thread]Pthread started and detached. No new addr.\n"); pthread_detach(pthread_self()); setPthreadName("run_http"); //#ifdef _DEBUG_AMBA //printf("\n[run_http_server_thread] start\n"); //#endif bHttpServerThreadStart = 1; while (bHttpServerThreadStart) { bHttpServerMainStart = 1; run_http_server("", zc, cnn_type/*, layer_count, http_nets, names, alphabet, nms*/, thresh, hier_thresh, dont_show, ext_output, save_labels, NULL, NULL, http_port, licenseType, advLicenseType, afsCode, layerFeatureType, strLicenseType); //printf("\n[run http server thread] in while bHttpServerThreadStart-1 bHttpServerThreadStart:%d\n", bHttpServerThreadStart); //printf("\n[run http server thread] in while bHttpServerThreadStart-2 :%d\n", bHttpServerThreadStart); //printf("\nerr_count: %u\n",err_count); //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); usSleep(1000); } //printf("\n[run http server thread] while out :%d\n", bHttpServerThreadStart); bHttpServerThreadStart = 0; bHttpServerMainStart = 0; //printf("\n-----------run http server thread:exit\n"); //20201014 - sophia add for restart pthread_exit(NULL); } extern int run_preload_http_server(int http_port); void *run_preload_http_server_thread(void *ptr) { pthread_detach(pthread_self()); setPthreadName("run_preload"); #if 1 bPreloadHttpServerThreadStart = 1; while (bPreloadHttpServerThreadStart) { bPreloadHttpServerMainStart = 1; #if 1 run_preload_http_server(http_port); #endif bPreloadHttpServerThreadStart = 0; //printf("\n**********************\n"); //printf("preload server close"); //printf("\n**********************\n"); usSleep(100000); } bPreloadHttpServerThreadStart = 0; bPreloadHttpServerMainStart = 0; #endif //20210617-Steven add for preload pthread_exit(NULL); } #ifdef GY_OS_V_SERIES #else void reset_counter(int index_counter, time_t now_time) { time_t ori_now_time = now_time; struct tm *nowTime = localtime(&now_time); int current_year = nowTime->tm_year + 1900; int current_month = nowTime->tm_mon + 1; int current_month_day = nowTime->tm_mday; int current_week_day = nowTime->tm_wday + 1; int current_hour = nowTime->tm_hour; int current_min = nowTime->tm_min; int current_sec = nowTime->tm_sec; if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 minute") == 0) { nowTime->tm_min = nowTime->tm_min + 1; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "5 minutes") == 0) { nowTime->tm_min = nowTime->tm_min + 5; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "30 minutes") == 0) { nowTime->tm_min = nowTime->tm_min + 30; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 hour") == 0) { nowTime->tm_hour = nowTime->tm_hour + 1; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 day") == 0) { nowTime->tm_mday = nowTime->tm_mday + 1; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 week") == 0) { nowTime->tm_mday = nowTime->tm_mday + 7; } else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 month") == 0) { nowTime->tm_mon = nowTime->tm_mon + 1; } time_t next_time = mktime(nowTime); int next_year = current_year; int next_month = current_month; int next_month_day = current_month_day; int next_week_day = current_week_day; int next_hour = current_hour; int next_min = current_min; int next_sec = current_sec; if (next_time != -1) { struct tm *nextTime = localtime(&next_time); next_year = nextTime->tm_year + 1900; next_month = nextTime->tm_mon + 1; next_month_day = nextTime->tm_mday; next_week_day = nextTime->tm_wday + 1; next_hour = nextTime->tm_hour; next_min = nextTime->tm_min; next_sec = nextTime->tm_sec; } else { next_time = ori_now_time; } struct tm * gmtTime = gmtime(&next_time); int gmt_year = gmtTime->tm_year + 1900; int gmt_month = gmtTime->tm_mon + 1; int gmt_month_day = gmtTime->tm_mday; int gmt_week_day = gmtTime->tm_wday + 1; int gmt_hour = gmtTime->tm_hour; int gmt_min = gmtTime->tm_min; int gmt_sec = gmtTime->tm_sec; eventCounterList[index_counter].reset_year = current_year; eventCounterList[index_counter].reset_month = current_month; eventCounterList[index_counter].reset_month_day = current_month_day; eventCounterList[index_counter].reset_week_day = current_week_day; eventCounterList[index_counter].reset_hour = current_hour; eventCounterList[index_counter].reset_min = current_min; eventCounterList[index_counter].reset_sec = current_sec; eventCounterList[index_counter].gmt_year = gmt_year; eventCounterList[index_counter].gmt_month = gmt_month; eventCounterList[index_counter].gmt_month_day = gmt_month_day; eventCounterList[index_counter].gmt_week_day = gmt_week_day; eventCounterList[index_counter].gmt_hour = gmt_hour; eventCounterList[index_counter].gmt_min = gmt_min; eventCounterList[index_counter].gmt_sec = gmt_sec; eventCounterList[index_counter].next_year = next_year; eventCounterList[index_counter].next_month = next_month; eventCounterList[index_counter].next_month_day = next_month_day; eventCounterList[index_counter].next_week_day = next_week_day; eventCounterList[index_counter].next_hour = next_hour; eventCounterList[index_counter].next_min = next_min; eventCounterList[index_counter].next_sec = next_sec; eventCounterList[index_counter].timetResetAt = ori_now_time; eventCounterList[index_counter].next_timetResetAt = next_time; time_t temp_next_time = next_time; time_t temp_gmt_time = mktime(gmtTime); if (temp_gmt_time != -1) { double dTime = 0.0; char sign_of_dtime[2] = { 0 }; if (temp_next_time > temp_gmt_time) { dTime = difftime(temp_next_time, temp_gmt_time); strcpy(sign_of_dtime,"+"); } else if (temp_next_time < temp_gmt_time) { dTime = difftime(temp_gmt_time, temp_next_time); strcpy(sign_of_dtime, "-"); } else { strcpy(sign_of_dtime, "+"); } int iHour = (int)(dTime / 60.0 / 60.0); int iMin = (int)((dTime - (double)iHour * 60.0 * 60.0) / 60.0); char ResetTime[50] = { 0 }; sprintf(ResetTime,"%02d:%02d:%02d%s%02d:%02d", gmt_hour, gmt_min, gmt_sec, sign_of_dtime, iHour, iMin); strcpy(eventCounterList[index_counter].ResetTime, ResetTime); } else { strcpy(eventCounterList[index_counter].ResetTime, ""); } eventCounterList[index_counter].counter_count = eventCounterList[index_counter].reset_value; eventCounterList[index_counter].already_reset = 1; //printf("\nreset time:%04d-%02d-%02dT%02d:%02d:%02d\n" //, eventCounterList[index_counter].reset_year //, eventCounterList[index_counter].reset_month //, eventCounterList[index_counter].reset_month_day //, eventCounterList[index_counter].reset_hour //, eventCounterList[index_counter].reset_min //, eventCounterList[index_counter].reset_sec //); //printf("\nnext time:%04d-%02d-%02dT%02d:%02d:%02d\n" // , eventCounterList[index_counter].next_year // , eventCounterList[index_counter].next_month // , eventCounterList[index_counter].next_month_day // , eventCounterList[index_counter].next_hour // , eventCounterList[index_counter].next_min // , eventCounterList[index_counter].next_sec //); } void set_counter_zone() { for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { eventCounterList[j].counter_zone = 0; } int tracking_channel_idx = 0; int base_zone = 1; for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { if (index_zone >= 1) { base_zone = base_zone * 2; } for (int trigger_idx = 0; trigger_idx < MAX_TRIGGER_EVENT; trigger_idx++) { if (viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].checked >= 1) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].detect_event_id); if (trigger_event_type == TRIGGER_GO_STRAIGHT || trigger_event_type == TRIGGER_QUEUING_VIOLATION) { char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].counter_name); int event_counter_num = StrSplit(Temp, eachEventCounter, ","); for (int index_event_counter = 0; index_event_counter < event_counter_num; index_event_counter++) { for (int index_event_list = 0; index_event_list < MAX_EVENT_COUNTERS; index_event_list++) { if (strlen(eachEventCounter[index_event_counter]) >= 1 && strcmp(eachEventCounter[index_event_counter], eventCounterList[index_event_list].counter_name) == 0) { eventCounterList[index_event_list].counter_zone += base_zone; break; } } } } break; } } } } int g_last_hour_for_counter_mail = -1; void run_counter_mail(char * mail_content,int mail_content_size) { if (strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") != 0 && strlen(SystemSetting.send_counter_at_specific_hour) >= 1) { time_t now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } struct tm *local_time = localtime(&now_time); int current_hour = local_time->tm_hour; if (g_last_hour_for_counter_mail == -1 || g_last_hour_for_counter_mail < current_hour || (g_last_hour_for_counter_mail == 23 && current_hour == 0)) { int object_hour = atoi(SystemSetting.send_counter_at_specific_hour); if (current_hour == object_hour) { if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0)) { QueueInfo q_info = { 0 }; q_info.image_buff_size = 0; memcpy(q_info.content, mail_content, mail_content_size); q_info.content[mail_content_size] = '\0'; strcpy(q_info.post_url, "post_to_mail"); if (strcmp(SystemSetting.language, "zh_tw") == 0) strcpy(q_info.behavior_desc, "\xe8\xa8\x88\xe6\x95\xb8\xe5\x99\xa8\xe6\x95\xb8\xe5\x80\xbc");//計數器數值 else//en_gb strcpy(q_info.behavior_desc, "Counter value");//計數器數值 QueuePush(q_info, _POST_NOTIFICATION); pthread_mutex_lock(&mutex_reset_counter); for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { reset_counter(j, now_time); } pthread_mutex_unlock(&mutex_reset_counter); g_last_hour_for_counter_mail = current_hour; } } } } } #endif //原本名稱是check_http_socket_thread,現在改成run_event_counter_thread void *run_event_counter_thread(void *ptr) { pthread_detach(pthread_self()); setPthreadName("run_counter"); #ifdef GY_OS_V_SERIES #else //printf("\n[run event counter thread]pthread create\n"); time_t now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } struct tm *nowTime = localtime(&now_time); //int reset_year = nowTime->tm_year + 1900; int reset_month = nowTime->tm_mon + 1; int reset_month_day = nowTime->tm_mday; int reset_week_day = nowTime->tm_wday + 1; int reset_hour = nowTime->tm_hour; int reset_min = nowTime->tm_min; //int reset_sec = nowTime->tm_sec; //struct tm * gmtTime = gmtime(&now_time); //int gmt_year = gmtTime->tm_year + 1900; //int gmt_month = gmtTime->tm_mon + 1; //int gmt_month_day = gmtTime->tm_mday; //int gmt_week_day = gmtTime->tm_wday + 1; //int gmt_hour = gmtTime->tm_hour; //int gmt_min = gmtTime->tm_min; //int gmt_sec = gmtTime->tm_sec; for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { reset_counter(j, now_time); } set_counter_zone(); while (bHttpServerThreadStart) { //printf("\n-----run event counter thread start\n"); //if (strcmp(eventCounterList[j].enable_reset_only_cloud, "No") == 0) if (//(strcmp(SystemSetting.cloud_enable_notification, "No") == 0) && (strcmp(SystemSetting.enable_email_notification, "No") == 0 || (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && Get_mail_post_interval() == -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0)) ) { set_record_process_note("counter_start"); now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } nowTime = localtime(&now_time); //int current_year = nowTime->tm_year + 1900; int current_month = nowTime->tm_mon + 1; int current_month_day = nowTime->tm_mday; int current_week_day = nowTime->tm_wday + 1; int current_hour = nowTime->tm_hour; int current_min = nowTime->tm_min; int current_sec = nowTime->tm_sec; #if 1 pthread_mutex_lock(&mutex_reset_counter); for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { //reset_year = eventCounterList[j].reset_year; reset_month = eventCounterList[j].reset_month; reset_month_day = eventCounterList[j].reset_month_day; reset_week_day = eventCounterList[j].reset_week_day; reset_hour = eventCounterList[j].reset_hour; reset_min = eventCounterList[j].reset_min; //reset_sec = eventCounterList[j].reset_sec; //gmt_year = eventCounterList[j].gmt_year; //gmt_month = eventCounterList[j].gmt_month; //gmt_month_day = eventCounterList[j].gmt_month_day; //gmt_week_day = eventCounterList[j].gmt_week_day; //gmt_hour = eventCounterList[j].gmt_hour; //gmt_min = eventCounterList[j].gmt_min; //gmt_sec = eventCounterList[j].gmt_sec; if (strcmp(eventCounterList[j].enable_reset_time_interval, "Yes") == 0) { if (strcmp(eventCounterList[j].reset_time_interval, "1 minute") == 0) { eventCounterList[j].dwell_time = current_sec; strcpy(eventCounterList[j].dwell_unit, "sec"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1S"); if (eventCounterList[j].already_reset == 1 && current_sec >= 30) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_sec < 30 && current_min != reset_min) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "5 minutes") == 0) { eventCounterList[j].dwell_time = current_min; strcpy(eventCounterList[j].dwell_unit, "min"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); if (eventCounterList[j].already_reset == 1 && current_min % 5 != 0) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_min % 5 == 0 && current_min != reset_min) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "30 minutes") == 0) { eventCounterList[j].dwell_time = current_min; strcpy(eventCounterList[j].dwell_unit, "min"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); if (eventCounterList[j].already_reset == 1 && current_min % 30 != 0) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_min % 30 == 0 && current_min != reset_min) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "1 hour") == 0) { eventCounterList[j].dwell_time = current_min; strcpy(eventCounterList[j].dwell_unit, "min"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); if (eventCounterList[j].already_reset == 1 && current_min != 0) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_min == 0 && current_hour != reset_hour) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "1 day") == 0) { eventCounterList[j].dwell_time = current_hour; strcpy(eventCounterList[j].dwell_unit, "hour"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1H"); if (eventCounterList[j].already_reset == 1 && current_hour % 24 != 0) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_hour % 24 == 0 && current_week_day != reset_week_day) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "1 week") == 0) { eventCounterList[j].dwell_time = current_week_day; strcpy(eventCounterList[j].dwell_unit, "wday"); strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); if (eventCounterList[j].already_reset == 1 && current_week_day != 1) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_month == 1 && current_month_day != reset_month_day) { reset_counter(j, now_time); } } else if (strcmp(eventCounterList[j].reset_time_interval, "1 month") == 0) { eventCounterList[j].dwell_time = current_month_day; strcpy(eventCounterList[j].dwell_unit, "mday"); strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); if (eventCounterList[j].already_reset == 1 && current_month_day != 1) { eventCounterList[j].already_reset = 0; } if (eventCounterList[j].already_reset == 0 && current_month_day == 1 && current_month != reset_month) { reset_counter(j, now_time); } } else { eventCounterList[j].dwell_time = current_min; strcpy(eventCounterList[j].dwell_unit, "min"); strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); } } } pthread_mutex_unlock(&mutex_reset_counter); #endif set_record_process_note("counter_end"); usSleep(1000000); } else { usSleep(5000000); } //printf("\n-----run event counter thread end\n"); } //printf("\n[run event counter thread] end\n"); #endif pthread_exit(NULL); } struct timeval currtime_control_alarm_gpio; static long last_ms_control_alarm_gpio = 0; //post the notification back to the origianl socket void *run_post_notification_thread(void *ptr) { //printf("\n[run post notification thread]pthread create\n"); pthread_detach(pthread_self()); setPthreadName("run_post"); QueueInfo q_info_copy = { 0 }; char sendLargeBuffer[BUFSIZE_V2] = { 0 }; pthread_mutex_lock(&mutex_curl); if (g_http_handle != NULL) { curl_easy_cleanup(g_http_handle); curl_global_cleanup(); curl_global_init(CURL_GLOBAL_SSL); g_http_handle = NULL; g_http_handle = curl_easy_init(); } pthread_mutex_unlock(&mutex_curl); int count_g_http_handle = 0; unsigned int count_to_refresh_smtp_service = 0; int count_delay = 0; int count_initial_global_curl = 0; #ifdef GY_OS_AMBA int count_ptz = 0; #endif while (bHttpServerThreadStart) { //printf("\n-----run post notification start\n"); set_record_process_note("run_post_start"); //printf("out que size = %d \n", QueueSize(_POST_NOTIFICATION)); if (!QueueIsEmpty(_POST_NOTIFICATION) && QueueSize(_POST_NOTIFICATION) >= 1) { //printf("\n-----------QueueSize(_POST_NOTIFICATION) = %d \n", QueueSize(_POST_NOTIFICATION)); //測試 #if 1 pthread_mutex_lock(&mutex_post_notification_pop); q_info_copy = QueueFront(_POST_NOTIFICATION); QueuePop(_POST_NOTIFICATION); pthread_mutex_unlock(&mutex_post_notification_pop); memset(sendLargeBuffer, 0x00, BUFSIZE_V2); //推播AA #if 1 //以下為推播----------- if (strcmp(q_info_copy.post_url,"post_to_cloud")==0) { //printf("\n----------------\n"); //printf("\nq_info_copy.cloud_aiengine:%s\n", q_info_copy.cloud_aiengine); //printf("\n----------------\n"); char behavior_ID_temp[50] = {0}; sprintf(behavior_ID_temp,"%d", q_info_copy.behavior_ID); char behavior_ID_16_temp[50] = { 0 }; sprintf(behavior_ID_16_temp, "0x%08X", q_info_copy.behavior_ID); //printf("\n-------%s\n", behavior_ID_16_temp); /* printf("\n----------------\n"); printf("\nbehavior_name:%s,behavior_ID_temp:%s,behavior_desc:%s\n", q_info_copy.behavior_name, behavior_ID_temp, q_info_copy.behavior_desc); printf("\n----------------\n");*/ //if 0 No PNS_Send_Multipart_POST 最大增長162,000byte #if 1 char returned_msg[MEMORY_SIZE] = { 0 }; PNS_Send_Multipart_POST(q_info_copy.cloud_aiengine, q_info_copy.behavior_name, behavior_ID_temp, behavior_ID_16_temp, q_info_copy.behavior_desc, SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/" , returned_msg, q_info_copy.image_buff, q_info_copy.image_buff_size, q_info_copy.rawtime); strcpy(SystemSetting.cloud_statue,returned_msg); //printf("\n------------Segmentation fault:%d\n",1); //怕PNS_Send_Multipart_POST的記憶體洩漏太多,定期清理,清理完後重新初始化 //curl_global_cleanup(); //curl_global_init(CURL_GLOBAL_SSL); #endif } else if (strcmp(q_info_copy.post_url, "post_to_mail") == 0) { //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); #if defined GY_OS_AMBA || defined GY_OS_NOVA SendMailEventCondition(q_info_copy.behavior_desc, q_info_copy.content, q_info_copy.image_buff, q_info_copy.image_buff_size); #endif //curl_global_cleanup(); //curl_global_init(CURL_GLOBAL_SSL); } else if (strcmp(q_info_copy.post_url, "curl_to_ftp") == 0) { //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); //#if defined GY_OS_AMBA net_curl_ftp_post_push_info_attached_image(q_info_copy.image_buff, q_info_copy.image_buff_size); //#endif //curl_global_cleanup(); //curl_global_init(CURL_GLOBAL_SSL); } #if defined GY_OS_AMBA else if (strlen(q_info_copy.snmp_host_ip) >= 1) { //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); SetSNMPRequest(&q_info_copy); //curl_global_cleanup(); //curl_global_init(CURL_GLOBAL_SSL); } #endif else { if (strlen(q_info_copy.post_url) >= 1) { char *temp_post_url = StrReplace(q_info_copy.post_url, "space", "%20"); strcpy(q_info_copy.post_url, temp_post_url); if (temp_post_url != NULL) { free(temp_post_url); temp_post_url = NULL; } //printf("\n----------q_info_copy.post_url:%s\n", q_info_copy.post_url); pthread_mutex_lock(&mutex_set_http_request); #ifdef GY_OS_NOVA if (strcmp(q_info_copy.host_name, "127.0.0.1") != 0 && strcmp(q_info_copy.host_name, "localhost") != 0) { SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); } else { SetHttpRequest_sock(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); } #endif #ifdef GY_OS_AMBA SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); #endif pthread_mutex_unlock(&mutex_set_http_request); } } //以上為推播----------- #endif //printf("\n------------Segmentation fault:%d\n", 2); #endif } #ifdef GY_OS_AMBA if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) { if (IsTracking() == 1) { if (count_ptz % 15 == 0) { count_ptz = 0; UpdatePTZIPcamSetting(); } else if (count_ptz % 15 == 4) { UpdatePTZCurPos(); } else if (count_ptz % 15 == 7) { update_PTZ_limits(); } else if (count_ptz % 15 == 10) { UpdateRecoveryTime(); } } else { if (count_ptz % 40 == 0) { count_ptz = 0; UpdatePTZIPcamSetting(); } } count_ptz++; } #endif if (count_delay % 200 == 0) { count_delay = 0; update_system_time(); } count_delay++; if (count_initial_global_curl % 15 == 0) { count_initial_global_curl = 0; pthread_mutex_lock(&mutex_curl); if (g_http_handle != NULL) { curl_easy_cleanup(g_http_handle); curl_global_cleanup(); curl_global_init(CURL_GLOBAL_SSL); g_http_handle = NULL; g_http_handle = curl_easy_init(); } else { curl_global_cleanup(); curl_global_init(CURL_GLOBAL_SSL); g_http_handle = curl_easy_init(); } pthread_mutex_unlock(&mutex_curl); } count_initial_global_curl++; if (g_IsSDK_3_0 == 0) { if (count_to_refresh_smtp_service % MAX_COUNT_TO_REFRESH_SMTP_SERVICE * 5 == 0) { count_to_refresh_smtp_service = 0; copy_ipcam_smtp_service_to_gynet(); } count_to_refresh_smtp_service++; } if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { if (strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { gettimeofday(&currtime_control_alarm_gpio, NULL); long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); if (last_ms_control_alarm_gpio == 0) { last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; } if (current_ms_control_alarm_gpio >= last_ms_control_alarm_gpio + atoi(viewChannelData[0].dwell_lpr_upon_triggered) * 1000) { copy_control_io_to_gynet(); last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; } } } if (count_g_http_handle >= 5) { //printf("\n------------Segmentation fault:%d\n", 3); count_g_http_handle = 0; pthread_mutex_lock(&mutex_curl); if (g_http_handle != NULL) { curl_easy_cleanup(g_http_handle); //curl_global_cleanup(); //curl_global_init(CURL_GLOBAL_SSL); g_http_handle = NULL; g_http_handle = curl_easy_init(); } else { g_http_handle = curl_easy_init(); } pthread_mutex_unlock(&mutex_curl); //printf("\n------------Segmentation fault:%d\n", 4); } else if (g_http_handle == NULL) { count_g_http_handle = 0; pthread_mutex_lock(&mutex_curl); if (g_http_handle == NULL) { g_http_handle = curl_easy_init(); } pthread_mutex_unlock(&mutex_curl); } count_g_http_handle++; set_record_process_note("run_post_end"); //printf("\n-----run post notification end\n"); usSleep(SLEEP_QUEUE_POP_POST*1000); } pthread_mutex_lock(&mutex_curl); curl_easy_cleanup(g_http_handle); g_http_handle = NULL; pthread_mutex_unlock(&mutex_curl); pthread_mutex_lock(&mutex_post_notification_pop); QueueClear(_POST_NOTIFICATION); pthread_mutex_unlock(&mutex_post_notification_pop); //printf("\n-------[run post notification thread] pthread_exit\n"); pthread_exit(NULL); } //post the getalarmmotion back to the origianl socket static char MultiPartBuffer[CONTENT_BUFSIZE] = { 0 }; static char contentBuffer[CONTENT_BUFSIZE] = { 0 }; static char contentBuffer_websocket[CONTENT_BUFSIZE] = { 0 }; void *run_getalarmmotion_thread(void *ptr) { //printf("\n[run getalarmmotion thread]pthread create\n"); pthread_detach(pthread_self()); setPthreadName("run_getalarm"); char sendBuffer[ALMBUFSIZE] = {0}; //int nmlocsendBufferSize = 1024; //int PAD_BUFFERSIZE = 512; char l_send_buf[ALMBUFSIZE] = { 0 }; UNIX_MESSAGE_V1_T l_unix_msg; int l_packet_len = 0; char tempStr[MAX_MSG_LEN] = { 0 }; QueueInfo q_info_copy = { 0 }; while (bHttpServerThreadStart) { //printf("\n getalarmmotion out que size = %d \n", QueueSize(_GETALARMMOTION)); if (!QueueIsEmpty(_GETALARMMOTION)) { //printf("\n-------run getalarmmotion start\n"); set_record_process_note("run_getalarm_start"); //memset(sendBuffer, 0x00, sizeof(sendBuffer)); //20201104 sophia add memset(MultiPartBuffer, 0x00, sizeof(MultiPartBuffer)); memset(contentBuffer, 0x00, sizeof(contentBuffer)); memset(contentBuffer_websocket, 0x00, sizeof(contentBuffer_websocket)); memset(websocket_alarm, 0x00, sizeof(websocket_alarm)); pthread_mutex_lock(&mutex_getalarmmotion); q_info_copy = QueueFront(_GETALARMMOTION); QueuePop(_GETALARMMOTION); pthread_mutex_unlock(&mutex_getalarmmotion); time_t now = time(0); //struct tm tm = *gmtime(&now); struct tm tm = *localtime(&now); struct timeval curTime; gettimeofday(&curTime, NULL); strcpy(contentBuffer, "CamTime: "); memset(tempStr, 0x00, sizeof(tempStr)); strftime(tempStr, sizeof(tempStr) - 1, "%Y-%m-%d %H:%M:%S", &tm); strcat(contentBuffer, tempStr); int milli = curTime.tv_usec / 1000; memset(tempStr, 0x00, sizeof(tempStr)); snprintf(tempStr, sizeof(tempStr) - 1, " %s%d", "ms:", milli); strcat(contentBuffer, tempStr); strcat(contentBuffer, "\r\n"); strcat(contentBuffer, "\r\n"); strcpy(contentBuffer_websocket, contentBuffer); strcat(contentBuffer, q_info_copy.content); strcat(contentBuffer, "\r\n"); strcat(contentBuffer, "\r\n"); strcat(contentBuffer_websocket, q_info_copy.content_no_base64_image); strcat(contentBuffer_websocket, "\r\n"); strcat(contentBuffer_websocket, "\r\n"); //strcat(contentBuffer, "--myboundary\r\n"); //strcat(contentBuffer, "\r\n"); //修正成g_IsRadarDevice和g_IsToFDevice支援content和content_no_base64_image,因為websocket的getalarmmotion要走no_base64_image。 //而一般getalarmmotion,則是使用content。 //memcpy(websocket_alarm, contentBuffer, strlen(contentBuffer)); memcpy(websocket_alarm, contentBuffer_websocket, strlen(contentBuffer_websocket)); long int contentLen_buffer = strlen(q_info_copy.content); strcpy(MultiPartBuffer, "--myboundary\r\n"); //strcat(MultiPartBuffer, "\r\n"); //strcat(MultiPartBuffer, "Host: localhost:8592\r\n"); //strcat(MultiPartBuffer, "Connection: keep-alive\r\n"); //strcat(MultiPartBuffer, "Pragma: no-cache\r\n"); //strcat(MultiPartBuffer, "Cache-Control: no-cache"); //strcat(MultiPartBuffer, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36\r\n"); //strcat(MultiPartBuffer, "Accept: */*\r\n"); //strcat(MultiPartBuffer, "Referer: \r\n"); //strcat(MultiPartBuffer, "Accept-Encoding: gzip, deflate\r\n"); //strcat(MultiPartBuffer, "Accept-Language: zh-TW,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n"); //strcat(MultiPartBuffer, "Cookie: \r\n"); //strcat(MultiPartBuffer, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundarylilinboundary\r\n"); strcat(MultiPartBuffer, "Content-Type: text/plain\r\n"); //strcat(MultiPartBuffer, "Content-Type: text/plain; charset=utf-8;\r\n"); memset(tempStr, 0x00, sizeof(tempStr)); snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", contentLen_buffer); strcat(MultiPartBuffer, tempStr); strcat(MultiPartBuffer, "\r\n"); //strcat(MultiPartBuffer, "Content-Type: text/html; charset=utf-8\r\n"); strcat(MultiPartBuffer, contentBuffer); //getalarmmotion doesn't need to append --myboundary END size_t MultiPartLen = strlen(MultiPartBuffer); for (int i = 0; i < MAX_CLIENT_SOCKET; i++) { int sock_idx = i; if (socketRecords[i].used == 1 && socketRecords[i].sock != -1 && socketRecords[i].isGetAlarmMotion) { //memset(sendBuffer, 0x00, nmlocsendBufferSize); //20201104 sophia add ////檢查是否重複迴圈,如果是,則關閉第一次的alarm。 //printf("\n[run getalarmmotion thread] socketRecords[%d].sock:%ld contentLen_buffer:%d MultiPartLen:%d\n", i, socketRecords[i].sock, contentLen_buffer, MultiPartLen); if (socketRecords[i].isUdpSocket == TRUE) { //printf("\n----------%d\n", strlen(q_info_copy.udp_aiengine)); ///getalarmmotion looping #if 1 if(strlen(q_info_copy.udp_aiengine) >= 1 && strlen(q_info_copy.udp_aiengine) <= 15000) { memset(sendBuffer, 0x00, sizeof(sendBuffer)); unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; //type unsigned int contentlen = strlen(q_info_copy.udp_aiengine); //len size_t sendBufferSize = 0; //================================================================ //get sendBuffer //if sendBuffer size too small, refresh a new one //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) { //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; //memset(sendBuffer, 0x00, nmlocsendBufferSize); } //start code { strcat(sendBuffer, "UMV01"); sendBufferSize = sendBufferSize + 5; } //type { memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); sendBufferSize = sendBufferSize + 4; } //len { memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); sendBufferSize = sendBufferSize + 4; } //#ifdef _DEBUG_AMBA /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); for (int pp = 0;pp < sendBufferSize;pp++) { printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); }*/ //#endif //content memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); sendBufferSize = sendBufferSize + contentlen; #ifdef _DEBUG_AMBA printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); #endif //================================================================ //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) { ALMQueueInfo alm_q_info = { 0 }; memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); alm_q_info.nSize = sendBufferSize + 1; alm_q_info.infoType = 1; //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if(ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) ALMQueuePush(alm_q_info, sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); } /*#ifdef _DEBUG_AMBA for (int bb = 0;bb < 15;bb++) { printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); } printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); #endif*/ } } else if(strlen(q_info_copy.udp_aiengine) > 15000 && strlen(q_info_copy.udp_aiengine) <= 30000) { memset(sendBuffer, 0x00, sizeof(sendBuffer)); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 1); /////////////////start unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; unsigned int UDP_PACKAGE_TYPE = 0x0000; //start type 0x0000 body type 0x0001 end type 0x0002 unsigned int contentlen = 15000; //len size_t sendBufferSize = 0; //================================================================ //get sendBuffer //if sendBuffer size too small, refresh a new one //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 2); //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) { //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; //memset(sendBuffer, 0x00, ALMBUFSIZE); } //start code { strcat(sendBuffer, "UMV02"); sendBufferSize = sendBufferSize + 5; } //type { memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); sendBufferSize = sendBufferSize + 4; } //type { memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); sendBufferSize = sendBufferSize + 4; } //len { memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); sendBufferSize = sendBufferSize + 4; } //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); //#ifdef _DEBUG_AMBA /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); for (int pp = 0;pp < sendBufferSize;pp++) { printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); }*/ //#endif //content memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); sendBufferSize = sendBufferSize + contentlen; #ifdef _DEBUG_AMBA printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); #endif //================================================================ //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 4); ALMQueueInfo alm_q_info_1 = { 0 }; //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) { memset(alm_q_info_1.pszContent, 0x00, sendBufferSize + 1); memcpy(alm_q_info_1.pszContent, sendBuffer, sendBufferSize + 1); //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); alm_q_info_1.nSize = sendBufferSize + 1; alm_q_info_1.infoType = 1; //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); /*#ifdef _DEBUG_AMBA for (int bb = 0;bb < 15;bb++) { printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); } printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); #endif*/ } //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 5); /////////////////end UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; UDP_PACKAGE_TYPE = 0x0002; //start type 0x0000 body type 0x0001 end type 0x0002 contentlen = strlen(q_info_copy.udp_aiengine) - 15000; //len sendBufferSize = 0; //================================================================ //get sendBuffer //if sendBuffer size too small, refresh a new one //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 6); //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) { //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; //memset(sendBuffer, 0x00, ALMBUFSIZE); } //start code { strcat(sendBuffer, "UMV02"); sendBufferSize = sendBufferSize + 5; } //type { memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); sendBufferSize = sendBufferSize + 4; } //type { memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); sendBufferSize = sendBufferSize + 4; } //len { memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); sendBufferSize = sendBufferSize + 4; } //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 7); //#ifdef _DEBUG_AMBA /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); for (int pp = 0;pp < sendBufferSize;pp++) { printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); }*/ //#endif //content memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine + 15000, contentlen); sendBufferSize = sendBufferSize + contentlen; #ifdef _DEBUG_AMBA printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); #endif //================================================================ //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 8); //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) { ALMQueueInfo alm_q_info_2 = { 0 }; memset(alm_q_info_2.pszContent, 0x00, sendBufferSize + 1); memcpy(alm_q_info_2.pszContent, sendBuffer, sendBufferSize + 1); //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); alm_q_info_2.nSize = sendBufferSize + 1; alm_q_info_2.infoType = 1; //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) { ALMQueuePush(alm_q_info_1, sock_idx); ALMQueuePush(alm_q_info_2, sock_idx); } pthread_mutex_unlock(&mutex_alm); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); } /*#ifdef _DEBUG_AMBA for (int bb = 0;bb < 15;bb++) { printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); } printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); #endif*/ //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 9); } } #endif //getalarmmotion cloud if(strcmp(SystemSetting.enable_cloud_v2,"Yes")==0 && strcmp(q_info_copy.post_url,"cloud_v2")==0 && strlen(q_info_copy.cloud_v2_aiengine)>=1) { memset(sendBuffer, 0x00, sizeof(sendBuffer)); unsigned int UNIX_MESSAGE_TYPE_POST_CLOUD = 0x0001; //type unsigned int contentlen = strlen(q_info_copy.cloud_v2_aiengine); //len //printf("\n-----------q_info_copy.cloud_v2_aiengine:%s\n", q_info_copy.cloud_v2_aiengine); size_t sendBufferSize = 0; //================================================================ //get sendBuffer //if sendBuffer size too small, refresh a new one //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) { //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; //memset(sendBuffer, 0x00, nmlocsendBufferSize); } //start code { strcat(sendBuffer, "UMV01"); sendBufferSize = sendBufferSize + 5; } //type { memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_POST_CLOUD, sizeof(UNIX_MESSAGE_TYPE_POST_CLOUD)); sendBufferSize = sendBufferSize + 4; } //len { memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); sendBufferSize = sendBufferSize + 4; } //#ifdef _DEBUG_AMBA /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); for (int pp = 0;pp < sendBufferSize;pp++) { printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); }*/ //#endif //content memcpy(sendBuffer + sendBufferSize, q_info_copy.cloud_v2_aiengine, contentlen); sendBufferSize = sendBufferSize + contentlen; #ifdef _DEBUG_AMBA printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); #endif //================================================================ //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) { ALMQueueInfo alm_q_info = { 0 }; memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); alm_q_info.nSize = sendBufferSize + 1; alm_q_info.infoType = 2; //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) ALMQueuePush(alm_q_info, sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); } /*#ifdef _DEBUG_AMBA for (int bb = 0;bb < 15;bb++) { printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); } printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); #endif*/ } } if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) { //send_count = 0; //printf("UDP 0003 \n"); memset(&l_unix_msg, 0, sizeof(UNIX_MESSAGE_V1_T)); l_unix_msg.type = UNIX_MESSAGE_TYPE_RTSP_META; { //printf("onvif lx, ty, rx, by = %.2f, %.2f, %.2f, %.2f \n", q_info_copy.onvif_object[0].left_x, q_info_copy.onvif_object[0].top_y, q_info_copy.onvif_object[0].right_x, q_info_copy.onvif_object[0].bottom_y); //printf("onvif cx, cy= %.2f, %.2f \n", q_info_copy.onvif_object[0].center_x, q_info_copy.onvif_object[0].center_y); create_onvif_packet(&l_unix_msg, q_info_copy.onvif_object, q_info_copy.onvif_object_num,q_info_copy.onvif_counter); //printf("l_unix_msg.buf = %s \n", l_unix_msg.buf); } l_unix_msg.length = strlen(l_unix_msg.buf); if (l_unix_msg.length >= 1) { //printf("[%s]\n", l_unix_msg.buf); l_packet_len = l_unix_msg.length + sizeof(unsigned int) + sizeof(unsigned int); memset(l_send_buf, 0, sizeof(l_send_buf)); memcpy(l_send_buf, UNIX_MESSAGE_V1, sizeof(UNIX_MESSAGE_V1)); memcpy(l_send_buf + sizeof(UNIX_MESSAGE_V1) - 1, (char *)&l_unix_msg, l_packet_len); l_packet_len += sizeof(UNIX_MESSAGE_V1); { ALMQueueInfo alm_q_info = { 0 }; memset(alm_q_info.pszContent, 0x00, l_packet_len + 1); memcpy(alm_q_info.pszContent, l_send_buf, l_packet_len + 1); //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); alm_q_info.nSize = l_packet_len + 1; alm_q_info.infoType = 6; //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) ALMQueuePush(alm_q_info, sock_idx); pthread_mutex_unlock(&mutex_alm); } } } } } else if(socketRecords[i].isWebSocketConnect == TRUE) { //printf("\n------ALMQueueSize(sock_idx):%d\n", ALMQueueSize(sock_idx)); //printf("\n[run getalarmmotion thread] MultiPartLen:%d\n", MultiPartLen); //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) if(strlen(websocket_alarm) >= 1) { ALMQueueInfo alm_q_info = { 0 }; //strcpy(alm_q_info.pszContent,MultiPartBuffer); strcpy(alm_q_info.pszContent, websocket_alarm); //strcpy(alm_q_info.websocket_content, websocket_alarm); //alm_q_info.nSize = strlen(alm_q_info.pszContent); alm_q_info.nSize = MultiPartLen; alm_q_info.infoType = 5; //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) ALMQueuePush(alm_q_info, sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); } } } else if(socketRecords[i].isGetAlarmMotion == TRUE) { if (strlen(MultiPartBuffer) >= 1) { ALMQueueInfo alm_q_info = { 0 }; strcpy(alm_q_info.pszContent, MultiPartBuffer); //strcpy(alm_q_info.websocket_content, websocket_alarm); //alm_q_info.nSize = strlen(alm_q_info.pszContent); alm_q_info.nSize = MultiPartLen; alm_q_info.infoType = 5; //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); if (AI_fps >= 1) { pthread_mutex_lock(&mutex_alm); if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) ALMQueuePush(alm_q_info, sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); } } } } } set_record_process_note("run_getalarm_end"); usSleep(10000); //printf("\n-------run getalarmmotion end\n"); } else { usSleep(10000); } } pthread_mutex_lock(&mutex_getalarmmotion); QueueClear(_GETALARMMOTION); pthread_mutex_unlock(&mutex_getalarmmotion); //printf("[run getalarmmotion thread] pthread_exit\n"); pthread_exit(NULL); } #if 1 void *run_send_udp_thread(void *ptr) { pthread_detach(pthread_self()); setPthreadName("run_udp"); //printf("\n[run_send_udp_thread]pthread create\n"); //printf("\n[run_send_udp_thread]no new address\n"); #ifdef _DEBUG_AMBA printf("\n[run_send_udp_thread] start\n"); #endif //_DEBUG_AMBA //int thread_id = (int)ptr; int l_sockfd; struct sockaddr_un serveraddr; char path[64] = "/tmp/udp_unix"; // Creating socket file descriptor bzero(&serveraddr, sizeof(serveraddr)); //memset(&serveraddr, 0, sizeof(serveraddr)); serveraddr.sun_family = AF_UNIX; strcpy(serveraddr.sun_path, path); l_sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); if (l_sockfd < 0) { printf("\nudp socket creation failed\n"); printf("\n[run_send_udp_thread] udp socket creation failed\n"); } else { //20210714 ADD int reuse = 1; setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); int qlen = 5; setsockopt(l_sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); for (int i = 0; i < MAX_CLIENT_SOCKET; i++) { if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) { socketRecords[i].sock = l_sockfd; //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); //socketRecords[i].thread_id = 0; socketRecords[i].channel_id = -1; //socketRecords[i].last_recv_time = time(0); //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; socketRecords[i].isGetAlarmMotion = TRUE; //socketRecords[i].isFirstAlarmMotion = FALSE; socketRecords[i].isUdpSocket = TRUE; socketRecords[i].isWebSocketConnect = FALSE; socketRecords[i].isNvrRequest = 0; socketRecords[i].isCredentialRequest = 0; socketRecords[i].debug_type = 2; #if defined GY_OS_AMBA //socketRecords[i].iIsAIRelay = 0; #endif //printf("\n(%d) [run_send_udp_thread] socketRecords[%d].sock:%d\n", l_sockfd, i, socketRecords[i].sock); socketRecords[i].used = 1; break; } } while (bHttpServerThreadStart) { //printf("\n----------run send udp thread start\n"); int sock_idx = -1; for (int i = 0; i < MAX_CLIENT_SOCKET; i++) { //if (socketRecord_ALM[i].sock == l_sockfd) { //sock_idx = i; //} if (socketRecords[i].used == 1) { if (socketRecords[i].sock == l_sockfd) { socketRecords[i].debug_type = 2; //socketRecords[i].last_recv_time = time(0); //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; sock_idx = i; break; } } } #ifdef _DEBUG_AMBA printf("\n(%d) [run_send_udp_thread] sock_idx:%d\n", l_sockfd, sock_idx); #endif if (sock_idx >= 0) { pthread_mutex_lock(&mutex_alm); int len = ALMQueueSize(sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\n(%d) [run_send_udp_thread] ALMQueueSize:%d\n", l_sockfd, len); if (len > 0) { set_record_process_note("udp_start"); //printf("\nKKKKKKKKK 1\n"); int l_ret = 1; for (int index_len = 0; index_len < len; index_len++) { pthread_mutex_lock(&mutex_alm); ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); int dupstr_len = alm_q_info.nSize; //char dupstr[ALMBUFSIZE] = { 0 }; //memset(dupstr, 0x00, dupstr_len); //memcpy(dupstr, alm_q_info.pszContent, dupstr_len); ALMQueuePop(sock_idx); pthread_mutex_unlock(&mutex_alm); //printf("\nKKKKKKKKK 2\n"); if (dupstr_len >= 1) { //printf("\nKKKKKKKKK 3\n"); int l_len = strlen(serveraddr.sun_path) + sizeof(serveraddr.sun_family); l_ret = sendto(l_sockfd, alm_q_info.pszContent, dupstr_len, 0, (struct sockaddr*)&serveraddr, l_len); if (l_ret <= 0) { printf("\n(%d) [run_send_udp_thread] send error\n", l_sockfd); printf("\nsendto error\n"); if (alm_q_info.infoType == 2) { memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP fail."); write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); } else if (alm_q_info.infoType == 3) { memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP fail."); write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); } //closesocket(l_sockfd); break; } else { if (alm_q_info.infoType == 2) { memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP OK."); write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); } else if (alm_q_info.infoType == 3) { memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP OK."); write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); } } } else { if (alm_q_info.infoType == 2) { memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: nSize could not be zero."); write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); } else if (alm_q_info.infoType == 3) { memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: nSize could not be zero."); write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); } } if (index_len < len - 1) { usSleep(10000); } } set_record_process_note("udp_end"); if (l_ret <= 0) { break; } usSleep(10000); } else { usSleep(10000); } } else { usSleep(1000000); } //printf("\n----------run send udp thread end\n"); } closesocket(l_sockfd); for (int i = 0; i < MAX_CLIENT_SOCKET; i++) { if (socketRecords[i].used == 1 && socketRecords[i].sock == l_sockfd) { socketRecords[i].sock = -1; //socketRecords[i].thread_id = 0; socketRecords[i].channel_id = -1; //socketRecords[i].last_recv_time = time(0); //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; socketRecords[i].isGetAlarmMotion = FALSE; //socketRecords[i].isFirstAlarmMotion = FALSE; socketRecords[i].isWebSocketConnect = FALSE; socketRecords[i].isUdpSocket = FALSE; socketRecords[i].isNvrRequest = 0; socketRecords[i].isCredentialRequest = 0; socketRecords[i].debug_type = 0; #if defined GY_OS_AMBA //socketRecords[i].iIsAIRelay = 0; #endif pthread_mutex_lock(&mutex_alm); ALMQueueClear(i); pthread_mutex_unlock(&mutex_alm); socketRecords[i].used = 0; break; } } } //printf("\n[run_send_udp_thread]pthread exit\n"); pthread_exit(NULL); } #endif //GY_OS_AMBA #if GY_OS_WIN int UpdateTrafficLightZone(int tracking_channel_idx) { CPoint zone_polygon[DETECTION_POINTS_COUNT] = { 0 }; int b_IsInsideZone = 0; int b_ZoneExist = 0; int point_x = 0; int point_y = 0; int diagonal_x = 0; int diagonal_y = 0; //int zone_width = 0; //int zone_height = 0; int traffic_light_zone_idx = viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1; int min_x = 1920 * 4; int point_idx = 0; int diagonal_idx = 0; for (int k = 0; k < DETECTION_POINTS_COUNT; k++) { if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x < min_x) { point_idx = k; min_x = viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x; } else if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x == min_x) { if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].y < viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y) { point_idx = k; } } } if (point_idx + 2 >= DETECTION_POINTS_COUNT) diagonal_idx = point_idx + 2 - DETECTION_POINTS_COUNT; else diagonal_idx = point_idx + 2; if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x > 0 || viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y > 0) b_ZoneExist = 1; if (b_ZoneExist) { point_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); point_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); diagonal_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); diagonal_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); //zone_width = diagonal_x - point_x; //zone_height = diagonal_y - point_y; trafficLightPoint.x = point_x; trafficLightPoint.y = point_y; traffic_light_zone_width = diagonal_x - point_x; traffic_light_zone_height = diagonal_y - point_y; } } #endif //GY_OS_WIN - UpdateTrafficLightZone #if defined GY_OS_AMBA || defined GY_OS_NOVA void linear_regression(detection_pos** p, int pointCount, double* a, double* b) { double sum_x, sum_x_sqare, sum_y, sum_xy; double a11, a12, a21, a22, b1, b2; sum_x = sum_x_sqare = sum_y = sum_xy = 0.0; int validCount = 0; double count_top = 0; double count_middle = 0; double count_bottom = 0; for (int i = 0; i < pointCount; ++i) { if (p[i]->left_x < 1 || p[i]->top_y < 1) continue; else { if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { count_top++; } else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { count_middle++; } else { count_bottom++; } } } double multi_ratio = 1; if (count_top >= 1.0) { multi_ratio *= count_top; } if (count_middle >= 1.0) { multi_ratio *= count_middle; } if (count_bottom >= 1.0) { multi_ratio *= count_bottom; } //printf("\n-------count_top:%lf,count_middle:%lf,count_bottom:%lf\n", count_top, count_middle, count_bottom); for (int i = 0; i < pointCount; ++i) { if (p[i]->left_x < 1 || p[i]->top_y < 1) continue; else { double temp_multi_ratio = 1.0; if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { temp_multi_ratio = multi_ratio / count_top; } else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { temp_multi_ratio = multi_ratio / count_middle; } else { temp_multi_ratio = multi_ratio / count_bottom; } //sum_x += p[i]->left_x + p[i]->width / 2; //sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2); //sum_y += p[i]->top_y + p[i]->height / 2; //sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2); //printf("[%d] x,y, w,h = %f, %f, %f, %f \n", i, p[i]->left_x, p[i]->top_y, p[i]->width, p[i]->height); sum_x += (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; //sum_y += p[i]->center_y + p[i]->height / 2; sum_y += (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; //sum_y += p[i]->center_y; sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; validCount += temp_multi_ratio; } } a11 = sum_x; //a12 = pointCount; a12 = validCount; a21 = sum_x_sqare; a22 = sum_x; b1 = sum_y; b2 = sum_xy; *a = (b1 * a22 - a12 * b2) / (a11 * a22 - a12 * a21); *b = (a11 * b2 - a21 * b1) / (a11 * a22 - a12 * a21); //printf("the line is y = %lf x + %lf\n", *a, *b); } void assign_row_number(detection_pos* PosInfo, detection_pos* pNext1, detection_pos* pNext2, int total_element_size, int element_size2, int parent_idx, float* arc) { detection_pos *detPoints[32]; double a = 0; double c = 0; double dist_tmp = 0; double dist_up = 0; double dist_down = 0; float height_up = 0; int n_lr = 0; int element_size_lr2 = element_size2; int name_len = 0; for (int n = 0; n < element_size2; n++) { pNext2 = PosInfo + total_element_size + n; //printf("\n[assign_row_number] _prefix1 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id,total_element_size,n, total_element_size + n); //n_lr = n; name_len = strlen(pNext2->name); if (memcmp(pNext2->name, MOVE_FORWARD_PREFIX, strlen(MOVE_FORWARD_PREFIX)) == 0) { //printf("\n[assign_row_number] _prefix1 pNext2->name:%s", pNext2->name); memmove(pNext2->name, pNext2->name + strlen(MOVE_FORWARD_PREFIX), name_len - strlen(MOVE_FORWARD_PREFIX)); pNext2->name[name_len - strlen(MOVE_FORWARD_PREFIX)] = '\0'; pNext2->number_row = 0; pNext2->obj_type = _PREFIX; element_size_lr2--; continue; } detPoints[n_lr] = pNext2; n_lr++; } linear_regression(detPoints, element_size_lr2, &a, &c); *arc = atan(a); //float degree = arch * 180 / MATH_PI; //printf("XXXXXXXXXXXXXXXXX element_size2 = %d \n", element_size2); for (int j = 0; j < element_size2; j++) { //printf("total_element_size = %d \n", total_element_size); pNext2 = PosInfo + total_element_size + j; pNext2->arc = *arc; //printf("\n[assign_row_number] _prefix2 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id, total_element_size, j, total_element_size + j); if (pNext2->number_row == 0) { //printf("\n[assign_row_number] _prefix2 pNext2->name:%s", pNext2->name); pNext2->left_x += pNext1->left_x; pNext2->top_y += pNext1->top_y; pNext2->parent_idx = parent_idx; pNext2->obj_type = _PREFIX; continue; } else { if (featureType & FEATURE_LPR_CNT && strcmp(pNext1->name, "L._Plate_CNT_VERTICAL") == 0) { if ((pNext2->left_x + pNext2->width / 2) <= (pNext2->top_y + pNext2->height / 2) * a + c) { pNext2->number_row = 1; //double sq = sqrt(a*a + (-1)*(-1)); dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + 1); if (dist_tmp > dist_up) { dist_up = dist_tmp; height_up = pNext2->width; } } else { pNext2->number_row = 2; dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + (-1)*(-1)); if (dist_tmp > dist_down) { dist_down = dist_tmp; height_up = pNext2->width; } } } else { if ((pNext2->top_y + pNext2->height / 2) <= (pNext2->left_x + pNext2->width / 2) * a + c) { pNext2->number_row = 1; //double sq = sqrt(a*a + (-1)*(-1)); dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); if (dist_tmp > dist_up) { dist_up = dist_tmp; height_up = pNext2->height; } } else { pNext2->number_row = 2; dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + (-1)*(-1)); if (dist_tmp > dist_down) { dist_down = dist_tmp; height_up = pNext2->height; } } } pNext2->left_x += pNext1->left_x; pNext2->top_y += pNext1->top_y; pNext2->parent_idx = parent_idx; pNext2->obj_type = _NUMBER; //printf("Set [%d] parent idx = %d \n", j, parent_idx); } } if ((dist_up + dist_down) < height_up * 0.5 || (dist_up == 0 && dist_down == 0 && height_up == 0)) { for (int j = 0; j < element_size2; j++) { pNext2 = PosInfo + total_element_size + j; if (pNext2->number_row == 0) { continue; } else { pNext2->number_row = 1; } } } } #endif #if defined GY_OS_AMBA || defined GY_OS_NOVA int SortObjects(detection_pos* PosInfo, int total_element_size) { detection_pos *pNext = NULL, *pFirstNumber = NULL; int pre_parent_idx = -1; int sortLogicUSA = 0; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if ((pNext->engine_type == FEATURE_LPR_USA) && pNext->obj_type == _NUMBER) { sortLogicUSA = 1; if (pNext->parent_idx != pre_parent_idx) { pFirstNumber = pNext; pNext->visual_left_x = pNext->left_x; pre_parent_idx = pNext->parent_idx; } else { for (int j = 0; j < pNext - pFirstNumber; j++) { if ((pFirstNumber + j)->obj_type == _PREFIX) continue; if (pNext->left_x + pNext->width / 2 > (pFirstNumber + j)->left_x && pNext->left_x + pNext->width / 2 < (pFirstNumber + j)->left_x + (pFirstNumber + j)->width) { pNext->visual_left_x = (pFirstNumber + j)->visual_left_x; break; } else { pNext->visual_left_x = pNext->left_x; } } } } else { pNext->visual_left_x = pNext->left_x; } } return sortLogicUSA; } #endif //GY_OS_WIN - SortObjects #if 1 void SetCorrectClassID(detection_pos *PosInfo, int total_element_size, int element_size1) { detection_pos *pNext = NULL, *pNext2 = NULL; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; int nDistance_y = 2160; if (g_IsToFDevice == 1) { if (pNext->class_id == 1) {//hand pNext->class_id = 250; } } else if (strcmp(pNext->name, "person")==0) { pNext->class_id = 0; } else if (strcmp(pNext->name, "bicycle")==0) { pNext->class_id = 1; } else if (strcmp(pNext->name, "car")==0) { pNext->class_id = 2; } else if (strcmp(pNext->name, "motorbike")==0) { pNext->class_id = 3; } else if (strcmp(pNext->name, "bus")==0) { pNext->class_id = 5; } else if (strcmp(pNext->name, "truck")==0) { pNext->class_id = 7; } else if(IsANPRCategory_L_Plate(pNext->name)){ if (strcmp(pNext->name, "ambulance") == 0) { pNext->class_id = 104; } if (strcmp(pNext->name, "stop_sign") == 0) { pNext->class_id = 11; } if (strncmp(pNext->name, "L._Plate_",9) == 0) { pNext->class_id = 900; } if (strcmp(pNext->name, "face") == 0) { pNext->class_id = 0; } } else if (IsANPRCategory(pNext->engine_type)) { if ((pNext->engine_type & FEATURE_LPR_THA)) { //泰國車牌 特殊1到9的class_id變成一般的1到9 if (pNext->class_id >= 39 && pNext->class_id <= 47) { pNext->class_id -= 38; } } } else { #ifdef GY_OS_AMBA if (strcmp(WeightFileModeName, "mod004") == 0) { if ((pNext->engine_type & FEATURE_TRAF_DET) && ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) )) ///Steven TEMP MARK { if (pNext->class_id == 15)//cat { pNext->class_id = 247; } else if (pNext->class_id == 16)//dog { pNext->class_id = 248; } else if (pNext->class_id == 8)//boat { pNext->class_id = 158; } } } else { if (strcmp(heartbeatData.events_default_version, "4") == 0) { if ((pNext->engine_type & FEATURE_TRAF_DET) && ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) )) ///Steven TEMP MARK { if (pNext->class_id == 15)//cat { pNext->class_id = 247; } else if (pNext->class_id == 16)//dog { pNext->class_id = 248; } else if (pNext->class_id == 5)//bus { pNext->class_id = 2; } else if (pNext->class_id == 6)//train { pNext->class_id = 2; } else if (pNext->class_id == 7)//truck { pNext->class_id = 2; } } } else { if ((pNext->engine_type & FEATURE_TRAF_DET) && ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) )) ///Steven TEMP MARK { if (pNext->class_id == 15)//cat { pNext->class_id = 247; } else if (pNext->class_id == 16)//dog { pNext->class_id = 248; } } } } #else if ((pNext->engine_type & FEATURE_TRAF_DET) && ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) )) ///Steven TEMP MARK { if (pNext->class_id == 15)//cat { pNext->class_id = 247; } else if (pNext->class_id == 16)//dog { pNext->class_id = 248; } } #endif if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { if (pNext->class_id == 39 || pNext->class_id == 40 || pNext->class_id == 114) { pNext->class_id = 39; } else if (pNext->class_id == 41 || pNext->class_id == 45) { pNext->class_id = 41; } else if (pNext->class_id == 110 || pNext->class_id == 115) { pNext->class_id = 433; } else if (pNext->class_id == 111 || pNext->class_id == 112) { pNext->class_id = 19; } else if (pNext->class_id == 116 || pNext->class_id == 117) { pNext->class_id = 102; } else if (pNext->class_id == 118 || pNext->class_id == 120) { pNext->class_id = 99; } } if ((pNext->engine_type & FEATURE_AIFIRE)) { //printf("fire id = %d \n", pNext->class_id); if (pNext->class_id <= 3) { pNext->class_id += 105; } else if (pNext->class_id == 6 || pNext->class_id == 7) { pNext->class_id += 314; } else { pNext->class_id += 141; } } if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIAREO)) { pNext->class_id += 136; } //printf("\nFEATURE_HUM_DET---1\n"); if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIMASK)) { //printf("fire id = %d \n", pNext->class_id); if (strcmp(WeightFileModeName, "mod003") != 0) { if (pNext->class_id == 88) { pNext->class_id = 80; //face } else if (pNext->class_id == 89) { pNext->class_id = 81; //half_mask } else if (pNext->class_id == 90) { pNext->class_id = 82; //mask } } else { pNext->class_id += 140; } } if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIHELM)) { if (pNext->class_id >= 95 && pNext->class_id <= 97) { pNext->class_id += 1; } else if(pNext->class_id == 98){ pNext->class_id = 318; } else if (pNext->class_id >= 99) { pNext->class_id += 271; } } if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AISHIP)) { //printf("fire id = %d \n", pNext->class_id); pNext->class_id += 150; } if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIPRODUCTION)) { //printf("fire id = %d \n", pNext->class_id); pNext->class_id += 430; } if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIAML)) { if (strcmp(WeightFileModeName, "mod003") != 0) { //printf("fire id = %d \n", pNext->class_id); pNext->class_id += 167; } else { pNext->class_id += 340; } } if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIRADAR)) { // printf("radar id = %d \n", pNext->class_id); pNext->class_id += 950; } if ((pNext->engine_type & FEATURE_AIRAIL) && (pNext->engine_type2 & FEATURE_AIFLOW)) { if (pNext->class_id >= 3) { pNext->class_id += 111; } else if (pNext->class_id == 9) { pNext->class_id = 129; } else { pNext->class_id += 110; } } if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AISPORTS) && strcmp(WeightFileModeName, "mod002") == 0) { pNext->class_id += 400; } if ((pNext->engine_type & FEATURE_TRAF_DET)) { /*#ifdef GY_OS_AMBA if (pNext->class_id == 80) { pNext->class_id = 88; // TUK TUK } else if (pNext->class_id == 81) { pNext->class_id = 89; // Truck trailer } else if (pNext->class_id == 82) { pNext->class_id = 90; // Pickup truck } #else if ( pNext->class_id == 81 || pNext->class_id == 82 || pNext->class_id == 85 ) { pNext->class_id = 2; } else if ( pNext->class_id == 6 || pNext->class_id == 80 || pNext->class_id == 83 || pNext->class_id == 131 || pNext->class_id == 132 || pNext->class_id == 133 || pNext->class_id == 134 ) { pNext->class_id = 7; } #endif*/ } if ((pNext->engine_type & FEATURE_LPR_LOGO)) { pNext->class_id += 500; detection_pos* pDistance = NULL; for (int j = 0; j < total_element_size; j++) { pNext2 = PosInfo + j; if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) { if (pNext->left_x > pNext2->left_x && (pNext->left_x + pNext->width) < (pNext2->left_x + pNext2->width) && pNext->top_y < pNext2->top_y) { if (pNext2->top_y - pNext->top_y < nDistance_y) { nDistance_y = pNext2->top_y - pNext->top_y; pDistance = pNext2; } } } } if (pDistance) { char temp_buf[50] = { 0 }; int index_temp_buf = 0; for (int m = 0; m < (int)strlen(pNext->name); m++) { if (m < (int)strlen(pNext->name) - 1 && pNext->name[m] == 'l' && pNext->name[m + 1] == '_') { m++; } else { temp_buf[index_temp_buf] = pNext->name[m]; index_temp_buf++; } } temp_buf[index_temp_buf] = '\0'; snprintf(pDistance->properties.logo, sizeof(pDistance->properties.logo), "%s", temp_buf); snprintf(pDistance->logo, sizeof(pDistance->logo), "%s", temp_buf); } } } } } #endif //GY_OS_WIN - SetCorrectClassID #if defined GY_OS_AMBA || defined GY_OS_NOVA int IsMatchAUSPattern(char* PlatePattern, char* area) { int nMatchPattern = 0; if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH)) { char *local = "ACT"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH)) { char *local = "NSW"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_SLI)) { char *local = "NSW"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NTE_VEH)) { char *local = "NT"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_QUE_VEH)) { char *local = "QUEENSLAND"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_SAU_VEH)) { char *local = "SA"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_TAS_VEH)) { char *local = "Tasmania"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_VIC_VEH)) { char *local = "VICTORIA"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_WAU_VEH)) { char *local = "WA"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH_PRE)) { char *local = "ACT"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH_PRE)) { char *local = "NSW"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 0; } return nMatchPattern; } #endif //GY_OS_WIN - IsMatchAUSPattern #if defined GY_OS_AMBA || defined GY_OS_NOVA int IsMatchGBRPattern(char* PlatePattern, char* area) { int nMatchPattern = 0; if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else { for (int i = 0; i < strlen(PlatePattern); i++) { if (*(PlatePattern + i) == '-') memmove(PlatePattern + i, PlatePattern + i + 1, strlen(PlatePattern) - i); } if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH_)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH_)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2_)) { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 0; } } return nMatchPattern; } #endif //GY_OS_WIN - IsMatchGBRPattern #if defined GY_OS_AMBA || defined GY_OS_NOVA int IsMatchIDNPattern(char* PlatePattern, char* area) { int nMatchPattern = 0; if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BANT_VEH)) { char *local = "Banten"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA1_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG1_VEH)) { char *local = "Yogyakarta"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA2_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA1_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA2_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAKA_VEH)) { char *local = "Jakarta"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUM_VEH)) { char *local = "West Sumatra"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WCNS_VEH)) { char *local = "West coast of North Sumatra"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BENG_VEH)) { char *local = "Bengkulu"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_LAMP_VEH)) { char *local = "Lampung"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSUM_VEH)) { char *local = "South Sumatra"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAMB_VEH)) { char *local = "Jambi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ECNS_VEH)) { char *local = "East coast of North Sumatra"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ACEH_VEH)) { char *local = "Aceh"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RIAU_VEH)) { char *local = "Riau"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BBEL_VEH)) { char *local = "Bangka Belitung"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RISL_VEH)) { char *local = "Riau Islands"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA1_VEH)) { char *local = "West Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SKAL_VEH)) { char *local = "South Kalimantan"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU1_VEH)) { char *local = "North Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUL_VEH)) { char *local = "West Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU1_VEH)) { char *local = "South Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_MALU_VEH)) { char *local = "Maluku"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NMAL_VEH)) { char *local = "North Maluku"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTT_VEH)) { char *local = "East Nusa Tenggara"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BALI_VEH)) { char *local = "Bali"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU2_VEH)) { char *local = "North Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_GORO_VEH)) { char *local = "Gorontalo"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CSUL_VEH)) { char *local = "Central Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU2_VEH)) { char *local = "South Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTL_VEH)) { char *local = "West Nusa Tenggara"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SESU_VEH)) { char *local = "Southeast Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU3_VEH)) { char *local = "South Sulawesi"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA2_VEH)) { char *local = "West Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTS_VEH)) { char *local = "West Nusa Tenggara"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTF_VEH)) { char *local = "East Nusa Tenggara"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTS_VEH)) { char *local = "East Nusa Tenggara"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA3_VEH)) { char *local = "West Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA3_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA4_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA5_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WKAL_VEH)) { char *local = "West Kalimantan"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CKAL_VEH)) { char *local = "Central Kalimantan"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EKAL_VEH)) { char *local = "East Kalimantan"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NKAL_VEH)) { char *local = "North Kalimantan"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA3_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA4_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA5_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA6_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_PAPU_VEH)) { char *local = "Papua"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WPAP_VEH)) { char *local = "West Papua"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA6_VEH)) { char *local = "Central Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA7_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SURA_VEH)) { char *local = "Surabaya"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA4_VEH)) { char *local = "West Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA8_VEH)) { char *local = "East Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG2_VEH)) { char *local = "Yogyakarta"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG3_VEH)) { char *local = "Yogyakarta"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA5_VEH)) { char *local = "West Java"; memcpy(area, local, strlen(local)); nMatchPattern = 1; } else { char *local = ""; memcpy(area, local, strlen(local)); nMatchPattern = 0; } return nMatchPattern; } #endif //GY_OS_WIN - IsMatchIDNPattern #if defined GY_OS_AMBA || defined GY_OS_NOVA int PlatePatternParser(detection_pos* PosInfo, int total_element_size, size_t featureType/*, float arc*/) { //printf("\n[PlatePatternParser] start\n"); detection_pos *pNext = PosInfo; //detection_pos *pBeginIndex = NULL; int nNumCount = 0; int result = 0; char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; /*char country[30] = { 0 }; char area[30] = { 0 };*/ int Index0orO = 0, Index1orI = 0, IndexPattern = 0; //char *dash = "-"; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->engine_type & FEATURE_LPR_TWN) { char country[30] = { 0 }; char area[30] = { 0 }; sprintf(country, "%s", "TWN"); //detection_pos *pNext = PosInfo; //int nNumCount = 0; //測試用假資料 //for (int i = 0; i < total_element_size; i++) //{ //pNext = PosInfo + i; //sprintf(pNext->name, "%s", "1"); //pNext->confidence = 35; //pNext->left_x = 165; //pNext->top_y = 127; //pNext->width = 4; //pNext->height = 26; //pNext->obj_type == _NUMBER; //} if (pNext->obj_type == _NUMBER) nNumCount++; else continue; if (nNumCount == 1) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); //if (strcmp(pNext->name, "1") == 0) { //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) { //pNext->obj_type = _MISTAKE; //result++; } } } else { pNext->arc = (pNext->arc > 0) ? pNext->arc : -pNext->arc; //float angle = arc * 180 / MATH_PI; #if 0 if (activeDisplayDash) { if (pNext->arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely { float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); float distWidth1 = (pNext - 1)->width / 2; float distWidth2 = pNext->width / 2; if (distCenter > (distWidth1 + distWidth2)*1.22) { pNext->obj_type = _DASH; pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; } } else { float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); float distWidth1 = (pNext - 1)->width / 2; float distWidth2 = pNext->width / 2; if (distCenter > (distWidth1 + distWidth2)*1.22) { pNext->obj_type = _DASH; pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; } } } #endif if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) { //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); //if (strcmp(pNext->name, "1") == 0) { //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) { //pNext->obj_type = _MISTAKE; //result++; } } nNumCount = 0; } } } #if 0 else if (pNext->engine_type & FEATURE_LPR_EUR) { char country[30] = { 0 }; char area[30] = { 0 }; sprintf(country, "%s", "EUR");//European //EU/UK/IN //detection_pos *pNext = PosInfo; //int nNumCount = 0; //測試用假資料 /*for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; sprintf(pNext->name, "%s", "1"); pNext->confidence = 35; pNext->left_x = 165; pNext->top_y = 127; pNext->width = 4; pNext->height = 26; pNext->obj_type == _NUMBER; }*/ if (pNext->obj_type == _NUMBER) nNumCount++; else continue; if (nNumCount == 1) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); //if (strcmp(pNext->name, "1") == 0) { //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) { //pNext->obj_type = _MISTAKE; //result++; } } } else { arc = (arc > 0) ? arc : -arc; //float angle = arc * 180 / MATH_PI; if (activeDisplayDash) { if (arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely { float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); float distWidth1 = (pNext - 1)->width / 2; float distWidth2 = pNext->width / 2; if (distCenter > (distWidth1 + distWidth2)*1.22) { pNext->obj_type = _DASH; pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; } } else { float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); float distWidth1 = (pNext - 1)->width / 2; float distWidth2 = pNext->width / 2; if (distCenter > (distWidth1 + distWidth2)*1.22) { pNext->obj_type = _DASH; pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; } } } if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) { //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); //if (strcmp(pNext->name, "1") == 0) { //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) { //pNext->obj_type = _MISTAKE; //result++; } } nNumCount = 0; } } } #endif #if 0 else if (pNext->engine_type & FEATURE_LPR_AUS) { /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; int Index0orO = 0, Index1orI = 0, IndexPattern = 0; char *dash = "-"; detection_pos *pNext = PosInfo*/ //for (int i = 0; i < total_element_size; i++) //{ pNext = PosInfo + i; if (pNext->parent_idx < 0) continue; if (IndexPattern == 0) { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; //pBeginIndex = PosInfo + i; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; }*/ } else { if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) { PossiblePlate[IndexPattern] = dash; IndexPattern++; } PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; }*/ if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) { if (Index0orO <= 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchAUSPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); } } else if (Index0orO > 0) { int rows = pow(2, Index0orO); int **array; array = malloc(rows * sizeof *array); for (int i = 0; i < rows; i++) { array[i] = malloc(Index0orO * sizeof *array[i]); } int *each = malloc(Index0orO * sizeof(int)); int c = 0; BinaryDFS(0, Index0orO, each, array, &c); for (int i = 0; i < rows; i++) { for (int j = 0; j < Index0orO; j++) { if (array[i][j] == _0) *ElementPos0orO[j] = '0'; else if (array[i][j] == _O) *ElementPos0orO[j] = 'O'; } //printf("\n"); if (Index0orO > 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchAUSPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } } if (each) { free(each); each = NULL; } for (int i = 0; i < rows; i++) { if (array[i]) { free(array[i]); array[i] = NULL; } } if (array) { free(array); array = NULL; } } for (int i = 0; i < MAX_PLATE_NUMBER; i++) { ElementPos0orO[i] = NULL; ElementPos1orI[i] = NULL; PossiblePlate[i] = NULL; IndexPattern = 0; Index0orO = 0; Index1orI = 0; } } } //} } #endif #if 0 else if (pNext->engine_type & FEATURE_LPR_EUR)//FEATURE_LPR_GBR { /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; int Index0orO = 0, Index1orI = 0, IndexPattern = 0; char *dash = "-"; detection_pos *pNext = PosInfo*/ //for (int i = 0; i < total_element_size; i++) //{ pNext = PosInfo + i; if (pNext->parent_idx < 0) continue; if (IndexPattern == 0) { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; //pBeginIndex = PosInfo + i; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; } } else { /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) { PossiblePlate[IndexPattern] = dash; IndexPattern++; }*/ PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; } if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) { if (Index0orO <= 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) { snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); }*/ if (bMatch) break; } else if (Index0orO > 0) { int rows = pow(2, Index0orO); int **array; array = malloc(rows * sizeof *array); for (int i = 0; i < rows; i++) { array[i] = malloc(Index0orO * sizeof *array[i]); } int *each = malloc(Index0orO * sizeof(int)); int c = 0; BinaryDFS(0, Index0orO, each, array, &c); for (int i = 0; i < rows; i++) { for (int j = 0; j < Index0orO; j++) { if (array[i][j] == _0) *ElementPos0orO[j] = '0'; else if (array[i][j] == _O) *ElementPos0orO[j] = 'O'; } if (Index0orO > 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } else if (Index0orO > 0 && Index1orI > 0) { int rows2 = pow(2, Index1orI); int **array2; array2 = malloc(rows2 * sizeof *array2); for (int index_i = 0; index_i < rows2; index_i++) { array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); } int *each2 = malloc(Index1orI * sizeof(int)); int c = 0; BinaryDFS(0, Index1orI, each2, array2, &c); for (int index_i = 0; index_i < rows2; index_i++) { for (int index_j = 0; index_j < Index1orI; index_j++) { if (array2[index_i][index_j] == _1) *ElementPos1orI[index_j] = '1'; else if (array2[index_i][index_j] == _I) *ElementPos1orI[index_j] = 'I'; } int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } for (int index_i = 0; index_i < rows2; index_i++) { if (array2[index_i] != NULL) { free(array2[index_i]); array2[index_i] = NULL; } } if (array2 != NULL) { free(array2); array2 = NULL; } if (each2 != NULL) { free(each2); each2 = NULL; } } } for (int i = 0; i < rows; i++) { if (array[i] != NULL) { free(array[i]); array[i] = NULL; } } if (array != NULL) { free(array); array = NULL; } if (each != NULL) { free(each); each = NULL; } } else if (Index1orI > 0) { int rows = pow(2, Index1orI); int **array; array = malloc(rows * sizeof *array); for (int i = 0; i < rows; i++) { array[i] = malloc(Index1orI * sizeof *array[i]); } int *each = malloc(Index1orI * sizeof(int)); int c = 0; BinaryDFS(0, Index1orI, each, array, &c); for (int i = 0; i < rows; i++) { for (int j = 0; j < Index1orI; j++) { if (array[i][j] == _1) *ElementPos1orI[j] = '1'; else if (array[i][j] == _I) *ElementPos1orI[j] = 'I'; //printf("%d", array[i][j]); } //printf("\n"); int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } for (int i = 0; i < rows; i++) { if (array[i] != NULL) { free(array[i]); array[i] = NULL; } } if (array != NULL) { free(array); array = NULL; } if (each != NULL) { free(each); each = NULL; } } for (int i = 0; i < MAX_PLATE_NUMBER; i++) { ElementPos0orO[i] = NULL; ElementPos1orI[i] = NULL; PossiblePlate[i] = NULL; IndexPattern = 0; Index0orO = 0; Index1orI = 0; } } } //} } #endif #if 1 else if (pNext->engine_type & FEATURE_LPR_GBR) { /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; int Index0orO = 0, Index1orI = 0, IndexPattern = 0; char *dash = "-"; detection_pos *pNext = PosInfo*/ //for (int i = 0; i < total_element_size; i++) //{ pNext = PosInfo + i; if (pNext->parent_idx < 0) continue; if (IndexPattern == 0) { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; //pBeginIndex = PosInfo + i; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; } } else { /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) { PossiblePlate[IndexPattern] = dash; IndexPattern++; }*/ PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) { ElementPos0orO[Index0orO] = pNext->name; Index0orO++; } if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) { ElementPos1orI[Index1orI] = pNext->name; Index1orI++; } if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) { if (Index0orO <= 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) { snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); }*/ if (bMatch) break; } else if (Index0orO > 0) { int rows = pow(2, Index0orO); int **array; array = malloc(rows * sizeof *array); for (int i = 0; i < rows; i++) { array[i] = malloc(Index0orO * sizeof *array[i]); } int *each = malloc(Index0orO * sizeof(int)); int c = 0; BinaryDFS(0, Index0orO, each, array, &c); for (int i = 0; i < rows; i++) { for (int j = 0; j < Index0orO; j++) { if (array[i][j] == _0) *ElementPos0orO[j] = '0'; else if (array[i][j] == _O) *ElementPos0orO[j] = 'O'; } if (Index0orO > 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } else if (Index0orO > 0 && Index1orI > 0) { int rows2 = pow(2, Index1orI); int **array2; array2 = malloc(rows2 * sizeof *array2); for (int index_i = 0; index_i < rows2; index_i++) { array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); } int *each2 = malloc(Index1orI * sizeof(int)); int c = 0; BinaryDFS(0, Index1orI, each2, array2, &c); for (int index_i = 0; index_i < rows2; index_i++) { for (int index_j = 0; index_j < Index1orI; index_j++) { if (array2[index_i][index_j] == _1) *ElementPos1orI[index_j] = '1'; else if (array2[index_i][index_j] == _I) *ElementPos1orI[index_j] = 'I'; } int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } for (int index_i = 0; index_i < rows2; index_i++) { if (array2[index_i] != NULL) { free(array2[index_i]); array2[index_i] = NULL; } } if (array2 != NULL) { free(array2); array2 = NULL; } if (each2 != NULL) { free(each2); each2 = NULL; } } } for (int i = 0; i < rows; i++) { if (array[i] != NULL) { free(array[i]); array[i] = NULL; } } if (array != NULL) { free(array); array = NULL; } if (each != NULL) { free(each); each = NULL; } } else if (Index1orI > 0) { int rows = pow(2, Index1orI); int **array; array = malloc(rows * sizeof *array); for (int i = 0; i < rows; i++) { array[i] = malloc(Index1orI * sizeof *array[i]); } int *each = malloc(Index1orI * sizeof(int)); int c = 0; BinaryDFS(0, Index1orI, each, array, &c); for (int i = 0; i < rows; i++) { for (int j = 0; j < Index1orI; j++) { if (array[i][j] == _1) *ElementPos1orI[j] = '1'; else if (array[i][j] == _I) *ElementPos1orI[j] = 'I'; //printf("%d", array[i][j]); } //printf("\n"); int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchGBRPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); break; } } for (int i = 0; i < rows; i++) { if (array[i] != NULL) { free(array[i]); array[i] = NULL; } } if (array != NULL) { free(array); array = NULL; } if (each != NULL) { free(each); each = NULL; } } for (int i = 0; i < MAX_PLATE_NUMBER; i++) { ElementPos0orO[i] = NULL; ElementPos1orI[i] = NULL; PossiblePlate[i] = NULL; IndexPattern = 0; Index0orO = 0; Index1orI = 0; } } } //} } #endif #if 0 else if (pNext->engine_type & FEATURE_LPR_IDN) { /*char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; int Index0orO = 0, Index1orI = 0, IndexPattern = 0; char *dash = "-"; detection_pos *pNext = PosInfo*/ //for (int i = 0; i < total_element_size; i++) //{ pNext = PosInfo + i; if (pNext->obj_type == _NUMBER) { if (IndexPattern == 0) { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; //pBeginIndex = PosInfo + i; } else { if (strlen(pNext->name) > 5) printf("Test number"); PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) { if (Index0orO <= 0 && Index1orI <= 0) { int m = 0; char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { PlatePattern[m] = *PossiblePlate[m]; m++; } char area[30] = { 0 }; int bMatch = IsMatchIDNPattern(PlatePattern, area); if (bMatch) { snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "IDN"); snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); } } for (int i = 0; i < MAX_PLATE_NUMBER; i++) { //ElementPos0orO[i] = NULL; //ElementPos1orI[i] = NULL; PossiblePlate[i] = NULL; IndexPattern = 0; Index0orO = 0; Index1orI = 0; } } } } //} } #endif else { //if (pNext->engine_type & FEATURE_LPR_TWN) // sprintf(country, "%s", "TWN"); char country[30] = { 0 }; char area[30] = { 0 }; int area_id = -1; pNext->properties.area_id = area_id; /*if (pNext->engine_type & FEATURE_LPR_CNA) sprintf(country, "%s", "CNA");*/ if (pNext->engine_type & FEATURE_LPR_USA) sprintf(country, "%s", "USA/CA"); else if (pNext->engine_type & FEATURE_LPR_EUR) sprintf(country, "%s", "EUR"); /*else if (pNext->engine_type & FEATURE_LPR_TWN) sprintf(country, "%s", "TWN");*/ else if (pNext->engine_type & FEATURE_LPR_JPN) sprintf(country, "%s", "JPN"); else if (pNext->engine_type & FEATURE_LPR_BGD) sprintf(country, "%s", "BGD"); else if (pNext->engine_type & FEATURE_LPR_MEA) sprintf(country, "%s", "MEA"); else if (pNext->engine_type & FEATURE_LPR_SEA || pNext->engine_type & FEATURE_LPR_IDN || pNext->engine_type & FEATURE_LPR_VNM) sprintf(country, "%s", "SEA"); else if (pNext->engine_type & FEATURE_LPR_THA) sprintf(country, "%s", "THA"); else if (pNext->engine_type & FEATURE_LPR_LAO) sprintf(country, "%s", "LAO"); else if (pNext->engine_type & FEATURE_LPR_PHL) sprintf(country, "%s", "PHL"); else if (pNext->engine_type & FEATURE_LPR_CNT) sprintf(country, "%s", "CNT"); else if (pNext->engine_type & FEATURE_LPR_AUS) sprintf(country, "%s", "AUS"); else sprintf(country, "%s", ""); if (IsANPRCategory(pNext->engine_type)) { //pNext = PosInfo + i; /*if (pNext->class_id >= 0) { if (strcmp(ppIniKeyValue[pNext->class_id], "") != 0) { strcpy(pNext->name, ppIniKeyValue[pNext->class_id]); } }*/ if (pNext->obj_type == _PLATE || pNext->obj_type == _LOGO) continue; if (pNext->obj_type == _PREFIX) { //printf("\n[PlatePatternParser]pNext->obj_type == _PREFIX area:%s area_id:%d\n", pNext->name, pNext->class_id); sprintf(area, "%s", pNext->name); area_id = pNext->class_id; // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty if (featureType & FEATURE_LPR_JPN /*|| featureType & FEATURE_LPR_CNA*/) { snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); (PosInfo + pNext->parent_idx)->properties.area_id = area_id; } else { snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); (PosInfo + pNext->parent_idx)->properties.area_id = area_id; } } if (IndexPattern == 0) { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; } else { PossiblePlate[IndexPattern] = pNext->name; IndexPattern++; if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) { if (Index0orO <= 0 && Index1orI <= 0) { int m = 0; //char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; while (PossiblePlate[m] != NULL) { //PlatePattern[m] = *PossiblePlate[m]; m++; } snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty /*if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_CNA) { snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); (PosInfo + pNext->parent_idx)->properties.area_id = area_id; } else { snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); (PosInfo + pNext->parent_idx)->properties.area_id = area_id; }*/ //break; } for (int j = 0; j < MAX_PLATE_NUMBER; j++) { //ElementPos0orO[i] = NULL; //ElementPos1orI[i] = NULL; PossiblePlate[j] = NULL; IndexPattern = 0; Index0orO = 0; Index1orI = 0; } } } } } } //printf("\n[PlatePatternParser] end\n"); return result; } #endif //GY_OS_WIN - PlatePatternParser #if defined GY_OS_AMBA || defined GY_OS_NOVA void ReplaceWithUTF8(detection_pos* PosInfo, int total_element_size) { detection_pos *pNext = NULL; int layer_idx = 0; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (i > 0 && pNext->parent_idx >= 0) { //printf("\npNext->engine_type\n") //if ( ((pNext->engine_type == (pNext - 1)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((pNext - 1)->engine_type) && pNext->obj_type == _NUMBER && (pNext - 1)->obj_type == _PLATE) ) if (((pNext->engine_type == (PosInfo + pNext->parent_idx)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((PosInfo + pNext->parent_idx)->engine_type) && (pNext->obj_type == _NUMBER || pNext->obj_type == _PREFIX) && (PosInfo + pNext->parent_idx)->obj_type == _PLATE)) { for (int j = 0; j < MAX_LAYER_NUM; j++) { if (j > 0) { if (layerFeatureType[j - 1] == pNext->engine_type && layerFeatureType[j] == pNext->engine_type) { layer_idx = j; break; } } } if (pNext->class_id >= 0) { if (strcmp(ppIniKeyValue[layer_idx][pNext->class_id], "") != 0) { strcpy(pNext->name, ppIniKeyValue[layer_idx][pNext->class_id]); } } } } if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { for (int j = 0; j < MAX_LAYER_NUM - 1; j++) { if (layerFeatureType[j] == pNext->engine_type && layerFeatureType[j + 1] == pNext->engine_type) { layer_idx = j + 1; break; } } if (pNext->properties.area_id >= 0) { if (strcmp(ppIniKeyValue[layer_idx][pNext->properties.area_id], "") != 0) { strcpy(pNext->properties.area, ppIniKeyValue[layer_idx][pNext->properties.area_id]); } } } } } void AssignPlateNumber(detection_pos* PosInfo, int total_element_size, int featureType) { detection_pos* pNext = NULL; detection_pos* pNext2 = NULL; detection_pos* pNext_correct = NULL; int differ_top_y = 20; int mea_record_idx = 0; #if 0 int record_correct_PosInfo_i_order[256]; int record_first_PosInfo_i = 0; int min_top_y = 100000; for (int i = 0; i < 256; i++) { if (i < total_element_size) { record_correct_PosInfo_i_order[i] = i; } else { record_correct_PosInfo_i_order[i] = -1; } } //Selection Sort: pNext->left_x for (int i = 0; i < total_element_size; i = i + 1) { pNext = PosInfo + i; for (int j = i + 1; j < total_element_size; j = j + 1) { pNext2 = PosInfo + j; if (pNext->left_x > pNext2->left_x) { //變數交換 int tmp_record_i = record_correct_PosInfo_i_order[i]; record_correct_PosInfo_i_order[i] = record_correct_PosInfo_i_order[j]; record_correct_PosInfo_i_order[j] = tmp_record_i; } } if (pNext->top_y < min_top_y) { min_top_y = pNext->top_y; } } for (int i = 0; i < total_element_size; i = i + 1) { pNext = PosInfo + record_correct_PosInfo_i_order[i]; if (abs((int)((pNext->top_y - min_top_y) / min_top_y * 100)) <= differ_top_y) { record_first_PosInfo_i = i; break; } } #endif int enable_the_first_word = 0; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (IsANPRCategory(pNext->engine_type)) { if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) { if (pNext->obj_type == _PREFIX) { if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) continue; } #if 0 if (featureType & FEATURE_LPR_TWN) { if (activeDisplayDash) { if (pNext->obj_type == _DASH) { if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); } } } } #endif //printf("\n------pNext->width:%f\n", pNext->width); #if 0 if (featureType & FEATURE_LPR_SEA) { if (pNext->width < 1) continue; } else { if (get_g_ori_yuv_width() <= 1280) { if (pNext->width < 70) continue; } else { if (pNext->width < 100) continue; } } #endif //if (strcmp(pNext->name, "_") == 0) // strcpy(pNext->name, " "); //printf("\n----------area:%s\n", (PosInfo + pNext->parent_idx)->properties.area); if (featureType & FEATURE_LPR_USA) { if (strlen((PosInfo + pNext->parent_idx)->properties.area)>=1) { differ_top_y = 20; } else { differ_top_y = 200; } } else if (featureType & FEATURE_LPR_TWN) { differ_top_y = 20; //printf("\n---------TW\n"); } else { differ_top_y = 20; } int check_if_the_first_word = 0; if (enable_the_first_word == 0) { for (int j = i + 1; j < total_element_size; j++) { pNext2 = PosInfo + j; //printf("\n-----yyyy:%d,%f,%f\n", abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)), pNext->top_y, pNext2->top_y); if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { } else { if (pNext->top_y <= pNext2->top_y) { } else { check_if_the_first_word = 1; } } enable_the_first_word = 1; break; } } int check_the_same_left_x = 0; for (int j = i - 1; j < i && j >= 0; j++) { pNext2 = PosInfo + j; if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { if ((j - 1) >= 0) { pNext_correct = PosInfo + (j - 1); if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); } } check_the_same_left_x = 1; } break; } if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { if (strlen((PosInfo + pNext->parent_idx)->properties.plate) == 0) { if (featureType & FEATURE_LPR_MEA) { //printf("area: %s, country: %s \n", (PosInfo + pNext->parent_idx)->properties.area, (PosInfo + pNext->parent_idx)->properties.country); //check number level //printf("B level: %d , s = %s\n", pNext->number_row, pNext->name); memset((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, '\0', sizeof((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name)); (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = 0; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = 0; ///record mea number (PosInfo + pNext->parent_idx)->plate_number_count = 0; mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; if (isdigit(pNext->name[0]) != 0) { (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; //printf("isdigit: %s \n", pNext->name); } if (isalpha(pNext->name[0]) != 0) { (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; //printf("isalpht: %s \n", pNext->name); } strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); (PosInfo + pNext->parent_idx)->plate_number_count++; strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; } else { strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; } //float temp = pNext->confidence; //(PosInfo + pNext->parent_idx)->confidence = temp; //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); } else { if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) { if (featureType & FEATURE_LPR_MEA) { //check number level //printf("A level: %d , s = %s, box_x = %f\n", pNext->number_row, pNext->name, pNext->box_x); ///record mea number mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; if (isdigit(pNext->name[0]) != 0) { (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; //printf("isdigit: %s \n", pNext->name); } if (isalpha(pNext->name[0]) != 0) { (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; //printf("isalpht: %s \n", pNext->name); } strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); (PosInfo + pNext->parent_idx)->plate_number_count++; strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); //printf("plate %d name = %s, y = %f, plate_y = %f, row = %d\n", i, (PosInfo + pNext->parent_idx)->properties.plate, pNext->top_y, (PosInfo + pNext->parent_idx)->plate_char_top_y, pNext->number_row); } else { if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); //float temp = (PosInfo + pNext->parent_idx)->confidence; //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); } } } else { strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); //float temp = (PosInfo + pNext->parent_idx)->confidence; //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); } //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); } } } } } enable_the_first_word = 0; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (IsANPRCategory(pNext->engine_type)) { if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) { if (pNext->obj_type == _PREFIX) { if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) continue; } #if 0 if (featureType & FEATURE_LPR_TWN) { if (activeDisplayDash) { if (pNext->obj_type == _DASH) { if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); } } } } #endif #if 0 if (get_g_ori_yuv_width() <= 1280) { if (pNext->width < 70) continue; } else { if (pNext->width < 100) continue; } #endif if (featureType & FEATURE_LPR_USA) { if (strlen((PosInfo + pNext->parent_idx)->properties.area) >= 1) { differ_top_y = 20; } else { differ_top_y = 200; } } else if (featureType & FEATURE_LPR_TWN) { differ_top_y = 20; } else { differ_top_y = 20; } int check_if_the_first_word = 0; if (enable_the_first_word == 0) { for (int j = i + 1; j < total_element_size; j++) { pNext2 = PosInfo + j; if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { check_if_the_first_word = 1; } else { if (pNext->top_y <= pNext2->top_y) { check_if_the_first_word = 1; } else { } } enable_the_first_word = 1; break; } } int check_the_same_left_x = 0; for (int j = i - 1; j < i && j >= 0; j++) { pNext2 = PosInfo + j; if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { if ((j - 1) >= 0) { pNext_correct = PosInfo + (j - 1); if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); } } check_the_same_left_x = 1; } break; } if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { if (strlen((PosInfo + pNext->parent_idx)->properties.plate) >= 0) { if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) { if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { } else { strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); //float temp = (PosInfo + pNext->parent_idx)->confidence; //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); } } //printf("[2]%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); } } } } } } #endif void ReplacePlateWithDB(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { detection_pos *pNext = NULL; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->obj_type != _PLATE) { continue; } if (strlen(pNext->properties.plate) <= 0) { continue; } if (pNext->confidence <= 0.0) { continue; } if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { for (int index_levenshtein = 0; index_levenshtein <= atoi(viewChannelData[tracking_channel_idx].levenshtein_distance); index_levenshtein++) { int check_if_OK = 0; char afterBuf[256] = { 0 }; strcpy(afterBuf, pNext->properties.plate); char afterBuf_dest[256] = { 0 }; if (check_if_in_white(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { strcpy(pNext->properties.plate, afterBuf_dest); } check_if_OK = 1; break; } else if (check_if_in_black(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { strcpy(pNext->properties.plate, afterBuf_dest); } check_if_OK = 1; break; } if (check_if_OK == 1) break; } } else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) { pNext->confidence = 0.0; } } } void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType,int tracking_channel_idx) { detection_pos *pNext = NULL,*pNext1 = NULL; detection_pos pNext_plate; double iDiffSec = 0.0; //float diff_box_y = 0; //g_PlateFilterTime = 3; //g_PlateFilterTimes = 10; //g_PlateRecorderFreeTime = 6; g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 if (g_PlateRecorderFreeTime == 0) { g_PlateRecorderFreeTime = 1; } if (g_PlateFilterTime == 0) { g_PlateFilterTime = 1; } if (g_PlateFilterTimes == 0) { g_PlateFilterTimes = 1; } //停車場,相同車牌只做1次。 //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); //Free over Recoder time for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 1) { iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_UpdateTime); //printf("\nFFF------------[%d]iDiffSec:%lf,g_PlateRecorderFreeTime:%d\n",j, iDiffSec, g_PlateRecorderFreeTime); if (g_PlateRecorderFreeTime >= 1 && iDiffSec > (double)g_PlateRecorderFreeTime) { g_PlateRecorderList[j].iGetCounter = 0; g_PlateRecorderList[j].t_UpdateTime = 0; g_PlateRecorderList[j].t_FirstGetTime = 0; g_PlateRecorderList[j].t_LoopTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PlateRecorderList[j].check_if_counted[m] = 0; } g_PlateRecorderList[j].iIfUse = 0; } } } //printf("---------> ver EEE \n"); //Filter plate by time and frequency for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->confidence <= 0.0) { continue; } if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { #if 1 for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 1) { pNext_plate.left_x = g_PlateRecorderList[j].box_x; pNext_plate.top_y = g_PlateRecorderList[j].box_y; pNext_plate.width = g_PlateRecorderList[j].box_w; pNext_plate.height = g_PlateRecorderList[j].box_h; pNext_plate.center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2.0; pNext_plate.center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2.0; if ((detection_overlap_ratio(&pNext_plate, pNext) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(&pNext_plate, pNext) > (90.0 / 100.0) || ((pNext_plate.center_x <= pNext->left_x + pNext->width && pNext_plate.center_x >= pNext->left_x) && (pNext_plate.center_y <= pNext->top_y + pNext->height && pNext_plate.center_y >= pNext->top_y)) ) { pNext->linked_plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->linked_plate); strcpy(pNext->car_type_name, pNext->name); break; } } } #endif } else if(IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { char afterBuf[256] = { 0 }; strcpy(afterBuf, pNext->properties.plate); //printf("\n-----------afterBuf:%s\n", afterBuf); pNext->properties.plate_length = Modify_Plate_and_Recount_Length(afterBuf, pNext->properties.plate); //printf("\n-----------[fff]pNext->properties.plate:%s\n", pNext->properties.plate); pNext->linked_plate_length = pNext->properties.plate_length; strcpy(pNext->linked_plate, pNext->properties.plate); if ((pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || pNext->properties.plate_length > atoi(viewChannelData[0].max_characters)) && strcmp(pNext->name, "ambulance") != 0 && strcmp(pNext->name, "blank") != 0 && strcmp(pNext->name, "stop_sign") != 0 && strcmp(pNext->name, "face") != 0) { } else { if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET) { if (viewChannelData[0].enable_traffic) { for (int m = 0; m < total_element_size; m++) { pNext1 = PosInfo + m; if (IsVehicleCategory(pNext1) || IsMotorbikeCategory(pNext1)) { if (detection_overlap_ratio(pNext, pNext1) > (90.0 / 100.0) || ((pNext->center_x <= pNext1->left_x + pNext1->width && pNext->center_x >= pNext1->left_x) && (pNext->center_y <= pNext1->top_y + pNext1->height && pNext->center_y >= pNext1->top_y)) ) { strcpy(pNext->car_type_name, pNext1->name); break; } } } } } int iFindMatchPlate = 0; int index_g_PlateRecorderList_max = -1; int iGetCounter_max = 0; int record_plate_index[MAX_PLATE_RECORDER] = { 0 }; int size_record_plate = 0; //printf("\n-----------Plate:%s\n", pNext->properties.plate); for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 1) { if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && strcmp(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) { iFindMatchPlate = 1; g_PlateRecorderList[j].t_UpdateTime = time(0); g_PlateRecorderList[j].iGetCounter++; if (strlen(pNext->car_type_name) >= 1) { strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); } else { strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); } g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; g_PlateRecorderList[j].box_x = pNext->left_x; g_PlateRecorderList[j].box_y = pNext->top_y; g_PlateRecorderList[j].box_w = pNext->width; g_PlateRecorderList[j].box_h = pNext->height; if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { if (g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes + 100) { g_PlateRecorderList[j].iGetCounter = g_PlateFilterTimes + 100; } } break; } } } if (iFindMatchPlate == 0) { for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 0) { if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { if (strstr(pNext->properties.plate, "-") != NULL) { g_PlateRecorderList[j].existing_dash = 1; } else { g_PlateRecorderList[j].existing_dash = 0; } } else { g_PlateRecorderList[j].existing_dash = 0; } if (strcmp(pNext->name, "ambulance") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else if (strcmp(pNext->name, "blank") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else if (strcmp(pNext->name, "stop_sign") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); } g_PlateRecorderList[j].t_FirstGetTime = time(0); g_PlateRecorderList[j].t_LoopTime = 0; g_PlateRecorderList[j].t_UpdateTime = time(0); g_PlateRecorderList[j].iGetCounter = 1; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PlateRecorderList[j].check_if_counted[m] = 0; } g_PlateRecorderList[j].box_x = pNext->left_x; g_PlateRecorderList[j].box_y = pNext->top_y; g_PlateRecorderList[j].box_w = pNext->width; g_PlateRecorderList[j].box_h = pNext->height; g_PlateRecorderList[j].last_box_x = pNext->left_x; g_PlateRecorderList[j].last_box_y = pNext->top_y; g_PlateRecorderList[j].last_box_w = pNext->width; g_PlateRecorderList[j].last_box_h = pNext->height; g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; g_PlateRecorderList[j].iPlateZoomOutCounter = 0; g_PlateRecorderList[j].iPlateZoomInCounter = 0; g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); g_PlateRecorderList[j].iIfUse = 1; iFindMatchPlate = 1; break; } } if (iFindMatchPlate == 0) { for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iGetCounter <= 0) { if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { if (strstr(pNext->properties.plate, "-") != NULL) { g_PlateRecorderList[j].existing_dash = 1; } else { g_PlateRecorderList[j].existing_dash = 0; } } else { g_PlateRecorderList[j].existing_dash = 0; } if (strcmp(pNext->name, "ambulance") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else if (strcmp(pNext->name, "blank") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else if (strcmp(pNext->name, "stop_sign") == 0) { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); } else { sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); } g_PlateRecorderList[j].t_FirstGetTime = time(0); g_PlateRecorderList[j].t_LoopTime = 0; g_PlateRecorderList[j].t_UpdateTime = time(0); g_PlateRecorderList[j].iGetCounter = 1; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PlateRecorderList[j].check_if_counted[m] = 0; } g_PlateRecorderList[j].box_x = pNext->left_x; g_PlateRecorderList[j].box_y = pNext->top_y; g_PlateRecorderList[j].box_w = pNext->width; g_PlateRecorderList[j].box_h = pNext->height; g_PlateRecorderList[j].last_box_x = pNext->left_x; g_PlateRecorderList[j].last_box_y = pNext->top_y; g_PlateRecorderList[j].last_box_w = pNext->width; g_PlateRecorderList[j].last_box_h = pNext->height; g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; g_PlateRecorderList[j].iPlateZoomOutCounter = 0; g_PlateRecorderList[j].iPlateZoomInCounter = 0; g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); g_PlateRecorderList[j].iIfUse = 1; iFindMatchPlate = 1; break; } } } } time_t early_t_FirstGetTime = time(0); for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 1) { //printf("\n-----sPlateNumber:%s,plate:%s,levenshtein_distance:%d\n", g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && LevenshteinDistance(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { if (g_PlateRecorderList[j].t_FirstGetTime < early_t_FirstGetTime) { early_t_FirstGetTime = g_PlateRecorderList[j].t_FirstGetTime; } record_plate_index[size_record_plate] = j; size_record_plate++; } } } for (int temp_j = 0; temp_j < size_record_plate; temp_j++) { int j = record_plate_index[temp_j]; g_PlateRecorderList[j].t_FirstGetTime = early_t_FirstGetTime; if (g_PlateRecorderList[j].iGetCounter > iGetCounter_max || (index_g_PlateRecorderList_max >= 0 && iGetCounter_max >= 1 && g_PlateRecorderList[j].iGetCounter == iGetCounter_max && g_PlateRecorderList[j].t_UpdateTime > g_PlateRecorderList[index_g_PlateRecorderList_max].t_UpdateTime)) { iDiffSec = difftime(time(0), g_PlateRecorderList[j].t_FirstGetTime); if (iDiffSec >= (double)g_PlateFilterTime || g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes) { index_g_PlateRecorderList_max = j; iGetCounter_max = g_PlateRecorderList[j].iGetCounter; } } //printf("\n---iGetCounter:%d,iGetCounter_max:%d,%s\n", g_PlateRecorderList[j].iGetCounter, iGetCounter_max, g_PlateRecorderList[j].sPlateNumber); } if (index_g_PlateRecorderList_max >= 0) { int j = index_g_PlateRecorderList_max; iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_FirstGetTime); if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { if (strlen(pNext->car_type_name) >= 1) { strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); } else { strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); } g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; g_PlateRecorderList[j].box_x = pNext->left_x; g_PlateRecorderList[j].box_y = pNext->top_y; g_PlateRecorderList[j].box_w = pNext->width; g_PlateRecorderList[j].box_h = pNext->height; //printf("\n-----------[%d]pNext->properties.plate up:%s,g_Plate:%s\n",j, pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber); pNext->properties.plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate); //printf("\n-----------pNext->properties.plate down:%s\n", pNext->properties.plate); pNext->linked_plate_length = pNext->properties.plate_length; strcpy(pNext->linked_plate, pNext->properties.plate); if((int)iDiffSec > 0 && ((int)iDiffSec) % g_PlateFilterTime == 0){ for (int index_record = 0; index_record < size_record_plate; index_record++) { if (record_plate_index[index_record] != j) { g_PlateRecorderList[index_record].iGetCounter = (g_PlateRecorderList[index_record].iGetCounter / 2) - 1; if(g_PlateRecorderList[index_record].iGetCounter <= 0) g_PlateRecorderList[index_record].iGetCounter = 0; } } } if (strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) { if (g_PlateRecorderList[j].t_LoopTime == 0) { g_PlateRecorderList[j].t_LoopTime = time(0); } double iDiffLoopSec = difftime(time(0), g_PlateRecorderList[j].t_LoopTime); if ((int)iDiffLoopSec > 0 && ((int)iDiffLoopSec) % g_PlateFilterTime == 0) { for (int k = 0; k < MAX_TRACKING_NUM; k++) { if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1 && strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, g_PlateRecorderList[j].sPlateNumber) == 0) { for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { pNext->check_if_having_been_counted[index_zone] = 0; g_TrackingRecords[tracking_channel_idx][k].check_if_having_been_counted[index_zone] = 0; g_PlateRecorderList[j].check_if_counted[index_zone] = 0; } g_TrackingRecords[tracking_channel_idx][k].disappear_count = 0; break; } } for (int k = 0; k < MAX_POST_RECODER_SIZE; k++) { if (g_PostRecorderList[k].iIfUse == 0 && g_longterm_PostRecorderList[k].iIfUse == 0) { break; } if (g_PostRecorderList[k].iIfUse == 1) { if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { g_PostRecorderList[k].iIfUse = 0; g_PostRecorderList[k].t_FirstGetTime = 0; g_PostRecorderList[k].t_FirstGetTime_total = 0; g_PostRecorderList[k].t_UpdateTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PostRecorderList[k].check_if_post[m] = 0; } g_PostRecorderList[k].check_if_cloud = 0; g_PostRecorderList[k].check_if_cloud_v2 = 0; g_PostRecorderList[k].check_if_cloud_record_v2 = 0; g_PostRecorderList[k].check_if_email = 0; g_PostRecorderList[k].check_if_ftp = 0; g_PostRecorderList[k].check_if_getalarmmotion = 0; g_PostRecorderList[k].box_x = 0; g_PostRecorderList[k].box_y = 0; g_PostRecorderList[k].box_w = 0; g_PostRecorderList[k].box_h = 0; g_PostRecorderList[k].object_id = 0; g_PostRecorderList[k].zone_idx = 0; strcpy(g_PostRecorderList[k].sPlateNumber, ""); g_PostRecorderList[k].count_trigger = 0; //g_PostRecorderList[k].the_same_id = 0; } } if (g_longterm_PostRecorderList[k].iIfUse == 1) { if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_longterm_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { g_longterm_PostRecorderList[k].iIfUse = 0; g_longterm_PostRecorderList[k].t_FirstGetTime = 0; g_longterm_PostRecorderList[k].t_FirstGetTime_total = 0; g_longterm_PostRecorderList[k].t_UpdateTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_longterm_PostRecorderList[k].check_if_post[m] = 0; } g_longterm_PostRecorderList[k].check_if_cloud = 0; g_longterm_PostRecorderList[k].check_if_cloud_v2 = 0; g_longterm_PostRecorderList[k].check_if_cloud_record_v2 = 0; g_longterm_PostRecorderList[k].check_if_email = 0; g_longterm_PostRecorderList[k].check_if_ftp = 0; g_longterm_PostRecorderList[k].check_if_getalarmmotion = 0; g_longterm_PostRecorderList[k].box_x = 0; g_longterm_PostRecorderList[k].box_y = 0; g_longterm_PostRecorderList[k].box_w = 0; g_longterm_PostRecorderList[k].box_h = 0; g_longterm_PostRecorderList[k].object_id = 0; g_longterm_PostRecorderList[k].zone_idx = 0; strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); g_longterm_PostRecorderList[k].count_trigger = 0; //g_longterm_PostRecorderList[k].the_same_id = 0; } } } g_PlateRecorderList[j].t_LoopTime = time(0); } } g_PlateRecorderList[j].t_UpdateTime = time(0); for (int index_record = 0; index_record < size_record_plate; index_record++) { if (record_plate_index[index_record] != j) { g_PlateRecorderList[index_record].t_UpdateTime = time(0); } } } } else { pNext->confidence = 0; } } } else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) { pNext->confidence = 0.0; } } qsort(&g_PlateRecorderList, MAX_PLATE_RECORDER, sizeof(PlateRecoder), sort_record_plate); } void ObjectFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { detection_pos *pNext = NULL/*, *pNext1 = NULL*/; //detection_pos pNext_plate; double iDiffSec = 0.0; //float diff_box_y = 0; //g_PlateFilterTime = 3; //g_PlateFilterTimes = 10; //g_PlateRecorderFreeTime = 6; //g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; //g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; //g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 //if (g_PlateRecorderFreeTime == 0) { //g_PlateRecorderFreeTime = 2; //} int object_free_time = atoi(SystemSetting.tracking_id_dwell) + 1;//2 //停車場,相同車牌只做1次。 //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); //Free over Recoder time for (int j = 0; j < MAX_OBJECT_RECORDER; j++) { if (g_ObjectRecorderList[j].iIfUse == 1) { iDiffSec = difftime(time(0),g_ObjectRecorderList[j].t_UpdateTime); //printf("\nEEE------------iDiffSec:%d\n", iDiffSec); if (object_free_time >= 1 && iDiffSec > (double)object_free_time) { g_ObjectRecorderList[j].iIfUse = 0; g_ObjectRecorderList[j].iGetCounter = 0; g_ObjectRecorderList[j].t_UpdateTime = 0; g_ObjectRecorderList[j].t_FirstGetTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_ObjectRecorderList[j].check_if_counted[m] = 0; } g_ObjectRecorderList[j].box_x = 0; g_ObjectRecorderList[j].box_y = 0; g_ObjectRecorderList[j].box_w = 0; g_ObjectRecorderList[j].box_h = 0; g_ObjectRecorderList[j].iTrackingID = 0; } } } //printf("---------> ver EEE \n"); //Filter plate by time and frequency for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0) { } else { if (IsANPRCategory(pNext->engine_type)) { } else { if (strlen(pNext->name) >= 1) { int iFindMatchObject = 0; for (int j = 0; j < MAX_OBJECT_RECORDER; j++) { //printf("if %d use = %d \n", j, g_ObjectRecorderList[j].iIfUse); if (g_ObjectRecorderList[j].iIfUse == 1) { if (g_ObjectRecorderList[j].iTrackingID == pNext->obj_tracking_id) { //printf("find match id \n"); iFindMatchObject = 1; g_ObjectRecorderList[j].t_UpdateTime = time(0); //g_ObjectRecorderList[j].iGetCounter++; //g_ObjectRecorderList[j].left_x = pNext->left_x; //g_ObjectRecorderList[j].top_y = pNext->top_y; g_ObjectRecorderList[j].box_x = pNext->left_x; g_ObjectRecorderList[j].box_y = pNext->top_y; g_ObjectRecorderList[j].box_w = pNext->width; g_ObjectRecorderList[j].box_h = pNext->height; //printf("%d history data, x = %f \n", j, g_ObjectRecorderList[j].box_x); //printf("y = %f ", g_ObjectRecorderList[j].box_y); //printf("h = %f ", g_ObjectRecorderList[j].box_h); //printf("w = %f ", g_ObjectRecorderList[j].box_w); //printf("ob_id = %d \n", g_ObjectRecorderList[j].iTrackingID); break; } } } //printf("iFindMatch = %d \n", iFindMatchObject); if (iFindMatchObject == 0) { for (int j = 0; j < MAX_OBJECT_RECORDER; j++) { if (g_ObjectRecorderList[j].iIfUse == 0) { g_ObjectRecorderList[j].iIfUse = 1; g_ObjectRecorderList[j].t_FirstGetTime = time(0); g_ObjectRecorderList[j].t_UpdateTime = time(0); g_ObjectRecorderList[j].iGetCounter = 1; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_ObjectRecorderList[j].check_if_counted[m] = 0; } g_ObjectRecorderList[j].box_x = pNext->left_x; g_ObjectRecorderList[j].box_y = pNext->top_y; g_ObjectRecorderList[j].box_w = pNext->width; g_ObjectRecorderList[j].box_h = pNext->height; g_ObjectRecorderList[j].iTrackingID = pNext->obj_tracking_id; //g_ObjectRecorderList[j].iTrackingIDidx = pNext->obj_tracking_id_idx; break; } //else if (j == MAX_OBJECT_RECORDER - 1) { //printf("\n---------MAX_OBJECT_RECORDER - 1\n"); //} } } } } } } qsort(&g_ObjectRecorderList, MAX_OBJECT_RECORDER, sizeof(ObjectRecoder), sort_record_object); } #if defined GY_OS_AMBA || defined GY_OS_NOVA void AddTWPlateDASH(detection_pos* PosInfo, int total_element_size, int featureType) { if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { detection_pos* pNext = NULL; int iPlate_len = 0; int iFront_alpha_num = 0; int iFront_digit_num = 0; int iBack_alpha_num = 0; int iBack_digit_num = 0; //for TWN plate, add dash if miss the dash. for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->obj_type != _PLATE) { continue; } if (strlen(pNext->properties.plate) <= 0) { continue; } if (pNext->confidence <= 0.0) { continue; } if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { //Plate miss "-" if (strstr(pNext->properties.plate, "-") == NULL) { iPlate_len = strlen(pNext->properties.plate); if (iPlate_len == 7) { insert_string(pNext->properties.plate, "-", 3); } else if (iPlate_len == 6) { iFront_alpha_num = 0; iFront_digit_num = 0; iBack_alpha_num = 0; iBack_digit_num = 0; int iFront_digit_num_length_4 = 0; int iBack_digit_num_length_4 = 0; int iFront_alpha_num_length_2 = 0; int iBack_alpha_num_length_2 = 0; for (int j = 0; j < 4; j++) { if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) { iFront_digit_num++; } if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_digit_num++; } if (j <= 3 && isdigit(pNext->properties.plate[j]) != 0) { iFront_digit_num_length_4++; } if (j <= 3 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_digit_num_length_4++; } if (j <= 2 && isalpha(pNext->properties.plate[j]) != 0) { iFront_alpha_num++; } if (j <= 2 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_alpha_num++; } if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) { iFront_alpha_num_length_2++; } if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_alpha_num_length_2++; } } if ((iFront_digit_num == 3 && iBack_alpha_num == 3) || (iFront_alpha_num == 3 && iBack_digit_num == 3)) { insert_string(pNext->properties.plate, "-", 3); } else if ((iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 2) || (iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 1)) { insert_string(pNext->properties.plate, "-", 4); } else if (iFront_alpha_num_length_2 <= 2 && iFront_alpha_num_length_2 >= 1 && iBack_digit_num_length_4 == 4) { insert_string(pNext->properties.plate, "-", 2); } else if (iFront_alpha_num <= 2 && iFront_alpha_num >= 1 && iBack_digit_num == 3) { insert_string(pNext->properties.plate, "-", 3); } } else if (iPlate_len == 5) { iFront_alpha_num = 0; iFront_digit_num = 0; iBack_alpha_num = 0; iBack_digit_num = 0; for (int j = 0; j < 3; j++) { if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) { iFront_digit_num++; } if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_digit_num++; } if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) { iFront_alpha_num++; } if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) { iBack_alpha_num++; } } if ((iFront_digit_num == 3 && iBack_alpha_num == 2) || (iFront_digit_num == 3 && iBack_digit_num == 1 && iBack_alpha_num == 1)) { insert_string(pNext->properties.plate, "-", 3); } else if ((iFront_alpha_num == 2 && iBack_digit_num == 3) || (iFront_alpha_num == 1 && iFront_digit_num == 1 && iBack_digit_num == 3)) { insert_string(pNext->properties.plate, "-", 2); } } else if (iPlate_len == 4) { insert_string(pNext->properties.plate, "-", 2); } //printf(">>>>>>>>>>>>>>>>>>>>>>>> plate: %s \n", pNext->properties.plate); } if (strstr(pNext->properties.plate, "-") == NULL) { pNext->confidence = 0.0; } } else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) { pNext->confidence = 0.0; } } } } void MEAPlateRule(detection_pos* PosInfo, int total_element_size) { detection_pos* pNext = NULL; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (IsANPRCategory_L_Plate(pNext->name)) { //printf("%d plate %d name = %s \n", i, pNext->parent_idx, pNext->properties.plate); check_rule(pNext); } } //printf("**************************************** \n"); } #endif #if 1 int CheckTriggerCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int tracking_obj_idx, int trigger_type, int total_element_size, detection_pos* PosInfo, int result_idx) { //int nNotChecked = 0; int nNeedTrigger = 0; double diffSecs = 0; double diffSecs2 = 0; int detection_count = 0; //char MetaData1[BUFSIZE] = { 0 }; //char MetaData2[BUFSIZE] = { 0 }; //char MetaOut1[512][50] = { 0 }; //char MetaOut2[512][50] = { 0 }; double d_no_parking_time = (double)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { d_no_parking_time = (double)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); } detection_count = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; detection_pos* pNext_b; //for (int i = 0; i < MAX_TRIGGER_EVENT; i++) //{ #if 0 if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].checked <= 0) return nNeedTrigger; #endif char ObjectName[30] = { 0 }; sprintf(ObjectName, "%s", pNext->name); UpperToLower(ObjectName); //char metadata1[512][STRSPLIT_SIZE] = { 0 }; //for vehicle //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); //printf("\n----CheckTriggerCondition--- start\n"); int metadata1_num = get_metadata1_num(detection_zone_idx); //printf("\n----CheckTriggerCondition--- end\n"); int temp_enable_person_for_metadata = person_if_existing_in_metaout(detection_zone_idx); //for (int i = 0; i < metadata1_num; i++) //{ //UpperToLower(metadata1[i]); //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); //if (strcmp("person", MetaOut1[i]) == 0) { //temp_enable_person_for_metadata = 1; //} //} g_enable_person_for_metadata[detection_zone_idx] = temp_enable_person_for_metadata; #if 0 char metadata2[10][STRSPLIT_SIZE] = { 0 }; //for person strcpy(MetaData2, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata2); int metadata2_num = StrSplit(MetaData2, metadata2, ","); for (int i = 0; i < metadata2_num; i++) { UpperToLower(metadata2[i]); TrimSpace(MetaOut2[i], sizeof(MetaOut2[i]), metadata2[i], 0); } #endif #if 0 unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); #endif //for name comparison without case sensitive //float dewell_time = 2.78;//2.78 //4.2 //float dewell_time2 = 4.2; if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { #if defined GY_OS_AMBA || defined GY_OS_NOVA if (trigger_type == TRIGGER_ALLOW_LIST) { if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) || (strcmp(pNext->name, "blank") == 0) || (strcmp(pNext->name, "stop_sign") == 0) //|| (strcmp(pNext->name, "face") == 0) ) { char afterBuf[256] = { 0 }; if (strcmp(pNext->name, "ambulance") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "blank") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "stop_sign") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else strcpy(afterBuf, pNext->properties.plate); if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) #ifdef GY_OS_AMBA //|| check_if_in_white_face(pNext->FDFR.face_name) #endif ) { char schedule_start[50] = { 0 }; char schedule_end[50] = { 0 }; char detect_endtime[50] = { 0 }; /*if (strcmp(pNext->name, "face") == 0) { #ifdef GY_OS_AMBA get_schedule_start_in_white_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_white_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_white_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); #endif } else */{ get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); } if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { char c_start_hour[10] = { 0 }; char c_start_minute[10] = { 0 }; char c_end_hour[10] = { 0 }; char c_end_minute[10] = { 0 }; c_start_hour[0] = schedule_start[0]; c_start_hour[1] = schedule_start[1]; c_start_hour[2] = '\0'; c_start_minute[0] = schedule_start[3]; c_start_minute[1] = schedule_start[4]; c_start_minute[2] = '\0'; int i_start_hour = atoi(c_start_hour); int i_start_minute = atoi(c_start_minute); int i_total_start_minute = i_start_hour * 60 + i_start_minute; c_end_hour[0] = schedule_end[0]; c_end_hour[1] = schedule_end[1]; c_end_hour[2] = '\0'; c_end_minute[0] = schedule_end[3]; c_end_minute[1] = schedule_end[4]; c_end_minute[2] = '\0'; int i_end_hour = atoi(c_end_hour); int i_end_minute = atoi(c_end_minute); int i_total_end_minute = i_end_hour * 60 + i_end_minute; time_t rawtime = time(0); struct tm * timeinfo; timeinfo = localtime(&rawtime); int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; ///////////////////////// char c_year_endtime[10] = { 0 }; c_year_endtime[0] = detect_endtime[0]; c_year_endtime[1] = detect_endtime[1]; c_year_endtime[2] = detect_endtime[2]; c_year_endtime[3] = detect_endtime[3]; c_year_endtime[4] = '\0'; int i_year_endtime = atoi(c_year_endtime); char c_month_endtime[10] = { 0 }; c_month_endtime[0] = detect_endtime[5]; c_month_endtime[1] = detect_endtime[6]; c_month_endtime[2] = '\0'; int i_month_endtime = atoi(c_month_endtime); char c_day_endtime[10] = { 0 }; c_day_endtime[0] = detect_endtime[8]; c_day_endtime[1] = detect_endtime[9]; c_day_endtime[2] = '\0'; int i_day_endtime = atoi(c_day_endtime); char c_hour_endtime[10] = { 0 }; c_hour_endtime[0] = detect_endtime[11]; c_hour_endtime[1] = detect_endtime[12]; c_hour_endtime[2] = '\0'; int i_hour_endtime = atoi(c_hour_endtime); char c_minute_endtime[10] = { 0 }; c_minute_endtime[0] = detect_endtime[14]; c_minute_endtime[1] = detect_endtime[15]; c_minute_endtime[2] = '\0'; int i_minute_endtime = atoi(c_minute_endtime); int check_if_OK = 0; if (1900 + timeinfo->tm_year < i_year_endtime) check_if_OK = 1; else if (1900 + timeinfo->tm_year == i_year_endtime) { if (1 + timeinfo->tm_mon < i_month_endtime) check_if_OK = 1; else if (1 + timeinfo->tm_mon == i_month_endtime) { if (timeinfo->tm_mday < i_day_endtime) check_if_OK = 1; else if (timeinfo->tm_mday == i_day_endtime) { if (timeinfo->tm_hour < i_hour_endtime) check_if_OK = 1; else if (timeinfo->tm_hour == i_hour_endtime) { if (timeinfo->tm_min < i_minute_endtime) check_if_OK = 1; } } } } if (((i_total_start_minute < i_total_end_minute && i_total_current_minute >= i_total_start_minute && i_total_current_minute <= i_total_end_minute) || (i_total_start_minute > i_total_end_minute && (i_total_current_minute >= i_total_start_minute || i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { //printf("trigger type 2 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone //printf("trigger type 3 \n"); diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #if 0 else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } #endif //printf("trigger type 4 \n"); /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } } } } else if (trigger_type == TRIGGER_BLOCK_LIST) { if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) || (strcmp(pNext->name, "blank") == 0) || (strcmp(pNext->name, "stop_sign") == 0) //|| (strcmp(pNext->name, "face") == 0) ) { char afterBuf[256] = { 0 }; if (strcmp(pNext->name, "ambulance") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "blank") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "stop_sign") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else strcpy(afterBuf, pNext->properties.plate); //printf("trigger type 1111 : %s\n", afterBuf); if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) #ifdef GY_OS_AMBA //|| check_if_in_black_face(pNext->FDFR.face_name) #endif ) { //printf("trigger type 2 \n"); char schedule_start[50] = { 0 }; char schedule_end[50] = { 0 }; char detect_endtime[50] = { 0 }; /*if (strcmp(pNext->name, "face") == 0) { #ifdef GY_OS_AMBA get_schedule_start_in_black_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_black_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_black_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); #endif } else */{ get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); } //printf("\n--------schedule_start:%s,schedule_end:%s\n", schedule_start, schedule_end); if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { char c_start_hour[10] = { 0 }; char c_start_minute[10] = { 0 }; char c_end_hour[10] = { 0 }; char c_end_minute[10] = { 0 }; c_start_hour[0] = schedule_start[0]; c_start_hour[1] = schedule_start[1]; c_start_hour[2] = '\0'; c_start_minute[0] = schedule_start[3]; c_start_minute[1] = schedule_start[4]; c_start_minute[2] = '\0'; int i_start_hour = atoi(c_start_hour); int i_start_minute = atoi(c_start_minute); int i_total_start_minute = i_start_hour * 60 + i_start_minute; c_end_hour[0] = schedule_end[0]; c_end_hour[1] = schedule_end[1]; c_end_hour[2] = '\0'; c_end_minute[0] = schedule_end[3]; c_end_minute[1] = schedule_end[4]; c_end_minute[2] = '\0'; int i_end_hour = atoi(c_end_hour); int i_end_minute = atoi(c_end_minute); int i_total_end_minute = i_end_hour * 60 + i_end_minute; time_t rawtime = time(0); struct tm * timeinfo; timeinfo = localtime(&rawtime); int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; /////////////////// char c_year_endtime[10] = { 0 }; c_year_endtime[0] = detect_endtime[0]; c_year_endtime[1] = detect_endtime[1]; c_year_endtime[2] = detect_endtime[2]; c_year_endtime[3] = detect_endtime[3]; c_year_endtime[4] = '\0'; int i_year_endtime = atoi(c_year_endtime); char c_month_endtime[10] = { 0 }; c_month_endtime[0] = detect_endtime[5]; c_month_endtime[1] = detect_endtime[6]; c_month_endtime[2] = '\0'; int i_month_endtime = atoi(c_month_endtime); char c_day_endtime[10] = { 0 }; c_day_endtime[0] = detect_endtime[8]; c_day_endtime[1] = detect_endtime[9]; c_day_endtime[2] = '\0'; int i_day_endtime = atoi(c_day_endtime); char c_hour_endtime[10] = { 0 }; c_hour_endtime[0] = detect_endtime[11]; c_hour_endtime[1] = detect_endtime[12]; c_hour_endtime[2] = '\0'; int i_hour_endtime = atoi(c_hour_endtime); char c_minute_endtime[10] = { 0 }; c_minute_endtime[0] = detect_endtime[14]; c_minute_endtime[1] = detect_endtime[15]; c_minute_endtime[2] = '\0'; int i_minute_endtime = atoi(c_minute_endtime); int check_if_OK = 0; if (1900 + timeinfo->tm_year < i_year_endtime) check_if_OK = 1; else if (1900 + timeinfo->tm_year == i_year_endtime) { if (1 + timeinfo->tm_mon < i_month_endtime) check_if_OK = 1; else if (1 + timeinfo->tm_mon == i_month_endtime) { if (timeinfo->tm_mday < i_day_endtime) check_if_OK = 1; else if (timeinfo->tm_mday == i_day_endtime) { if (timeinfo->tm_hour < i_hour_endtime) check_if_OK = 1; else if (timeinfo->tm_hour == i_hour_endtime) { if (timeinfo->tm_min < i_minute_endtime) check_if_OK = 1; } } } } if (((i_total_start_minute < i_total_end_minute && i_total_current_minute >= i_total_start_minute && i_total_current_minute <= i_total_end_minute) || (i_total_start_minute > i_total_end_minute && (i_total_current_minute >= i_total_start_minute || i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #if 0 else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } #endif //printf("\nnNeedTrigger:%d\n", nNeedTrigger); //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } } } } else if (trigger_type == TRIGGER_GUEST_LIST) { if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) || (strcmp(pNext->name, "blank") == 0) || (strcmp(pNext->name, "stop_sign") == 0) //|| (strcmp(pNext->name, "face") == 0) ) { char afterBuf[256] = { 0 }; if (strcmp(pNext->name, "ambulance") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "blank") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else if (strcmp(pNext->name, "stop_sign") == 0) { strcpy(afterBuf, pNext->name); LowerToUpper(afterBuf); } else strcpy(afterBuf, pNext->properties.plate); int check_if_white_or_black_within_lifetime = 0; #if 1 if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { char schedule_start[50] = { 0 }; char schedule_end[50] = { 0 }; char detect_endtime[50] = { 0 }; get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { char c_start_hour[10] = { 0 }; char c_start_minute[10] = { 0 }; char c_end_hour[10] = { 0 }; char c_end_minute[10] = { 0 }; c_start_hour[0] = schedule_start[0]; c_start_hour[1] = schedule_start[1]; c_start_hour[2] = '\0'; c_start_minute[0] = schedule_start[3]; c_start_minute[1] = schedule_start[4]; c_start_minute[2] = '\0'; int i_start_hour = atoi(c_start_hour); int i_start_minute = atoi(c_start_minute); int i_total_start_minute = i_start_hour * 60 + i_start_minute; c_end_hour[0] = schedule_end[0]; c_end_hour[1] = schedule_end[1]; c_end_hour[2] = '\0'; c_end_minute[0] = schedule_end[3]; c_end_minute[1] = schedule_end[4]; c_end_minute[2] = '\0'; int i_end_hour = atoi(c_end_hour); int i_end_minute = atoi(c_end_minute); int i_total_end_minute = i_end_hour * 60 + i_end_minute; time_t rawtime = time(0); struct tm * timeinfo; timeinfo = localtime(&rawtime); int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; ///////////////////////// char c_year_endtime[10] = { 0 }; c_year_endtime[0] = detect_endtime[0]; c_year_endtime[1] = detect_endtime[1]; c_year_endtime[2] = detect_endtime[2]; c_year_endtime[3] = detect_endtime[3]; c_year_endtime[4] = '\0'; int i_year_endtime = atoi(c_year_endtime); char c_month_endtime[10] = { 0 }; c_month_endtime[0] = detect_endtime[5]; c_month_endtime[1] = detect_endtime[6]; c_month_endtime[2] = '\0'; int i_month_endtime = atoi(c_month_endtime); char c_day_endtime[10] = { 0 }; c_day_endtime[0] = detect_endtime[8]; c_day_endtime[1] = detect_endtime[9]; c_day_endtime[2] = '\0'; int i_day_endtime = atoi(c_day_endtime); char c_hour_endtime[10] = { 0 }; c_hour_endtime[0] = detect_endtime[11]; c_hour_endtime[1] = detect_endtime[12]; c_hour_endtime[2] = '\0'; int i_hour_endtime = atoi(c_hour_endtime); char c_minute_endtime[10] = { 0 }; c_minute_endtime[0] = detect_endtime[14]; c_minute_endtime[1] = detect_endtime[15]; c_minute_endtime[2] = '\0'; int i_minute_endtime = atoi(c_minute_endtime); int check_if_OK = 0; if (1900 + timeinfo->tm_year < i_year_endtime) check_if_OK = 1; else if (1900 + timeinfo->tm_year == i_year_endtime) { if (1 + timeinfo->tm_mon < i_month_endtime) check_if_OK = 1; else if (1 + timeinfo->tm_mon == i_month_endtime) { if (timeinfo->tm_mday < i_day_endtime) check_if_OK = 1; else if (timeinfo->tm_mday == i_day_endtime) { if (timeinfo->tm_hour < i_hour_endtime) check_if_OK = 1; else if (timeinfo->tm_hour == i_hour_endtime) { if (timeinfo->tm_min < i_minute_endtime) check_if_OK = 1; } } } } if (((i_total_start_minute < i_total_end_minute && i_total_current_minute >= i_total_start_minute && i_total_current_minute <= i_total_end_minute) || (i_total_start_minute > i_total_end_minute && (i_total_current_minute >= i_total_start_minute || i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { check_if_white_or_black_within_lifetime = 1; } } } if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { //printf("trigger type 2 \n"); char schedule_start[50] = { 0 }; char schedule_end[50] = { 0 }; char detect_endtime[50] = { 0 }; get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { char c_start_hour[10] = { 0 }; char c_start_minute[10] = { 0 }; char c_end_hour[10] = { 0 }; char c_end_minute[10] = { 0 }; c_start_hour[0] = schedule_start[0]; c_start_hour[1] = schedule_start[1]; c_start_hour[2] = '\0'; c_start_minute[0] = schedule_start[3]; c_start_minute[1] = schedule_start[4]; c_start_minute[2] = '\0'; int i_start_hour = atoi(c_start_hour); int i_start_minute = atoi(c_start_minute); int i_total_start_minute = i_start_hour * 60 + i_start_minute; c_end_hour[0] = schedule_end[0]; c_end_hour[1] = schedule_end[1]; c_end_hour[2] = '\0'; c_end_minute[0] = schedule_end[3]; c_end_minute[1] = schedule_end[4]; c_end_minute[2] = '\0'; int i_end_hour = atoi(c_end_hour); int i_end_minute = atoi(c_end_minute); int i_total_end_minute = i_end_hour * 60 + i_end_minute; time_t rawtime = time(0); struct tm * timeinfo; timeinfo = localtime(&rawtime); int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; /////////////////// char c_year_endtime[10] = { 0 }; c_year_endtime[0] = detect_endtime[0]; c_year_endtime[1] = detect_endtime[1]; c_year_endtime[2] = detect_endtime[2]; c_year_endtime[3] = detect_endtime[3]; c_year_endtime[4] = '\0'; int i_year_endtime = atoi(c_year_endtime); char c_month_endtime[10] = { 0 }; c_month_endtime[0] = detect_endtime[5]; c_month_endtime[1] = detect_endtime[6]; c_month_endtime[2] = '\0'; int i_month_endtime = atoi(c_month_endtime); char c_day_endtime[10] = { 0 }; c_day_endtime[0] = detect_endtime[8]; c_day_endtime[1] = detect_endtime[9]; c_day_endtime[2] = '\0'; int i_day_endtime = atoi(c_day_endtime); char c_hour_endtime[10] = { 0 }; c_hour_endtime[0] = detect_endtime[11]; c_hour_endtime[1] = detect_endtime[12]; c_hour_endtime[2] = '\0'; int i_hour_endtime = atoi(c_hour_endtime); char c_minute_endtime[10] = { 0 }; c_minute_endtime[0] = detect_endtime[14]; c_minute_endtime[1] = detect_endtime[15]; c_minute_endtime[2] = '\0'; int i_minute_endtime = atoi(c_minute_endtime); int check_if_OK = 0; if (1900 + timeinfo->tm_year < i_year_endtime) check_if_OK = 1; else if (1900 + timeinfo->tm_year == i_year_endtime) { if (1 + timeinfo->tm_mon < i_month_endtime) check_if_OK = 1; else if (1 + timeinfo->tm_mon == i_month_endtime) { if (timeinfo->tm_mday < i_day_endtime) check_if_OK = 1; else if (timeinfo->tm_mday == i_day_endtime) { if (timeinfo->tm_hour < i_hour_endtime) check_if_OK = 1; else if (timeinfo->tm_hour == i_hour_endtime) { if (timeinfo->tm_min < i_minute_endtime) check_if_OK = 1; } } } } if (((i_total_start_minute < i_total_end_minute && i_total_current_minute >= i_total_start_minute && i_total_current_minute <= i_total_end_minute) || (i_total_start_minute > i_total_end_minute && (i_total_current_minute >= i_total_start_minute || i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { check_if_white_or_black_within_lifetime = 1; } } } #endif if (check_if_white_or_black_within_lifetime == 0) { //printf("trigger type 2 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone //printf("trigger type 3 \n"); diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #if 0 else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } #endif //printf("trigger type 4 \n"); /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } } else if (trigger_type == TRIGGER_GO_STRAIGHT) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n");*/ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if(check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx)==1) { if (IsANPRCategory_L_Plate(pNext->name)==1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } } } else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { if (IsANPRCategory_L_Plate(pNext->name) == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } } } } else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { if (IsANPRCategory_L_Plate(pNext->name) == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } } } } else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { if (IsANPRCategory_L_Plate(pNext->name) == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } } } } else if (trigger_type == TRIGGER_PARKING_VIOLATION) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { //printf("1111 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) // printf("1111-1 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) // printf("1111-2 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; int nDiffSecs2 = (int)diffSecs2; float distCenter = 0; pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); if (/*(strcmp(ObjectName, "car") == 0 || (strcmp(ObjectName, "truck") == 0)) && */distCenter > 1) { //printf("distCenter = %f \n", distCenter); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); //printf("\ndiffSecs: %d\n",(int)diffSecs); //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0 /*|| strstr(ObjectName, "plate") != NULL*/) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { #if 0 //Open for 華電 避免塞車誤報 //printf("AAAAAAA %s \n", "nNeedTrigger 1"); //nNeedTrigger = 1; //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); //printf("center diff = %d \n", distCenter); //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] //check prev iou > 60 //printf("iou self 1 = %d \n", pNext->iou_prev_self); if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 1; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //printf("33334444 \n"); nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; #endif } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { #if 0 //Open for 華電 避免塞車誤報 //printf("iou self 2 = %d \n", pNext->iou_prev_self); //check prev iou > 60 if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 2; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //Normal if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) { nNeedTrigger = 2; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #endif } #if 0 //Open for 華電 避免塞車誤報 if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) { pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; break; } else break; #else //printf("33338888 \n"); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; #endif } } } } //printf("4444 \n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_ZONE_VIOLATION) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if(check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } #ifdef GY_OS_AMBA else if (trigger_type == TRIGGER_SPEED_HIGH) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_SPEED_LOW) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } #endif else if (trigger_type == TRIGGER_ALL_OBJECTS) { if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) && ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) ) { //printf("\nAAAAAAAAAAA: 1\n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { int nearest_index = -1; float nearest_distance = (float)INF; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { if (check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx) && IsGarbageCategory(pNext_bring)) { //nNeedTrigger = 1; //printf("\n-----plate(%f,%f),object(%f,%f)\n", pNext->center_x, pNext->center_y, pNext_bring->center_x, pNext_bring->center_y); float temp_nearest_distance = sqrt(pow(pNext->center_x- pNext_bring->center_x,2)+ pow(pNext->center_y - pNext_bring->center_y,2)); if (temp_nearest_distance < nearest_distance) { nearest_index = j; nearest_distance = temp_nearest_distance; } } } } } if (nearest_index >= 0) { detection_pos *pNext_bring = PosInfo + nearest_index; pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; pNext_bring->zone_violation_idx[detection_zone_idx] = 1; strcpy(pNext_bring->linked_plate, pNext->properties.plate); pNext_bring->linked_plate_length = pNext->properties.plate_length; if (pNext_bring->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; } } } } } else { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 /*&& ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)*/) { int nearest_index = -1; float nearest_distance = (float)INF; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; if (check_if_object_in_zone_simple_version_not_plate(pNext_bring, detection_zone_idx) /*&& IsGarbageCategory(pNext_bring)*/) { float temp_nearest_distance = sqrt(pow(pNext->center_x - pNext_bring->center_x, 2) + pow(pNext->center_y - pNext_bring->center_y, 2)); if (temp_nearest_distance < nearest_distance) { nearest_index = j; nearest_distance = temp_nearest_distance; } } } } if (nearest_index >= 0) { detection_pos *pNext_bring = PosInfo + nearest_index; pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; pNext_bring->zone_violation_idx[detection_zone_idx] = 1; strcpy(pNext_bring->linked_plate, pNext->properties.plate); pNext_bring->linked_plate_length = pNext->properties.plate_length; if (pNext_bring->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; } } } } } } #endif } else{ if (trigger_type == TRIGGER_MISSING_UNATTENDED) { //printf("1111 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) // printf("1111-1 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) // printf("1111-2 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; int nDiffSecs2 = (int)diffSecs2; float distCenter = 0; pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); if ((strcmp(ObjectName, "object") == 0) && distCenter > 1) { //printf("distCenter = %f \n", distCenter); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); //printf("\ndiffSecs: %d\n",(int)diffSecs); //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); if (strcmp(ObjectName,"object")==0) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { #if 0 //Open for 華電 避免塞車誤報 //printf("AAAAAAA %s \n", "nNeedTrigger 1"); //nNeedTrigger = 1; //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); //printf("center diff = %d \n", distCenter); //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] //check prev iou > 60 //printf("iou self 1 = %d \n", pNext->iou_prev_self); if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 1; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //printf("33334444 \n"); nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; #endif } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { #if 0 //Open for 華電 避免塞車誤報 //printf("iou self 2 = %d \n", pNext->iou_prev_self); //check prev iou > 60 if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 2; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //Normal if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) { nNeedTrigger = 2; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #endif } #if 0 //Open for 華電 避免塞車誤報 if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) { pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } #else //printf("33338888 \n"); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; #endif } } } //printf("4444 \n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { if (strcmp(ObjectName, "object") == 0) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } else if (trigger_type == TRIGGER_GO_STRAIGHT) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ( (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //break; } } } } } else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //break; } } } } } } else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //break; } } } } } } else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) { if (get_g_check_if_current_light_is_red() == 1) { int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) { //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; /* printf("\n----center direction queue:"); for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); } printf("----center direction end--\n"); */ int check_if_stability = 1; if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); if (diff_angle > 180.0) diff_angle = 360.0 - diff_angle; if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { check_if_stability = 0; //printf("\ndrop out\n"); } } } if (check_if_stability == 1) { //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; } pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //break; } } } } } } else if (trigger_type == TRIGGER_PARKING_VIOLATION) { //printf("1111 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) // printf("1111-1 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) // printf("1111-2 \n"); //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; int nDiffSecs2 = (int)diffSecs2; float distCenter = 0; pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); if (/*(strcmp(ObjectName, "car") == 0 || strcmp(ObjectName, "truck") == 0 || strcmp(ObjectName, "car_front_back") == 0)*/ (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && distCenter > 1) { //printf("distCenter = %f \n", distCenter); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); //printf("\ndiffSecs: %d\n",(int)diffSecs); //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) if(check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); //for (int j = 0; j < metadata1_num; j++) { if (check_vehicle_over_time(pNext, detection_zone_idx, d_no_parking_time)) /*|| strstr(ObjectName, "plate") != NULL*/ { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { #if 0 //Open for 華電 避免塞車誤報 //printf("AAAAAAA %s \n", "nNeedTrigger 1"); //nNeedTrigger = 1; //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); //printf("center diff = %d \n", distCenter); //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] //check prev iou > 60 //printf("iou self 1 = %d \n", pNext->iou_prev_self); if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 1; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //printf("33334444 \n"); nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; #endif } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { #if 0 //Open for 華電 避免塞車誤報 //printf("iou self 2 = %d \n", pNext->iou_prev_self); //check prev iou > 60 if (pNext->iou_prev_self >= 98) { if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) { if (pNext->near_iou_count[detection_zone_idx] <= 1) { //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); nNeedTrigger = 2; //pNext->trigger_type = trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; } #else //Normal if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) { nNeedTrigger = 2; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } #endif } #if 0 //Open for 華電 避免塞車誤報 if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) { pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } //else //break; #else //printf("33338888 \n"); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; #endif } } } } //printf("4444 \n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } else if (trigger_type == TRIGGER_ZONE_VIOLATION) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || // (diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } #ifdef GY_OS_AMBA else if (trigger_type == TRIGGER_DISTANCE_VIOLATION) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) //printf("\n--------g_max_tof_range:%f\n", g_max_tof_range); //printf("\n-------atof(tofData.distance_threshold):%f\n", atof(tofData.distance_threshold)); int check_if_OK_tof = 0; if (strcmp(tofData.distance_options, "gt") == 0) { if (strcmp(tofData.distance_min_max, "min") == 0) { if (g_min_tof_distance > atof(tofData.distance_threshold) && pNext->min_distance != 0) { check_if_OK_tof = 1; } } else if (strcmp(tofData.distance_min_max, "max") == 0) { if (g_max_tof_distance > atof(tofData.distance_threshold) && pNext->max_distance != 0) { check_if_OK_tof = 1; } } } else if (strcmp(tofData.distance_options, "lt") == 0) { if (strcmp(tofData.distance_min_max, "min") == 0) { if (g_min_tof_distance < atof(tofData.distance_threshold) && pNext->min_distance != 0) { check_if_OK_tof = 1; } } else if (strcmp(tofData.distance_min_max, "max") == 0) { if (g_max_tof_distance < atof(tofData.distance_threshold) && pNext->max_distance != 0) { check_if_OK_tof = 1; } } } if(check_if_OK_tof == 1) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (strcmp(ObjectName,"tof_point") == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_HIGH_VIOLATION) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) int check_if_OK_tof = 0; if (strcmp(tofData.height_options, "gt") == 0) { if (strcmp(tofData.height_min_max, "min") == 0) { if (g_min_tof_height > atof(tofData.height_threshold) && pNext->min_height != 0) { check_if_OK_tof = 1; } } else if (strcmp(tofData.height_min_max, "max") == 0) { if (g_max_tof_height > atof(tofData.height_threshold) && pNext->max_height != 0) { check_if_OK_tof = 1; } } } else if (strcmp(tofData.height_options, "lt") == 0) { if (strcmp(tofData.height_min_max, "min") == 0) { if (g_min_tof_height < atof(tofData.height_threshold) && pNext->min_height != 0) { check_if_OK_tof = 1; } } else if (strcmp(tofData.height_min_max, "max") == 0) { if (g_max_tof_height < atof(tofData.height_threshold) && pNext->max_height != 0) { check_if_OK_tof = 1; } } } if (check_if_OK_tof == 1) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (strcmp(ObjectName, "tof_point") == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } #endif else if (trigger_type == TRIGGER_FORGET_TO_GIVE_WAY) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); //pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_check_giveway[detection_zone_idx] = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_SPEED_HIGH) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if(pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_SPEED_LOW) { //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { //nNeedTrigger = 2; //post: yes, counter: no nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } else if (trigger_type == TRIGGER_TAMPERING) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //if (detection_count > 1) //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); //int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (strcmp(ObjectName, "tampering") == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) //{ nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //} //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) //{ //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) //{ //nNeedTrigger = 2; //post: yes, counter: no //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //} //} /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } } } else if (trigger_type == TRIGGER_ALL_OBJECTS) { if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) && ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) ) { //printf("\nAAAAAAAAAAA: 1\n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { int temp_count_meta = 0; temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) { if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { int check_if_not_bring = 1; for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { check_if_not_bring = 0; break; } } if (check_if_not_bring) { //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //if(check_if_existing_in_metaout(BringName, detection_zone_idx)) { strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); temp_count_meta++; pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; //break; } } } } } } } } int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //int count_correct_meta = 0; //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) //{ //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) //if(check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) { //count_correct_meta++; //break; } //} } //if (count_correct_meta == metadata1_num - 1) if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; pNext->num_bring_with_object[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; } } else if ((strcmp(ObjectName, "person") == 0) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { int temp_count_meta = 0; temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) { if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { int check_if_not_bring = 1; for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { check_if_not_bring = 0; break; } } if (check_if_not_bring) { //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) { strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); temp_count_meta++; pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; //break; } } } } } } } } int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //int count_correct_meta = 0; //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) //{ //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) { //count_correct_meta++; //break; } //} } //if (count_correct_meta >= 1) if (pNext->num_bring_with_object[detection_zone_idx] >= 1) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; pNext->num_bring_with_object[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; } } else if ((IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //if (check_if_existing_in_metaout(BringName, detection_zone_idx) && IsGarbageCategory(pNext_bring)) if (IsGarbageCategory(pNext_bring)) { //nNeedTrigger = 1; pNext->trigger_type = trigger_type | pNext->trigger_type; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; if (pNext->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; } } } } } } } } } else { //printf("\nAAAAAAAAAAA: 2\n"); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //printf("\nAAAAAAAAAAA: 2-1------%d\n", get_g_check_if_all_existing(detection_zone_idx)); //if ((int)pNext->obj_dwell_time % 2 == 0) if (get_g_check_if_all_existing(detection_zone_idx) == 1) { //printf("\nAAAAAAAAAAA: 2-2\n"); //for (int j = 0; j < metadata1_num; j++) { if(check_if_object_in_zone_simple_version_not_plate(pNext, detection_zone_idx)) { //printf("\nAAAAAAAAAAA: 2-3\n"); //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } else if (trigger_type == TRIGGER_LACK_OF_ANY_OBJECT) { if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) && ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) ) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { int temp_count_meta = 0; temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) { if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { int check_if_not_bring = 1; for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { check_if_not_bring = 0; break; } } if (check_if_not_bring) { //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //if (strcmp(BringName, MetaOut1[index_meta]) == 0) //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) { strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); temp_count_meta++; pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; //break; } } } } } } } } int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //int count_correct_meta = 0; //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) { //count_correct_meta++; //break; } //} } //if (count_correct_meta == metadata1_num - 1) if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) { } else { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; pNext->num_bring_with_object[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; } } else if ((strcmp(ObjectName, "person") == 0 || IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { int temp_count_meta = 0; temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) { if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { int check_if_not_bring = 1; for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { check_if_not_bring = 0; break; } } if (check_if_not_bring) { //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //if (strcmp(BringName, MetaOut1[index_meta]) == 0) //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) { strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); temp_count_meta++; pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; //break; } } } } } } } } int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //int count_correct_meta = 0; //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) { //count_correct_meta++; //break; } //} } //if (count_correct_meta >= 1) if (pNext->num_bring_with_object[detection_zone_idx] >= 1) { } else { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; pNext->num_bring_with_object[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; } } } } else { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; /*if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0)*/ { if (get_g_check_if_NAND(detection_zone_idx) == 1) { //for (int j = 0; j < metadata1_num; j++) { //if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) if (check_if_object_in_zone_simple_version(pNext, detection_zone_idx)) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); /* printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); printf("\ntrigger_type:%d\n",trigger_type); */ if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } /* printf("\nnNeedTrigger:%d\n", nNeedTrigger); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); */ //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } } else if (trigger_type == TRIGGER_QUEUING_VIOLATION) { if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_line >= 1) { } else { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { int check_if_enable_linked_to_dwell_time = 0; #ifdef GY_OS_V_SERIES #else #if 1 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)) || g_IsCustomWeight == 1) { char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); int event_counter_num = StrSplit(Temp, eachEventCounter, ","); //printf("\n------UU:4\n"); for (int i = 0; i < event_counter_num; i++) { for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { if (strlen(eachEventCounter[i]) >= 1 && strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) { if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0) { check_if_enable_linked_to_dwell_time = 1; break; } } } if (check_if_enable_linked_to_dwell_time == 1) break; } } #endif #endif if(check_if_enable_linked_to_dwell_time == 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //pNext->trigger_type = trigger_type; pNext->zone_violation_idx[detection_zone_idx] = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else if (check_if_enable_linked_to_dwell_time == 1) { int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //pNext->trigger_type = trigger_type; pNext->zone_violation_idx[detection_zone_idx] = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } } #if 0 else if (trigger_type == TRIGGER_MISSING_OBJECT_DETECTION) { /* printf("\n----------------------------------\n"); printf("\nobj_first_dwell_time: %lf\n",pNext->obj_first_dwell_time); printf("\nobj_last_dwell_time: %lf\n", pNext->obj_last_dwell_time); printf("\n----------------------------------\n");*/ /*if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { } }*/ if (pNext->obj_dwell_time > g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time + d_no_parking_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { { nNeedTrigger = 1; pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = 0.0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = 0.0; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 2; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //if (diffSecs >= dewell_time2) { //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } //break; } } } } #endif #if 0 if (trigger_event_type == TRIGGER_TURN_LEFT) { if (trigger_type == TRIGGER_TURN_LEFT) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_TURN_RIGHT) { if (trigger_type == TRIGGER_TURN_RIGHT) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { //if (strcmp(ObjectName, MetaOut1[j]) == 0) if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_WRONG_WAY) { if (trigger_type == TRIGGER_WRONG_WAY) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) { if (trigger_type == TRIGGER_TURN_LEFT_VIOLATION) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) { if (trigger_type == TRIGGER_TURN_RIGHT_VIOLATION) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) { if (trigger_type == TRIGGER_U_TURN_VIOLATION) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line /*&& g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx] == backward_line*/ && forward_line > 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } /* if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) { if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) { if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) { if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) { diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); if (diffSecs < dewell_time) { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; } pNext->trigger_type = trigger_type; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } else { //for (int j = 0; j < metadata1_num; j++) { if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) { nNeedTrigger = 0; //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } } } */ #endif /* if (trigger_event_type == TRIGGER_BG_LEARNING) { if (trigger_type == TRIGGER_BG_LEARNING) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) { //lasting time since enter zone diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); if (detection_count > 1) diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); int nDiffSecs = (int)diffSecs; //int nDiffSecs2 = (int)diffSecs2; //if ((int)pNext->obj_dwell_time % 2 == 0) { //for (int j = 0; j < metadata1_num; j++) { if (strcmp(ObjectName, "bg_learning") == 0) { //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) { nNeedTrigger = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) { if (nDiffSecs % TRIGGER_INTERVAL == 0) { nNeedTrigger = 2; //post: yes, counter: no g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; } } //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); pNext->trigger_type = trigger_type; //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); pNext->zone_violation_idx[detection_zone_idx] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } } } }*/ } if (strcmp(SystemSetting.enable_person_independent, "Yes") == 0) { //printf("\nTTTTTTTTTT : 1\n"); if (strcmp(ObjectName, "person") == 0) { int temp_count_meta = 0; temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; //printf("\nTTTTTTTTTT : 2\n"); for (int j = 0; j < total_element_size; j++) { if (j != result_idx) { detection_pos *pNext_bring = PosInfo + j; if (!IsANPRCategory(pNext_bring->engine_type)) { char BringName[30] = { 0 }; sprintf(BringName, "%s", pNext_bring->name); UpperToLower(BringName); if (strcmp(BringName, "person") != 0) { //printf("\nTTTTTTTTTT : 3\n"); //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) { { //nNeedTrigger = 0; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext_bring->trigger_type = 0; //pNext->detection_zone_idx = detection_zone_idx; pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; pNext_bring->zone_violation_idx[detection_zone_idx] = 0; pNext_bring->check_person_inter = 1; if (pNext_bring->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = 0; int det_count_temp = g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].detection_count; if(det_count_temp >= 1) g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].prev_detections[det_count_temp - 1].check_person_inter = 1; } } //printf("\nTTTTTTTTTT : 4\n"); if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { int check_if_not_bring = 1; for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { check_if_not_bring = 0; break; } } if (check_if_not_bring) { //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { if (check_if_existing_in_metaout(BringName, detection_zone_idx)) { strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); if (detection_count >= 1) strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); temp_count_meta++; pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; if (detection_count >= 1) g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; //break; } } } } //printf("\nTTTTTTTTTT : 5\n"); } } } } } //printf("\nTTTTTTTTTT : 6\n"); //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { int count_correct_meta = 0; //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) { for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) { count_correct_meta++; //break; } } } if (count_correct_meta >= 1) { nNeedTrigger = 0; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = 0; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; pNext->check_person_inter = 1; if (detection_count >= 1) g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; //nNeedTrigger = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; //pNext->trigger_type = trigger_type | pNext->trigger_type; //pNext->detection_zone_idx = detection_zone_idx; //pNext->trigger_idx[detection_zone_idx] = trigger_idx; //pNext->zone_violation_idx[detection_zone_idx] = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } else { pNext->check_person_inter = 0; if (detection_count >= 1) g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; } //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; //pNext->num_bring_with_object[detection_zone_idx] = 0; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; } //printf("\nTTTTTTTTTT : 7\n"); } else { if (!IsANPRCategory(pNext->engine_type)) { //printf("\nTTTTTTTTTT : 8\n"); if (pNext->check_person_inter == 1) { nNeedTrigger = 0; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = 0; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; //printf("\nTTTTTTTTTT : 9\n"); } else { //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; //if (diff_secs_in_zone < d_no_parking_time && diff_secs_in_zone > 0) { nNeedTrigger = 0; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; pNext->trigger_type = 0; //pNext->detection_zone_idx = detection_zone_idx; pNext->trigger_idx[detection_zone_idx] = trigger_idx; pNext->zone_violation_idx[detection_zone_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; pNext->check_person_inter = 1; if (detection_count >= 1) g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; } //printf("\nTTTTTTTTTT : 10\n"); } } else { pNext->check_person_inter = 0; if (detection_count >= 1) g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; //printf("\nTTTTTTTTTT : 11\n"); } } } return nNeedTrigger; } #endif #if 1 char g_last_token_name[256] = { 0 }; char g_last_token_confidence[10] = { 0 }; char g_last_token_left_x[10] = { 0 }; char g_last_token_top_y[10] = { 0 }; char g_last_token_width[10] = { 0 }; char g_last_token_height[10] = { 0 }; char g_last_token_center_x[10] = { 0 }; char g_last_token_center_y[10] = { 0 }; char g_last_token_center_speed[35] = { 0 }; char g_last_token_center_direction[10] = { 0 }; char g_last_token_center_stability[10] = { 0 }; char g_last_token_obj_tracking_id[10] = { 0 }; char g_last_token_obj_dwell_time[20] = { 0 }; char g_last_token_class_id[10] = { 0 }; char g_last_token_color[20] = { 0 }; char g_last_token_plate[256] = { 0 }; char g_last_token_country[256] = { 0 }; char g_last_token_area[256] = { 0 }; char g_last_token_plate_list[256] = { 0 }; char g_last_token_logo[256] = { 0 }; char g_last_token_behavior_id[1024] = { 0 }; char g_last_token_zone_id[10] = { 0 }; char g_last_token_behavior_name[256] = { 0 }; char g_last_token_linked_plate[256] = { 0 }; size_t ReplaceKeyWords(detection_pos* pNext, int space_zone,int space_id,char* InputString,char *OutputString,int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64,int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) { char *replacement = NULL; char *replacement_t = NULL; char msg[MAX_MSG_LEN] = { 0 }; replacement = InputString; //避免後面的replacement沒有辦法做free。 replacement_t = StrReplace(replacement, "<|test_token|>", "Hello"); replacement = replacement_t; if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (strcmp(heartbeatData.events_default_version, "4") == 0) { if (strcmp(pNext->name, "car") == 0) { sprintf(msg, "%s", "vehicle"); strcpy(g_last_token_name, "vehicle"); } else if (strcmp(pNext->name, "person") == 0) { sprintf(msg, "%s", "human"); strcpy(g_last_token_name, "human"); } else { sprintf(msg, "%s", pNext->name); strcpy(g_last_token_name, pNext->name); } } else { sprintf(msg, "%s", pNext->name); strcpy(g_last_token_name, pNext->name); } replacement_t = StrReplace(replacement, "<|name|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_name); replacement_t = StrReplace(replacement, "<|name|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", (int)pNext->confidence); sprintf(g_last_token_confidence, "%d", (int)pNext->confidence); replacement_t = StrReplace(replacement, "<|confidence|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_confidence); replacement_t = StrReplace(replacement, "<|confidence|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (show_large_bbox == 1) { sprintf(msg, "%d", (int)(pNext->left_x - pNext->width / 3.0)); sprintf(g_last_token_left_x, "%d", (int)(pNext->left_x - pNext->width / 3.0)); } else { sprintf(msg, "%d", (int)pNext->left_x); sprintf(g_last_token_left_x, "%d", (int)pNext->left_x); } replacement_t = StrReplace(replacement, "<|left_x|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_left_x); replacement_t = StrReplace(replacement, "<|left_x|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (show_large_bbox == 1) { sprintf(msg, "%d", (int)(pNext->top_y - pNext->height / 3.0)); sprintf(g_last_token_top_y, "%d", (int)(pNext->top_y - pNext->height / 3.0)); } else { sprintf(msg, "%d", (int)pNext->top_y); sprintf(g_last_token_top_y, "%d", (int)pNext->top_y); } replacement_t = StrReplace(replacement, "<|top_y|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_top_y); replacement_t = StrReplace(replacement, "<|top_y|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (show_large_bbox == 1) { sprintf(msg, "%d", (int)(pNext->width * 5.0 / 3.0)); sprintf(g_last_token_width, "%d", (int)(pNext->width * 5.0 / 3.0)); } else { sprintf(msg, "%d", (int)pNext->width); sprintf(g_last_token_width, "%d", (int)pNext->width); } replacement_t = StrReplace(replacement, "<|width|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_width); replacement_t = StrReplace(replacement, "<|width|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (show_large_bbox == 1) { sprintf(msg, "%d", (int)(pNext->height * 5.0 / 3.0)); sprintf(g_last_token_height, "%d", (int)(pNext->height * 5.0 / 3.0)); } else { sprintf(msg, "%d", (int)pNext->height); sprintf(g_last_token_height, "%d", (int)pNext->height); } replacement_t = StrReplace(replacement, "<|height|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_height); replacement_t = StrReplace(replacement, "<|height|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", (int)pNext->center_x); sprintf(g_last_token_center_x, "%d", (int)pNext->center_x); replacement_t = StrReplace(replacement, "<|center_x|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_center_x); replacement_t = StrReplace(replacement, "<|center_x|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", (int)pNext->center_y); sprintf(g_last_token_center_y, "%d", (int)pNext->center_y); replacement_t = StrReplace(replacement, "<|center_y|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_center_y); replacement_t = StrReplace(replacement, "<|center_y|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } char msg_center_speed[35] = { 0 }; if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { strcat(msg_center_speed, " km/h"); } else { strcat(msg_center_speed, " mi/h"); } } else { sprintf(msg_center_speed, "%s", ""); } sprintf(g_last_token_center_speed, "%s", msg_center_speed); replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg_center_speed, "%s", g_last_token_center_speed); replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { sprintf(msg, "%d", (int)pNext->center_direction); sprintf(g_last_token_center_direction, "%d", (int)pNext->center_direction); } else { sprintf(msg, "%s", ""); sprintf(g_last_token_center_direction, "%s", ""); } replacement_t = StrReplace(replacement, "<|center_direction|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_center_direction); replacement_t = StrReplace(replacement, "<|center_direction|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { sprintf(msg, "%d", (int)pNext->center_stability); sprintf(g_last_token_center_stability, "%d", (int)pNext->center_stability); } else { sprintf(msg, "%s", ""); sprintf(g_last_token_center_stability, "%s", ""); } replacement_t = StrReplace(replacement, "<|center_stability|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_center_stability); replacement_t = StrReplace(replacement, "<|center_stability|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", (int)pNext->obj_tracking_id); sprintf(g_last_token_obj_tracking_id, "%d", (int)pNext->obj_tracking_id); replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_obj_tracking_id); replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", (int)(pNext->obj_dwell_time * 100) / 100); sprintf(g_last_token_obj_dwell_time, "%d", (int)(pNext->obj_dwell_time * 100) / 100); replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_obj_dwell_time); replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { sprintf(msg, "%d", pNext->class_id); sprintf(g_last_token_class_id, "%d", pNext->class_id); replacement_t = StrReplace(replacement, "<|class_id|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(msg, "%s", g_last_token_class_id); replacement_t = StrReplace(replacement, "<|class_id|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } #ifdef GY_OS_AMBA char mycolor[20] = { 0 }; if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { if (!IsANPRCategory(pNext->engine_type)) { if (pNext->image_id != -1 && get_check_first_downsized_cropped_roi_for_object() == 1) { if (pNext->color_id == 1) strcpy(mycolor, "Red"); else if (pNext->color_id == 2) strcpy(mycolor, "Orange"); else if (pNext->color_id == 3) strcpy(mycolor, "Yellow"); else if (pNext->color_id == 4) strcpy(mycolor, "Green"); else if (pNext->color_id == 5) strcpy(mycolor, "Blue"); else if (pNext->color_id == 6) strcpy(mycolor, "Cyan"); else if (pNext->color_id == 7) strcpy(mycolor, "Purple"); else if (pNext->color_id == 8) strcpy(mycolor, "Black"); else if (pNext->color_id == 9) strcpy(mycolor, "White"); else if (pNext->color_id == 11) strcpy(mycolor, "Darkgray"); else if (pNext->color_id == 10) strcpy(mycolor, "Gray");//Silver } } } } else { sprintf(mycolor, "%s", ""); } if (detection_zone_idx >= 0 && trigger_idx >= 0) { sprintf(g_last_token_color, "%s", mycolor); replacement_t = StrReplace(replacement, "<|color|>", mycolor); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { sprintf(mycolor, "%s", g_last_token_color); replacement_t = StrReplace(replacement, "<|color|>", mycolor); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } #endif if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { replacement_t = StrReplace(replacement, "<|plate|>", pNext->properties.plate); sprintf(g_last_token_plate, "%s", pNext->properties.plate); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|plate|>", g_last_token_plate); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { replacement_t = StrReplace(replacement, "<|country|>", pNext->properties.country); sprintf(g_last_token_country, "%s", pNext->properties.country); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|country|>", g_last_token_country); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { replacement_t = StrReplace(replacement, "<|area|>", pNext->properties.area); sprintf(g_last_token_area, "%s", pNext->properties.area); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|area|>", g_last_token_area); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { replacement_t = StrReplace(replacement, "<|plate_list|>", pNext->properties.plate_list); sprintf(g_last_token_plate_list, "%s", pNext->properties.plate_list); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|plate_list|>", g_last_token_plate_list); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { replacement_t = StrReplace(replacement, "<|logo|>", pNext->logo); sprintf(g_last_token_logo, "%s", pNext->logo); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|logo|>", g_last_token_logo); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } #ifdef GY_OS_AMBA int hex_token_base = 1; int sum_hex = 0; for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { if (index_zone >= 1) { hex_token_base *= 2; } if (viewDetectionZone[tracking_channel_idx][index_zone].prev_queuing_num >= 1) { sum_hex += hex_token_base; } } char buf_hex[50] = { 0 }; sprintf(buf_hex, "%d", sum_hex); replacement_t = StrReplace(replacement, "<|hextoint|>", buf_hex); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; #endif int behavior_ID = 0; if (detection_zone_idx >= 0 && trigger_idx >= 0) behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); sprintf(msg, "%d", behavior_ID);//(int)pNext->trigger_type if (detection_zone_idx >= 0 && trigger_idx >= 0) { replacement_t = StrReplace(replacement, "<|behavior_id|>", msg); sprintf(g_last_token_behavior_id, "%s", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|behavior_id|>", g_last_token_behavior_id); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { sprintf(msg, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); sprintf(g_last_token_zone_id, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); replacement_t = StrReplace(replacement, "<|zone_id|>", msg); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|zone_id|>", g_last_token_zone_id); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } char behavior_name[256] = { 0 }; if ((behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { strcpy(behavior_name, "Prohibit_zone"); } else if ((behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { strcpy(behavior_name, "Distance_violation"); } else if ((behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { strcpy(behavior_name, "Height_detection"); } else if ((behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { strcpy(behavior_name, "Forget_to_give_way_detection");//不禮讓偵測 } else if ((behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { strcpy(behavior_name, "Max_speed_detection"); } else if ((behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { strcpy(behavior_name, "Min_speed_detection"); } else if ((behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { strcpy(behavior_name, "Zone_with_dwell_Parking_violation");//禁區限時偵測 / 違規停車 } else if ((behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { strcpy(behavior_name, "Tripwire_Traffic_flow");//警戒線 / 直行偵測 } else if ((behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { strcpy(behavior_name, "Tripwire_on_red_Running_red_lights");//紅燈警戒線 / 紅燈直行 } else if ((behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { strcpy(behavior_name, "Turning_left_on_red");//紅燈左轉 } else if ((behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { strcpy(behavior_name, "Turning_right_on_red");//紅燈右轉 } else if ((behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { strcpy(behavior_name, "Turn_left");//左轉偵測 } else if ((behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { strcpy(behavior_name, "Turn_right");//右轉偵測 } else if ((behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { strcpy(behavior_name, "LPR_allowed_list_detection_in_zone");//白名單警戒區偵測 } else if ((behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { strcpy(behavior_name, "LPR_visitor_list_detection_in_zone");//訪客名單警戒區偵測 } else if ((behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { strcpy(behavior_name, "LPR_denial_list_detection_in_zone");//黑名單警戒區偵測 } else if ((behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { strcpy(behavior_name, "Density_detection");//密度偵測 } else if ((behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { strcpy(behavior_name, "AI_missing_object_detection");//AI遺失物偵測 } else if ((behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { strcpy(behavior_name, "Unattended_or_missing_object");//遺失物及遺留物偵測 } else if ((behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { strcpy(behavior_name, "Tampering_detection");//防破壞偵測 } else if ((behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { strcpy(behavior_name, "All_objects_detection_AND");//物種同時存在偵測 (AND) } else if ((behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { strcpy(behavior_name, "Lack_of_any_object_detection_NAND");//缺少任一物種同時存在偵測 (NAND) } if (detection_zone_idx >= 0 && trigger_idx >= 0) { replacement_t = StrReplace(replacement, "<|behavior_name|>", behavior_name); sprintf(g_last_token_behavior_name, "%s", behavior_name); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|behavior_name|>", g_last_token_behavior_name); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { replacement_t = StrReplace(replacement, "<|linked_plate|>", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); sprintf(g_last_token_linked_plate, "%s", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } else { if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { replacement_t = StrReplace(replacement, "<|linked_plate|>", g_last_token_linked_plate); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } //time_t rawtime = time(0); time_t rawtime = g_osdSysTimeStamp; struct tm * timeinfo; timeinfo = localtime(&rawtime); //printf("\n---g_osdSysTimeStamp:%ld,%04d-%02d-%02dT%02d:%02d:%02d\n", g_osdSysTimeStamp, 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, //timeinfo->tm_min, timeinfo->tm_sec); /* char buf_time_info[256] = { 0 }; sprintf(buf_time_info, "%04d-%02d-%02dT%02d:%02d:%02d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); */ char buf_time_t[50] = { 0 }; sprintf(buf_time_t, "%ld", rawtime); replacement_t = StrReplace(replacement, "<|time_t|>", buf_time_t); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_year[20] = { 0 }; sprintf(buf_year, "%04d", 1900 + timeinfo->tm_year); replacement_t = StrReplace(replacement, "<|YYYY|>", buf_year); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_month[20] = { 0 }; sprintf(buf_month, "%02d", 1 + timeinfo->tm_mon); replacement_t = StrReplace(replacement, "<|MM|>", buf_month); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_date[10] = { 0 }; sprintf(buf_date, "%02d", timeinfo->tm_mday); replacement_t = StrReplace(replacement, "<|DD|>", buf_date); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_hour[10] = { 0 }; sprintf(buf_hour, "%02d", timeinfo->tm_hour); replacement_t = StrReplace(replacement, "<|hh|>", buf_hour); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_minute[10] = { 0 }; sprintf(buf_minute, "%02d", timeinfo->tm_min); replacement_t = StrReplace(replacement, "<|mm|>", buf_minute); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_second[10] = { 0 }; sprintf(buf_second, "%02d", timeinfo->tm_sec); replacement_t = StrReplace(replacement, "<|ss|>", buf_second); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; struct tm * gmtinfo; gmtinfo = gmtime(&rawtime); char buf_gmthour[10] = { 0 }; sprintf(buf_gmthour, "%02d", gmtinfo->tm_hour); replacement_t = StrReplace(replacement, "<|GMThh|>", buf_gmthour); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; #ifdef GY_OS_V_SERIES #else for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { char temp_label[30] = { 0 }; sprintf(temp_label, "<|counter%02d_count|>", index_counter + 1); char temp_counter_count[30] = { 0 }; sprintf(temp_counter_count,"%d", eventCounterList[index_counter].counter_count); replacement_t = StrReplace(replacement, temp_label, temp_counter_count); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char temp_label_dwell[30] = { 0 }; sprintf(temp_label_dwell, "<|counter%02d_dwell|>", index_counter + 1); char temp_counter_timetResetAt[50] = { 0 }; sprintf(temp_counter_timetResetAt, "%d", eventCounterList[index_counter].dwell_time); replacement_t = StrReplace(replacement, temp_label_dwell, temp_counter_timetResetAt); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char temp_label_dwell_unit[50] = { 0 }; sprintf(temp_label_dwell_unit, "<|counter%02d_dwell_unit|>", index_counter + 1); replacement_t = StrReplace(replacement, temp_label_dwell_unit, eventCounterList[index_counter].dwell_unit); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } #endif char fetch_mac_addr[30] = { 0 }; if (g_match_mac) strcpy(fetch_mac_addr, g_mac_address); else { GetMACAddress(fetch_mac_addr); //printf("mac addr = %s \n", fetch_mac_addr); int i = 0; while (fetch_mac_addr[i] != '\0') { if (fetch_mac_addr[i] == '\n') { fetch_mac_addr[i] = '\0'; break; } i++; } } replacement_t = StrReplace(replacement, "<|mac_address|>", fetch_mac_addr); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; replacement_t = StrReplace(replacement, "<|device_name|>", g_device_name); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; replacement_t = StrReplace(replacement, "<|dataset_ver|>", Buffer_ver); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char temp_soft_ver[50] = { 0 }; strcat(temp_soft_ver, APP_VERSION); strcat(temp_soft_ver, "-"); strcat(temp_soft_ver, WeightFileModeName); replacement_t = StrReplace(replacement, "<|soft_ver|>", temp_soft_ver); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_frame_id[50] = { 0 }; sprintf(buf_frame_id, "%u", get_frame_id()); replacement_t = StrReplace(replacement, "<|frame_id|>", buf_frame_id); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_parking_space[50] = { 0 }; sprintf(buf_parking_space, "%d", viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space); replacement_t = StrReplace(replacement, "<|total_space|>", buf_parking_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; if (space_zone >= 0 && space_id >= 0) { int temp_space_id = space_id; for (int index_zone = 0; index_zone < space_zone; index_zone++) { temp_space_id += (viewDetectionZone[tracking_channel_idx][space_zone].parking_space + 1); } char buf_space_id[50] = { 0 }; sprintf(buf_space_id, "%02d", temp_space_id + 1); replacement_t = StrReplace(replacement, "<|space_id|>", buf_space_id); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_space_zone[50] = { 0 }; sprintf(buf_space_zone, "%d", space_zone + 1); replacement_t = StrReplace(replacement, "<|space_zone|>", buf_space_zone); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_space_status[50] = { 0 }; sprintf(buf_space_status, "%d", g_parking_space_check_table[space_zone][space_id]); replacement_t = StrReplace(replacement, "<|space_status|>", buf_space_status); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; time_t rawtime_space = g_parking_space_status_change_time[space_zone][space_id]; struct tm * timeinfo_space; struct tm * gmtinfo_space; timeinfo_space = localtime(&rawtime_space); gmtinfo_space = gmtime(&rawtime_space); char buf_time_t_space[50] = { 0 }; sprintf(buf_time_t_space, "%ld", rawtime_space); replacement_t = StrReplace(replacement, "<|space_time_t|>", buf_time_t_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_year_space[20] = { 0 }; sprintf(buf_year_space, "%04d", 1900 + timeinfo_space->tm_year); replacement_t = StrReplace(replacement, "<|space_YYYY|>", buf_year_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_month_space[20] = { 0 }; sprintf(buf_month_space, "%02d", 1 + timeinfo_space->tm_mon); replacement_t = StrReplace(replacement, "<|space_MM|>", buf_month_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_date_space[10] = { 0 }; sprintf(buf_date_space, "%02d", timeinfo_space->tm_mday); replacement_t = StrReplace(replacement, "<|space_DD|>", buf_date_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_gmthour_space[10] = { 0 }; sprintf(buf_gmthour_space, "%02d", gmtinfo_space->tm_hour); replacement_t = StrReplace(replacement, "<|space_GMThh|>", buf_gmthour_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_hour_space[10] = { 0 }; sprintf(buf_hour, "%02d", timeinfo_space->tm_hour); replacement_t = StrReplace(replacement, "<|space_hh|>", buf_hour_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_minute_space[10] = { 0 }; sprintf(buf_minute_space, "%02d", timeinfo_space->tm_min); replacement_t = StrReplace(replacement, "<|space_mm|>", buf_minute_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_second_space[10] = { 0 }; sprintf(buf_second_space, "%02d", timeinfo_space->tm_sec); replacement_t = StrReplace(replacement, "<|space_ss|>", buf_second_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; char buf_difftime_space[10] = { 0 }; sprintf(buf_difftime_space, "%d", (int)difftime(g_osdSysTimeStamp, rawtime_space)); replacement_t = StrReplace(replacement, "<|difftime|>", buf_difftime_space); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } if (enable_base64_image == 1) { char buf_image_size[50] = { 0 }; sprintf(buf_image_size, "%d", image_buff_size_base64); replacement_t = StrReplace(replacement, "<|snap_size|>", buf_image_size); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; replacement_t = StrReplace(replacement, "<|snap_image|>", image_buff_base64); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; if (pNext != NULL && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && pNext->image_id >= 0 && pNext->image_id < MAX_PLATE_BUF_NUM && cropped_image_size_base64[pNext->image_id] >= 1) { if (cropped_image_base64 != NULL && cropped_image_base64[pNext->image_id] != NULL) { char buf_image_size[50] = { 0 }; sprintf(buf_image_size, "%d", cropped_image_size_base64[pNext->image_id]); replacement_t = StrReplace(replacement, "<|cropped_size|>", buf_image_size); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; cropped_image_base64[pNext->image_id][cropped_image_size_base64[pNext->image_id]] = '\0'; replacement_t = StrReplace(replacement, "<|cropped_image|>", cropped_image_base64[pNext->image_id]); if (replacement != NULL) { free(replacement); replacement = NULL; } replacement = replacement_t; } } } strcpy(OutputString, replacement); if (replacement != NULL) { free(replacement); replacement = NULL; } //printf("\n-----%s\n", OutputString); return strlen(OutputString); } //ReplaceKeyWords// size_t ReplaceKeyWords_space(detection_pos* pNext,char *SequenceString, int space_zone, int space_id, char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) { //printf("\n-------ReplaceKeyWords space----0\n"); size_t content_size = 0; //printf("\n-------ReplaceKeyWords space----1\n"); if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString,"<|space_zone|><|space_id|>")==0 && strstr(InputString,"<|space_zone|>")!=NULL && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) { //printf("\n-------ReplaceKeyWords space----2\n"); char content_temp[BUFSIZE_V3] = { 0 }; strcpy(content_temp,"["); for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) { char content_current[BUFSIZE_V3] = { 0 }; ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) { strcat(content_temp, content_current); } else { strcat(content_temp, content_current); strcat(content_temp, ","); } } } strcat(content_temp, "]"); content_size = strlen(content_temp); strcpy(OutputString, content_temp); //printf("\n-------ReplaceKeyWords space----3\n"); //printf("\n-------OutputString:%s\n", OutputString); } else if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString, "<|space_id|>") == 0 && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) { //printf("\n-------ReplaceKeyWords space----4\n"); char content_temp[BUFSIZE_V3] = { 0 }; strcpy(content_temp, "["); for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) { char content_current[BUFSIZE_V3] = { 0 }; ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) { strcat(content_temp, content_current); } else { strcat(content_temp, content_current); strcat(content_temp, ","); } } } strcat(content_temp, "]"); content_size = strlen(content_temp); strcpy(OutputString, content_temp); //viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space //printf("\n-------OutputString:%s\n", OutputString); //printf("\n-------ReplaceKeyWords space----5\n"); } else if(pNext != NULL) { //printf("\n-------ReplaceKeyWords space----6\n"); char content_temp[BUFSIZE_V3] = { 0 }; ReplaceKeyWords(pNext, space_zone, space_id, InputString, content_temp, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); content_size = strlen(content_temp); strcpy(OutputString, content_temp); //printf("\n-------ReplaceKeyWords space----7\n"); } else { content_size = 0; } return content_size; } #endif //會用到UTF8 Encoder void UpdateBehaviorData(QueueInfo* q_info, int tracking_channel_idx, int detection_zone_idx,int trigger_idx, int enable_lang) { q_info->behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); if ((q_info->behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//禁區偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Prohibit zone");//禁區偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_ZONE_VIOLATION"); } else if ((q_info->behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe8\xb7\x9d\xe9\x9b\xa2\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\xb5\xe6\xb8\xac");//距離違規偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Distance violation");//距離違規偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_DISTANCE_VIOLATION"); } else if ((q_info->behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe9\xab\x98\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//高度偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Height detection");//高度偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_HIGH_VIOLATION"); } else if ((q_info->behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe4\xb8\x8d\xe7\xa6\xae\xe8\xae\x93\xe5\x81\xb5\xe6\xb8\xac");//不禮讓偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Forget to give way detection");//不禮讓偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_FORGET_TO_GIVE_WAY"); } else if ((q_info->behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe5\xa4\xa7\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//最大速度偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Max speed detection");//最大速度偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_SPEED_HIGH"); } else if ((q_info->behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe4\xbd\x8e\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//最低速度偵測 UTF8 Encoder else//en_gb strcpy(q_info->behavior_desc, "Min speed detection");//最低速度偵測 UTF8 Encoder strcpy(q_info->behavior_name, "TRIGGER_SPEED_LOW"); } else if ((q_info->behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe9\x99\x90\xe6\x99\x82\xe5\x81\xb5\xe6\xb8\xac\x20\x2f\x20\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\x9c\xe8\xbb\x8a");//禁區限時偵測 / 違規停車 else//en_gb strcpy(q_info->behavior_desc, "Zone with dwell / Parking violation");//禁區限時偵測 / 違規停車 strcpy(q_info->behavior_name, "TRIGGER_PARKING_VIOLATION"); } else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\x9b\xb4\xe8\xa1\x8c\xe5\x81\xb5\xe6\xb8\xac");//警戒線 / 直行偵測 else//en_gb strcpy(q_info->behavior_desc, "Tripwire / Traffic flow");//警戒線 / 直行偵測 strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT"); } else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\xb4\x85\xe7\x87\x88\xe7\x9b\xb4\xe8\xa1\x8c");//紅燈警戒線 / 紅燈直行 else//en_gb strcpy(q_info->behavior_desc, "Tripwire on red / Running red lights");//紅燈警戒線 / 紅燈直行 strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT_RED_LIGHT"); } else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\xb7\xa6\xe8\xbd\x89");//紅燈左轉 else//en_gb strcpy(q_info->behavior_desc, "Turning left on red");//紅燈左轉 strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT_RED_LIGHT"); } else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\x8f\xb3\xe8\xbd\x89");//紅燈右轉 else//en_gb strcpy(q_info->behavior_desc, "Turning right on red");//紅燈右轉 strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT_RED_LIGHT"); } else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe5\xb7\xa6\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//左轉偵測 else//en_gb strcpy(q_info->behavior_desc, "Turn left");//左轉偵測 strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT"); } else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe5\x8f\xb3\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//右轉偵測 else//en_gb strcpy(q_info->behavior_desc, "Turn right");//右轉偵測 strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT"); } else if ((q_info->behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\x99\xbd\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//白名單警戒區偵測 else//en_gb strcpy(q_info->behavior_desc, "LPR allowed list detection in zone");//白名單警戒區偵測 strcpy(q_info->behavior_name, "TRIGGER_ALLOW_LIST"); } else if ((q_info->behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe8\xa8\xaa\xe5\xae\xa2\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//訪客名單警戒區偵測 else//en_gb strcpy(q_info->behavior_desc, "LPR visitor list detection in zone");//訪客名單警戒區偵測 strcpy(q_info->behavior_name, "TRIGGER_GUEST_LIST"); } else if ((q_info->behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe9\xbb\x91\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//黑名單警戒區偵測 else//en_gb strcpy(q_info->behavior_desc, "LPR denial list detection in zone");//黑名單警戒區偵測 strcpy(q_info->behavior_name, "TRIGGER_BLOCK_LIST"); } else if ((q_info->behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe5\xaf\x86\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//密度偵測 else//en_gb strcpy(q_info->behavior_desc, "Density detection");//密度偵測 strcpy(q_info->behavior_name, "TRIGGER_QUEUING_VIOLATION"); } else if ((q_info->behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\x41\x49\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//AI遺失物偵測 else//en_gb strcpy(q_info->behavior_desc, "AI missing object detection");//AI遺失物偵測 strcpy(q_info->behavior_name, "TRIGGER_MISSING_OBJECT_DETECTION"); } else if ((q_info->behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x8f\x8a\xe9\x81\xba\xe7\x95\x99\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//遺失物及遺留物偵測 else//en_gb strcpy(q_info->behavior_desc, "Unattended or missing object");//遺失物及遺留物偵測 strcpy(q_info->behavior_name, "TRIGGER_MISSING_UNATTENDED"); } else if ((q_info->behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe9\x98\xb2\xe7\xa0\xb4\xe5\xa3\x9e\xe5\x81\xb5\xe6\xb8\xac");//防破壞偵測 else//en_gb strcpy(q_info->behavior_desc, "Tampering detection");//防破壞偵測 strcpy(q_info->behavior_name, "TRIGGER_TAMPERING"); } else if ((q_info->behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x41\x4e\x44\x29");//同樣物種同時存在偵測 else//en_gb strcpy(q_info->behavior_desc, "All objects detection (AND)");//物種同時存在偵測 (AND) strcpy(q_info->behavior_name, "TRIGGER_ALL_OBJECTS"); } else if ((q_info->behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe7\xbc\xba\xe5\xb0\x91\xe4\xbb\xbb\xe4\xb8\x80\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x4e\x41\x4e\x44\x29");//缺少任一物種同時存在偵測 (NAND) else//en_gb strcpy(q_info->behavior_desc, "Lack of any object detection (NAND)");//缺少任一物種同時存在偵測 (NAND) strcpy(q_info->behavior_name, "TRIGGER_LACK_OF_ANY_OBJECT"); } //TRIGGER_SPEED_HIGH和TRIGGER_SPEED_LOW前面就有了 /* else if (q_info->behavior_ID & TRIGGER_BG_LEARNING) { if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) strcpy(q_info->behavior_desc, "\xe5\xad\xb8\xe7\xbf\x92\xe8\x83\x8c\xe6\x99\xaf\xe4\xb8\xad");//學習背景中 else//en_gb strcpy(q_info->behavior_desc, "BG learning");//學習背景中 strcpy(q_info->behavior_name, "TRIGGER_BG_LEARNING"); }*/ } long Get_eventCounterList_post_interval(int index_counter) { #ifdef GY_OS_V_SERIES #else if (strcmp(eventCounterList[index_counter].post_interval,"1 minute") == 0) { return 60; } else if (strcmp(eventCounterList[index_counter].post_interval, "5 minutes") == 0) { return 60 * 5; } else if (strcmp(eventCounterList[index_counter].post_interval, "30 minutes") == 0) { return 60 * 30; } else if (strcmp(eventCounterList[index_counter].post_interval, "1 hour") == 0) { return 60 * 60; } else if (strcmp(eventCounterList[index_counter].post_interval, "1 day") == 0) { return 60 * 60 * 24; } else if (strcmp(eventCounterList[index_counter].post_interval, "1 week") == 0) { return 60 * 60 * 24 * 7; } else if (strcmp(eventCounterList[index_counter].post_interval, "1 month") == 0) { return 60 * 60 * 24 * 30; } else #endif return -1; } long Get_mail_post_interval() { if (strcmp(SystemSetting.email_reset_time_interval, "1 minute") == 0) { return 60; } else if (strcmp(SystemSetting.email_reset_time_interval, "5 minutes") == 0) { return 60 * 5; } else if (strcmp(SystemSetting.email_reset_time_interval, "30 minutes") == 0) { return 60 * 30; } else if (strcmp(SystemSetting.email_reset_time_interval, "1 hour") == 0) { return 60 * 60; } else if (strcmp(SystemSetting.email_reset_time_interval, "1 day") == 0) { return 60 * 60 * 24; } else if (strcmp(SystemSetting.email_reset_time_interval, "1 week") == 0) { return 60 * 60 * 24 * 7; } else if (strcmp(SystemSetting.email_reset_time_interval, "1 month") == 0) { return 60 * 60 * 24 * 30; } else return -1; } struct timeval currtime_CheckPostEventCondition[MAX_DETECTION_ZONE]; static long last_ms_CheckPostEventCondition[MAX_DETECTION_ZONE] = { 0 }; #ifdef GY_OS_AMBA struct timeval currtime_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE]; static long last_ms_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE] = { 0 }; #endif struct timeval currtime_CheckPostEventCondition_cloud; static long last_ms_CheckPostEventCondition_cloud = 0; struct timeval currtime_CheckPostEventCondition_cloud_v2; static long last_ms_CheckPostEventCondition_cloud_v2 = 0; //struct timeval currtime_CheckPostEventCondition_cloud_record_v2; //static long last_ms_CheckPostEventCondition_cloud_record_v2 = 0; struct timeval currtime_CheckPostEventCondition_counter[MAX_DETECTION_ZONE]; static long last_ms_CheckPostEventCondition_counter[MAX_DETECTION_ZONE] = { 0 }; struct timeval currtime_CheckPostEventCondition_email; static long last_ms_CheckPostEventCondition_email = 0; //#ifdef GY_OS_AMBA struct timeval currtime_CheckPostEventCondition_ftp; static long last_ms_CheckPostEventCondition_ftp = 0; //#endif void initial_g_PostRecorderList() { for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { g_PostRecorderList[i].iIfUse = 0; g_PostRecorderList[i].t_FirstGetTime = 0; g_PostRecorderList[i].t_FirstGetTime_total = 0; g_PostRecorderList[i].t_UpdateTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PostRecorderList[i].check_if_post[m] = 0; } g_PostRecorderList[i].check_if_cloud = 0; g_PostRecorderList[i].check_if_cloud_v2 = 0; g_PostRecorderList[i].check_if_cloud_record_v2 = 0; g_PostRecorderList[i].check_if_email = 0; g_PostRecorderList[i].check_if_ftp = 0; g_PostRecorderList[i].check_if_getalarmmotion = 0; g_PostRecorderList[i].box_x = 0.0; g_PostRecorderList[i].box_y = 0.0; g_PostRecorderList[i].box_w = 0.0; g_PostRecorderList[i].box_h = 0.0; g_PostRecorderList[i].object_id = 0.0; g_PostRecorderList[i].zone_idx = 0.0; strcpy(g_PostRecorderList[i].sPlateNumber, ""); strcpy(g_PostRecorderList[i].name, ""); g_PostRecorderList[i].count_trigger = 0; //g_PostRecorderList[i].the_same_id = 0; //-------------------------------- g_longterm_PostRecorderList[i].iIfUse = 0; g_longterm_PostRecorderList[i].t_FirstGetTime = 0; g_longterm_PostRecorderList[i].t_FirstGetTime_total = 0; g_longterm_PostRecorderList[i].t_UpdateTime = 0; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_longterm_PostRecorderList[i].check_if_post[m] = 0; } g_longterm_PostRecorderList[i].check_if_cloud = 0; g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; g_longterm_PostRecorderList[i].check_if_email = 0; g_longterm_PostRecorderList[i].check_if_ftp = 0; g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; g_longterm_PostRecorderList[i].box_x = 0.0; g_longterm_PostRecorderList[i].box_y = 0.0; g_longterm_PostRecorderList[i].box_w = 0.0; g_longterm_PostRecorderList[i].box_h = 0.0; g_longterm_PostRecorderList[i].object_id = 0.0; g_longterm_PostRecorderList[i].zone_idx = 0.0; strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); strcpy(g_longterm_PostRecorderList[i].name, ""); g_longterm_PostRecorderList[i].count_trigger = 0; //g_longterm_PostRecorderList[i].the_same_id = 0; } } void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int force_to_push,char* aiengine_data,int counter_idx, char* image_buff,int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) { long d_no_parking_time = (long)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { d_no_parking_time = (long)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); } gettimeofday(&currtime_CheckPostEventCondition[detection_zone_idx], NULL); long current_ms_CheckPostEventCondition = (currtime_CheckPostEventCondition[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition[detection_zone_idx].tv_usec / 1000); gettimeofday(&currtime_CheckPostEventCondition_cloud, NULL); long current_ms_CheckPostEventCondition_cloud = (currtime_CheckPostEventCondition_cloud.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud.tv_usec / 1000); gettimeofday(&currtime_CheckPostEventCondition_cloud_v2, NULL); long current_ms_CheckPostEventCondition_cloud_v2 = (currtime_CheckPostEventCondition_cloud_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_v2.tv_usec / 1000); //gettimeofday(&currtime_CheckPostEventCondition_cloud_record_v2, NULL); //long current_ms_CheckPostEventCondition_cloud_record_v2 = (currtime_CheckPostEventCondition_cloud_record_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_record_v2.tv_usec / 1000); gettimeofday(&currtime_CheckPostEventCondition_counter[detection_zone_idx], NULL); long current_ms_CheckPostEventCondition_counter = (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_usec / 1000); gettimeofday(&currtime_CheckPostEventCondition_email, NULL); long current_ms_CheckPostEventCondition_email = (currtime_CheckPostEventCondition_email.tv_sec * 1000) + (currtime_CheckPostEventCondition_email.tv_usec / 1000); gettimeofday(&currtime_CheckPostEventCondition_ftp, NULL); long current_ms_CheckPostEventCondition_ftp = (currtime_CheckPostEventCondition_ftp.tv_sec * 1000) + (currtime_CheckPostEventCondition_ftp.tv_usec / 1000); #ifdef GY_OS_AMBA gettimeofday(&currtime_CheckPostEventCondition_snmp[detection_zone_idx], NULL); long current_ms_CheckPostEventCondition_snmp = (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_usec / 1000); #endif //printf("\n--------------QueueSize:%d\n",(int)QueueSize(_POST_NOTIFICATION)); int check_if_ok_for_location = 0; int index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; int size_g_PostRecorderList = 0; //int check_if_ok_for_location_longterm = 0; int index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; int size_g_PostRecorderList_longterm = 0; unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0) { //printf("\nFFFFFFF : 1\n"); if (pNext != NULL /*&& aiengine_data != NULL && strlen(aiengine_data) >= 1*/ && counter_idx == -1) { //printf("\nFFFFFFF : 2\n"); if (strlen(pNext->name) >= 1 && pNext->width > 0 && pNext->height > 0 /*&& !(IsANPRCategory_L_Plate(pNext->name))*/) { //printf("\nFFFFFFF : 3\n"); //Free over Recoder time int iFindMatchPost = 0; int iFindMatchPost_longterm = 0; time_t now_time = time(0); double max_dwell_short = 0.0; for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { if (g_PostRecorderList[i].iIfUse == 0 && g_longterm_PostRecorderList[i].iIfUse == 0) { break; } if (g_PostRecorderList[i].iIfUse == 1 /*&& g_PostRecorderList[i].zone_idx == detection_zone_idx*/) { if (g_PostRecorderList[i].box_w > 0 && g_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { detection_pos temp_A = { 0 }; temp_A.left_x = g_PostRecorderList[i].box_x; temp_A.top_y = g_PostRecorderList[i].box_y; temp_A.width = g_PostRecorderList[i].box_w; temp_A.height = g_PostRecorderList[i].box_h; strcpy(temp_A.name, g_PostRecorderList[i].name); float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); //float 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; 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) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; } iFindMatchPost = 1; //g_PostRecorderList[i].t_UpdateTime = now_time; //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; check_if_ok_for_location = 1; if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList[size_g_PostRecorderList] = i; size_g_PostRecorderList++; } } } else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) { if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; } iFindMatchPost = 1; //g_PostRecorderList[i].t_UpdateTime = now_time; //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; check_if_ok_for_location = 1; if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList[size_g_PostRecorderList] = i; size_g_PostRecorderList++; } } } else { 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.35) { double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); if (temp_dTime > max_dwell_short) { max_dwell_short = temp_dTime; } iFindMatchPost = 1; //g_PostRecorderList[i].t_UpdateTime = now_time; //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; check_if_ok_for_location = 1; if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList[size_g_PostRecorderList] = i; size_g_PostRecorderList++; } } } } else { 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; } iFindMatchPost = 1; //g_PostRecorderList[i].t_UpdateTime = now_time; //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; check_if_ok_for_location = 1; if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList[size_g_PostRecorderList] = i; size_g_PostRecorderList++; } } } } } } } } if (g_longterm_PostRecorderList[i].iIfUse == 1 /*&& g_longterm_PostRecorderList[i].zone_idx == detection_zone_idx*/) { if (g_longterm_PostRecorderList[i].box_w > 0 && g_longterm_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { detection_pos temp_A = { 0 }; temp_A.left_x = g_longterm_PostRecorderList[i].box_x; temp_A.top_y = g_longterm_PostRecorderList[i].box_y; temp_A.width = g_longterm_PostRecorderList[i].box_w; temp_A.height = g_longterm_PostRecorderList[i].box_h; strcpy(temp_A.name, g_longterm_PostRecorderList[i].name); float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); //float 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; 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) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; //check_if_ok_for_location_longterm = 1; if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; size_g_PostRecorderList_longterm++; } } } else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) { if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; //check_if_ok_for_location_longterm = 1; if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; size_g_PostRecorderList_longterm++; } } } else { 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.35) { iFindMatchPost_longterm = 1; //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; //check_if_ok_for_location_longterm = 1; if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; size_g_PostRecorderList_longterm++; } } } } else { 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; g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; //check_if_ok_for_location_longterm = 1; if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; size_g_PostRecorderList_longterm++; } } } } } } } } } #if 1 if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { if (iFindMatchPost_longterm == 0) { //printf("\nFFFFFFF : 4\n"); for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { if (g_longterm_PostRecorderList[i].iIfUse == 0) { g_longterm_PostRecorderList[i].iIfUse = 1; g_longterm_PostRecorderList[i].t_FirstGetTime = now_time; g_longterm_PostRecorderList[i].t_FirstGetTime_total = now_time; g_longterm_PostRecorderList[i].t_UpdateTime = now_time; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_longterm_PostRecorderList[i].check_if_post[m] = 0; } g_longterm_PostRecorderList[i].check_if_cloud = 0; g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; g_longterm_PostRecorderList[i].check_if_email = 0; g_longterm_PostRecorderList[i].check_if_ftp = 0; g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; g_longterm_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; g_longterm_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; g_longterm_PostRecorderList[i].box_w = pNext->width / 3.0; g_longterm_PostRecorderList[i].box_h = pNext->height / 3.0; g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); if (IsANPRCategory_L_Plate(pNext->name)) { strcpy(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate); } else { strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); } strcpy(g_longterm_PostRecorderList[i].name, pNext->name); g_longterm_PostRecorderList[i].count_trigger = 1; //g_longterm_PostRecorderList[i].the_same_id = 0; //check_if_ok_for_location_longterm = 1; if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; size_g_PostRecorderList_longterm++; } break; } } } } #endif if (iFindMatchPost == 0) { //printf("\nFFFFFFF : 4\n"); for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) { if (g_PostRecorderList[i].iIfUse == 0) { g_PostRecorderList[i].iIfUse = 1; g_PostRecorderList[i].t_FirstGetTime = now_time; g_PostRecorderList[i].t_FirstGetTime_total = now_time; g_PostRecorderList[i].t_UpdateTime = now_time; for (int m = 0; m < MAX_DETECTION_ZONE; m++) { g_PostRecorderList[i].check_if_post[m] = 0; } g_PostRecorderList[i].check_if_cloud = 0; g_PostRecorderList[i].check_if_cloud_v2 = 0; g_PostRecorderList[i].check_if_cloud_record_v2 = 0; g_PostRecorderList[i].check_if_email = 0; g_PostRecorderList[i].check_if_ftp = 0; g_PostRecorderList[i].check_if_getalarmmotion = 0; g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; g_PostRecorderList[i].box_w = pNext->width / 3.0; g_PostRecorderList[i].box_h = pNext->height / 3.0; g_PostRecorderList[i].object_id = pNext->obj_tracking_id; g_PostRecorderList[i].zone_idx = detection_zone_idx; //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); if (IsANPRCategory_L_Plate(pNext->name)){ strcpy(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate); } else { strcpy(g_PostRecorderList[i].sPlateNumber, ""); } strcpy(g_PostRecorderList[i].name, pNext->name); g_PostRecorderList[i].count_trigger = 1; //g_PostRecorderList[i].the_same_id = 0; check_if_ok_for_location = 1; if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { index_g_PostRecorderList[size_g_PostRecorderList] = i; size_g_PostRecorderList++; } break; } } } } } } //printf("\n--------check_if_ok_for_location :%d\n", check_if_ok_for_location); #ifdef GY_OS_AMBA if (pNext == NULL || strcmp(SystemSetting.enable_post_only_if_both_detected, "No") == 0 || (strcmp(SystemSetting.enable_post_only_if_both_detected, "Yes") == 0 && pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) || !(viewChannelData[0].enable_anpr) || !(viewChannelData[0].enable_face) || !(viewChannelData[0].enable_traffic) || !IsANPRCategory(featureType) || !(featureType & FEATURE_TRAF_DET)) #endif { if (activePostNotification && counter_idx == -1 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { //printf("\n----------------check_if_post:%d,size_g_PostRecorderList:%d\n", g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx], size_g_PostRecorderList); //printf("\n--------CheckPostEventCondition:1\n"); 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_post[detection_zone_idx] == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_post[detection_zone_idx] == 0)))) { //printf("\n--------CheckPostEventCondition:2\n"); if (last_ms_CheckPostEventCondition[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition - last_ms_CheckPostEventCondition[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { //printf("\n--------CheckPostEventCondition:3\n"); char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); int post_event_num = StrSplit(Temp, eachPostEvent, ","); //printf("\n------UU:5\n"); //char *replacement = NULL; //char *replacement_t = NULL; int check_if_SD_recording_post = 0; int index_SD_post = -1; int check_if_white_LED_post = 0; int index_LED_post = -1; int index_first_post = -1; if (post_event_num >= 1 && strcmp(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name,"Null")!=0) { for (int i = 0; i < post_event_num; i++) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) { if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) { if (index_first_post == -1) { index_first_post = j; } if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "SD recording") != NULL && g_check_if_no_brand == 0) { index_SD_post = j; check_if_SD_recording_post = 1; } if (g_camera_white_LED == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "White LED") != NULL && g_check_if_no_brand == 0) { index_LED_post = j; check_if_white_LED_post = 1; } } else { /* printf("Post queue is full!\n"); pthread_mutex_lock(&mutex_post_notification_pop); pthread_mutex_lock(&mutex_curl); if(QueueSize(_POST_NOTIFICATION) >= 1) QueueClear(_POST_NOTIFICATION); pthread_mutex_unlock(&mutex_curl); pthread_mutex_unlock(&mutex_post_notification_pop); printf("Post queue is full!end\n");*/ } //break; } } } if (index_SD_post == -1 && index_LED_post >= 0) { index_SD_post = index_LED_post; } if (index_SD_post == -1) { index_SD_post = index_first_post; } //printf("\n-----------index_SD_post:%d\n", index_SD_post); int check_if_status_cloud = 0; if (index_SD_post >= 0) { time_t rawtime_temp = g_post_SysTimeStamp; //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); //if(aiengine_data != NULL) //printf("\n------------aiengine_data:%s\n", aiengine_data); //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && g_check_if_no_brand == 0 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL)) ) { 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_cloud == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { check_if_status_cloud = 1; } } } //printf("\n---------check_if_SD_recording_post:%d,check_if_status_cloud:%d\n", check_if_SD_recording_post, check_if_status_cloud); if ((check_if_SD_recording_post == 0 && check_if_white_LED_post == 0) || check_if_status_cloud == 1) { last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_post[detection_zone_idx] = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_post[detection_zone_idx] = 1; } //printf("\n--------CheckPostEventCondition:4\n"); for (int post_times = 0; post_times < 2; post_times++) { int temp_index_post = 0; if (post_times == 0 && index_SD_post >= 0) { temp_index_post = index_SD_post; } else { if (check_if_SD_recording_post == 1 && check_if_white_LED_post == 1 && index_LED_post >= 0) { temp_index_post = index_LED_post; } else { break; } } pthread_mutex_lock(&mutex_post_notification_pop); postEventList[temp_index_post].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[temp_index_post].post_event_name); strcpy(q_info.post_protocol, postEventList[temp_index_post].post_protocol); strcpy(q_info.post_method, postEventList[temp_index_post].post_event_method); strcpy(q_info.host_name, postEventList[temp_index_post].post_host_ip); strcpy(q_info.host_port, postEventList[temp_index_post].post_host_port); strcpy(q_info.post_timeout, postEventList[temp_index_post].post_timeout); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (strlen(postEventList[temp_index_post].post_url) >= 1) { //if (pNext != NULL) { size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[temp_index_post].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); //} //else { //strcpy(q_info.post_url, postEventList[temp_index_post].post_url); //} q_info.post_url[url_size] = '\0'; } else q_info.post_url[0] = '\0'; //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); strcpy(q_info.post_username, postEventList[temp_index_post].post_username); strcpy(q_info.post_password, postEventList[temp_index_post].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[temp_index_post].post_jpeg_file_name); if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } if (strcmp(postEventList[temp_index_post].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[temp_index_post].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[temp_index_post].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[temp_index_post].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[temp_index_post].post_content) >= 1) { //if (pNext != NULL) { //printf("\n------check post 2--------6------3\n"); q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); //q_info.content_size = 0; //printf("\n-----size:%lu\n", q_info.content_size); //printf("\n------check post 2--------6------4\n"); //} //else { //strcpy(q_info.content, postEventList[temp_index_post].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[temp_index_post].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[temp_index_post].post_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); //} //else { //strcpy(q_info.content, postEventList[temp_index_post].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } //printf("\n----------_POST_NOTIFICATION\n"); //printf("\n------check post 3\n"); if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { //printf("\n------check post 3--------1\n"); if (force_to_push == 1) { //printf("\n------check post 3--------2\n"); for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { if(g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } //printf("\n------check post 3--------3\n"); } else { //printf("\n------check post 3--------4\n"); if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); //printf("\n------check post 3--------5\n"); } } //printf("\n------check post 4\n"); pthread_mutex_unlock(&mutex_post_notification_pop); } //if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && check_if_SD_recording_post == 1 && //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1))) if (check_if_status_cloud == 1) { //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) { //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) { //printf("\n------------Segmentation fault:%d\n", 5); QueueInfo q_info = { 0 }; strcpy(q_info.post_url, "post_to_cloud"); strcpy(q_info.cloud_aiengine, aiengine_data); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } q_info.rawtime = rawtime_temp; if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); /** printf("\n-------------\n"); printf("\nbehavior_ID: %d\n", q_info.behavior_ID); printf("\n-------------\n");*/ QueuePush(q_info, _POST_NOTIFICATION); //printf("\n------------Segmentation fault:%d\n", 6); } last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; } } } } } } for (int i = 0; i < post_event_num; i++) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) { if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) { if (index_SD_post != j && index_LED_post != j) { last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; for (int k = 0; k < size_g_PostRecorderList; k++) { g_PostRecorderList[index_g_PostRecorderList[k]].check_if_post[detection_zone_idx] = 1; } for (int k = 0; k < size_g_PostRecorderList_longterm; k++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[k]].check_if_post[detection_zone_idx] = 1; } pthread_mutex_lock(&mutex_post_notification_pop); postEventList[j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[j].post_event_name); strcpy(q_info.post_protocol, postEventList[j].post_protocol); strcpy(q_info.post_method, postEventList[j].post_event_method); strcpy(q_info.host_name, postEventList[j].post_host_ip); strcpy(q_info.host_port, postEventList[j].post_host_port); strcpy(q_info.post_timeout, postEventList[j].post_timeout); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (strlen(postEventList[j].post_url) >= 1) { //if (pNext != NULL) { size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); //} //else { //strcpy(q_info.post_url, postEventList[j].post_url); //} q_info.post_url[url_size] = '\0'; } else q_info.post_url[0] = '\0'; //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); strcpy(q_info.post_username, postEventList[j].post_username); strcpy(q_info.post_password, postEventList[j].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[j].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[j].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[j].post_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); //} //else { //strcpy(q_info.content, postEventList[j].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[j].post_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); //} //else { //strcpy(q_info.content, postEventList[j].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } //printf("\n----------_POST_NOTIFICATION\n"); if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { if (force_to_push == 1) { for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } else { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } pthread_mutex_unlock(&mutex_post_notification_pop); } } } } } } else { time_t rawtime_temp = g_post_SysTimeStamp; int check_if_status_cloud = 0; //printf("\n--------CheckPostEventCondition:4\n"); //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); //if(aiengine_data != NULL) //printf("\n------------aiengine_data:%s\n", aiengine_data); //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); /* if (aiengine_data != NULL) { printf("\n--------strlen(aiengine_data):%d\n", strlen(aiengine_data)); } else { printf("\n-------strlen(aiengine_data):NULL\n"); } if (pNext == NULL) { printf("\n--------pNext:NULL\n"); } else { printf("\n--------pNext:not NUll\n"); }*/ if (aiengine_data != NULL && strlen(aiengine_data) >= 1 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { //printf("\n--------CheckPostEventCondition:5--1\n"); 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_cloud == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { //printf("\n--------CheckPostEventCondition:5--2\n"); if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { check_if_status_cloud = 1; } } } //printf("\n--------check_if_status_cloud:%d\n", check_if_status_cloud); if (check_if_status_cloud == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && g_check_if_no_brand == 0) { //printf("\n--------CheckPostEventCondition:6\n"); //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) { //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) { //printf("\n------------Segmentation fault:%d\n", 5); QueueInfo q_info = { 0 }; strcpy(q_info.post_url, "post_to_cloud"); strcpy(q_info.cloud_aiengine, aiengine_data); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } q_info.rawtime = rawtime_temp; if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); /** printf("\n-------------\n"); printf("\nbehavior_ID: %d\n", q_info.behavior_ID); printf("\n-------------\n");*/ QueuePush(q_info, _POST_NOTIFICATION); //printf("\n------------Segmentation fault:%d\n", 6); } last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; } } } } } } } } if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0 && counter_idx == -1 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { 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_cloud_v2 == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud_v2)))) { if (last_ms_CheckPostEventCondition_cloud_v2 == 0 || (current_ms_CheckPostEventCondition_cloud_v2 - last_ms_CheckPostEventCondition_cloud_v2) >= atoi(SystemSetting.cloud_v2_notification_dwell) * 1000) { //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) { //printf("\n------------Segmentation fault:%d\n", 5); QueueInfo q_info = { 0 }; strcpy(q_info.post_url, "cloud_v2"); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (strlen(SystemSetting.cloud_v2_content) >= 1) { //if (pNext != NULL) { size_t v2_size = ReplaceKeyWords(pNext, -1, -1, SystemSetting.cloud_v2_content, q_info.cloud_v2_aiengine, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 1); //} //else { //strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); //} q_info.cloud_v2_aiengine[v2_size] = '\0'; } else q_info.cloud_v2_aiengine[0] = '\0'; //strcpy(q_info.cloud_v2_aiengine, aiengine_data); if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); /** printf("\n-------------\n"); printf("\nbehavior_ID: %d\n", q_info.behavior_ID); printf("\n-------------\n");*/ QueuePush(q_info, _GETALARMMOTION); //printf("\n------------Segmentation fault:%d\n", 6); } last_ms_CheckPostEventCondition_cloud_v2 = current_ms_CheckPostEventCondition_cloud_v2; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud_v2 = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud_v2 = 1; } } } } #ifdef GY_OS_AMBA if (activeSNMPPost && /*strcmp(SystemSetting.enable_cloud, "Yes") == 0 &&*/ counter_idx == -1) { //printf("\n--------CheckPostEventCondition:2\n"); if (last_ms_CheckPostEventCondition_snmp[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition_snmp - last_ms_CheckPostEventCondition_snmp[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { //printf("\n--------CheckPostEventCondition:3\n"); char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); int post_event_num = StrSplit(Temp, eachPostEvent, ","); //printf("\n------UU:10\n"); //char *replacement = NULL; //char *replacement_t = NULL; for (int i = 0; i < post_event_num; i++) { for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) { if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], SNMPManagementList[j].snmp_event_name) == 0) { if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && SNMPManagementList[j].check_if_delivering == 0) { //printf("\n--------CheckPostEventCondition:4\n"); pthread_mutex_lock(&mutex_post_notification_pop); SNMPManagementList[j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value,"<|hextoint|>")==0){ size_t snmp_size = ReplaceKeyWords(pNext, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); q_info.snmp_value[snmp_size] = '\0'; } else { strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); } //printf("\n------q_info.snmp_value:%s\n", q_info.snmp_value); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } //printf("\n----------_POST_NOTIFICATION\n"); if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { if (force_to_push == 1) { for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } else { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } pthread_mutex_unlock(&mutex_post_notification_pop); } else { /* printf("Post queue is full!\n"); pthread_mutex_lock(&mutex_post_notification_pop); pthread_mutex_lock(&mutex_curl); if(QueueSize(_POST_NOTIFICATION) >= 1) QueueClear(_POST_NOTIFICATION); pthread_mutex_unlock(&mutex_curl); pthread_mutex_unlock(&mutex_post_notification_pop); printf("Post queue is full!end\n");*/ } break; } } } last_ms_CheckPostEventCondition_snmp[detection_zone_idx] = current_ms_CheckPostEventCondition_snmp; } } #endif #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 (activePostNotification && counter_idx >= 0 && Get_eventCounterList_post_interval(counter_idx) != -1) { if (last_ms_CheckPostEventCondition_counter[detection_zone_idx] == 0 || (Get_eventCounterList_post_interval(counter_idx) != -1 && (current_ms_CheckPostEventCondition_counter - last_ms_CheckPostEventCondition_counter[detection_zone_idx]) >= Get_eventCounterList_post_interval(counter_idx) * 1000)) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strlen(postEventList[j].post_event_name) >= 1 && strcmp(eventCounterList[counter_idx].link_to_post_event_name, postEventList[j].post_event_name) == 0) { if (postEventList[j].check_if_delivering == 0) { pthread_mutex_lock(&mutex_post_notification_pop); postEventList[j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[j].post_event_name); strcpy(q_info.post_protocol, postEventList[j].post_protocol); strcpy(q_info.post_method, postEventList[j].post_event_method); strcpy(q_info.host_name, postEventList[j].post_host_ip); strcpy(q_info.host_port, postEventList[j].post_host_port); strcpy(q_info.post_timeout, postEventList[j].post_timeout); if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (strlen(postEventList[j].post_url) >= 1) { //if (pNext != NULL) { size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,0); //} //else { //strcpy(q_info.post_url, postEventList[j].post_url); //} q_info.post_url[url_size] = '\0'; } else q_info.post_url[0] = '\0'; //printf("\n------ q_info.post_url #2:%s\n", q_info.post_url); strcpy(q_info.post_username, postEventList[j].post_username); strcpy(q_info.post_password, postEventList[j].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); if (image_buff_size >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[j].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[j].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[j].post_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); //} //else { //strcpy(q_info.content, postEventList[j].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[j].post_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); //} //else { //strcpy(q_info.content, postEventList[j].post_content); //} q_info.content[q_info.content_size] = '\0'; } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } /*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)) || g_IsCustomWeight == 1) { char buf_content[256] = { '\0' }; sprintf(buf_content, "{\"counter_name\":\"%s\",\"counter_count\":%d}", eventCounterList[counter_idx].counter_name, eventCounterList[counter_idx].counter_count); strcpy(q_info.content, buf_content); }*/ if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { if (force_to_push == 1) { for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } else { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } } pthread_mutex_unlock(&mutex_post_notification_pop); } else { /* printf("Post queue is full!\n"); pthread_mutex_lock(&mutex_post_notification_pop); pthread_mutex_lock(&mutex_curl); if(QueueSize(_POST_NOTIFICATION) >= 1) QueueClear(_POST_NOTIFICATION); pthread_mutex_unlock(&mutex_curl); pthread_mutex_unlock(&mutex_post_notification_pop); printf("Post queue is full!end\n");*/ } break; } } last_ms_CheckPostEventCondition_counter[detection_zone_idx] = current_ms_CheckPostEventCondition_counter; } } } #endif if (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && counter_idx == -1 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_email == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_email == 0)))) { if (last_ms_CheckPostEventCondition_email == 0 || (Get_mail_post_interval() == -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) || (Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000) || force_to_push == 1) { if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) { QueueInfo q_info = { 0 }; if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (image_buff_size_base64 >= 1) { memcpy(q_info.image_buff, image_buff_base64, image_buff_size_base64); q_info.image_buff_size = image_buff_size_base64; } else { q_info.image_buff_size = 0; } if (strlen(emailData.email_content) >= 1) { //if (pNext != NULL) { q_info.content_size = ReplaceKeyWords(pNext, -1, -1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); //} //else { //strcpy(q_info.content, emailData.email_content); //} q_info.content[q_info.content_size] = '\0'; } else { q_info.content[0] = ' '; q_info.content[1] = '\0'; } strcpy(q_info.post_url, "post_to_mail"); UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); QueuePush(q_info, _POST_NOTIFICATION); #ifdef GY_OS_V_SERIES #else if (Get_mail_post_interval() != -1) { 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) { pthread_mutex_lock(&mutex_reset_counter); time_t now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { reset_counter(j, now_time); } pthread_mutex_unlock(&mutex_reset_counter); } } #endif } last_ms_CheckPostEventCondition_email = current_ms_CheckPostEventCondition_email; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_email = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_email = 1; } } } } //#ifdef GY_OS_AMBA if (strcmp(SystemSetting.enable_ftp, "Yes") == 0 && counter_idx == -1 && (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { 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_ftp == 0 && (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_ftp == 0)))){ if (last_ms_CheckPostEventCondition_ftp == 0 || (current_ms_CheckPostEventCondition_ftp - last_ms_CheckPostEventCondition_ftp) > d_no_parking_time * 1000 || force_to_push == 1) { if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) { QueueInfo q_info = { 0 }; if (pNext != NULL) { strcpy(q_info.q_name, pNext->name); if (pNext->linked_plate_length >= 1) { strcpy(q_info.q_plate, pNext->linked_plate); } else { strcpy(q_info.q_plate, pNext->properties.plate); } } if (image_buff_size_base64 >= 1) { memcpy(q_info.image_buff, image_buff, image_buff_size); q_info.image_buff_size = image_buff_size; } else { q_info.image_buff_size = 0; } /* if (strlen(emailData.email_content) >= 1) { if (pNext != NULL) { ReplaceKeyWords(pNext,-1,-1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); } else { strcpy(q_info.content, emailData.email_content); } } else*/ { q_info.content[0] = ' '; q_info.content[1] = '\0'; } strcpy(q_info.post_url, "curl_to_ftp"); //UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); if (q_info.image_buff_size >= 1) { QueuePush(q_info, _POST_NOTIFICATION); } } last_ms_CheckPostEventCondition_ftp = current_ms_CheckPostEventCondition_ftp; for (int i = 0; i < size_g_PostRecorderList; i++) { g_PostRecorderList[index_g_PostRecorderList[i]].check_if_ftp = 1; } for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_ftp = 1; } } } } //#endif } } struct timeval currtime_HeartbeatPost; static long last_ms_HeartbeatPost = 0; #if defined GY_OS_AMBA struct timeval currtime_snmp_HeartbeatPost; static long last_ms_snmp_HeartbeatPost = 0; #endif void HeartbeatPost() { if (activePostNotification && strcmp(heartbeatData.enable_heartbeat,"Yes")==0) { gettimeofday(&currtime_HeartbeatPost, NULL); long current_ms_HeartbeatPost = (currtime_HeartbeatPost.tv_sec * 1000) + (currtime_HeartbeatPost.tv_usec / 1000); if (last_ms_HeartbeatPost == 0 || (current_ms_HeartbeatPost - last_ms_HeartbeatPost) >= atoi(heartbeatData.heartbeat_dwell) * 1000 * 60) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strcmp(heartbeatData.heartbeat_link_to_post_event_name, postEventList[j].post_event_name) == 0) { if (postEventList[j].check_if_delivering == 0) { pthread_mutex_lock(&mutex_post_notification_pop); int index_j = j; postEventList[index_j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); strcpy(q_info.post_method, postEventList[index_j].post_event_method); strcpy(q_info.host_name, postEventList[index_j].post_host_ip); strcpy(q_info.host_port, postEventList[index_j].post_host_port); strcpy(q_info.post_url, postEventList[index_j].post_url); strcpy(q_info.post_username, postEventList[index_j].post_username); strcpy(q_info.post_password, postEventList[index_j].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[index_j].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } pthread_mutex_unlock(&mutex_post_notification_pop); } break; } } last_ms_HeartbeatPost = current_ms_HeartbeatPost; } } #if defined GY_OS_AMBA if (activeSNMPPost && strcmp(heartbeatData.enable_snmp_heartbeat, "Yes") == 0) { gettimeofday(&currtime_snmp_HeartbeatPost, NULL); long current_ms_snmp_HeartbeatPost = (currtime_snmp_HeartbeatPost.tv_sec * 1000) + (currtime_snmp_HeartbeatPost.tv_usec / 1000); if (last_ms_snmp_HeartbeatPost == 0 || (current_ms_snmp_HeartbeatPost - last_ms_snmp_HeartbeatPost) >= (long)(atof(heartbeatData.snmp_heartbeat_dwell) * 1000.0)) { for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) { if (strcmp(heartbeatData.snmp_heartbeat_link_to_post_event_name, SNMPManagementList[j].snmp_event_name) == 0) { if (SNMPManagementList[j].check_if_delivering == 0) { pthread_mutex_lock(&mutex_post_notification_pop); SNMPManagementList[j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value, "<|hextoint|>") == 0) { size_t snmp_size = ReplaceKeyWords(NULL, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, 0, 0, 0, NULL, 0, 0, NULL, 0, 0); q_info.snmp_value[snmp_size] = '\0'; } else { strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); } if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } pthread_mutex_unlock(&mutex_post_notification_pop); } break; } } last_ms_snmp_HeartbeatPost = current_ms_snmp_HeartbeatPost; } } #endif } #ifdef GY_OS_AMBA struct timeval currtime_check_start_PTZ_autotracking_Post; static long last_ms_check_start_PTZ_autotracking_Post = 0; int last_state_PTZ_autotracking_for_start = 0; int current_state_PTZ_autotracking_for_start = 0; void check_start_PTZ_autotracking_Post() { if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { current_state_PTZ_autotracking_for_start = 1; } else { current_state_PTZ_autotracking_for_start = 0; } gettimeofday(&currtime_check_start_PTZ_autotracking_Post, NULL); long current_ms_check_start_PTZ_autotracking_Post = (currtime_check_start_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_start_PTZ_autotracking_Post.tv_usec / 1000); if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_start_autotracking, "Yes") == 0) { if (last_ms_check_start_PTZ_autotracking_Post == 0 || (current_ms_check_start_PTZ_autotracking_Post - last_ms_check_start_PTZ_autotracking_Post) >= 2000) { if (last_state_PTZ_autotracking_for_start == 0 && current_state_PTZ_autotracking_for_start == 1) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strcmp(heartbeatData.ptz_start_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) { if (postEventList[j].check_if_delivering == 0) { pthread_mutex_lock(&mutex_post_notification_pop); int index_j = j; postEventList[index_j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); strcpy(q_info.post_method, postEventList[index_j].post_event_method); strcpy(q_info.host_name, postEventList[index_j].post_host_ip); strcpy(q_info.host_port, postEventList[index_j].post_host_port); strcpy(q_info.post_url, postEventList[index_j].post_url); strcpy(q_info.post_username, postEventList[index_j].post_username); strcpy(q_info.post_password, postEventList[index_j].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[index_j].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } pthread_mutex_unlock(&mutex_post_notification_pop); } break; } } last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; } else{ last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; } } } } struct timeval currtime_check_end_PTZ_autotracking_Post; static long last_ms_check_end_PTZ_autotracking_Post = 0; int last_state_PTZ_autotracking_for_end = 0; int current_state_PTZ_autotracking_for_end = 0; void check_end_PTZ_autotracking_Post() { if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { current_state_PTZ_autotracking_for_end = 1; } else { current_state_PTZ_autotracking_for_end = 0; } gettimeofday(&currtime_check_end_PTZ_autotracking_Post, NULL); long current_ms_check_end_PTZ_autotracking_Post = (currtime_check_end_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_end_PTZ_autotracking_Post.tv_usec / 1000); if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_end_autotracking, "Yes") == 0) { if (last_ms_check_end_PTZ_autotracking_Post == 0 || (current_ms_check_end_PTZ_autotracking_Post - last_ms_check_end_PTZ_autotracking_Post) >= 2000) { if (last_state_PTZ_autotracking_for_end == 1 && current_state_PTZ_autotracking_for_end == 0) { for (int j = 0; j < MAX_POST_EVENTS; j++) { if (strcmp(heartbeatData.ptz_end_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) { if (postEventList[j].check_if_delivering == 0) { pthread_mutex_lock(&mutex_post_notification_pop); int index_j = j; postEventList[index_j].check_if_delivering = 1; QueueInfo q_info = { 0 }; strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); strcpy(q_info.post_method, postEventList[index_j].post_event_method); strcpy(q_info.host_name, postEventList[index_j].post_host_ip); strcpy(q_info.host_port, postEventList[index_j].post_host_port); strcpy(q_info.post_url, postEventList[index_j].post_url); strcpy(q_info.post_username, postEventList[index_j].post_username); strcpy(q_info.post_password, postEventList[index_j].post_password); strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { q_info.enable_filename_fixed = 1; } else { q_info.enable_filename_fixed = 0; } if (strlen(postEventList[index_j].post_customized_header) >= 1) { strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); } else q_info.post_customized_header[0] = '\0'; if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { q_info.enable_attached_image = 0; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { q_info.enable_attached_image = 1; if (strlen(postEventList[index_j].post_content) >= 1) { strcpy(q_info.content, postEventList[index_j].post_content); q_info.content_size = strlen(postEventList[index_j].post_content); } else q_info.content[0] = '\0'; } else { q_info.enable_attached_image = 0; q_info.content[0] = '\0'; } if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) QueuePush(q_info, _POST_NOTIFICATION); } pthread_mutex_unlock(&mutex_post_notification_pop); } break; } } last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; } else{ last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; } } } } #endif curl_information_smtp_t user_smtp; void SendMailEventCondition(char *my_subject,char * my_content, char* image_buff, int image_buff_size) { char snapshot_addr[MAX_IMG_SIZE] = { 0 }; size_t snapshot_size = 0; if (image_buff_size >= 1) { snapshot_size = (size_t)image_buff_size; memcpy(snapshot_addr, image_buff, snapshot_size); } strcpy(user_smtp.receiver[0], IPCAMService.email_address1); strcpy(user_smtp.receiver[1], IPCAMService.email_address2); strcpy(user_smtp.receiver[2], IPCAMService.email_address3); strcpy(user_smtp.receiver[3], IPCAMService.email_address4); strcpy(user_smtp.receiver[4], IPCAMService.email_address5); strcpy(user_smtp.address, IPCAMService.email_address); strcpy(user_smtp.server, IPCAMService.smtp_server); sprintf(user_smtp.auth_mode, "%d", IPCAMService.smtp_auth_mode); strcpy(user_smtp.port, IPCAMService.smtp_port); sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); strcpy(user_smtp.user, IPCAMService.auth_account); strcpy(user_smtp.password, IPCAMService.auth_password); strcpy(user_smtp.subject, my_subject); strcpy(user_smtp.memory_data.memory, my_content); user_smtp.memory_data.size = strlen(my_content); strcpy(user_smtp.attachment, "snap.jpg"); if (net_curl_smtp_data(&user_smtp, snapshot_addr,(int)snapshot_size) < 0) { printf("\nSMTP Fail\n"); } else { printf("\nSMTP OK\n"); } } void ResetCheckIfDelivering() { for (int i = 0; i < MAX_POST_EVENTS; i++) { postEventList[i].check_if_delivering = 0; } //#ifdef GY_OS_AMBA //for (int i = 0; i < MAX_SNMP_MANAGEMENT; i++) //{ //SNMPManagementList[i].check_if_delivering = 0; //} //#endif } #ifdef GY_OS_V_SERIES #else //struct timeval last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE], now_t_CheckEventCounterCondition; //static long s_last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE] = { 0 }; //static long s_now_t_CheckEventCounterCondition = 0; int g_record_counter_count[MAX_EVENT_COUNTERS] = { 0 }; long g_record_counter_time[MAX_EVENT_COUNTERS] = { 0 }; #endif struct timeval currtime_CheckEventCounterCondition[MAX_EVENT_COUNTERS]; static long last_ms_CheckEventCounterCondition[MAX_EVENT_COUNTERS] = { 0 }; void CheckEventCounterCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int enable_counter_post, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) { #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 || unlockingKeyInnoFR_success == 1 ) { char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); int event_counter_num = StrSplit(Temp, eachEventCounter, ","); //printf("\n------UU:11\n"); //gettimeofday(&now_t_CheckEventCounterCondition, NULL); //s_now_t_CheckEventCounterCondition = now_t_CheckEventCounterCondition.tv_sec; //單位為秒 float dwell_time_event_counter = (float)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { dwell_time_event_counter = (float)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); } unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); /////////////////////////// char ObjectName[30] = { 0 }; if (pNext != NULL) { sprintf(ObjectName, "%s", pNext->name); UpperToLower(ObjectName); } //char metadata1[512][STRSPLIT_SIZE] = {0}; //for vehicle //char MetaData1[BUFSIZE] = { 0 }; //char MetaOut1[512][50] = { 0 }; //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); //int metadata1_num = get_metadata1_num(detection_zone_idx); //for (int i = 0; i < metadata1_num; i++) //{ //UpperToLower(metadata1[i]); //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); //} //////////////////////// for (int i = 0; i < event_counter_num; i++) { for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { if (strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) { gettimeofday(&currtime_CheckEventCounterCondition[j], NULL); long current_ms_CheckEventCounterCondition = (currtime_CheckEventCounterCondition[j].tv_sec * 1000) + (currtime_CheckEventCounterCondition[j].tv_usec / 1000); if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") != 0 || (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0 && (last_ms_CheckEventCounterCondition[j] == 0 || (current_ms_CheckEventCounterCondition - last_ms_CheckEventCounterCondition[j]) > dwell_time_event_counter * 1000))) { last_ms_CheckEventCounterCondition[j] = current_ms_CheckEventCounterCondition; //eventCounterList[j].metadata1_num = metadata1_num; //for (int m = 0; m < metadata1_num; m++) { //strcpy(eventCounterList[j].MetaOut1[m], get_meta_class(m, detection_zone_idx)); //} if (pNext == NULL) { if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; if (eventCounterList[j].counter_count > 2000000000) { eventCounterList[j].counter_count = 2000000000; } } else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; if (eventCounterList[j].counter_count < 0) { eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value } } else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { //eventCounterList[j].counter_count = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; g_record_counter_time[j] = g_osdSysTimeStamp; } else { if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { eventCounterList[j].counter_count = g_record_counter_count[j]; g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; g_record_counter_time[j] = g_osdSysTimeStamp; } } } } else if ((strcmp(eventCounterList[j].enable_time_range, "Yes") != 0 && (((!((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) ) || (pNext != NULL && !(IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) || (pNext != NULL && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) )) ) || (pNext != NULL && strcmp(eventCounterList[j].enable_time_range, "Yes") == 0 && pNext->det_time >= eventCounterList[j].timetTimeRangeFrom && pNext->det_time < eventCounterList[j].timetTimeRangeTo)) { //printf("\n----------eventCounterList[j].counter_count:%d\n", eventCounterList[j].counter_count); //printf("\n----------viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num:%d\n", viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num); if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; if (eventCounterList[j].counter_count > 2000000000) { eventCounterList[j].counter_count = 2000000000; } } else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; if (eventCounterList[j].counter_count < 0) { eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value } } else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; g_record_counter_time[j] = g_osdSysTimeStamp; } else { if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { eventCounterList[j].counter_count = g_record_counter_count[j]; g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; g_record_counter_time[j] = g_osdSysTimeStamp; } } } //printf("\neventCounterList[%d].counter_count:%d\n",j, eventCounterList[j].counter_count); } } if (enable_counter_post == 1) { if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment != -2) CheckPostEventCondition(pNext, tracking_channel_idx, detection_zone_idx, trigger_idx, 0, "", j, image_buff, image_buff_size, image_buff_base64, image_buff_size_base64, cropped_image_base64, cropped_image_size_base64); } break; } } } //printf("\n-------------------\n"); } #endif } void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, CPoint* zone_polygon,int side_number,int zone_index,int iSource_ori_w, int iSource_ori_h) { CPoint p_person[MAX_SENSOR_TYPE0]; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 0; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 0; int count_four_points_touch = 0; int count_touch = 0; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { if (g_sensors_type == 0) { p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / iSource_ori_w); p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / iSource_ori_h); } else { p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / iSource_ori_w); p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / iSource_ori_h); } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] = isInside(zone_polygon, side_number, p_person[index_p]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] == 1) { count_touch++; } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] = isInside(zone_polygon, 4, p_person[index_p]); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] == 1) { count_four_points_touch++; } } //printf("\n----------count_four_points_touch:%d\n", count_four_points_touch); //printf("\n----------count_touch:%d\n", count_touch); int threahold_div = g_sensors_type == 0 ? 1 : 7; 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; } if (count_touch >= 1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 1; pNext->IsInsideZone[zone_index] = 1; } } struct timeval last_t_UpdateZoneStatus, now_t_UpdateZoneStatus; static long s_last_t_UpdateZoneStatus[MAX_DETECTION_ZONE] = {0}; static long s_now_t_UpdateZoneStatus = 0; void MissingObjectDetection_VanishInZone(int tracking_channel_idx) { for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { if (s_last_t_UpdateZoneStatus[j] == 0) { gettimeofday(&last_t_UpdateZoneStatus, NULL); s_last_t_UpdateZoneStatus[j] = last_t_UpdateZoneStatus.tv_sec; } } gettimeofday(&now_t_UpdateZoneStatus, NULL); s_now_t_UpdateZoneStatus = now_t_UpdateZoneStatus.tv_sec; //單位為秒 int check_if_missing = 0; for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION) { float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; if ((s_now_t_UpdateZoneStatus - s_last_t_UpdateZoneStatus[j]) > dwell_time_missing_object_detection) { s_last_t_UpdateZoneStatus[j] = s_now_t_UpdateZoneStatus; for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) break; else { int check_if_ever_existing = 0; for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) break; else if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]) { check_if_ever_existing = 1; break; } } if (check_if_ever_existing == 1) { for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { if (viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) break; else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] == 0 || index_obj_tracking_id_in_zone_temp == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { check_if_missing = 1; break; } } if (check_if_missing == 1) { printf("\n-------------TRIGGER_MISSING_OBJECT_DETECTION check_if_missing: Yes------------\n"); break; } } } } //TRIGGER_MISSING_OBJECT_DETECTION #if 0 printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION\n"); for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { printf("%d,", viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); } printf("\n-----------------------------------------\n"); printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last\n"); for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); } printf("\n-----------------------------------------\n"); printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last_two\n"); for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); } printf("\n-----------------------------------------\n"); #endif int k = 0; for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) break; else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]!= 0 && viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) { viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[k] = viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; k++; } } } for (int index_obj_tracking_id_in_zone = k; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; } if (check_if_missing == 1) { viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; } else { viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; } } } } } } } void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, float fInSourceOri_w, float fInSourceOri_h, int total_element_size, detection_pos* PosInfo, int result_idx) { int side_number = 6;//side_number = viewDetectionZone[tracking_channel_idx][j].point_num; CPoint zone_polygon[6] = { 0 }; int b_ZoneExist = 0; detection_pos* pNext2 = NULL; int BindNewLicensePlateOk = 0; char ObjectName[30] = { 0 }; sprintf(ObjectName, "%s", pNext->name); UpperToLower(ObjectName); if (IsANPRCategory(featureType)) { if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, pNext->properties.plate); pNext->linked_plate_length = pNext->properties.plate_length; } if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; } if (viewChannelData[0].enable_traffic) { for (int m = 0; m < total_element_size; m++) { pNext2 = PosInfo + m; if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) ) { strcpy(pNext->car_type_name, pNext2->name); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); break; } } } } } else if (viewChannelData[0].enable_traffic) { //BindLicensePlateToVehicle if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { for (int k = 0/*result_idx + 1*/; k < total_element_size; k++) { pNext2 = PosInfo + k; if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) { if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) ) { pNext2->car_logo_idx = result_idx; strcpy(pNext2->car_type_name, pNext->name); if (pNext2->obj_tracking_id_idx >= 0) { strcpy(g_TrackingRecords[tracking_channel_idx][pNext2->obj_tracking_id_idx].car_type_name, pNext2->car_type_name); } //Steven MARK 20200930 //printf("track_obj_id[%d]Plate = %s \n", tracking_obj_idx, pNext2->properties.plate); if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate)) { //if (levenshtein_distance(pNext2->properties.plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate) <= 3) //{ if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, pNext2->properties.plate); pNext->linked_plate_length = pNext2->properties.plate_length; strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext2->properties.plate); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext2->properties.plate_length; //printf("track_obj_id[%d]linkPlate = %s \n", tracking_obj_idx, pUpdateZoneNext->linked_plate); BindNewLicensePlateOk = 1; } //} } break; } } } if (!BindNewLicensePlateOk) { if (strlen(pNext->linked_plate) == 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length >= atoi(viewChannelData[0].min_characters) && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate); pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length; } } else { if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; } } } } } } for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { int check_existing_in_metaout = 0; check_existing_in_metaout = check_if_existing_in_metaout(ObjectName, j); //int metadata1_num = get_metadata1_num(j); if (check_existing_in_metaout == 0 && strcmp(ObjectName, "object") != 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0 && strcmp(ObjectName, "face") != 0 && IsANPRCategory_L_Plate(pNext->name) == 0) { continue; } int check_if_go_straight_existing = 0; int check_if_speed_existing = 0; float ratio_area_zone_polygon = 0.0; int index_of_trigger_event_to_checked = -1; unsigned int trigger_event_type = 0; for (int m = 0; m < MAX_TRIGGER_EVENT; m++) { if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); if ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) { check_if_go_straight_existing = 1; } else if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || /*|| (featureType & FEATURE_LPR_TWN) != 0*/ ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) ) { if (check_existing_in_metaout == 1 || (check_existing_in_metaout == 0 && strcmp(pNext->name, "blank") == 0)) { if (viewDetectionZone[tracking_channel_idx][j].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][j].parking_line >= 1) { viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = m; int index_plot = -1; float min_parking_distance = 10000; for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][j].parking_space; index_parking++) { /* detection_pos pNext_plot; pNext_plot.left_x = g_parking_space_recording_x[j][index_parking] - pNext->width * 0.25; pNext_plot.top_y = g_parking_space_recording_y[j][index_parking] - pNext->height * 0.25; pNext_plot.width = pNext->width * 0.5; pNext_plot.height = pNext->height * 0.5;*/ if (g_parking_space_recording_x[j][index_parking] != 0 && g_parking_space_recording_y[j][index_parking] != 0) { if (g_parking_space_recording_x[j][index_parking] >= pNext->left_x - pNext->width * 0.25 && g_parking_space_recording_x[j][index_parking] <= (pNext->left_x + pNext->width*1.25) && g_parking_space_recording_y[j][index_parking] >= pNext->top_y - pNext->height * 0.25 && g_parking_space_recording_y[j][index_parking] <= (pNext->top_y + pNext->height*1.25) && g_temp_parking_space_check_table[j][index_parking] == 0 /*&& detection_overlap_ratio_union(pNext,&pNext_plot) >= 0.9*/) { if (index_plot == -1) { index_plot = index_parking; min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); } else { float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); if (temp_min_parking_distance < min_parking_distance) { index_plot = index_parking; min_parking_distance = temp_min_parking_distance; } } } else if (strcmp(pNext->name, "blank") == 0) { if (index_plot == -1) { index_plot = index_parking; min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); } else { float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); if (temp_min_parking_distance < min_parking_distance) { index_plot = index_parking; min_parking_distance = temp_min_parking_distance; } } } } } if (index_plot >= 0) { g_temp_parking_space_check_table[j][index_plot] = 1; pNext->zone_violation_idx[j] = 1; } } } } } else { if (!(IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE)) { ratio_area_zone_polygon = polygon_area(zone_polygon, 6) / (float)(CANVAS_WIDTH * CANVAS_HEIGHT); if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { } else if (trigger_event_type == TRIGGER_SPEED_HIGH || trigger_event_type == TRIGGER_SPEED_LOW) { check_if_speed_existing = 1; } } else if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { if (trigger_event_type == TRIGGER_SPEED_HIGH || trigger_event_type == TRIGGER_SPEED_LOW) { check_if_speed_existing = 1; } } } index_of_trigger_event_to_checked = m; break; } } if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { if (j == atoi(viewChannelData[tracking_channel_idx].red_light_zone)) { continue; } } b_ZoneExist = 0; //zone_polygon 在client端寫入設定檔時已轉為 889*500 for (int k = 0; k < 6; k++) { if (viewDetectionZone[tracking_channel_idx][j].Points[k].x > 0 || viewDetectionZone[tracking_channel_idx][j].Points[k].y > 0) b_ZoneExist = 1; zone_polygon[k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); zone_polygon[k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); } if (!b_ZoneExist || j == viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1) continue; if (g_IsRadarDevice == 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0) // 2022-10-20 Ken { if ((((pNext->width * pNext->height) / ((float)fInSourceOri_w * (float)fInSourceOri_h)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_max_proportion_in_zone) / 100.0)) || (((pNext->width * pNext->height) / ((float)fInSourceOri_w *(float)fInSourceOri_h)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_min_proportion_in_zone) / 100.0)) ) { continue; } } if (g_IsPTZDevice == 0 && trigger_event_type == 0) continue; if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1 && strncmp(viewDetectionZone[tracking_channel_idx][j].enable_speed, "No", strlen("No")) == 0) { continue; } //int iIfDoZone = 1; //int do_event_trigger = 1; //if (iIfDoZone == 1 || g_check_if_set_no_preset_no_autopan == 1) { //printf("\n------------ratio_area_zone_polygon:%f\n", ratio_area_zone_polygon); Record_Point_Touch_and_IsInsideZone(pNext, tracking_channel_idx, tracking_obj_idx, det_count_idx, zone_polygon, side_number, j, fInSourceOri_w, fInSourceOri_h); } if (g_check_if_metadata_stop_happened[j] == 1) { continue; } //printf("\n------------get_g_check_if_current_light_is_red:%d\n", get_g_check_if_current_light_is_red()); //if(do_event_trigger == 1 || g_check_if_set_no_preset_no_autopan == 1) { if (det_count_idx > 0 && index_of_trigger_event_to_checked >= 0) { //printf("\n---BBB------pNext->engine_type:%d\n", pNext->engine_type); //printf("\n---BBB------pNext->obj_type:%d\n", pNext->obj_type); if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0) { //printf("\n-----------------B2\n"); int current_count_touch = 0; int last_count_touch = 0; float threshold_for_count_touch = 0.77; int threshold_for_last_count_touch = 55; int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; threshold_for_last_count_touch = 560 / threahold_div; } else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { threshold_for_count_touch = 0.67; threshold_for_last_count_touch = 480 / threahold_div; } else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { threshold_for_count_touch = 0.68; threshold_for_last_count_touch = 420 / threahold_div; } else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { threshold_for_count_touch = 0.68; threshold_for_last_count_touch = 360 / threahold_div; } else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { threshold_for_count_touch = 0.69; threshold_for_last_count_touch = 300 / threahold_div; } else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { threshold_for_count_touch = 0.69; threshold_for_last_count_touch = 260 / threahold_div; } else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { threshold_for_count_touch = 0.7; threshold_for_last_count_touch = 220 / threahold_div; } else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { threshold_for_count_touch = 0.7; threshold_for_last_count_touch = 190 / threahold_div; } else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { threshold_for_count_touch = 0.71; threshold_for_last_count_touch = 170 / threahold_div; } else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { threshold_for_count_touch = 0.71; threshold_for_last_count_touch = 150 / threahold_div; } else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { threshold_for_count_touch = 0.73; threshold_for_last_count_touch = 105 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { threshold_for_count_touch = 0.74; threshold_for_last_count_touch = 85 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { threshold_for_count_touch = 0.76; threshold_for_last_count_touch = 65 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { threshold_for_count_touch = 0.77; threshold_for_last_count_touch = 55 / threahold_div; } else { threshold_for_count_touch = 0.78; threshold_for_last_count_touch = 45 / threahold_div; } for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; } //printf("\n------------current_count_touch:%d\n", current_count_touch); //printf("\n------------last_count_touch:%d\n", last_count_touch); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { if (g_sensors_type == 0) { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); } else { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); } } 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 }; for (int k = 0; k < 4; k++) { array_zone_count[k] = 0; } for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } } for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 for (int kl = 0; kl < 4; kl++) { //zone個數 if (array_zone_count[kl] >= k) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; break; } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { break; } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; printf("\n[p==q | p!=q error]------------------\n"); printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } } { //printf("\n-------------GO STRAIGHT: start------------\n"); int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_GO_STRAIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } } else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) { memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { if (g_sensors_type == 0) { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); } else { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); } } 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)) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; printf("\n[p=q error]------------------\n"); printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } else { int m = 0; int array_zone_count[4] = { 0 }; for (int k = 0; k < 4; k++) { array_zone_count[k] = 0; } for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; /*if (strcmp(pNext->name, "person") == 0) { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } else*/ { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } } for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 for (int kl = 0; kl < 4; kl++) { //zone個數 if (array_zone_count[kl] >= k) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; break; } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { break; } } #if 1 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; printf("\n[p!=q error]------------------\n"); printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } #endif /* if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { //printf("\n------------YYYYYYYYYYYYYYYYY\n"); for (int kl = 0; kl < g_max_sensor_size; kl++) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); } } }*/ } } //printf("\n-------------------[doIntersect]: end\n"); //printf("\nFEATURE_HUM_DET---4\n"); { //printf("\n-------------GO STRAIGHT: start------------\n"); int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_GO_STRAIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); /* else if (trigger_event_type == TRIGGER_TURN_LEFT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_WRONG_WAY) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); */ if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } //會造成誤報,如果ID不對的話 else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) continue; memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; } } } else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); //第一次進到zone 紀錄時間 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); } //printf("\n----------------A:2\n"); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_SPEED_HIGH) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_SPEED_LOW) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } } else { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); } int nNeedTrigger = 0; //printf("\n-----------In_zone\n"); if (trigger_event_type == TRIGGER_ALLOW_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_BLOCK_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GUEST_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_ALL_OBJECTS) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); if (nNeedTrigger) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } } } else { //TRIGGER_SPEED_HIGH和TRIGGER_SPEED_LOW後面有放。 if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) { #if 1 { if (trigger_event_type == TRIGGER_TAMPERING) { if (strcmp(ObjectName, "tampering") == 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; //pNext->detection_zone_idx = j; pNext->trigger_idx[j] = index_of_trigger_event_to_checked; pNext->zone_violation_idx[j] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 1) { //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); //第一次進到zone 紀錄時間 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); } //printf("\n----------------A:2\n"); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; { //TRIGGER_MISSING_OBJECT_DETECTION float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; if (check_if_existing_in_metaout(ObjectName, j)) { int check_obj_tracking_id_in_zone = 0; for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id) { check_obj_tracking_id_in_zone = 1; break; } } #if 1 if (check_obj_tracking_id_in_zone == 0) { for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0 || (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time) > dwell_time_missing_object_detection) viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; break; } if (index_obj_tracking_id_in_zone == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { for (int index_obj_tracking_id_in_zone_temp = MAX_OBJ_TRACKING_ID_IN_ZONE - 1; index_obj_tracking_id_in_zone_temp >= 1; index_obj_tracking_id_in_zone_temp--) { viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp - 1]; } viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[0] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; } } } #endif if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = pNext->obj_dwell_time; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; pNext->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = pNext->obj_dwell_time; pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; } } } int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_ZONE_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_DISTANCE_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_DISTANCE_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_HIGH_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_HIGH_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_MISSING_UNATTENDED) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_MISSING_UNATTENDED, total_element_size, PosInfo, result_idx); //else if (trigger_event_type == TRIGGER_BG_LEARNING) //nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BG_LEARNING, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_ALL_OBJECTS) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_LACK_OF_ANY_OBJECT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_FORGET_TO_GIVE_WAY, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } 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)) || g_IsCustomWeight == 1) { { nNeedTrigger = 0; if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_QUEUING_VIOLATION, total_element_size, PosInfo, result_idx); if (nNeedTrigger) viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = index_of_trigger_event_to_checked; } } } else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; { int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_ZONE_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } #endif } else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1){ if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); //第一次進到zone 紀錄時間 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); } //printf("\n----------------A:2\n"); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_SPEED_HIGH) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_SPEED_LOW) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } else { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; } } else if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0){ //printf("\n-----------------B2\n"); int current_count_touch = 0; int last_count_touch = 0; float threshold_for_count_touch = 0.77; int threshold_for_last_count_touch = 55; int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 if (ratio_area_zone_polygon >= 0.75) { threshold_for_count_touch = 0.67; threshold_for_last_count_touch = 560 / threahold_div; } else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { threshold_for_count_touch = 0.67; threshold_for_last_count_touch = 480 / threahold_div; } else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { threshold_for_count_touch = 0.68; threshold_for_last_count_touch = 420 / threahold_div; } else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { threshold_for_count_touch = 0.68; threshold_for_last_count_touch = 360 / threahold_div; } else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { threshold_for_count_touch = 0.69; threshold_for_last_count_touch = 300 / threahold_div; } else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { threshold_for_count_touch = 0.69; threshold_for_last_count_touch = 260 / threahold_div; } else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { threshold_for_count_touch = 0.7; threshold_for_last_count_touch = 220 / threahold_div; } else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { threshold_for_count_touch = 0.7; threshold_for_last_count_touch = 190 / threahold_div; } else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { threshold_for_count_touch = 0.71; threshold_for_last_count_touch = 170 / threahold_div; } else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { threshold_for_count_touch = 0.71; threshold_for_last_count_touch = 150 / threahold_div; } else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { threshold_for_count_touch = 0.73; threshold_for_last_count_touch = 105 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { threshold_for_count_touch = 0.74; threshold_for_last_count_touch = 85 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { threshold_for_count_touch = 0.76; threshold_for_last_count_touch = 65 / threahold_div; } else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { threshold_for_count_touch = 0.77; threshold_for_last_count_touch = 55 / threahold_div; } else{ threshold_for_count_touch = 0.78; threshold_for_last_count_touch = 45 / threahold_div; } for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; } //printf("\n------------current_count_touch:%d\n", current_count_touch); //printf("\n------------last_count_touch:%d\n", last_count_touch); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx-1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { if (g_sensors_type == 0) { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); } else { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); } } 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 }; for (int k = 0; k < 4; k++) { array_zone_count[k] = 0; } for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx-1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } } for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 for (int kl = 0; kl < 4; kl++) { //zone個數 if (array_zone_count[kl] >= k) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; break; } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { break; } } #if 1 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; printf("\n[p==q | p!=q error]------------------\n"); printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } #endif } { //printf("\n-------------GO STRAIGHT: start------------\n"); int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_GO_STRAIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } } else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) { memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { if (g_sensors_type == 0) { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); } else { p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); } } 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)) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; printf("\n[p=q error]------------------\n"); printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } else { int m = 0; int array_zone_count[4] = { 0 }; for (int k = 0; k < 4; k++) { array_zone_count[k] = 0; } for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; /*if (strcmp(pNext->name, "person") == 0) { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } else*/ { for (int kl = 0; kl < g_max_sensor_size; kl++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (doIntersect(p1[kl], q1[kl], p2, q2)) { array_zone_count[k]++; } } } } } for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 for (int kl = 0; kl < 4; kl++) { //zone個數 if (array_zone_count[kl] >= k) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; break; } } if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { break; } } #if 1 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { int m = 0; float object_mean_x = 0.0; float object_mean_y = 0.0; float object_count = 0.0; for (int k = 0; k < g_max_sensor_size; k++) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { object_count++; object_mean_x += (float)q1[k].x; object_mean_y += (float)q1[k].y; } } if (object_count >= 1.0) { object_mean_x /= object_count; object_mean_y /= object_count; float min_distance = 0; float min_zone_line = 0; for (int k = 0; k < 4; k++) { if (k == 4 - 1) m = 0; else m = k + 1; CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; printf("\n[p!=q error]------------------\n"); printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; if (min_zone_line == 0) { min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); min_zone_line = k + 1; } else { float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); if (distance_temp < min_distance) { min_zone_line = k + 1; } } } g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; } } #endif /* if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { //printf("\n------------YYYYYYYYYYYYYYYYY\n"); for (int kl = 0; kl < g_max_sensor_size; kl++) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); } } }*/ } } //printf("\n-------------------[doIntersect]: end\n"); //printf("\nFEATURE_HUM_DET---4\n"); { //printf("\n-------------GO STRAIGHT: start------------\n"); int nNeedTrigger = 0; if (trigger_event_type == TRIGGER_GO_STRAIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); /* else if (trigger_event_type == TRIGGER_TURN_LEFT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_WRONG_WAY) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); */ if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } //會造成誤報,如果ID不對的話 else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) { if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) continue; memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; } } } } } else if(det_count_idx == 0 && index_of_trigger_event_to_checked >= 0) { if (IsANPRCategory_L_Plate(pNext->name)==1 && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, pNext->properties.plate); pNext->linked_plate_length = pNext->properties.plate_length; } if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; } if (viewChannelData[0].enable_traffic) { for (int m = 0; m < total_element_size; m++) { pNext2 = PosInfo + m; if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { if (detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) ) { strcpy(pNext->car_type_name, pNext2->name); strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); break; } } } } //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { int nNeedTrigger = 0; //printf("\n-----------In_zone\n"); if (trigger_event_type == TRIGGER_ALLOW_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_BLOCK_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_GUEST_LIST) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); if (nNeedTrigger) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; } } } else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) { #ifdef GY_OS_AMBA if (trigger_event_type == TRIGGER_TAMPERING) { if (strcmp(ObjectName, "tampering") == 0) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; //pNext->detection_zone_idx = j; pNext->trigger_idx[j] = index_of_trigger_event_to_checked; pNext->zone_violation_idx[j] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; } } #endif #if 1 if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { if (trigger_event_type == TRIGGER_ZONE_VIOLATION) { //for (int k = 0; k < metadata1_num; k++) { if (check_if_existing_in_metaout(ObjectName, j)) { g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; pNext->trigger_type = TRIGGER_ZONE_VIOLATION | pNext->trigger_type; //pNext->detection_zone_idx = j; pNext->trigger_idx[j] = index_of_trigger_event_to_checked; pNext->zone_violation_idx[j] = 1; g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; //break; } } } } #endif } } } } } void ApplyTrackingTableAndPrevDetection(detection_pos* PosInfo, int total_element_size,int tracking_channel_idx,int id_idx,int obj_idx) { //printf("\n--------%d,%d\n", (int)(PosInfo + obj_idx)->width, (int)(PosInfo + obj_idx)->height); if ((PosInfo + obj_idx)->width > 0 && (PosInfo + obj_idx)->height > 0) { int det_count = 0; int plate_len = 0, old_plate_len = 0; det_count = g_TrackingRecords[tracking_channel_idx][id_idx].detection_count; det_count++; if (det_count > TRACKING_BUFFER_SIZE) { det_count = TRACKING_BUFFER_SIZE; } if (det_count >= 2) {//第二次frame以上 if (IsANPRCategory((PosInfo + obj_idx)->engine_type) && strlen((PosInfo + obj_idx)->properties.plate) >= 1) { for (int j = 0; j < MAX_PLATE_RECORDER; j++) { if (g_PlateRecorderList[j].iIfUse == 1) { if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 //&& strcmp((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) && LevenshteinDistance((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { float ratio_y = ((PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y) / (float)get_g_ori_yuv_height(); float ratio_x = ((PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x) / (float)get_g_ori_yuv_width(); float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); if (fabs(ratio_x_y) <= g_thres_bbox_stability_plate) { (PosInfo + obj_idx)->top_y = g_PlateRecorderList[j].last_box_y; (PosInfo + obj_idx)->height = g_PlateRecorderList[j].last_box_h; (PosInfo + obj_idx)->left_x = g_PlateRecorderList[j].last_box_x; (PosInfo + obj_idx)->width = g_PlateRecorderList[j].last_box_w; (PosInfo + obj_idx)->center_y = g_PlateRecorderList[j].last_box_center_y; (PosInfo + obj_idx)->center_x = g_PlateRecorderList[j].last_box_center_x; (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; } else { float delta_y = (PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y; float delta_x = (PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x;; (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); } break; } } } } else { float ratio_y = ((PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y) / (float)get_g_ori_yuv_height(); float ratio_x = ((PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x) / (float)get_g_ori_yuv_width(); float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); if (fabs(ratio_x_y) <= g_thres_bbox_stability) { (PosInfo + obj_idx)->top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y; (PosInfo + obj_idx)->height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height; (PosInfo + obj_idx)->left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x; (PosInfo + obj_idx)->width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width; (PosInfo + obj_idx)->center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; (PosInfo + obj_idx)->center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; } else { float delta_y = (PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; float delta_x = (PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); } } (PosInfo + obj_idx)->check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter; for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { (PosInfo + obj_idx)->num_bring_with_object[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone]; for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { strcpy((PosInfo + obj_idx)->bring_with_object[index_zone][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[index_zone][index_bring]); } (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone]; //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone]; } g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; (PosInfo + obj_idx)->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; (PosInfo + obj_idx)->obj_dwell_time = (int)difftime((PosInfo + obj_idx)->det_time, g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time) % MAX_OBJ_DWELL_TIME; (PosInfo + obj_idx)->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time; (PosInfo + obj_idx)->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time; //strcpy((PosInfo + obj_idx)->replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name); } else if (det_count == 1) {//第一次frame初始化 g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = g_initial_background_learning_rate_x; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = g_initial_background_learning_rate_y; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_initial_background_learning_rate_error_x; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_initial_background_learning_rate_error_y; g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = g_initial_background_mean_diff_x; g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = g_initial_background_mean_diff_y; g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = g_initial_background_error_diff_x; g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = g_initial_background_error_diff_y; (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; (PosInfo + obj_idx)->check_person_inter = 0; for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { (PosInfo + obj_idx)->num_bring_with_object[index_zone] = 0; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] = 0; (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = 0; //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = 0; g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone] = 0; //g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone] = 0; } if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count != 0) g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = 0; if (g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count != 0) g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; g_TrackingIDAndChannel[tracking_channel_idx]++; if (td_weight_num >= 1 && check_if_correct_mail == 1) { if (g_TrackingIDAndChannel[tracking_channel_idx] > 19999 || g_TrackingIDAndChannel[tracking_channel_idx] < 10001) g_TrackingIDAndChannel[tracking_channel_idx] = 10001; } else { if (g_TrackingIDAndChannel[tracking_channel_idx] > 9999) g_TrackingIDAndChannel[tracking_channel_idx] = 1; } (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; (PosInfo + obj_idx)->obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = (PosInfo + obj_idx)->det_time; //g_TrackingRecords[tracking_channel_idx][id_idx].frame_count = 0; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].name, (PosInfo + obj_idx)->name); //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name, (PosInfo + obj_idx)->replaced_name); for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time_to_enter_zone[index_zone] = -1; g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[index_zone] = -1; (PosInfo + obj_idx)->obj_speed[index_zone] = -1; g_TrackingRecords[tracking_channel_idx][id_idx].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; } //g_TrackingRecords[tracking_channel_idx][id_idx].avg_det_interval = 1.1; (PosInfo + obj_idx)->obj_dwell_time = 0; (PosInfo + obj_idx)->obj_first_dwell_time = 0; g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time = 0; (PosInfo + obj_idx)->obj_last_dwell_time = 0; g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time = 0; } g_TrackingRecords[tracking_channel_idx][id_idx].bAssign_flag = 1; g_TrackingRecords[tracking_channel_idx][id_idx].Assign_obj_idx = obj_idx; g_TrackingRecords[tracking_channel_idx][id_idx].detection_count = det_count; //g_TrackingRecords[tracking_channel_idx][id_idx].fake_detection_count = 0; if (det_count >= 1) { if ((PosInfo + obj_idx)->obj_type == _PLATE && strlen((PosInfo + obj_idx)->properties.plate) >= 1) { plate_len = strlen((PosInfo + obj_idx)->properties.plate); old_plate_len = strlen(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); //printf("[%d] plate1 = %s, %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate); if (plate_len >= old_plate_len) { strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); } else if (plate_len < old_plate_len) { //strcpy((PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); strcpy((PosInfo + obj_idx)->car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name); } //printf("[%d] plate2 = %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate); } } #if 1 for (int n = 0; n < det_count - 1; n++) { strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].name); //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].replaced_name); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence2; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].progress_bar = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].progress_bar; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type2; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].top_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_direction = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_direction; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_stability = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_stability; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].width; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].height; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].plate_char_top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].plate_char_top_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].parent_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].parent_idx; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_logo_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_logo_idx; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].number_row = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].number_row; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_type; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].visual_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].visual_left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].class_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].class_id; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sec_color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sec_color_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_type; #ifdef GY_OS_AMBA g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_distance; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_distance; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_height; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_height; #endif for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_idx[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_violation_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_violation_idx[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_check_giveway[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_check_giveway[index_zone]; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].near_iou_count[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].near_iou_count[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone_four_points[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone_four_points[index_zone]; if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id == g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id) { g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_having_been_counted[index_zone]; } else { //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = 0; } g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_speed[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_speed[index_zone]; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].s_last_t_Counter[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_within_zone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_within_zone[index_zone]; } g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_w = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_w; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_h = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_h; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].dash_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].dash_left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_milli_sec = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_milli_sec; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_dwell_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_first_dwell_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_last_dwell_time; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate_length; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_type_name); strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].logo); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.country, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.pose, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose)); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area_id; //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.counter_count[index_counter] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.counter_count[index_counter]; //} memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_list, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list)); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_length; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id_idx; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].vote_value = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].vote_value; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].disappear_count = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].disappear_count; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].iou_prev_self = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].iou_prev_self; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].test_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].test_id; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].image_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].image_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].adjust_obj_speed; //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sPlateDirection, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sPlateDirection); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_person_inter; for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].num_bring_with_object[k]; for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].bring_with_object[k][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].bring_with_object[k][index_bring]); } g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n + 1]; g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n + 1]; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n + 1][index_p]; g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n + 1][index_p]; } } g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n + 1]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n + 1]; } if (det_count >= 1) { strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].name, (PosInfo + obj_idx)->name); //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].replaced_name, (PosInfo + obj_idx)->replaced_name); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence = (PosInfo + obj_idx)->confidence; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence2 = (PosInfo + obj_idx)->confidence2; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].progress_bar = (PosInfo + obj_idx)->progress_bar; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type = (PosInfo + obj_idx)->engine_type; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type2 = (PosInfo + obj_idx)->engine_type2; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x = (PosInfo + obj_idx)->left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y = (PosInfo + obj_idx)->top_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x = (PosInfo + obj_idx)->center_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y = (PosInfo + obj_idx)->center_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_direction = (PosInfo + obj_idx)->center_direction; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_stability = (PosInfo + obj_idx)->center_stability; //printf("\n-------prev #2:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width = (PosInfo + obj_idx)->width; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height = (PosInfo + obj_idx)->height; //printf("\n-------prev #3:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].plate_char_top_y = (PosInfo + obj_idx)->plate_char_top_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].parent_idx = (PosInfo + obj_idx)->parent_idx; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_logo_idx = (PosInfo + obj_idx)->car_logo_idx; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].number_row = (PosInfo + obj_idx)->number_row; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_type = (PosInfo + obj_idx)->obj_type; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].visual_left_x = (PosInfo + obj_idx)->visual_left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].class_id = (PosInfo + obj_idx)->class_id; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color, (PosInfo + obj_idx)->color); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color_id = (PosInfo + obj_idx)->color_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sec_color_id = (PosInfo + obj_idx)->sec_color_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_type = (PosInfo + obj_idx)->trigger_type; #ifdef GY_OS_AMBA g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_distance = (PosInfo + obj_idx)->min_distance; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_distance = (PosInfo + obj_idx)->max_distance; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_height = (PosInfo + obj_idx)->min_height; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_height = (PosInfo + obj_idx)->max_height; #endif for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_idx[index_zone] = (PosInfo + obj_idx)->trigger_idx[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_violation_idx[index_zone] = (PosInfo + obj_idx)->zone_violation_idx[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_check_giveway[index_zone] = (PosInfo + obj_idx)->zone_check_giveway[index_zone]; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].near_iou_count[index_zone] = (PosInfo + obj_idx)->near_iou_count[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone[index_zone] = (PosInfo + obj_idx)->IsInsideZone[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone_four_points[index_zone] = (PosInfo + obj_idx)->IsInsideZone_four_points[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_having_been_counted[index_zone] = (PosInfo + obj_idx)->check_if_having_been_counted[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_speed[index_zone] = (PosInfo + obj_idx)->obj_speed[index_zone]; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].s_last_t_Counter[index_zone] = (PosInfo + obj_idx)->s_last_t_Counter[index_zone]; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; } g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id = (PosInfo + obj_idx)->obj_tracking_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_x = (PosInfo + obj_idx)->box_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_y = (PosInfo + obj_idx)->box_y; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_w = (PosInfo + obj_idx)->box_w; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_h = (PosInfo + obj_idx)->box_h; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].dash_left_x = (PosInfo + obj_idx)->dash_left_x; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time = (PosInfo + obj_idx)->det_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_milli_sec = (PosInfo + obj_idx)->det_milli_sec; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_dwell_time = (PosInfo + obj_idx)->obj_dwell_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_first_dwell_time = (PosInfo + obj_idx)->obj_first_dwell_time; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_last_dwell_time = (PosInfo + obj_idx)->obj_last_dwell_time; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate, (PosInfo + obj_idx)->linked_plate); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate_length = (PosInfo + obj_idx)->linked_plate_length; strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].logo, (PosInfo + obj_idx)->logo); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate, sizeof((PosInfo + obj_idx)->properties.plate)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.country, (PosInfo + obj_idx)->properties.country, sizeof((PosInfo + obj_idx)->properties.country)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area, (PosInfo + obj_idx)->properties.area, sizeof((PosInfo + obj_idx)->properties.area)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.logo, (PosInfo + obj_idx)->properties.logo, sizeof((PosInfo + obj_idx)->properties.logo)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.color, (PosInfo + obj_idx)->properties.color, sizeof((PosInfo + obj_idx)->properties.color)); memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.pose, (PosInfo + obj_idx)->properties.pose, sizeof((PosInfo + obj_idx)->properties.pose)); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area_id = (PosInfo + obj_idx)->properties.area_id; //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.counter_count[index_counter] = (PosInfo + obj_idx)->properties.counter_count[index_counter]; //} memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_list, (PosInfo + obj_idx)->properties.plate_list, sizeof((PosInfo + obj_idx)->properties.plate_list)); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_length = (PosInfo + obj_idx)->properties.plate_length; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id_idx = (PosInfo + obj_idx)->obj_tracking_id_idx; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].vote_value = (PosInfo + obj_idx)->vote_value; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = (PosInfo + obj_idx)->disappear_count; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].iou_prev_self = (PosInfo + obj_idx)->iou_prev_self; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].test_id = (PosInfo + obj_idx)->test_id; //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].image_id = (PosInfo + obj_idx)->image_id; g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].adjust_obj_speed = (PosInfo + obj_idx)->adjust_obj_speed; //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sPlateDirection, (PosInfo + obj_idx)->sPlateDirection); g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter = (PosInfo + obj_idx)->check_person_inter; for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] = (PosInfo + obj_idx)->num_bring_with_object[k]; for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[k][index_bring], (PosInfo + obj_idx)->bring_with_object[k][index_bring]); } g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][det_count - 1] = 0; g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][det_count - 1] = 0; for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][det_count - 1][index_p] = 0; g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][det_count - 1][index_p] = 0; } } g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[det_count - 1] = (PosInfo + obj_idx)->center_direction; g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[det_count - 1] = (PosInfo + obj_idx)->center_stability; } #endif if (det_count >= 1) { //printf("\n-----www----%f,%f\n", g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y); if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width > 0.0 && g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height > 0.0) { float diff_x = 0; float diff_y = 0; //float diff_time = 0; if (det_count >= 2) { diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_x; diff_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_y; if (strcmp((PosInfo + obj_idx)->name, "person")==0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; } //diff_time = difftime(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].det_time); #ifdef GY_OS_AMBA if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { if (((int)(PosInfo + obj_idx)->center_direction) != DIRECTION_DEFAULT && det_count >= 3) { float obj_speed; float obj_speed_old; float obj_speed_very_old; detection_pos *PosInfo_very_old, *PosInfo_old, *PosInfo_new; PosInfo_new = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1]; PosInfo_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2]; PosInfo_very_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 3]; float fIou_union_1 = detection_overlap_ratio_union(PosInfo_new, PosInfo_old); float fIou_union_2 = detection_overlap_ratio_union(PosInfo_new, PosInfo_very_old); if (fIou_union_1 < 0.85 && fIou_union_2 < 0.85) { pthread_mutex_lock(&mutex_perspective_transform); g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = -1; int count_speed_zone = 0; for (int social_zone_idx = 0; social_zone_idx < viewChannelData[tracking_channel_idx].count_zone; social_zone_idx++) { if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 /*&& strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "No", strlen("No")) == 0*/) { if (viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray != NULL) { obj_speed = SetPerspectiveTransform_GetObjSpeed(PosInfo_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); obj_speed_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); obj_speed_very_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_old, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); float temp_obj_speed = pow(obj_speed * obj_speed_old * obj_speed_very_old, 1.0 / 3.0); if (temp_obj_speed < 0.1) temp_obj_speed = 0.1; if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] == -1) { g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = temp_obj_speed; } else if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] >= 0) { //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = sqrt(g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * temp_obj_speed); } (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; if (g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg == -1) { g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; } else { g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg += g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; } count_speed_zone++; } }/* else if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 && strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "Yes", strlen("Yes")) == 0) { for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { if (SpeedData[i].flag_protected == 1) { // get_g_ori_yuv_height() get_g_ori_yuv_width(); float point_x = SpeedData[i].x * get_g_ori_yuv_width() / SpeedData[i].res_width; float point_y = SpeedData[i].y * get_g_ori_yuv_height() / SpeedData[i].res_height; float bbox_min_x = (PosInfo + obj_idx)->left_x; float bbox_min_y = (PosInfo + obj_idx)->top_y; float bbox_max_x = (PosInfo + obj_idx)->left_x + (PosInfo + obj_idx)->width; float bbox_max_y = (PosInfo + obj_idx)->top_y + (PosInfo + obj_idx)->height; if (point_x > bbox_min_x && point_x < bbox_max_x && point_y > bbox_min_y && point_y < bbox_max_y) { g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = SpeedData[i].speed; (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; count_speed_zone++; SpeedData[i].flag_protected = 0; break; } } } } */ } if (count_speed_zone >= 1) { g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg /= count_speed_zone; (PosInfo + obj_idx)->adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg; } pthread_mutex_unlock(&mutex_perspective_transform); } } } #endif } float temp_diff_x = diff_x; float temp_diff_y = diff_y; diff_x = diff_x + diff_x * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x; diff_y = diff_y + diff_y * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y; if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = 0; } if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = 0; } g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_x = (PosInfo + obj_idx)->center_x + diff_x; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_y = (PosInfo + obj_idx)->center_y + diff_y; //g_TrackingRecords[tracking_channel_idx][id_idx].det_interval = diff_time; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.left_x = (PosInfo + obj_idx)->left_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.top_y = (PosInfo + obj_idx)->top_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.width = (PosInfo + obj_idx)->width + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2;//* (ratio_w) g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.height = (PosInfo + obj_idx)->height + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2;//* (ratio_h) g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_x = (PosInfo + obj_idx)->box_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_y = (PosInfo + obj_idx)->box_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_w = (PosInfo + obj_idx)->box_w + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2; g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_h = (PosInfo + obj_idx)->box_h + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2; float sum_diff_x = 0; float sum_diff_y = 0; for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { sum_diff_x += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x); sum_diff_y += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y); } g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = sum_diff_x / (float)det_count; g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = sum_diff_y / (float)det_count; float sum_2_diff_x = 0; float sum_2_diff_y = 0; for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { sum_2_diff_x += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x, 2.0); sum_2_diff_y += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y, 2.0); } g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = sqrt(sum_2_diff_x); g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = sqrt(sum_2_diff_y); g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = (temp_diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x + 1.0); g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = (temp_diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y + 1.0); g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x * 1.0; g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y * 1.0; g_initial_background_learning_rate_x = g_initial_background_learning_rate_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x * 0.01; g_initial_background_learning_rate_y = g_initial_background_learning_rate_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y * 0.01; g_initial_background_learning_rate_error_x = g_initial_background_learning_rate_error_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 0.01; g_initial_background_learning_rate_error_y = g_initial_background_learning_rate_error_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 0.01; } } } } //#ifdef GY_OS_WIN //#define CHAO_METH #define METH_1 #define IOU_HISTORY_FRAMES 3 //VOTE number #define VOTE_NAME 20 #define VOTE_PERSON 25 #define VOTE_WITHIN_ZONE 70 #define VOTE_MAX_UNION_PREDICT_IOU 100 #define VOTE_MAX_PREDICT_IOU 100 #define VOTE_MAX_UNION_PREV_IOU 90 #define VOTE_MAX_PREV_IOU 90 #define VOTE_MAX_UNION_PREDICT_IOU_BONUS 50 #define VOTE_MAX_PREDICT_IOU_BONUS 50 #define VOTE_MAX_UNION_PREV_IOU_BONUS 45 #define VOTE_MAX_PREV_IOU_BONUS 45 #define VOTE_SIZE_AVOID_PUNISH 25 //30 #define VOTE_WRONG_NAME_PUNISH 15 //30 #define VOTE_NEIGHBOR 80 #define VOTE_STATIC 70 #define VOTE_THE_SAME_SIZE 45 #define VOTE_PLATE 350 //50 #define VOTE_PLATE_MIN_SCORE 50 //#endif //GY_OS_WIN - DEFINE //#ifdef GY_OS_WIN void reset_id_obj(int tracking_channel_idx, int id_idx) { int disappearCount = g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count; if (strlen(g_TrackingRecords[tracking_channel_idx][id_idx].name) >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][id_idx].name) == 1) { if (disappearCount >= DISAPPEAR_FRAME_MAX * 20) { memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); } } else { if (disappearCount >= DISAPPEAR_FRAME_MAX) { memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); } } } //#endif //GY_OS_WIN - reset_id_obj //#ifdef GY_OS_WIN float prev_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; float predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; float union_predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; float union_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; int vote_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; //#endif //GY_OS_WIN //#ifdef GY_OS_WIN void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) { float fIOU, predit_IOU, union_IOU, union_predit_IOU; detection_pos* pNext = NULL; int det_count; // iou about obj to obj. //detection_pos* pNext_b = NULL; //float fIou_union; for (int i = 0; i < MAX_TRACKING_NUM; i++) { //iou_count = 0; det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; //frame_count = g_TrackingRecords[tracking_channel_idx][i].frame_count; if (det_count == 0) continue; for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //與上一次 union_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //與上一次 predit_IOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //與預測點 union_predit_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //與預測點 if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1 || (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1)) { if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1 && IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate) == 0*/) { fIOU = 1.0; predit_IOU = 1.0; union_predit_IOU = 1.0; union_IOU = 1.0; } else{ fIOU = 0.0; predit_IOU = 0.0; union_predit_IOU = 0.0; union_IOU = 0.0; } } else if (fIOU > 0.0 || predit_IOU > 0.0 || union_predit_IOU > 0.0 || union_IOU > 0.0){ if (IsVehicleCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { } 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 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; if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { } else { fIOU = 0.0; union_IOU = 0.0; } predit_IOU = 0.0; union_predit_IOU = 0.0; } } } else if (strcmp(pNext->name, "person") == 0 || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { if (strcmp(pNext->name, "person") == 0 && strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { } 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 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; if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { } else { fIOU = 0.0; union_IOU = 0.0; } predit_IOU = 0.0; union_predit_IOU = 0.0; } } } else if (IsGarbageCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { if (IsGarbageCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { } else { fIOU = 0.0; predit_IOU = 0.0; union_predit_IOU = 0.0; union_IOU = 0.0; } } else if (IsMotorbikeCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { } else { if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { fIOU = 0.0; predit_IOU = 0.0; union_predit_IOU = 0.0; union_IOU = 0.0; } } } } prev_iou_table[i][j] = fIOU; predit_iou_table[i][j] = predit_IOU; union_predit_iou_table[i][j] = union_predit_IOU; union_iou_table[i][j] = union_IOU; } } } //#endif //GY_OS_WIN - update_iou_table //#ifdef GY_OS_WIN void update_vote_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) { detection_pos* pNext = NULL; detection_pos* pNext2 = NULL; int det_count; int vote_value = 0; int max_iou_idx = -1; float max_iou = 0.0; int max_predict_iou_idx = -1; float max_predict_iou = 0.0; int max_union_iou_idx = -1; float max_union_iou = 0.0; int max_union_predict_iou_idx = -1; float max_union_predict_iou = 0.0; float pre_H, pre_W; float delta_w, delta_h; //int old_confidence; if (IsANPRCategory(featureType)) { for (int m = 0; m < total_element_size; m++) { pNext = PosInfo + m; if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { for (int k = 0; k < total_element_size; k++) { pNext2 = PosInfo + k; if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) { if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) ) { strcpy(pNext2->car_type_name, pNext->name); if (strlen(pNext2->properties.plate) > strlen(pNext->linked_plate)) { if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, pNext2->properties.plate); pNext->linked_plate_length = pNext2->properties.plate_length; } } break; } } } } } } for (int k = 0; k < MAX_TRACKING_NUM; k++) { max_iou = 0.0; max_iou_idx = -1; max_predict_iou = 0.0; max_predict_iou_idx = -1; max_union_iou = 0.0; max_union_iou_idx = -1; max_union_predict_iou = 0.0; max_union_predict_iou_idx = -1; det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; if (det_count == 0) continue; for (int m = 0; m < total_element_size; m++) { pNext = PosInfo + m; vote_value = 0; vote_table[k][m] = vote_value; ////與歷史和預測點的面積,分數加權 { vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU * prev_iou_table[k][m]); if (prev_iou_table[k][m] > max_iou) { max_iou = prev_iou_table[k][m]; max_iou_idx = m; } vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU * predit_iou_table[k][m]); if (predit_iou_table[k][m] > max_predict_iou) { max_predict_iou = predit_iou_table[k][m]; max_predict_iou_idx = m; } vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU * union_iou_table[k][m]); //與上次歷史點的聯集面積為分母的IOU if (union_iou_table[k][m] > max_union_iou) { max_union_iou = union_iou_table[k][m]; max_union_iou_idx = m; } vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU * union_predit_iou_table[k][m]); //與預測點聯集面積為分母的 IOU if (union_predit_iou_table[k][m] > max_union_predict_iou) { max_union_predict_iou = union_predit_iou_table[k][m]; max_union_predict_iou_idx = m; } } if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { //printf("\n-------pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { vote_table[k][m] += VOTE_PLATE_MIN_SCORE; if (prev_iou_table[k][m] > max_iou) { max_iou = prev_iou_table[k][m]; max_iou_idx = m; } if (predit_iou_table[k][m] > max_predict_iou) { max_predict_iou = predit_iou_table[k][m]; max_predict_iou_idx = m; } //與上次歷史點的聯集面積為分母的IOU if (union_iou_table[k][m] > max_union_iou) { max_union_iou = union_iou_table[k][m]; max_union_iou_idx = m; } //與預測點聯集面積為分母的 IOU if (union_predit_iou_table[k][m] > max_union_predict_iou) { max_union_predict_iou = union_predit_iou_table[k][m]; max_union_predict_iou_idx = m; } //printf("\n-------same plate #1\n"); } else { vote_table[k][m] = 0; //printf("\n-------not same plate #2\n"); } } else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { //printf("\n----#2---pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); //printf("\n---------same car\n"); vote_table[k][m] += VOTE_PLATE_MIN_SCORE; //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); } } //個別項目加入對應權重 //max_iou_idx if (max_iou_idx != -1) { vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU_BONUS); //obj name same pNext = PosInfo + max_iou_idx; if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) { if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { vote_table[k][max_iou_idx] += VOTE_PLATE; //printf("\n-------same plate #1\n"); } } else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { vote_table[k][max_iou_idx] += VOTE_PLATE; //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); } } } if (max_union_iou_idx != -1) { vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU_BONUS); //obj name same pNext = PosInfo + max_union_iou_idx; if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) { if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { vote_table[k][max_union_iou_idx] += VOTE_PLATE; //printf("\n-------same plate #2\n"); } } else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { vote_table[k][max_union_iou_idx] += VOTE_PLATE; //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); } } } if (max_predict_iou_idx != -1) { vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU_BONUS); //obj name same pNext = PosInfo + max_predict_iou_idx; if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) { if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { vote_table[k][max_predict_iou_idx] += VOTE_PLATE; //printf("\n-------same plate #1\n"); } } else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { vote_table[k][max_predict_iou_idx] += VOTE_PLATE; //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); } } } if (max_union_predict_iou_idx != -1) { vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU_BONUS); pNext = PosInfo + max_union_predict_iou_idx; if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) { if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; //printf("\n-------same plate #3\n"); } } else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); } } } for (int m = 0; m < total_element_size; m++) { pNext = PosInfo + m; if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { } else { vote_table[k][m] = 0; continue; } } if (IsVehicleCategory(pNext)) { if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "car") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "bus") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "truck") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "tuktuk") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "trailer") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "pickup") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "SUV") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "dual_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "single_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "van")) { } else { if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; } } } else if (IsMotorbikeCategory(pNext)) { if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "motorbike") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ok") || strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ng")) { } else { if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; } } } else { /*if (strcmp(pNext->name,"new_object")==0) { int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width, pNext->height, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0); if (checkisInside == 1) { vote_table[k][m] += VOTE_PERSON; } else { if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; } } } else */ //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { //if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) { //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; //} //else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) { //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH * 10; //} //} } if (get_g_check_if_show_parking() == 1) { for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { if (g_TrackingRecords[tracking_channel_idx][k].check_if_within_zone[index_zone] == PosInfo->check_if_within_zone[index_zone]) { vote_table[k][m] += VOTE_WITHIN_ZONE; } } } //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { //vote_table[k][m] += VOTE_NAME; //if (strcmp("person", pNext->name) == 0) //{ //vote_table[k][m] += VOTE_PERSON; //} //} #if 1 //與預測點比較長寬 pre_H = g_TrackingRecords[tracking_channel_idx][k].predict_detection.height; pre_W = g_TrackingRecords[tracking_channel_idx][k].predict_detection.width; delta_h = 1.0 - fabs(pNext->height / pre_H - 1.0); delta_w = 1.0 - fabs(pNext->width / pre_W - 1.0); vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_h; vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_w; double new_width = 0.0; double new_height = 0.0; double new_slide = 0.0; double new_pred_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].predict_detection.left_x; double new_pred_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].predict_detection.top_y; double new_pred_vec = sqrt(new_pred_vec_x*new_pred_vec_x + new_pred_vec_y * new_pred_vec_y); if (strcmp(pNext->name, "person") == 0 && strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { new_width = pre_W * 5.5; new_height = pre_H * 4.5; new_slide = sqrt(new_width*new_width + new_height * new_height); } else { new_width = pre_W * 2.5; new_height = pre_H * 2.5; new_slide = sqrt(new_width*new_width + new_height * new_height); } //鄰近的預測點 if (new_pred_vec <= new_slide) { vote_table[k][m] += VOTE_NEIGHBOR * (new_slide - new_pred_vec) / (new_slide); } 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)); //檢查長度和寬度是否在一定範圍內 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; int threshold_2 = 10; int threshold_3 = 25; if (deltaX <= threshold && deltaY <= threshold && deltaWidth <= threshold && deltaHeight <= threshold) { vote_table[k][m] += VOTE_STATIC; } else if (deltaX <= threshold_2 && deltaY <= threshold_2 && deltaWidth <= threshold_2 && deltaHeight <= threshold_2) { vote_table[k][m] += VOTE_STATIC * 0.8; } else if (deltaX <= threshold_3 && deltaY <= threshold_3 && deltaWidth <= threshold_3 && deltaHeight <= threshold_3) { vote_table[k][m] += VOTE_STATIC * 0.2; } } #endif #if 1 //跟歷史軌跡比較方向 if (det_count >= 2) { double new_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x; double new_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y; //double new_vec = sqrt(new_vec_x*new_vec_x + new_vec_y* new_vec_y); double old_vec_x = 0.0; double old_vec_y = 0.0; old_vec_x = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].left_x; old_vec_y = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].top_y; //位移方向相反 if (old_vec_x < 0) { if (new_vec_x > 0 && abs(new_vec_x) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)) //3 { vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; } else { } } if (old_vec_x > 0) { if (new_vec_x < 0 && abs(new_vec_x) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2))//3 { vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; } else { } } if (old_vec_y < 0) { if (new_vec_y > 0 && abs(new_vec_y) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 { vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; } else { } } if (old_vec_y > 0) { if (new_vec_y < 0 && abs(new_vec_y) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 { vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; } else { } } } #endif } } } //#endif //GY_OS_WIN - update_vote_table int find_possible_obj(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, int id_idx,int use_high_or_low_score) { int max_vote_value = 0; int obj_idx = -1; detection_pos* pNext = NULL; //printf("\n-------id_idx:%d\n", id_idx); if(use_high_or_low_score == 0) max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_0; else if(use_high_or_low_score == 1) max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_1; else if (use_high_or_low_score == 2) max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_2; else if (use_high_or_low_score == 3) max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_3; for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->obj_tracking_id > 0) continue; //printf("\n---------vote_table[id_idx][%d]:%d\n",j, vote_table[id_idx][j]); if (vote_table[id_idx][j] > max_vote_value) { max_vote_value = vote_table[id_idx][j]; obj_idx = j; } } ///if bbox j already assign id, check vote_value //printf("\n------id_idx:%d---obj_idx:%d\n", id_idx, obj_idx); if (obj_idx != -1) { //printf("\n---------obj_idx:%d\n", obj_idx); pNext = PosInfo + obj_idx; //pNext->vote_value = max_vote_value; pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; pNext->obj_tracking_id_idx = id_idx; } //if bbox j already assign id, check vote_value return obj_idx; } //#endif //GY_OS_WIN - find_possible_obj int Modify_Plate_and_Recount_Length(char *input_plate,char *output_plate) { char afterBuf[256] = { 0 }; strcpy(afterBuf, input_plate); char buf[64] = { 0 }; memset(buf, 0x00, sizeof(buf)); strcpy(buf, afterBuf); int k = 0; int plate_length = 0; //printf("\n------1\n"); //printf("\nbuf:%s\n",buf); //printf("\n------2\n"); for (int m = 0; m < strlen(buf); m++) { //printf("[%x]",buf[m]); if (buf[m] >= 65 && buf[m] <= 90) { if (buf[m] == 73 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { afterBuf[m] = '1'; } else if (buf[m] == 79 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { afterBuf[m] = '0'; } //alphabets++; afterBuf[k] = afterBuf[m]; k++; plate_length++; } else if (buf[m] >= 97 && buf[m] <= 122) { if (buf[m] == 105 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { afterBuf[m] = '1'; } else if (buf[m] == 111 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { afterBuf[m] = '0'; } if ((featureType & FEATURE_LPR_TWN) <= 0) { //alphabets++; afterBuf[k] = afterBuf[m]; k++; plate_length++; } } else if (buf[m] >= 48 && buf[m] <= 57) { //digits++; afterBuf[k] = afterBuf[m]; k++; plate_length++; } else { //specialcharacters++; if ((featureType & FEATURE_LPR_JPN) > 0) { //參考日文表UTF-8,三個c組成一個日文,第一個c,會介於227-239之間。 if (buf[m] >= 227 && buf[m] <= 239 && (m + 2) < strlen(buf)) { afterBuf[k] = afterBuf[m]; k++; afterBuf[k] = afterBuf[m + 1]; k++; afterBuf[k] = afterBuf[m + 2]; k++; m = m + 2; plate_length++; } } else if ((featureType & FEATURE_LPR_THA) > 0 || (featureType & FEATURE_LPR_BGD) > 0) { //參考泰文表或孟加拉文UTF-8,三個c組成一個泰文或孟加拉文,第一個c,會是224。 if (buf[m] == 224 && (m + 2) < strlen(buf)) { afterBuf[k] = afterBuf[m]; k++; afterBuf[k] = afterBuf[m + 1]; k++; afterBuf[k] = afterBuf[m + 2]; k++; m = m + 2; plate_length++; } } else if ((featureType & FEATURE_LPR_MEA) > 0) { //參考阿拉伯UTF-8,兩個c組成一個阿拉伯,第一個c,會是6或7。 if (buf[m] >= 216 && buf[m] <= 217 && (m + 1) < strlen(buf)) { //if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) { //afterBuf[k] = afterBuf[m]; //k++; //afterBuf[k] = afterBuf[m + 1]; //k++; m = m + 1; //plate_length++; } //else { //m = m + 1; //} } //支援減號, 空白 else if (buf[m] == 45 || buf[m] == 32) { afterBuf[k] = afterBuf[m]; k++; plate_length++; } } else if ((featureType & FEATURE_LPR_TWN) > 0) { //支援部分中文字UTF-8,三個c組成一個中文,第一個c,會介於228-233之間。 if (buf[m] >= 228 && buf[m] <= 233 && (m + 2) < strlen(buf)) { if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) { afterBuf[k] = afterBuf[m]; k++; afterBuf[k] = afterBuf[m + 1]; k++; afterBuf[k] = afterBuf[m + 2]; k++; m = m + 2; plate_length++; } else { m = m + 2; } } else if (buf[m] == 45) {//支援減號 if (activeDisplayDash) { afterBuf[k] = afterBuf[m]; k++; plate_length++; } } } } } //printf("\n------\n"); afterBuf[k] = '\0'; //printf("\nafterBuf:%s\n", afterBuf); if (((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION && strcmp(WeightFileModeName, "mod003") == 0)) { strcpy(afterBuf, input_plate); k = strlen(input_plate); afterBuf[k] = '\0'; plate_length = k; } if (plate_length >= atoi(viewChannelData[0].min_characters) && plate_length <= atoi(viewChannelData[0].max_characters)) strcpy(output_plate, afterBuf); else plate_length = 0; return plate_length; } void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size) { #ifdef GY_OS_AMBA detection_pos* pNext = NULL; for (int i = 0; i < total_element_size; i++) { //printf("\n[start all nets] while 10-1\n"); pNext = PosInfo + i; /** sizeof(detection_pos)*/ if (strlen(pNext->name) == 0) { continue; } char c_logo[50] = { 0 }; int iCar_idx = pNext->car_logo_idx;//pNext->car_logo_idx detection_pos *pNext_car; if (iCar_idx >= 0) { pNext_car = PosInfo + iCar_idx;//iCar_idx int iLogo_idx = pNext_car->car_logo_idx; detection_pos *pNext_logo = NULL; //printf("\n----------iLogo_idx:%d\n", iLogo_idx); if (IsVehicleCategory(pNext_car)) { if (iLogo_idx >= 0) { pNext_logo = PosInfo + iLogo_idx; //printf("\n---------pNext_logo->name:%s\n", pNext_logo->name); if (pNext_logo->name && strlen(pNext_logo->name) > 0 && !IsANPRCategory_L_Plate(pNext_logo->name) && !IsVehicleCategory(pNext_logo) && strcmp(pNext_logo->name, "person") != 0 && (pNext_logo->name[0] != '0' && pNext_logo->name[0] != '1' && pNext_logo->name[0] != '2' && pNext_logo->name[0] != '3' && pNext_logo->name[0] != '4' && pNext_logo->name[0] != '5' && pNext_logo->name[0] != '6' && pNext_logo->name[0] != '7' && pNext_logo->name[0] != '8' && pNext_logo->name[0] != '9') ) { char temp_buf[50] = { 0 }; int index_temp_buf = 0; for (int m = 0; m < (int)strlen(pNext_logo->name); m++) { if (m < (int)strlen(pNext_logo->name) - 1 && pNext_logo->name[m] == 'l' && pNext_logo->name[m + 1] == '_') { m++; } else { temp_buf[index_temp_buf] = pNext_logo->name[m]; index_temp_buf++; } } temp_buf[index_temp_buf] = '\0'; sprintf(c_logo, "%s", temp_buf); } else { sprintf(c_logo, "%s", ""); } strcpy(pNext_logo->logo, c_logo); } else { sprintf(c_logo, "%s", ""); } strcpy(pNext_car->logo, c_logo); } else { sprintf(c_logo, "%s", ""); } strcpy(pNext->properties.logo, c_logo); } int check_if_logo = 0; char temp_name[30] = { 0 }; int index_temp_name = 0; for (int index_name = 0; index_name < (int)strlen(pNext->name); index_name++) { if (index_name < (int)strlen(pNext->name) - 1 && pNext->name[index_name] == 'l' && pNext->name[index_name + 1] == '_') { index_name++; check_if_logo = 1; } else { temp_name[index_temp_name] = pNext->name[index_name]; index_temp_name++; } } temp_name[index_temp_name] = '\0'; if (check_if_logo == 1) { strcpy(pNext->name, temp_name); strcpy(pNext->properties.logo, temp_name); } } #endif } void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_temp, int tracking_channel_idx, time_t curr_det_time, int i_InSourceOri_w, int i_InSourceOri_h) { int total_element_size = * total_element_size_temp; struct timeval currtime; gettimeofday(&currtime, NULL); int det_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); gettimeofday(&currtime, NULL); long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 long last_ms = now_ms; double dw_FPS_time_delta = (double)(now_ms - last_ms); /*double dur; clock_t start, end; start = clock();*/ #ifdef GY_OS_NOVA g_sensors_type = 1; #endif #ifdef GY_OS_AMBA g_sensors_type = 1; //g_sensors_type = atoi(SystemSetting.sensors_type); #endif //g_max_sensor_size = g_sensors_type == 0 ? MAX_SENSOR_TYPE0 : MAX_SENSOR_TYPE1; float ratio_w = (float)i_InSourceOri_w;//0.25f float ratio_h = (float)i_InSourceOri_h;//0.3f //printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); //printf("\nGetObjectTrackingIDNew: %d\n",10); //printf("\nratio_w: %f\n", ratio_w); //printf("\nratio_h: %f\n", ratio_h); //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); detection_pos* pNext = NULL; //detection_pos* pNext_temp = NULL; for (int k = 0; k < MAX_DETECTION_ZONE; k++) { //eventCounterList[j].counter_count = 0; viewDetectionZone[tracking_channel_idx][k].queuing_trigger_event_idx = -1; } //printf("----det time = %d ms\n", det_ms); //2020-04-10 Updated for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; pNext->obj_tracking_id = 0; //pNext->vote_value = 0; pNext->det_time = curr_det_time; pNext->det_milli_sec = det_ms; pNext->trigger_type = 0; //pNext->disappear_count = 0; pNext->obj_tracking_id_idx = -1; pNext->replaced_id = 0; pNext->replaced_id_idx = -1; //printf("[%d] p_name 10 = %s \n", i, pNext->name); //pNext->iou_prev_self = 0; pNext->adjust_obj_speed = -1; pNext->check_if_replaced_in_zone = 0; //strcpy(pNext->replaced_name, ""); //pNext->image_id = -1; pNext->obj_dwell_time = 0; pNext->obj_first_dwell_time = 0; pNext->obj_last_dwell_time = 0; } memset(prev_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); memset(predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); memset(union_predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); memset(union_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); memset(vote_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); for (int i = 0; i < MAX_TRACKING_NUM; i++) { reset_id_obj(tracking_channel_idx, i); g_TrackingRecords[tracking_channel_idx][i].bAssign_flag = 0; //g_TrackingRecords[tracking_channel_idx][i].vote_value = 0; g_TrackingRecords[tracking_channel_idx][i].Assign_obj_idx = -1; } /// update_iou_table(PosInfo, total_element_size, tracking_channel_idx); update_vote_table(PosInfo, total_element_size, tracking_channel_idx); /// //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #1:%lf ms\n", dw_FPS_time_delta); int det_count = 0; #if 1 ///Search Multi connection bbox int closest_obj_idx = -1; int bFindTrackingObjects = 0; for (int index_score = 0; index_score < 4; index_score++) { for (int i = 0; i < MAX_TRACKING_NUM; i++) { //reset_id_obj(&g_TrackingRecords[tracking_channel_idx][i],i); det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; if (det_count == 0) continue; if (g_TrackingRecords[tracking_channel_idx][i].bAssign_flag == 1) continue; //first time : find_possible_obj for high score //second time : find_possible_obj for low score //more time : find_possible_obj for lower score closest_obj_idx = find_possible_obj(PosInfo, total_element_size, tracking_channel_idx, i, index_score); bFindTrackingObjects = 0; if (closest_obj_idx != -1) bFindTrackingObjects = 1; //printf("\n-------i:%d-------closest_obj_idx:%d\n",i, closest_obj_idx); if (bFindTrackingObjects) { ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, i, closest_obj_idx); } } } #endif //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #2:%lf ms\n", dw_FPS_time_delta); ///Assign New obj ID to new bounding box for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; det_count = 0; if (pNext->obj_tracking_id <= 0) { ///Check prev data again float max_prev_iou = 0.0; int closest_id_idx = -1; for (int j = 0; j < MAX_TRACKING_NUM; j++) { if (g_TrackingRecords[tracking_channel_idx][j].bAssign_flag) continue; det_count = g_TrackingRecords[tracking_channel_idx][j].detection_count; if (det_count >= 1) { float fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1]); if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 1) { if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate) == 0*/) { //if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; break; } } else if (strcmp(pNext->name, "ambulance") == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; //break; } } else if (strcmp(pNext->name, "blank") == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; //break; } } else if (strcmp(pNext->name, "stop_sign") == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; //break; } } else if (strcmp(pNext->name, "face") == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; //break; } } else if (det_count >= 2) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate) == 0*/) { //if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; break; } } } } else if (g_TrackingRecords[tracking_channel_idx][j].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { //if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; break; } } else if (det_count >= 2 && g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate_length >= 1 && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); //if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; break; } } else if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][j].name) == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } else if (det_count >= 2) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } } //printf("\n---------max_prev_iou:%f,top_y:%f\n", max_prev_iou,pNext->top_y); } else if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "car") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "bus") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "truck") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "tuktuk") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "trailer") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "pickup") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "SUV") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "dual_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "single_headlight") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "van"))) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } else if (det_count >= 2) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } } } else if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "motorbike") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ok") || strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ng"))) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } else if (det_count >= 2) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } } } else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(heartbeatData.events_default_version, "4") == 0) { if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } else if (det_count >= 2) { fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); if (fIOU > max_prev_iou) { max_prev_iou = fIOU; closest_id_idx = j; } } } } } if (closest_id_idx != -1) { //pNext->vote_value = max_prev_iou; pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][closest_id_idx].obj_tracking_id; pNext->obj_tracking_id_idx = closest_id_idx; ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, closest_id_idx, i); } else { for (int m = 0; m < MAX_TRACKING_NUM; m++) { if (g_TrackingRecords[tracking_channel_idx][m].bAssign_flag) continue; det_count = g_TrackingRecords[tracking_channel_idx][m].detection_count; if (det_count == 0) { //pNext->vote_value = 0; pNext->obj_tracking_id = 0; pNext->obj_tracking_id_idx = m; ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, m, i); break; } } } } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #3:%lf ms\n", dw_FPS_time_delta); if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) { for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && pNext->obj_dwell_time >= 1 && strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && pNext->height >= 1 && pNext->width >= 1) { int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width * 1.5, pNext->height * 1.5, g_ori_yuv_width, g_ori_yuv_height, 0); 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) { det_count = g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].detection_count; for (int index_det = det_count - 1 - 1; index_det >= 0; index_det--) { if (strlen(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name) >= 1 && strcmp(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name, "object") != 0) { memset(pNext->name, 0x00, sizeof(pNext->name)); strcpy(pNext->name, g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name); break; } } if (strcmp(heartbeatData.events_default_version, "4") == 0) { if (pNext->height / pNext->width <= 1.05 || ((pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height)) >= 0.05 || pNext->width / (float)g_ori_yuv_width > 0.05) { memset(pNext->name, 0x00, sizeof(pNext->name)); strcpy(pNext->name, "car"); pNext->check_if_replaced_in_zone = 1; } else { memset(pNext->name, 0x00, sizeof(pNext->name)); strcpy(pNext->name, "person"); pNext->check_if_replaced_in_zone = 1; } } } } } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #4:%lf ms\n", dw_FPS_time_delta); time_t current_time = time(0); for (int j = 0; j < MAX_DETECTION_ZONE; j++) { pop_not_to_track_vehicles(j, current_time); } ///開始做事件觸發UpdateZoneStatus for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) { //if (strcmp(pNext->name, "object") == 0) //{ //if (strlen(pNext->replaced_name) >= 1) { //strcpy(pNext->name, pNext->replaced_name); //} //} { int k = pNext->obj_tracking_id_idx; det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; UpdateZoneStatus(pNext, tracking_channel_idx, k, det_count - 1, ratio_w, ratio_h, total_element_size, PosInfo, i); } } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #5:%lf ms\n", dw_FPS_time_delta); /////////-------------- for (int k = 0; k < MAX_TRACKING_NUM; k++) { if (g_TrackingRecords[tracking_channel_idx][k].bAssign_flag == 0) { det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; if (det_count >= 1) { g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].disappear_count++; } g_TrackingRecords[tracking_channel_idx][k].disappear_count++; } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #6:%lf ms\n", dw_FPS_time_delta); #if 1 int ZoneQueuingCount[MAX_DETECTION_ZONE] = { 0 }; int ZoneGivewayCount[MAX_DETECTION_ZONE] = { 0 }; for (int i = 0; i < MAX_DETECTION_ZONE; i++) { ZoneQueuingCount[i] = 0; ZoneGivewayCount[i] = 0; } ////////----------Forget to give way detection 不禮讓偵測 int index_zone_protect = -1; int index_zone_keep_away = -1; int index_zone_protect_2 = -1; int index_zone_keep_away_2 = -1; if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect) == 1) { index_zone_protect = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect); } if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away) == 1) { index_zone_keep_away = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away); } if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2) == 1) { index_zone_protect_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2); } if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2) == 1) { index_zone_keep_away_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2); } if ((index_zone_protect >= 0 && index_zone_keep_away >= 0) || (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0)) { for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_check_giveway[i] == 1) { ZoneGivewayCount[i]++; } } } if (index_zone_protect >= 0 && index_zone_keep_away >= 0) { if (ZoneGivewayCount[index_zone_protect] >= 1 && ZoneGivewayCount[index_zone_keep_away] >= 1) { for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away].trigger_event[k].detect_event_id); if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_check_giveway[index_zone_keep_away] == 1) { pNext->zone_violation_idx[index_zone_keep_away] = 1; pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; pNext->trigger_idx[index_zone_keep_away] = k; if (pNext->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; } } } break; } } } } if (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0) { if (ZoneGivewayCount[index_zone_protect_2] >= 1 && ZoneGivewayCount[index_zone_keep_away_2] >= 1) { for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away_2].trigger_event[k].detect_event_id); if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_check_giveway[index_zone_keep_away_2] == 1) { pNext->zone_violation_idx[index_zone_keep_away_2] = 1; pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; pNext->trigger_idx[index_zone_keep_away_2] = k; if (pNext->obj_tracking_id_idx >= 0) { g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; } } } break; } } } } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #7:%lf ms\n", dw_FPS_time_delta); ///計數器計算 /*end = clock(); dur = (double)(end - start); printf("\nGet Object Tracking ID New[5]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); start = clock();*/ for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_violation_idx[i] == 1) { ZoneQueuingCount[i]++; } } } //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #8:%lf ms\n", dw_FPS_time_delta); /* end = clock(); dur = (double)(end - start); printf("\nGet Object Tracking ID New[6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); start = clock();*/ for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) { /* if (ZoneQueuingCount[i]>0) { printf("\n---------------\n"); printf("\nZoneQueuingCount[%d]:%d\n",i, ZoneQueuingCount[i]); printf("\n---------------\n"); }*/ #ifdef GY_OS_V_SERIES int check_if_enable_linked_to_dwell_time = 0; viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; #else int check_if_enable_linked_to_dwell_time = 0; #if 1 for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; char Temp[MAX_MSG_LEN * 10] = { 0 }; strcpy(Temp, viewDetectionZone[tracking_channel_idx][i].trigger_event[k].counter_name); int event_counter_num = StrSplit(Temp, eachEventCounter, ","); //printf("\n------UU:14\n"); for (int w = 0; w < event_counter_num; w++) { for (int m = 0; m < MAX_EVENT_COUNTERS; m++) { if (strlen(eachEventCounter[w]) >= 1 && strcmp(eachEventCounter[w], eventCounterList[m].counter_name) == 0) { if (strcmp(eventCounterList[m].enable_linked_to_dwell_time, "Yes") == 0) { check_if_enable_linked_to_dwell_time = 1; break; } } } if (check_if_enable_linked_to_dwell_time == 1) break; } } } #endif #endif 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)) || g_IsCustomWeight == 1) { if (viewDetectionZone[tracking_channel_idx][i].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][i].parking_line >= 1) { for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) { viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx = k; int count_plot = 0; for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][i].parking_space; index_plot++) { if (g_parking_space_check_table[i][index_plot] == 1) { count_plot++; } } viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = count_plot; if (viewDetectionZone[tracking_channel_idx][i].prev_queuing_num >= viewDetectionZone[tracking_channel_idx][i].queuing_count && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; int temp_m = -1; if (pNext->zone_violation_idx[i] == 1) { //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; //pNext->detection_zone_idx = i; pNext->trigger_idx[i] = k; for (int m = 0; m < MAX_TRACKING_NUM; m++) { if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) { g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; g_TrackingRecords[tracking_channel_idx][m].trigger_zone_id = i + 1; temp_m = m; break; } } } pNext->check_if_having_been_counted[i] = 0; if(temp_m >= 0) g_TrackingRecords[tracking_channel_idx][temp_m].check_if_having_been_counted[i] = 0; } } else { for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_violation_idx[i] == 1) { pNext->zone_violation_idx[i] = 0; } } } } } } } else{ if (check_if_enable_linked_to_dwell_time == 0) { viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; } for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { if (ZoneQueuingCount[i] >= viewDetectionZone[tracking_channel_idx][i].queuing_count && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) { viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; for (int j = 0; j < total_element_size; j++) { pNext = PosInfo + j; if (pNext->zone_violation_idx[i] == 1) { //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; //pNext->detection_zone_idx = i; pNext->trigger_idx[i] = k; for (int m = 0; m < MAX_TRACKING_NUM; m++) { if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) { g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; break; } } } } } } } } } } else { viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; } } /** end = clock(); dur = (double)(end - start); printf("\nGet Object Tracking ID New[7]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC));*/ #endif //gettimeofday(&currtime, NULL); //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 //dw_FPS_time_delta = (double)(now_ms - last_ms); //dw_FPS_time_delta = fabs(dw_FPS_time_delta); //printf("\n-----Get Object Tracking IDNew #9:%lf ms\n", dw_FPS_time_delta); *total_element_size_temp = total_element_size; } #ifdef GY_OS_WIN unsigned int GetObjectSocialDistance(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, IplImage* ipl_img, float distance_heigh, float distance_width) { float x1 = viewDetectionZone[tracking_channel_idx][0].Points[0].x; float y1 = viewDetectionZone[tracking_channel_idx][0].Points[0].y; float x2 = viewDetectionZone[tracking_channel_idx][0].Points[1].x; float y2 = viewDetectionZone[tracking_channel_idx][0].Points[1].y; float x3 = viewDetectionZone[tracking_channel_idx][0].Points[2].x; float y3 = viewDetectionZone[tracking_channel_idx][0].Points[2].y; float x4 = viewDetectionZone[tracking_channel_idx][0].Points[3].x; float y4 = viewDetectionZone[tracking_channel_idx][0].Points[3].y; float d_x1, d_y1, d_x2, d_y2, d_x3, d_y3, d_x4, d_y4; #if 1 CvPoint2D32f src_points[4]; CvPoint2D32f dst_points[4]; float ratio_window_h, ratio_window_w; ratio_window_h = ipl_img->height / CANVAS_HEIGHT; ratio_window_w = ipl_img->width / CANVAS_WIDTH; //window size -> real resultion of camera x1 = x1 * ratio_window_w; y1 = y1 * ratio_window_h; x2 = x2 * ratio_window_w; y2 = y2 * ratio_window_h; x3 = x3 * ratio_window_w; y3 = y3 * ratio_window_h; x4 = x4 * ratio_window_w; y4 = y4 * ratio_window_h; //x1 = (x1 / CANVAS_WIDTH) * 3840; //y1 = (y1 / CANVAS_HEIGHT) * 2160; //x2 = (x2 / CANVAS_WIDTH) * 3840; //y2 = (y2 / CANVAS_HEIGHT) * 2160; //x3 = (x3 / CANVAS_WIDTH) * 3840; //y3 = (y3 / CANVAS_HEIGHT) * 2160; //x4 = (x4 / CANVAS_WIDTH) * 3840; //y4 = (y4 / CANVAS_HEIGHT) * 2160; //d_x1 = (d_x1 / CANVAS_WIDTH) * 3840; //d_y1 = (d_y1 / CANVAS_HEIGHT) * 2160; //d_x2 = (d_x2 / CANVAS_WIDTH) * 3840; //d_y2 = (d_y2 / CANVAS_HEIGHT) * 2160; //d_x3 = (d_x3 / CANVAS_WIDTH) * 3840; //d_y3 = (d_y3 / CANVAS_HEIGHT) * 2160; //d_x4 = (d_x4 / CANVAS_WIDTH) * 3840; //d_y4 = (d_y4 / CANVAS_HEIGHT) * 2160; d_x1 = 0; d_y1 = 0; d_x2 = distance_width; d_y2 = 0; d_x3 = distance_width; d_y3 = distance_heigh; d_x4 = 0; d_y4 = distance_heigh; src_points[0].x = x1; src_points[0].y = y1; src_points[1].x = x2; src_points[1].y = y2; src_points[2].x = x3; src_points[2].y = y3; src_points[3].x = x4; src_points[3].y = y4; dst_points[0].x = d_x1; dst_points[0].y = d_y1; dst_points[1].x = d_x2; dst_points[1].y = d_y2; dst_points[2].x = d_x3; dst_points[2].y = d_y3; dst_points[3].x = d_x4; dst_points[3].y = d_y4; CvMat *M = cvCreateMat(3, 3, CV_32FC1); cvGetPerspectiveTransform(src_points, dst_points, M); PerspectiveTransform(PosInfo, total_element_size, M, distance_heigh, distance_width, ipl_img->height, ipl_img->width); #if 0 IplImage* dst = NULL; CvSize ImageSize1 = cvSize(994, 364); dst = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3); cvZero(dst); CvScalar fillval = cvScalarAll(0); cvWarpPerspective(ipl_img, dst, M, CV_INTER_LINEAR, fillval); cvNamedWindow("Affine_Transform", 1); cvShowImage("Affine_Transform", dst); cvWaitKey(1); #endif //cvReleaseImage(&dst); //cvReleaseMat(M); cvReleaseMat(&M); #endif } #endif //GY_OS_WIN - GetObjectSocialDistance void BindLicensePlateToVehicle(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) { detection_pos* pNext = NULL; detection_pos* pNext2 = NULL; int BindNewLicensePlateOk = 0; for (int i = 0; i < total_element_size; i++) { pNext = PosInfo + i; if (i == total_element_size - 1) break; if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { //printf("tracking_channel_idx ==== %d \n", tracking_channel_idx); for (int k = 0; k < MAX_TRACKING_NUM; k++) { if (g_TrackingRecords[tracking_channel_idx][k].obj_tracking_id == pNext->obj_tracking_id) { for (int j = i + 1; j < total_element_size; j++) { pNext2 = PosInfo + j; if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) { if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0)) { if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][k].linked_plate)) { int det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; //StrReplace(pNext2->properties.plate, "-", ""); if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, pNext2->properties.plate); pNext->linked_plate_length = pNext2->properties.plate_length; strcpy(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext2->properties.plate); g_TrackingRecords[tracking_channel_idx][k].linked_plate_length = pNext2->properties.plate_length; if (det_count > 0) { strcpy(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate, pNext2->properties.plate); g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate_length = pNext2->properties.plate_length; } BindNewLicensePlateOk = 1; } } break; } } } if (!BindNewLicensePlateOk) { if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= atoi(viewChannelData[0].min_characters) && g_TrackingRecords[tracking_channel_idx][k].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][k].linked_plate); pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][k].linked_plate_length; } } } } } } } int number_of_digits(long long n) { int count = 0; while (n != 0) { // n = n/10 n /= 10; ++count; } return count; } void check_license(int license, int adv_license, int bMacMatch, time_t start_time, time_t end_time, char* filename) { pthread_mutex_lock(&mutex_check_license); //printf("\n[check_license] start\n"); //printf("\n[check_license] filename:%s\n", filename); //memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); //#ifdef GY_OS_WIN char* fileBuf = ReadAllBytes(filename); if (fileBuf) { cJSON *s_root, *tlt_code; s_root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (s_root) { tlt_code = cJSON_GetObjectItem(s_root, "TLT code"); //trial launch time //cJSON* virtual_mac = cJSON_GetObjectItem(s_root, "VM code"); //virtual MAC //解碼上次執行時間 - step 1:base64 decode size_t base64_decode_length = 0; char EncryptKeyData[256]; char DecryptKeyData[256]; memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); unsigned char OriEncryptData[512] = { 0 }; base64_decode(tlt_code->valuestring, strlen(tlt_code->valuestring), &base64_decode_length, OriEncryptData); memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); //解碼上次執行時間 - step 2:AES descrytion KeyExpansion(key, expandedKey); AESDecryptArrayToArray(EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); //取得上次執行時間明碼資訊 time_t last_launch_time = atoll(DecryptKeyData); //檢查本次與上次執行時間是否正確 time_t now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } while (number_of_digits(last_launch_time) > number_of_digits(now_time)) { last_launch_time /= 10; } char strLaunchTime[16] = { 0 }; #ifdef GY_OS_WIN snprintf(strLaunchTime, sizeof(strLaunchTime), "%I64d", now_time); #endif #if defined GY_OS_AMBA || defined GY_OS_NOVA //這邊要用lld,不能用ld,會有問題 snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); #endif //printf("\nstrLaunchTime:%s", strLaunchTime); //#endif /*{ char buff[20]; struct tm * timeinfo; timeinfo = localtime(&now_time); strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); printf("\nnow_time:%s", buff); } { char buff[20]; struct tm * timeinfo; timeinfo = localtime(&start_time); strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); printf("\nstart_time:%s", buff); } { char buff[20]; struct tm * timeinfo; timeinfo = localtime(&end_time); strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); printf("\nend_time:%s", buff); } { char buff[20]; struct tm * timeinfo; timeinfo = localtime(&last_launch_time); strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); printf("\nlast_launch_time:%s", buff); }*/ //printf("\n--------------license:%d\n", license); if (license == 0 && check_if_fe_fail == 0) { licenseType = _NO_LICENSE; afsCode = _NOT_LICENSED; strcpy(strLicenseStatus, "Invalid license"); printf("\n[check_license] Invalid license:%d\n", licenseType); } else if (check_if_fe_fail == 1 || license == _PERMANENT_LICENSE_MULTI || license == _PERMANENT_LICENSE_SINGLE || license == _PERMANENT_LICENSE_MULTI_POST || license == _PERMANENT_LICENSE_SINGLE_POST || license == _LICENSE_FPS06 || license == _LICENSE_FPS12 || license == _LICENSE_FPS18 || license == _LICENSE_FPS24 || license == _LICENSE_FPS30 || license == _LICENSE_FPS36 || license == _LICENSE_FPS42 || license == _LICENSE_FPS48 || license == _LICENSE_FPS54 || license == _LICENSE_FPS60) { switch (license) { case _PERMANENT_LICENSE_MULTI: licenseType = _PERMANENT_LICENSE_MULTI; http_license_fps = 60; break; case _PERMANENT_LICENSE_SINGLE: licenseType = _PERMANENT_LICENSE_SINGLE; break; case _PERMANENT_LICENSE_MULTI_POST: licenseType = _PERMANENT_LICENSE_MULTI_POST; break; case _PERMANENT_LICENSE_SINGLE_POST: licenseType = _PERMANENT_LICENSE_SINGLE_POST; break; case _LICENSE_FPS06: licenseType = _LICENSE_FPS06; http_license_fps = 6; break; case _LICENSE_FPS12: licenseType = _LICENSE_FPS12; http_license_fps = 12; break; case _LICENSE_FPS18: licenseType = _LICENSE_FPS18; http_license_fps = 18; break; case _LICENSE_FPS24: licenseType = _LICENSE_FPS24; http_license_fps = 24; break; case _LICENSE_FPS30: licenseType = _LICENSE_FPS30; http_license_fps = 30; break; case _LICENSE_FPS36: licenseType = _LICENSE_FPS36; http_license_fps = 36; break; case _LICENSE_FPS42: licenseType = _LICENSE_FPS42; http_license_fps = 42; break; case _LICENSE_FPS48: licenseType = _LICENSE_FPS48; http_license_fps = 48; break; case _LICENSE_FPS54: licenseType = _LICENSE_FPS54; http_license_fps = 54; break; case _LICENSE_FPS60: licenseType = _LICENSE_FPS60; http_license_fps = 60; break; default: licenseType = _LICENSE_FPS06; http_license_fps = 6; } switch (adv_license) { case _AD_LICENSE_BASIC: advLicenseType = _AD_LICENSE_BASIC; break; case _AD_LICENSE_01: advLicenseType = _AD_LICENSE_01; break; default: advLicenseType = _AD_LICENSE_BASIC; } if (!bMacMatch) { afsCode = _MAC_MISMATCH; strcpy(strLicenseStatus, "License mismatch the system ID"); } else { afsCode = _LICENSED; strcpy(strLicenseStatus, "Licensed."); } } else if (license == _TRIAL_LICENSE_MULTI || license == _TRIAL_LICENSE_SINGLE || license == _TRIAL_LICENSE_FPS06 || license == _TRIAL_LICENSE_FPS12 || license == _TRIAL_LICENSE_FPS18 || license == _TRIAL_LICENSE_FPS24 || license == _TRIAL_LICENSE_FPS30 || license == _TRIAL_LICENSE_FPS36 || license == _TRIAL_LICENSE_FPS42 || license == _TRIAL_LICENSE_FPS48 || license == _TRIAL_LICENSE_FPS54 || license == _TRIAL_LICENSE_FPS60) { switch (license) { case _TRIAL_LICENSE_MULTI: licenseType = _TRIAL_LICENSE_MULTI; http_license_fps = 60; break; case _TRIAL_LICENSE_SINGLE: licenseType = _TRIAL_LICENSE_SINGLE; break; case _TRIAL_LICENSE_FPS06: licenseType = _TRIAL_LICENSE_FPS06; http_license_fps = 6; break; case _TRIAL_LICENSE_FPS12: licenseType = _TRIAL_LICENSE_FPS12; http_license_fps = 12; break; case _TRIAL_LICENSE_FPS18: licenseType = _TRIAL_LICENSE_FPS18; http_license_fps = 18; break; case _TRIAL_LICENSE_FPS24: licenseType = _TRIAL_LICENSE_FPS24; http_license_fps = 24; break; case _TRIAL_LICENSE_FPS30: licenseType = _TRIAL_LICENSE_FPS30; http_license_fps = 30; break; case _TRIAL_LICENSE_FPS36: licenseType = _TRIAL_LICENSE_FPS36; http_license_fps = 36; break; case _TRIAL_LICENSE_FPS42: licenseType = _TRIAL_LICENSE_FPS42; http_license_fps = 42; break; case _TRIAL_LICENSE_FPS48: licenseType = _TRIAL_LICENSE_FPS48; http_license_fps = 48; break; case _TRIAL_LICENSE_FPS54: licenseType = _TRIAL_LICENSE_FPS54; http_license_fps = 54; break; case _TRIAL_LICENSE_FPS60: licenseType = _TRIAL_LICENSE_FPS60; http_license_fps = 60; break; default: licenseType = _TRIAL_LICENSE_FPS06; http_license_fps = 6; } switch (adv_license) { case _AD_LICENSE_BASIC: advLicenseType = _AD_LICENSE_BASIC; break; case _AD_LICENSE_01: advLicenseType = _AD_LICENSE_01; break; default: advLicenseType = _AD_LICENSE_BASIC; } if (!bMacMatch) { afsCode = _MAC_MISMATCH; strcpy(strLicenseStatus, "Trial mismatch the system ID"); } else if (now_time < start_time-3600*24) { afsCode = _UNINITIALIZED; strcpy(strLicenseStatus, "Trial has expired. Trial not initialized."); //Trial not initialized } else if (last_launch_time- 3600 * 24 > now_time) //若前次時間大於本次時間, 表示系統時間被修改過 { printf("\n------------------[Incorrect system time detected]-------------------\n"); char msg_temp[512] = { 0 }; printf("\nlast_launch_time: %lld , now_time: %lld\n", (long long int)last_launch_time, (long long int)now_time); sprintf(msg_temp,"last_launch_time: %lld , now_time: %lld", (long long int)last_launch_time, (long long int)now_time); afsCode = _EXPIRED; strcpy(strLicenseStatus, "Trial has expired. Incorrect system time detected."); strcat(strLicenseStatus, msg_temp); now_time = last_launch_time; } else if (now_time > end_time+3600*24) { afsCode = _EXPIRED; strcpy(strLicenseStatus, "Trial has expired"); } else { afsCode = _LICENSED; char Msg[256] = { 0 }; double diffDays = difftime(end_time, now_time) / (60 * 60 * 24); if (diffDays < 0) diffDays = 0; snprintf(Msg, sizeof(Msg), "Licensed(%d days left)", (int)diffDays); strcpy(strLicenseStatus, Msg); } } //#ifdef GY_OS_WIN //將本次執行時間加密, 寫入檔案 if (!(last_launch_time > now_time)) { //printf("\n[check_license] write file\n"); KeyExpansion(key, expandedKey); unsigned char EncryptData[1 * 1024]; memset(EncryptData, 0x00, sizeof(EncryptData)); int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); size_t base64_encode_length = 0; char launchTime[1024] = { 0 }; base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); *(launchTime + base64_encode_length) = '\0'; cJSON_ReplaceItemInObject(s_root, "TLT code", cJSON_CreateString(launchTime)); char* JsonString = cJSON_Print(s_root); FILE *f = fopen(filename, "w"); if (f == NULL) { printf("---------------------------Error opening setting file!-----------------------------\n"); #if 1 stop_test_nn_cavalry("Error opening setting file!"); //stop_server(); #endif //exit(EXIT_FAILURE); } else { fprintf(f, "%s\n", JsonString); fclose(f); } if (JsonString) { free(JsonString); JsonString = NULL; } } if (s_root) { cJSON_Delete(s_root); s_root = NULL; } //#endif stAMBAcontent.licenseType = licenseType; stAMBAcontent.afsCode = afsCode; stAMBAcontent.advLicenseType = advLicenseType; //printf("\n-------strLicenseStatus:%s\n", strLicenseStatus); //printf("\n[check_license] licenseType:%d %d %d\n", licenseType, afsCode,advLicenseType); } } pthread_mutex_unlock(&mutex_check_license); } void SetDatasetCategory(int licenseType, char* strDatasetCategory) { switch (licenseType) { case _PERMANENT_LICENSE_MULTI: case _LICENSE_FPS06: case _LICENSE_FPS12: case _LICENSE_FPS18: case _LICENSE_FPS24: case _LICENSE_FPS30: case _LICENSE_FPS36: case _LICENSE_FPS42: case _LICENSE_FPS48: case _LICENSE_FPS54: case _LICENSE_FPS60: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; case _PERMANENT_LICENSE_SINGLE: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; case _TRIAL_LICENSE_MULTI: case _TRIAL_LICENSE_FPS06: case _TRIAL_LICENSE_FPS12: case _TRIAL_LICENSE_FPS18: case _TRIAL_LICENSE_FPS24: case _TRIAL_LICENSE_FPS30: case _TRIAL_LICENSE_FPS36: case _TRIAL_LICENSE_FPS42: case _TRIAL_LICENSE_FPS48: case _TRIAL_LICENSE_FPS54: case _TRIAL_LICENSE_FPS60: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; case _TRIAL_LICENSE_SINGLE: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; case _PERMANENT_LICENSE_MULTI_POST: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; case _PERMANENT_LICENSE_SINGLE_POST: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI break; default: sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI } } void check_feature() { char strDatasetCategory[MAX_MSG_LEN] = { 0 }; char *strDatasetCountry = NULL; memset(strLicenseType, 0x00, sizeof(strLicenseType)); int nHasFeature = 0; if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && g_IsRadarDevice == 0 && g_IsToFDevice == 0 && unlockingKeyInnoFR_success == 0) { if (!IsExistingWeight(featureType, featureType2)) { sprintf(strLicenseType, " Weight Error:"); } } if (g_match_mac == 1 || unlockingKeyInnoFR == 1) { if (g_IsHelm_without_car == 1) { } else { if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA)) { #ifdef GY_OS_NOVA sprintf(strDatasetCategory, "%s", "EDGEFENCE (Home Security)");//01AI #endif #ifdef GY_OS_AMBA sprintf(strDatasetCategory, "%s", "EDGEFLOW (Home Security)");//01AI #endif strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { #ifdef GY_OS_NOVA sprintf(strDatasetCategory, "%s", "EDGEDENSITY (Flow Counter)");//03AI #endif #ifdef GY_OS_AMBA sprintf(strDatasetCategory, "%s", "EDGECAP (Flow Counter)");//03AI #endif strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } } if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0){ sprintf(strDatasetCategory, "%s", "EDGEGARBAGE (Garbage Recognition)"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { sprintf(strDatasetCategory, "%s", "EDGERAIL (Rail Security)"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { sprintf(strDatasetCategory, "%s", "EDGESPORTS (Sports Recognition)"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) { sprintf(strDatasetCategory, "%s", "EDGEFIRE (Environment Safety)");//05AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) { sprintf(strDatasetCategory, "%s", "EDGEAERO (Aero Recognition)"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } //printf("\nFEATURE_HUM_DET---6\n"); if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { sprintf(strDatasetCategory, "%s", "EDGESAFTY (Construction Site Safety)");//04AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } //printf("\nFEATURE_HUM_DET---7\n"); if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) { if (strcmp(WeightFileModeName, "mod003") != 0) { sprintf(strDatasetCategory, "%s", "EDGEMASK (Health Care)");//02AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } else { sprintf(strDatasetCategory, "%s", "EDGEGENDER (Human gender)");//02AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } } if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) { sprintf(strDatasetCategory, "%s", "EDGEVESSEL (Vessel Recognition)");//08AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) { sprintf(strDatasetCategory, "%s", "EDGEPRODUCTION (Production Line)"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { if (strcmp(WeightFileModeName, "mod003") != 0) { sprintf(strDatasetCategory, "%s", "EDGEANIMAL (Animal Recognition)");//09AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } else { sprintf(strDatasetCategory, "%s", "EDGEFRONTBACK (Car Front & Back)");//09AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } } //printf("\nFEATURE_HUM_DET---8\n"); if ((featureType & FEATURE_POK_DET) != 0) { sprintf(strDatasetCategory, "%s", "Poker pattern recognition"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_HUM_POS) != 0) { sprintf(strDatasetCategory, "%s", "Human pose estimator"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LED_DGT) != 0) { sprintf(strDatasetCategory, "%s", "LED digits recognition"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_SHOES_DET) != 0) { sprintf(strDatasetCategory, "%s", "Shoes recognition"); strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_LOGO) != 0) { sprintf(strDatasetCategory, "%s", "EDGECARMAKE (Car Make)");//07AI strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_TWN) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "TW/EC (Taiwan, Ecuador)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_EUR) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "EU (Belgium, Italy, Croatia, France, Turkey, Germany, Spain, Portugal, Slovenia)"; //European //EU/UK/IN strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_SEA) != 0 || (featureType & FEATURE_LPR_VNM) != 0 || (featureType & FEATURE_LPR_IDN) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "MY/HK/SG/VN/ID (Malaysia, Hong Kong, Singapore, Vietnam, Indonesia)";//South East Asia strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } /* if ((featureType & FEATURE_LPR_CNA) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "China"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; }*/ if ((featureType & FEATURE_LPR_MEA) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "AE/SA (UAE, Saudi Arabia)";//Middle East Asia strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_USA) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "US/CA (50 states, Guam, Canada)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_AUS) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "AU (Australia)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_GBR) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "GB/IN (UK, India)"; //UK/IN //United Kingdom strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_JPN) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "JP (Japan)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_THA) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "TH (Thailand)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; }/* if ((featureType & FEATURE_LPR_LAO) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "Laos"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; }*/ if ((featureType & FEATURE_LPR_BGD) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "BD (Bangladesh)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_PHL) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "PH (Philippines)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if ((featureType & FEATURE_LPR_CNT) != 0) { SetDatasetCategory(licenseType, strDatasetCategory); strDatasetCountry = "CNT (Container)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, "-"); strcat(strLicenseType, strDatasetCountry); strcat(strLicenseType, ","); nHasFeature = 1; } if (td_weight_num >= 1 && check_if_correct_mail == 1) { char *strDatasetCategory = "Third Party"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if (g_IsRadarDevice == 1) { char *strDatasetCategory = "EDGERADAR (Radar Recognition)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if (g_IsToFDevice == 1) { char *strDatasetCategory = "EDGETOF (ToF Recognition)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); nHasFeature = 1; } if (unlockingKeyInnoFR_success == 1) { char *strDatasetCategory = "EDGEFACE (Face Recognition)"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); //printf("setting License Type : EDGEFACE (Face Recognition)\n"); //printf("srtLicenseType = %s\n", strLicenseType); nHasFeature = 1; } if (!nHasFeature) { char *strDatasetCategory = "No license"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); } //printf("srtLicenseType = %s\n", strLicenseType); //printf("featureType = %d\n", featureType); //printf("featureType2 = %d\n", featureType2); } else{ char *strDatasetCategory = "Mac address is not supported"; strcat(strLicenseType, " "); strcat(strLicenseType, strDatasetCategory); strcat(strLicenseType, ","); } } //void stop_detector() //{ // bHttpServerThreadStart = 0; //} //20201027 sophia add /* command: /usr/local/bin/nvclient -k user.password0 /usr/local/bin/nvclient -k user.account0 ... /usr/local/bin/nvclient -k user.password9 /usr/local/bin/nvclient -k user.account9 return : NVRAM Client, Version:1.0.0 Get nvram data, ret:0 Key=user.account0 Data=admin TStamp=172 Max data size=32 */ //#if defined GY_OS_AMBA void get_image_dn() { { if (imageDnData.color_mode == 1) { imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; imageDnData.current_day_or_night_mode = 1; for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; } if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { imageDnData.check_if_switch_happened[0] = 1; usSleep(2500000); } else { imageDnData.check_if_switch_happened[0] = 0; } } else if (imageDnData.color_mode == 2) { imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; imageDnData.current_day_or_night_mode = 2; for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; } if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { imageDnData.check_if_switch_happened[0] = 1; usSleep(2500000); } else { imageDnData.check_if_switch_happened[0] = 0; } } //printf("\n-----------imageDnData.check_if_switch_happened[0]:%d\n", imageDnData.check_if_switch_happened[0]); } } int get_check_if_existing_any_switch_happened() { int rtn = 0; for (int i = 0; i < MAX_SIZE_SWITCH_HAPPENED; i++) { if (imageDnData.check_if_switch_happened[i] == 1) { rtn = 1; break; } } return rtn; } //#endif //20201027 sophia add void update_config_account_setting(void) { char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); //printf("Program binary path is: %s\n", buf); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char configPATH[1024] = { 0 }; char config_bakPATH[1024] = { 0 }; strcpy(configPATH, exePath); strcpy(config_bakPATH, exePath); strcat(configPATH, "config.json"); strcat(config_bakPATH, "config_bak.json"); //post events setting //char filename[] = "config.json"; char* filename; filename = configPATH; if (!FileExist(filename)) { printf("%s doesn't exist.\n", filename); } else { //printf("read config.json.\n"); #if 1 char* fileBuf = ReadAllBytes(filename); if (fileBuf) { cJSON* root, *account_setting; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } #if 1 account_setting = cJSON_GetObjectItem(root, "account_setting"); if (root) { //printf("config.json parse OK.1\n"); cJSON* account_data_array, *content; cJSON* account_username, *account_password, *account_type, *account_status; account_data_array = cJSON_CreateArray(); #if 1 for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) { content = cJSON_CreateObject(); cJSON_AddItemToArray(account_data_array, content); char buf_account[512] = { 0 }; urldecode((unsigned char *)accountData[i].account_username, (unsigned char *)buf_account); char buf_account2[512] = { 0 }; urldecode((unsigned char *)accountData[i].account_password, (unsigned char *)buf_account2); account_username = cJSON_CreateString(buf_account); cJSON_AddItemToObject(content, "account_username", account_username); account_password = cJSON_CreateString(buf_account2); cJSON_AddItemToObject(content, "account_password", account_password); account_type = cJSON_CreateNumber(accountData[i].account_type); cJSON_AddItemToObject(content, "account_type", account_type); account_status = cJSON_CreateNumber(accountData[i].account_status); cJSON_AddItemToObject(content, "account_status", account_status); } usSleep(2000); size_t base64_encode_length = 0; unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); char* AccountJsonString = cJSON_Print(account_data_array); //printf("\n--------------AccountJsonString: %s\n", AccountJsonString); KeyExpansion(key, expandedKey); size_t encryptSize = AESEncryptArrayToArray(AccountJsonString, strlen(AccountJsonString), expandedKey, EncryptKeyData, sizeof(EncryptKeyData)); char ResultEncryptData[MAX_ACCOUNT_DATA_BUFF_SIZE] = { 0 }; base64_encode(EncryptKeyData, encryptSize, &base64_encode_length, ResultEncryptData); *(ResultEncryptData + base64_encode_length) = '\0'; usSleep(2000); cJSON_ReplaceItemInObject(account_setting, "account_data", cJSON_CreateString((const char *)ResultEncryptData)); if (AccountJsonString) { free(AccountJsonString); AccountJsonString = NULL; } //save back to config.json & bak char* JsonString = cJSON_Print(root); FILE* fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); //copy config.json to config_bak.json CopyFileTo(filename, config_bakPATH); } else { //fclose(fp); printf("Fail to open Config.json \n"); } #endif if (root) { //cJSON_Delete(root); cJSON_Delete(root); root = NULL; } #if 1 if (account_data_array != NULL) { for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) { cJSON_DeleteItemFromArray(account_data_array,i); } cJSON_free(account_data_array); account_data_array = NULL; } #endif #if 1 if (JsonString != NULL) { free(JsonString); JsonString = NULL; } #endif usSleep(2000); } else printf("config.json parse FAIL.1\n"); #endif } #endif } } void update_accountData() { int count_username = 0; #ifdef GY_OS_AMBA for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 4; i++) #else for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 5; i++) #endif { if (i == MAX_ACCOUNT_DATA_NUM) count_username = 0; FILE *fp = NULL; char path[1024] = { 0 }; char command[1024] = { 0 }; const char *find = "Data="; int find_len = 5; memset(path, 0, sizeof(path)); memset(command, 0, sizeof(command)); #ifdef GY_OS_AMBA if (i < MAX_ACCOUNT_DATA_NUM) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.account%d", i); else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); else if (i == MAX_ACCOUNT_DATA_NUM * 2) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.mirror"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.flip"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.rotate"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) sprintf(command, "timeout 3s /usr/local/bin/nvclient -k FEATURE_SYS_DUAL_SENSOR"); #else if (i < MAX_ACCOUNT_DATA_NUM) sprintf(command, "/usr/local/bin/nvclient -k user.account%d", i); else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) sprintf(command, "/usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); else if (i == MAX_ACCOUNT_DATA_NUM * 2) sprintf(command, "/usr/local/bin/nvclient -k image.mirror"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) sprintf(command, "/usr/local/bin/nvclient -k image.flip"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) sprintf(command, "/usr/local/bin/nvclient -k image.rotate"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) sprintf(command, "/usr/local/bin/nvclient -k features.irled.type"); else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) sprintf(command, "/usr/local/bin/nvclient -k features.irled2.type"); #endif #ifdef _DEBUG_AMBA printf("\n[read_ipcam_account_setting] i:%d - command:%s", i, command); #endif /* Open the command for reading.*/ fp = vpopen(command, "r"); if (fp == NULL) { fp = vpopen(command, "r"); } if (fp == NULL) { printf("\nFailed to run command: %s\n", command); printf("Error opening file unexist.ent: %s\n", strerror(errno)); char fail_buffer[2048] = { 0 }; sprintf(fail_buffer, "\nFailed to run command: %s\n", command); write_to_log_if_error_nvclient(fail_buffer); //write_to_log_if_error(fail_buffer); /* pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { printf("create auto reboot thread faile \n"); }*/ } else { /* Read the output a line at a time - output it.*/ while (fgets(path, sizeof(path), fp) != NULL) { char *p = strstr(path, find); int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n //printf("\n(%d):cpylen:%d\n",i,cpy_len); if (p != NULL && cpy_len >= 1) { char *cpy_start = p + find_len; #ifdef _DEBUG_AMBA printf("\n%s strlen(path):%d", p + find_len, strlen(path)); #endif if (cpy_len >= 1) { char temp_cpy[100] = { 0 }; strncpy(temp_cpy, cpy_start, cpy_len); temp_cpy[cpy_len] = '\0'; if (i < MAX_ACCOUNT_DATA_NUM) { if (strstr(temp_cpy, " ") == NULL) { char temp_account[512] = { 0 }; urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account,512); memcpy(accountData[count_username].account_username, temp_account, strlen(temp_account)); accountData[count_username].account_username[strlen(temp_account)] = '\0'; } count_username++; } else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) { if (strstr(temp_cpy, " ") == NULL) { char temp_account[512] = { 0 }; urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account, 512); memcpy(accountData[count_username].account_password, temp_account, strlen(temp_account)); accountData[count_username].account_password[strlen(temp_account)] = '\0'; } count_username++; } else if (i == MAX_ACCOUNT_DATA_NUM * 2) { //if (g_IsPTZDevice == 0) { if (strstr(temp_cpy, " ") == NULL) { strncpy(accountData[0].account_mirror, temp_cpy, cpy_len); accountData[0].account_mirror[cpy_len] = '\0'; } } } else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) { //if (g_IsPTZDevice == 0) { if (strstr(temp_cpy, " ") == NULL) { strncpy(accountData[0].account_flip, temp_cpy, cpy_len); accountData[0].account_flip[cpy_len] = '\0'; } } } else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) { //if (g_IsPTZDevice == 0) { if (strstr(temp_cpy, " ") == NULL) { strncpy(accountData[0].account_rotate, temp_cpy, cpy_len); accountData[0].account_rotate[cpy_len] = '\0'; } } } else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) { //if (g_IsPTZDevice == 0) if(strstr(temp_cpy,"1") != NULL) { #ifdef GY_OS_AMBA g_dual_sensor = 1; #else g_camera_white_LED = 1; #endif } } else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) { //if (g_IsPTZDevice == 0) if (strstr(temp_cpy, "1") != NULL) { g_camera_white_LED = 1; } } } break; } memset(path, 0, sizeof(path)); } if (fp != NULL) { if (vpclose(fp) < 0) printf("\nupdate accountData: vpclose fail\n"); fp = NULL; } } usSleep(1000); } } void update_accountData_port() { char read_port_cmd[1024]; memset(&read_port_cmd, 0, sizeof(read_port_cmd)); #ifdef GY_OS_AMBA char read_port_cmd_1[256] = "timeout 3s /usr/local/bin/nvclient -k http.port"; #else char read_port_cmd_1[256] = "/usr/local/bin/nvclient -k http.port"; #endif strcat(read_port_cmd, read_port_cmd_1); FILE *read_port = vpopen(read_port_cmd, "r"); if (read_port == NULL) { printf("\n[read_ipcam_account_setting]:Error to read port"); } else { const char *find = "Data="; int find_len = 5; char path[1024] = { 0 }; /* Read the output a line at a time - output it.*/ while (fgets(path, sizeof(path), read_port) != NULL) { char *p = strstr(path, find); int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n if (p != NULL && cpy_len > 0) { char *cpy_start = p + find_len; if (cpy_len >= 1) { strncpy(accountData[0].account_port, cpy_start, cpy_len); accountData[0].account_port[cpy_len] = '\0'; } //printf("\n[read_ipcam_account_setting]:Correct to read port %s\n",accountData[0].account_port); break; } memset(path, 0, sizeof(path)); } if (read_port != NULL) vpclose(read_port); } } void accountData_written_to_events_json() { char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char eventsPATH[1024] = { 0 }; strcpy(eventsPATH, exePath); strcat(eventsPATH, "events.json"); char *filename_events; filename_events = eventsPATH; if (!FileExist(filename_events)) { printf("%s doesn't exist.\n", filename_events); } else { //size_t nfileSize_events = ReadFileSize(filename_events); char *fileBuf_events = ReadAllBytes(filename_events); if (fileBuf_events) { //printf("\n[read_ipcam_account_setting]\n"); //printf("\nfileBuf_events: %s\n", fileBuf_events); cJSON *root, *notification, *http_post_events, *http_post; root = cJSON_Parse(fileBuf_events); if (fileBuf_events) { free(fileBuf_events); fileBuf_events = NULL; } if (root == NULL) { printf("root is NULL\n"); int del = remove(filename_events); if (!del) { //printf("events.json is deleted successfully."); } else { printf("events.json cannot be deleted.\n"); } #if 1 stop_test_nn_cavalry("events json not exist"); //stop_server(); #endif pthread_exit(NULL); } else { notification = cJSON_GetObjectItem(root, "notification"); { http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); int i = 0; cJSON_ArrayForEach(http_post, http_post_events) { if (i <= 3) { if (strlen(accountData[0].account_port) >= 1) cJSON_ReplaceItemInObject(http_post, "post_host_port", cJSON_CreateString(accountData[0].account_port)); if (strlen(accountData[0].account_username) >= 1) { char buf_account[512] = { 0 }; urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); cJSON_ReplaceItemInObject(http_post, "post_username", cJSON_CreateString(buf_account)); } if (strlen(accountData[0].account_password) >= 1) { char buf_account2[512] = { 0 }; urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); cJSON_ReplaceItemInObject(http_post, "post_password", cJSON_CreateString(buf_account2)); } } else break; i++; } } char *filename = eventsPATH; char* JsonString = cJSON_Print(root); FILE *fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); } else { fclose(fp); printf("Fail to open events.json \n"); } if (JsonString != NULL) { free(JsonString); JsonString = NULL; } if (root) { cJSON_Delete(root); root = NULL; } } } } } static char events_port[512] = { 0 }; static char events_username[512] = {0}; static char events_password[512] = { 0 }; void get_current_events_json_data() { char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char eventsPATH[1024] = { 0 }; char events_bakPATH[1024] = { 0 }; strcpy(eventsPATH, exePath); strcat(eventsPATH, "events.json"); strcpy(events_bakPATH, exePath); strcat(events_bakPATH, "events_bak.json"); char *filename_events; filename_events = eventsPATH; if (!FileExist(filename_events)) { printf("%s doesn't exist.\n", filename_events); } else { //size_t nfileSize_events = ReadFileSize(filename_events); char *fileBuf_events = ReadAllBytes(filename_events); if (fileBuf_events) { //printf("\n[read_ipcam_account_setting]\n"); //printf("\nfileBuf_events: %s\n", fileBuf_events); cJSON *root, *notification, *http_post_events, *http_post, *post_host_port, *post_username, *post_password; root = cJSON_Parse(fileBuf_events); if (fileBuf_events) { free(fileBuf_events); fileBuf_events = NULL; } if (root == NULL) { printf("root is NULL\n"); int del = remove(filename_events); if (!del) { //printf("events.json is deleted successfully."); } else { printf("events.json cannot be deleted.\n"); } if (FileExist(events_bakPATH)) { printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); CopyFileTo(events_bakPATH, eventsPATH); } else { #if 1 stop_test_nn_cavalry("events_bak json not exist"); //stop_server(); #endif } pthread_exit(NULL); } else { notification = cJSON_GetObjectItem(root, "notification"); { http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); int i = 0; cJSON_ArrayForEach(http_post, http_post_events) { post_host_port = cJSON_GetObjectItem(http_post, "post_host_port"); post_username = cJSON_GetObjectItem(http_post, "post_username"); post_password = cJSON_GetObjectItem(http_post, "post_password"); strcpy(events_port, post_host_port->valuestring); char temp_account[512] = { 0 }; urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); memcpy(events_username, temp_account, strlen(temp_account)); events_username[strlen(temp_account)] = '\0'; char temp_account2[512] = { 0 }; urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); memcpy(events_password, temp_account2, strlen(temp_account2)); events_password[strlen(temp_account2)] = '\0'; //strcpy(events_username, post_username->valuestring); //strcpy(events_password, post_password->valuestring); break; i++; } } if (root) { cJSON_Delete(root); root = NULL; } } } } } /*void *run_osd_time_sync_thread() { pthread_detach(pthread_self()); setPthreadName("run_osd_time"); //update_system_time(); //int count_delay = 0; int count_post = 0; while (bHttpServerThreadStart) { //if (count_delay >= 10) { //count_delay = 0; //update_system_time(); } //else { //count_delay++; g_osdSysTimeStamp++; } #if 1 if (count_post >= 14400) { count_post = 0; if (check_if_correct_post == 1) { if (check_if_run_post == 1) { } else if(check_if_run_post == 0){ char temp_msg[8192] = { 0 }; snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "There is cloud post error existing for 4 hours. Reboot the camera to restart gynet."); 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"); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { printf("create auto reboot thread faile \n"); } } } } else { if (check_if_run_post != 0) { count_post = 0; } count_post++; } #endif usSleep(1000000); } pthread_exit(NULL); }*/ #ifdef GY_OS_AMBA #define SHELLSCRIPT "sh /emmc/plugin/Aida_data/run_osd_server.sh" #define SHELLSCRIPT_TOF_DRIVER "sh /emmc/plugin/Aida_data/run_tof_driver.sh" void *run_osd_server_thread(void* ptr) { pthread_detach(pthread_self()); setPthreadName("osd_server"); if (strcmp(SystemSetting.enable_display_OSD, "Yes")==0 /*&& strcmp(SystemSetting.enable_cloud,"Yes")==0*/) { pthread_t auto_system_thread_id; if (pthread_create(&auto_system_thread_id, 0, auto_system, NULL)) { printf("\ncreate auto system thread faile \n"); } pthread_join(auto_system_thread_id, NULL); //usSleep(2000000); g_check_if_OK_to_start_osd_server = 1; pthread_mutex_lock(&mutex_run_osd); close_udp_socket(); init_udp_socket(); pthread_mutex_unlock(&mutex_run_osd); usSleep(2000000); char cmd_1[256] = "killall -15 osd_server"; FILE *read_port = vpopen(cmd_1, "r"); if (read_port != NULL) vpclose(read_port); usSleep(2000000); g_check_if_OK_to_start_osd_server = 0; #if 1 system(SHELLSCRIPT); #endif #if 0 char cmd_2[256] = "/emmc/plugin/Aida_data/osd_server server"; read_port = vpopen(cmd_2, "r"); if (read_port != NULL) vpclose(read_port); #endif usSleep(2000000); } else{ g_check_if_OK_to_start_osd_server = 1; close_udp_socket(); usSleep(2000000); char cmd_2[256] = "killall -15 osd_server"; FILE *read_port = vpopen(cmd_2, "r"); if (read_port != NULL) vpclose(read_port); usSleep(2000000); g_check_if_OK_to_start_osd_server = 0; } pthread_exit(NULL); } #endif struct timeval currtime_read_ipcam_account_setting_thread; static long last_ms_currtime_read_ipcam_account_setting_thread = 0; void *read_ipcam_account_setting_thread(void* ptr) { pthread_detach(pthread_self()); setPthreadName("read_ipcam"); //printf("\n----------read ipcam account setting thread start\n"); gettimeofday(&currtime_read_ipcam_account_setting_thread, NULL); long current_ms_currtime_read_ipcam_account_setting_thread = (currtime_read_ipcam_account_setting_thread.tv_sec * 1000) + (currtime_read_ipcam_account_setting_thread.tv_usec / 1000); if (last_ms_currtime_read_ipcam_account_setting_thread == 0 || current_ms_currtime_read_ipcam_account_setting_thread - last_ms_currtime_read_ipcam_account_setting_thread >= 5000) { if (g_control_read_ipcam == 0) { pthread_mutex_lock(&mutex_read_ipcam); g_control_read_ipcam = 1; get_current_events_json_data(); /*while (bHttpServerThreadStart)*/ { read_ipcam_account_setting(); //usSleep(READ_IPCAM_SETTING*1000); } int get_OK = 0; char temp_device_name[512] = { 0 }; get_OK = PNS_Get_Device_Name(1, temp_device_name); //int len_device = 0; if (get_OK >= 1) { url_decode(temp_device_name,strlen(temp_device_name)); strcpy(g_device_name, temp_device_name); } g_control_read_ipcam = 0; pthread_mutex_unlock(&mutex_read_ipcam); } last_ms_currtime_read_ipcam_account_setting_thread = current_ms_currtime_read_ipcam_account_setting_thread; } //printf("\n----------read ipcam account setting thread end\n"); pthread_exit(NULL); } int g_start_update_config = 0; void read_ipcam_account_setting() { update_accountData(); update_accountData_port(); if (g_start_update_config == 0) { update_config_account_setting(); g_start_update_config = 1; } if (strlen(accountData[0].account_port) >= 1 && strlen(accountData[0].account_username) >= 1 && strlen(events_port) >= 1 && strlen(events_username) >= 1) { if (strcmp(accountData[0].account_port, events_port) != 0 || strcmp(accountData[0].account_username, events_username) != 0 || strcmp(accountData[0].account_password, events_password) != 0) { if (g_start_update_config == 1) { update_config_account_setting(); } accountData_written_to_events_json(); for (int i = 0; i < 4; i++) { strcpy(postEventList[i].post_host_port, accountData[0].account_port); strcpy(postEventList[i].post_username, accountData[0].account_username); strcpy(postEventList[i].post_password, accountData[0].account_password); } get_current_events_json_data(); } } #if 0 printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); printf("\naccountData[0].account_mirror: %s\n", accountData[0].account_mirror); printf("\naccountData[0].account_flip: %s\n", accountData[0].account_flip); printf("\naccountData[0].account_rotate: %s\n", accountData[0].account_rotate); printf("\naccountData[0].account_port: %s\n", accountData[0].account_port); printf("\naccountData[0].account_username: %s\n", accountData[0].account_username); printf("\naccountData[0].account_password: %s\n", accountData[0].account_password); printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); #endif } int external_memory_fragmentation_management() { FILE * pPipe = NULL; char cmd[256] = { 0 }; int size_psBuffer = 256; char psBuffer[256] = { 0 }; int chunk_number = -1; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s echo 1 > /proc/sys/vm/compact_memory"); #else sprintf(cmd, "echo 1 > /proc/sys/vm/compact_memory"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) { } else { printf("\nFail: external memory fragmentation management #1\n"); } if (pPipe != NULL) vpclose(pPipe); memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); #else sprintf(cmd, "cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) { //printf("Run: external memory fragmetation\n"); char* temp; memset(psBuffer, 0x00, sizeof(psBuffer)); temp = fgets(psBuffer, size_psBuffer, pPipe); if (temp != NULL) { chunk_number = atoi(psBuffer); printf("\n[buddyinfo] chunk_number:%d\n", chunk_number); } } else { printf("\nFail: external memory fragmentation management #2\n"); } if (pPipe != NULL) vpclose(pPipe); return chunk_number; } // 2020.11.23 Sophia added. // 2021.05.12 Cayman modified returned values. extern char* strptime_c(const char* buf, const char* fmt, struct tm* tm); int reload_dataset_from_jsonfile(void) { time_t start_time = 0; time_t now_time = 0; now_time = (time_t)time(0); struct tm *localnowTime = localtime(&now_time); int diffSecs = 0; if (cgi_whenTime_buff != NULL && cgi_startTime_buff != NULL) { memcpy(cgi_whenTime_buff, localnowTime, sizeof(struct tm)); diffSecs = cgi_whenTime_buff->tm_sec - cgi_startTime_buff->tm_sec; } if (abs(diffSecs) < 2) return 1; start_time = time(0); cgi_reload_start_Time = localtime(&start_time); if (cgi_startTime_buff != NULL) { memcpy(cgi_startTime_buff, cgi_reload_start_Time, sizeof(struct tm)); } char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char configPATH[1024] = { 0 }; char eventsPATH[1024] = { 0 }; strcpy(configPATH, exePath); strcpy(eventsPATH, exePath); strcat(configPATH, "config.json"); strcat(eventsPATH, "events.json"); char *filename_event; filename_event = eventsPATH; if (!FileExist(filename_event)) { printf("%s doesn't exist.\n", filename_event); return 1; } size_t nfileSize_event = ReadFileSize(filename_event); printf("nfileSize_event:%ld\n", (long int)nfileSize_event); char *fileBuf_event = ReadAllBytes(filename_event); if (fileBuf_event == NULL) { printf("fileBuf_event is NULL\n"); return 1; } cJSON /* *n_root,*/ *notification, *events_default_version,*enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, *post_customized_header; cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr,*enable_check_ptz_start_autotracking, *enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; //n_root = cJSON_Parse(fileBuf_event); cJSON *root; root = cJSON_Parse(fileBuf_event); if (fileBuf_event) { free(fileBuf_event); fileBuf_event = NULL; } if (root == NULL) { printf("root is NULL\n"); return 1; } notification = cJSON_GetObjectItem(root, "notification"); events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); enable_post = cJSON_GetObjectItem(notification, "enable_post"); enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; if (events_default_version) { strcpy(heartbeatData.events_default_version, events_default_version->valuestring); } else { strcpy(heartbeatData.events_default_version, "1"); } if (enable_post) activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; else activeSNMPPost = _FALSE; if (enable_heartbeat) { strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); } else { strcpy(heartbeatData.enable_heartbeat, "No"); } if (enable_snmp_heartbeat) { strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); } else { strcpy(heartbeatData.enable_snmp_heartbeat, "No"); } if (snmp_heartbeat_dwell) { strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); } else { strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); } if (snmp_heartbeat_link_to_post_event_name) { strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); } else { strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); } if (enable_check_ptz_start_autotracking) { strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); } else { strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); } if (enable_check_ptz_end_autotracking) { strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); } else { strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); } if (enable_only_once_to_post) { strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); } else { strcpy(heartbeatData.enable_only_once_to_post, "Yes"); } if (enable_obj_once_to_post) { strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); } else { strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); } if (enable_location_once_to_post) { strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); } else { strcpy(heartbeatData.enable_location_once_to_post, "Yes"); } if (enable_nvr_once_to_getalarmmotion) { strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); } else { strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); } if (enable_8592_once_to_getalarmmotion) { strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); } else { strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); } if (dwell_to_the_same_location) { strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); } else { strcpy(heartbeatData.dwell_to_the_same_location, "5"); } if (heartbeat_dwell) { strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); } else { strcpy(heartbeatData.heartbeat_dwell, "10"); } if (heatmap_max) { strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); } else { strcpy(heartbeatData.heatmap_max, "100"); } if (enable_heatmap) { strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); } else { strcpy(heartbeatData.enable_heatmap, "No"); } if (heatmap_frequency) { strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); } else { strcpy(heartbeatData.heatmap_frequency, "5"); } if (lpr_title) { strcpy(heartbeatData.lpr_title, lpr_title->valuestring); } else { strcpy(heartbeatData.lpr_title, "My Car Park"); } if (heartbeat_link_to_post_event_name) { strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); } else { strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); } if (ptz_start_autotracking_link_to_post_event_name) { strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); } else { strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); } if (ptz_end_autotracking_link_to_post_event_name) { strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); } else { strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); } if (enable_counter_snap) { strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); } else { strcpy(heartbeatData.enable_counter_snap, "No"); } if (enable_barcode_qr) { strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); } else { strcpy(heartbeatData.enable_barcode_qr, "No"); } int i = 0; cJSON_ArrayForEach(detect2, http_post_events) { post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); post_url = cJSON_GetObjectItem(detect2, "post_url"); post_username = cJSON_GetObjectItem(detect2, "post_username"); post_password = cJSON_GetObjectItem(detect2, "post_password"); post_content = cJSON_GetObjectItem(detect2, "post_content"); post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); char temp_account[512] = { 0 }; urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); postEventList[i].post_username[strlen(temp_account)] = '\0'; char temp_account2[512] = { 0 }; urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); postEventList[i].post_password[strlen(temp_account2)] = '\0'; strcpy(postEventList[i].post_protocol, post_protocol->valuestring); strcpy(postEventList[i].post_event_method, post_event_method->valuestring); strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); strcpy(postEventList[i].post_host_port, post_host_port->valuestring); strcpy(postEventList[i].post_url, post_url->valuestring); //strcpy(postEventList[i].post_username, post_username->valuestring); //strcpy(postEventList[i].post_password, post_password->valuestring); strcpy(postEventList[i].post_content, post_content->valuestring); strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); if (post_sequence) strcpy(postEventList[i].post_sequence, post_sequence->valuestring); else { strcpy(postEventList[i].post_sequence, ""); } if (post_timeout) strcpy(postEventList[i].post_timeout, post_timeout->valuestring); else { strcpy(postEventList[i].post_timeout, "5"); } if(post_file_format) strcpy(postEventList[i].post_file_format, post_file_format->valuestring); else { strcpy(postEventList[i].post_file_format, "text"); } if(post_jpeg_file_name_format) strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); else { strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); } if(post_jpeg_file_name) strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); else { strcpy(postEventList[i].post_jpeg_file_name, "snap"); } i++; } #ifdef GY_OS_V_SERIES cJSON *counter_name; #else cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; cJSON *link_to_post_event_name, *post_interval; event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); i = 0; cJSON_ArrayForEach(detect3, event_counters) { counter_name = cJSON_GetObjectItem(detect3, "counter_name"); counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); reset_value = cJSON_GetObjectItem(detect3, "reset_value"); enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); reset_at = cJSON_GetObjectItem(detect3, "reset_at"); enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); post_interval = cJSON_GetObjectItem(detect3, "post_interval"); strcpy(eventCounterList[i].counter_name, counter_name->valuestring); strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); if (reset_value) eventCounterList[i].reset_value = atoi(reset_value->valuestring); else eventCounterList[i].reset_value = 0; strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); strcpy(eventCounterList[i].reset_at, reset_at->valuestring); strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); struct tm tm; strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); #if 0 eventCounterList[i].timetResetAt = mktime(&tm); struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); eventCounterList[i].reset_month = resetTime->tm_mon; eventCounterList[i].reset_month_day = resetTime->tm_mday; eventCounterList[i].reset_week_day = resetTime->tm_wday; eventCounterList[i].reset_hour = resetTime->tm_hour; eventCounterList[i].reset_min = resetTime->tm_min; eventCounterList[i].reset_sec = resetTime->tm_sec; #endif strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); eventCounterList[i].timetTimeRangeFrom = mktime(&tm); strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); eventCounterList[i].timetTimeRangeTo = mktime(&tm); if (link_to_post_event_name) { strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); } else { strcpy(eventCounterList[i].link_to_post_event_name, ""); } if (post_interval) { strcpy(eventCounterList[i].post_interval, post_interval->valuestring); } else { strcpy(eventCounterList[i].post_interval, "5 minutes"); } if (enable_reset_only_cloud) { strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); } else { strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); } if (enable_linked_to_dwell_time) { strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); } else { strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); } i++; } cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); if (report_counters) { i = 0; cJSON_ArrayForEach(a_report, report_counters) { if (a_report) { counter_a = cJSON_GetObjectItem(a_report, "counter_a"); counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); counter_b = cJSON_GetObjectItem(a_report, "counter_b"); counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); enable_report = cJSON_GetObjectItem(a_report, "enable_report"); counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); detection_output = cJSON_GetObjectItem(a_report, "detection_output"); output_icon = cJSON_GetObjectItem(a_report, "output_icon"); if (counter_a) { strcpy(reportCounterList[i].counter_a, counter_a->valuestring); } else { strcpy(reportCounterList[i].counter_a, "Counter01"); } if (counter_a_name) { strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); } else { strcpy(reportCounterList[i].counter_a_name, "Name"); } if (counter_a_zone) { strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); } else { strcpy(reportCounterList[i].counter_a_zone, "1"); } if (counter_b) { strcpy(reportCounterList[i].counter_b, counter_b->valuestring); } else { strcpy(reportCounterList[i].counter_b, ""); } if (counter_b_name) { strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); } else { strcpy(reportCounterList[i].counter_b_name, ""); } if (counter_b_zone) { strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); } else { strcpy(reportCounterList[i].counter_b_zone, "0"); } if (counter_c_name) { strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); } else { strcpy(reportCounterList[i].counter_c_name, ""); } if (report_max_value) { strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); } else { strcpy(reportCounterList[i].report_max_value, "100"); } if (enable_report) { strcpy(reportCounterList[i].enable_report, enable_report->valuestring); } else { strcpy(reportCounterList[i].enable_report, "No"); } if (counter_mode) { strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); } else { strcpy(reportCounterList[i].counter_mode, "0"); } if (initial_icon) { strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); } else { strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); } if (detection_output) { strcpy(reportCounterList[i].detection_output, detection_output->valuestring); } else { strcpy(reportCounterList[i].detection_output, "No entry for cars"); } if (output_icon) { strcpy(reportCounterList[i].output_icon, output_icon->valuestring); } else { strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); } i++; } } if (i < MAX_REPORT_COUNTERS) { for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { strcpy(reportCounterList[index_report].counter_a, "Counter01"); strcpy(reportCounterList[index_report].counter_a_name, "Name"); strcpy(reportCounterList[index_report].counter_a_zone, "1"); strcpy(reportCounterList[index_report].counter_b, ""); strcpy(reportCounterList[index_report].counter_b_name, ""); strcpy(reportCounterList[index_report].counter_b_zone, "0"); strcpy(reportCounterList[index_report].counter_c_name, ""); strcpy(reportCounterList[index_report].report_max_value, "100"); strcpy(reportCounterList[index_report].enable_report, "No"); strcpy(reportCounterList[index_report].counter_mode, "0"); strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); } } } else { for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { strcpy(reportCounterList[index_report].counter_a, "Counter01"); strcpy(reportCounterList[index_report].counter_a_name, "Name"); strcpy(reportCounterList[index_report].counter_a_zone, "1"); strcpy(reportCounterList[index_report].counter_b, ""); strcpy(reportCounterList[index_report].counter_b_name, ""); strcpy(reportCounterList[index_report].counter_b_zone, "0"); strcpy(reportCounterList[index_report].counter_c_name, ""); strcpy(reportCounterList[index_report].report_max_value, "100"); strcpy(reportCounterList[index_report].enable_report, "No"); strcpy(reportCounterList[index_report].counter_mode, "0"); strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); } } cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, *snmp_oid, *snmp_value, *snmp_type; snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); if (snmp_management) { i = 0; cJSON_ArrayForEach(a_snmp, snmp_management) { if (a_snmp) { snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); if (snmp_event_name) { strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); } else { char temp_name[20] = { 0 }; sprintf(temp_name,"SNMP %d",i+1); strcpy(SNMPManagementList[i].snmp_event_name, temp_name); } if (snmp_version) { strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); } else { strcpy(SNMPManagementList[i].snmp_version, "v1"); } if (snmp_group_name) { strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); } else { strcpy(SNMPManagementList[i].snmp_group_name, "public"); } if (snmp_host_ip) { strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); } else { strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); } if (snmp_host_port) { strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); } else { strcpy(SNMPManagementList[i].snmp_host_port, "161"); } if (snmp_oid) { strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); } else { strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); } if (snmp_value) { strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); } else { strcpy(SNMPManagementList[i].snmp_value, "mylocation"); } if (snmp_type) { strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); } else { strcpy(SNMPManagementList[i].snmp_type, "string"); } i++; } } if (i < MAX_SNMP_MANAGEMENT) { for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { char temp_name[10] = { 0 }; if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { sprintf(temp_name, "SNMP %d", index_snmp + 1); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } else { sprintf(temp_name, "%s", "Heartbeat"); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } } } } else { for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { char temp_name[10] = { 0 }; if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { sprintf(temp_name, "SNMP %d", index_snmp + 1); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } else { sprintf(temp_name, "%s", "Heartbeat"); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } } } #endif #if 0 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) { pthread_mutex_lock(&mutex_reset_counter); time_t now_time = g_osdSysTimeStamp; if (now_time < 1000000000) { now_time = time(0); } for (int j = 0; j < MAX_EVENT_COUNTERS; j++) { reset_counter(j, now_time); } pthread_mutex_unlock(&mutex_reset_counter); } #endif cJSON *email_setting,*email_content; email_setting = cJSON_GetObjectItem(root, "email_setting"); if (email_setting) { email_content = cJSON_GetObjectItem(email_setting, "email_content"); if (email_content) strcpy(emailData.email_content, email_content->valuestring); else strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); } else { strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); } //trigger events settings char *filename_config; filename_config = configPATH; if (!FileExist(filename_config)) { printf("%s doesn't exist.\n", filename_config); return 1; } size_t nfileSize_config = ReadFileSize(filename_config); printf("nfileSize_config:%ld\n", (long int)nfileSize_config); char *fileBuf_config = ReadAllBytes(filename_config); if (fileBuf_config == NULL) { printf("fileBuf_config is NULL\n"); return 1; } //cJSON* cam_ip, * http_port, * video_port, * cam_username, * cam_pwd, * channel_id; cJSON* view_setting, * camera, * camera_name, * enable_anpr, *enable_face, * enable_traffic, * enable_logo, * tab_view_size, * enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking, *ptz_tracking_mode, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, *cJSON_enable_only_show_metadata1,*count_zone, *ivs_mode, * detection_zone, * detect, *levenshtein_distance, *obj_min_proportion, *obj_max_proportion,*min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute,*queuing_count, *ptz_zone_to_preset,*trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, *point_number, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6, *enable_speed,*set_distance,*world_distance_unit,*world_distance_side1,*world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion,*confidence_unknown_object, *confidence2_unknown_object,*dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, *plate_filter_times,*plate_filter_time,*plate_free_time,*obj_max_proportion_in_zone,*obj_min_proportion_in_zone,*red_light_zone,*no_give_way_zone_to_protect,*no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2, *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed; //cJSON* root = cJSON_Parse(fileBuf_config); //printf("\n-----------------reload: %s\n", fileBuf_config); if (g_config_root == NULL) { g_config_root = cJSON_Parse(fileBuf_config); if (fileBuf_config) { free(fileBuf_config); fileBuf_config = NULL; } if (g_config_root == NULL) { printf("root is NULL\n"); return 1; } } view_setting = cJSON_GetObjectItem(g_config_root, "view_setting"); for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) { char CameraID[20] = { 0 }; sprintf(CameraID, "camera%02d", n + 1); camera = cJSON_GetObjectItem(view_setting, CameraID); /*cam_ip = cJSON_GetObjectItem(camera, "ip"); http_port = cJSON_GetObjectItem(camera, "http_port"); video_port = cJSON_GetObjectItem(camera, "video_port"); cam_username = cJSON_GetObjectItem(camera, "username"); cam_pwd = cJSON_GetObjectItem(camera, "password"); channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ camera_name = cJSON_GetObjectItem(camera, "camera_name"); levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); min_characters = cJSON_GetObjectItem(camera, "min_characters"); max_characters = cJSON_GetObjectItem(camera, "max_characters"); plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 confidence3 = cJSON_GetObjectItem(camera, "confidence3"); //None 沒有用到 confidence4 = cJSON_GetObjectItem(camera, "confidence4"); //None 沒有用到 count_zone = cJSON_GetObjectItem(camera, "count_zone"); strcpy(viewChannelData[n].camera_name, camera_name->valuestring); strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); strcpy(viewChannelData[n].min_characters, min_characters->valuestring); strcpy(viewChannelData[n].max_characters, max_characters->valuestring); if (plate_filter_times) viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); else viewChannelData[n].i_plate_filter_times = 4; if (plate_filter_time) viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); else viewChannelData[n].i_plate_filter_time = 3; if (plate_free_time) viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); else viewChannelData[n].i_plate_free_time = 3; strcpy(viewChannelData[n].confidence, confidence->valuestring); strcpy(viewChannelData[n].confidence2, confidence2->valuestring); strcpy(viewChannelData[n].confidence3, confidence3->valuestring); strcpy(viewChannelData[n].confidence4, confidence4->valuestring); //printf("\nenable_lpr_db-----6\n"); pthread_mutex_lock(&mutex_enable_lpr_db); enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); pthread_mutex_unlock(&mutex_enable_lpr_db); enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); set_enable_zone_crop_1(enable_zone_crop_1->valueint); viewChannelData[n].count_zone = count_zone->valueint; tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); //printf("\n[reload_dataset_from_jsonfile]tab_view_size: %s\n", tab_view_size->valuestring); char temp_array[256] = { 0 }; strcpy(temp_array, tab_view_size->valuestring); char outArray[2][STRSPLIT_SIZE] = {0}; StrSplit(temp_array, outArray, "x"); //printf("\n------UU:15\n"); viewChannelData[n].channel_idx = n; if (outArray[0]) viewChannelData[n].tab_view_width = atoi(outArray[0]); if (outArray[1]) viewChannelData[n].tab_view_height = atoi(outArray[1]); //printf("\n[reload_dataset_from_jsonfile]end:tab_view_size: %s\n", tab_view_size->valuestring); enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); if (strcmp(enable_anpr->valuestring, "Yes") == 0) viewChannelData[n].enable_anpr = 1; else viewChannelData[n].enable_anpr = 0; enable_face = cJSON_GetObjectItem(camera, "enable_face"); if (strcmp(enable_face->valuestring, "Yes") == 0) viewChannelData[n].enable_face = 1; else viewChannelData[n].enable_face = 0; enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); if (strcmp(enable_traffic->valuestring, "Yes") == 0) viewChannelData[n].enable_traffic = 1; else viewChannelData[n].enable_traffic = 0; enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); if (strcmp(enable_logo->valuestring, "Yes") == 0) viewChannelData[n].enable_logo = 1; else viewChannelData[n].enable_logo = 0; enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); if (enable_add_face_frequent_list) if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) viewChannelData[n].enable_add_face_frequent_list = 1; else viewChannelData[n].enable_add_face_frequent_list = 0; else { viewChannelData[n].enable_add_face_frequent_list = 0; } enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); strcpy(viewChannelData[n].enable_PTZ ,enable_PTZ->valuestring); ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); //Tracking MODE //1: First in First out //2: Bigger first //3: All ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); if (ptz_tracking_mode) viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); else { viewChannelData[n].ptz_tracking_mode = 1; } ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); if (ptz_tracking_by_enter_zone) { if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) viewChannelData[n].ptz_tracking_by_enter_zone = 1; else viewChannelData[n].ptz_tracking_by_enter_zone = 0; } else { viewChannelData[n].ptz_tracking_by_enter_zone = 1; } enable_track = cJSON_GetObjectItem(camera, "enable_track"); if (enable_track) strcpy(viewChannelData[n].enable_track, enable_track->valuestring); else { strcpy(viewChannelData[n].enable_track, "No"); } enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); if (enable_tracking_limits) strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); else { strcpy(viewChannelData[n].enable_tracking_limits, "No"); } ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); if (ptz_pan_left_limit) strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); else { strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); } ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); if (ptz_pan_right_limit) strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); else { strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); } ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); if (ptz_tilt_up_limit) strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); else { strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); } ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); if (ptz_tilt_down_limit) strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); else { strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); } ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); if (ptz_speed) strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); else { strcpy(viewChannelData[n].ptz_speed, "3"); } enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); if (enable_unknown_object) strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); else { strcpy(viewChannelData[n].enable_unknown_object, "No"); } enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); if (enable_ivs_person_detection) strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); else { strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); } assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); if (assign_ivs_object_to) strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); else { strcpy(viewChannelData[n].assign_ivs_object_to, ""); } enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); if (enable_ambulance) strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); else { strcpy(viewChannelData[n].enable_ambulance, "No"); } enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); if (enable_blank_plate) strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); else { strcpy(viewChannelData[n].enable_blank_plate, "No"); } enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); if (enable_stop_sign) strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); else { strcpy(viewChannelData[n].enable_stop_sign, "No"); } enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); if (enable_show_unknown_object) strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); else { strcpy(viewChannelData[n].enable_show_unknown_object, "No"); } enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); if (enable_ivs_fix_mode) strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); else { strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); } enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); if (enable_ivs_and_ai) strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); else { strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); } enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); if (enable_lpr_upon_triggered) strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); else { strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); } dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); if (dwell_lpr_upon_triggered) strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); else { strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); } unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); if(unknown_object_max_proportion) strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); else strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); if (unknown_object_min_proportion) strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); else strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); if (confidence_unknown_object) strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); else strcpy(viewChannelData[n].confidence_unknown_object, "0"); confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); if (confidence2_unknown_object) strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); else strcpy(viewChannelData[n].confidence2_unknown_object, "0"); dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); if(dwell_unknown_object) strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); else strcpy(viewChannelData[n].dwell_unknown_object, "30"); dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); if (dwell_minute_focus_on) strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); else strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); if (person_obj_fov) strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); else strcpy(viewChannelData[n].person_obj_fov, "100"); ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); if (ivs_mode) strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); else strcpy(viewChannelData[n].ivs_mode, "3"); getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); if (getnetwork_buffer_id) { if (strlen(viewChannelData[n].getnetwork_buffer_id)>=1 && strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) { #ifdef GY_OS_AMBA printf("\n-----------------------get network buffer id: exit-----------------------\n"); char temp_msg[8192] = { 0 }; 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"); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { printf("\ncreate auto reboot thread faile \n"); } #else #endif } } else strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); if (red_light_zone) strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); else strcpy(viewChannelData[n].red_light_zone, ""); no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); if (no_give_way_zone_to_protect) strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); else strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); if (no_give_way_zone_to_keep_away) strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); else strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); if (no_give_way_zone_to_protect_2) strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); else strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); if (no_give_way_zone_to_keep_away_2) strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); else strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); if (ptz_sensitivity) viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); else { viewChannelData[n].ptz_sensitivity = 6; } //printf("\n-------------ptz_sensitivity:%d\n", viewChannelData[n].ptz_sensitivity); ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); viewChannelData[n].enable_traffic_light_zone = 0; int i = 0; cJSON_ArrayForEach(detect, detection_zone) { obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); detection_time = cJSON_GetObjectItem(detect, "detection_time"); metadata1 = cJSON_GetObjectItem(detect, "metadata1"); metadata2 = cJSON_GetObjectItem(detect, "metadata2"); metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); direction1 = cJSON_GetObjectItem(detect, "direction1"); direction2 = cJSON_GetObjectItem(detect, "direction2"); no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); point_number = cJSON_GetObjectItem(detect, "point_number"); parking_space = cJSON_GetObjectItem(detect, "parking_space"); parking_line = cJSON_GetObjectItem(detect, "parking_line"); //Social Distance set_distance = cJSON_GetObjectItem(detect, "set_distance"); world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); //Social Distance /* if(point_number) printf("load point number = %d \n", point_number->valueint); */ x1 = cJSON_GetObjectItem(detect, "x1"); y1 = cJSON_GetObjectItem(detect, "y1"); x2 = cJSON_GetObjectItem(detect, "x2"); y2 = cJSON_GetObjectItem(detect, "y2"); x3 = cJSON_GetObjectItem(detect, "x3"); y3 = cJSON_GetObjectItem(detect, "y3"); x4 = cJSON_GetObjectItem(detect, "x4"); y4 = cJSON_GetObjectItem(detect, "y4"); x5 = cJSON_GetObjectItem(detect, "x5"); y5 = cJSON_GetObjectItem(detect, "y5"); x6 = cJSON_GetObjectItem(detect, "x6"); y6 = cJSON_GetObjectItem(detect, "y6"); strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); if(metadata_stop) strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); if (no_parking_time) viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); if (no_parking_time_in_minute) viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); if (queuing_count) viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); if (parking_space) { viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); } if (parking_line) { viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); } //Social Distance if (set_distance) { viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); } if (world_distance_unit) { strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); } if (world_distance_side1) { viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); } //Fake data //viewDetectionZone[n][i].world_distance[0] = 1000; //viewDetectionZone[n][i].world_distance[2] = 1000; if (world_distance_side2) { viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); } //Social Distance if(obj_max_proportion_in_zone) strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); if(obj_min_proportion_in_zone) strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); if (point_number) { viewDetectionZone[n][i].point_num = point_number->valueint; } if (enable_speed) strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); if (enable_radar_speed) strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); if (enable_ivs_zone) strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); if (world_time_unit) strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); viewDetectionZone[n][i].Points[0].x = x1->valueint; viewDetectionZone[n][i].Points[0].y = y1->valueint; viewDetectionZone[n][i].Points[1].x = x2->valueint; viewDetectionZone[n][i].Points[1].y = y2->valueint; viewDetectionZone[n][i].Points[2].x = x3->valueint; viewDetectionZone[n][i].Points[2].y = y3->valueint; viewDetectionZone[n][i].Points[3].x = x4->valueint; viewDetectionZone[n][i].Points[3].y = y4->valueint; viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); if (x5 && x6) { viewDetectionZone[n][i].Points[4].x = x5->valueint; viewDetectionZone[n][i].Points[4].y = y5->valueint; viewDetectionZone[n][i].Points[5].x = x6->valueint; viewDetectionZone[n][i].Points[5].y = y6->valueint; viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); } viewChannelData[n].tab_view_width_ratio = (float)1; viewChannelData[n].tab_view_height_ratio = (float)1; viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); //viewChannelData[n].tab_view_height = 1; strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) { viewChannelData[n].enable_traffic_light_zone = i + 1; //UpdateTrafficLightZone(n); } #ifdef GY_OS_AMBA if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) { int social_zone_idx = i; if (social_zone_idx >= 0) { pthread_mutex_lock(&mutex_perspective_transform); if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); pthread_mutex_unlock(&mutex_perspective_transform); } } #endif i++; if (i < MAX_DETECTION_ZONE) { } else { break; } } //int arraySize = cJSON_GetArraySize(detection_zone); int k = 0; for (int j = 0; j < MAX_DETECTION_ZONE; j++) { k = 0; cJSON_ArrayForEach(detect, trigger_events[j]) { checked = cJSON_GetObjectItem(detect, "checked"); detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); counter_name = cJSON_GetObjectItem(detect, "counter_name"); counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); if (counter_increment) { if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; else viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; } else viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } } } cJSON *system_setting,*enable_cloud,*enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*nms_thres, *tracking_id_dwell,*enable_person_independent,*enable_onvif_profile_m, *enable_crop_mode,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language,*display_properties,*display_OSD, *enable_bounding_box,*enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror,*ai_mirror_feature,*enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content,*enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, *enable_email_notification,*email_reset_time_interval,*enable_system_logs,*enable_email_jpeg, *send_counter_at_specific_hour,*display_dash,*sensors_type,*enable_ftp,*ftp_url,*ftp_port,*ftp_username,*ftp_password,*ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; system_setting = cJSON_GetObjectItem(g_config_root, "system_setting"); enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); enable_crop_mode = cJSON_GetObjectItem(system_setting, "enable_crop_mode"); strcpy(SystemSetting.enable_crop_mode, enable_crop_mode->valuestring); nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); strcpy(SystemSetting.nms_thres, nms_thres->valuestring); tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); strcpy(SystemSetting.enable_python, enable_python->valuestring); enable_python_file = cJSON_GetObjectItem(system_setting, "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); cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); strcpy(SystemSetting.cloud_account, cloud_account->valuestring); cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); strcpy(SystemSetting.cloud_password, cloud_password->valuestring); cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); language = cJSON_GetObjectItem(system_setting, "language"); strcpy(SystemSetting.language, language->valuestring); display_dash = cJSON_GetObjectItem(system_setting, "display dash"); activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; display_properties = cJSON_GetObjectItem(system_setting, "display properties"); strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); strcpy(SystemSetting.sensors_type, sensors_type->valuestring); enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); send_counter_at_specific_hour = cJSON_GetObjectItem(system_setting, "send_counter_at_specific_hour"); strcpy(SystemSetting.send_counter_at_specific_hour, send_counter_at_specific_hour->valuestring); email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); strcpy(SystemSetting.ftp_url, ftp_url->valuestring); ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); strcpy(SystemSetting.ftp_port, ftp_port->valuestring); ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); strcpy(SystemSetting.ftp_username, ftp_username->valuestring); ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); strcpy(SystemSetting.ftp_password, ftp_password->valuestring); ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); cJSON *about_box,*cJSON_strUnlockingKey; about_box = cJSON_GetObjectItem(g_config_root, "about_box"); if (about_box) { cJSON_strUnlockingKey = cJSON_GetObjectItem(about_box, "unlocking key"); if (cJSON_strUnlockingKey && strlen(cJSON_strUnlockingKey->valuestring)>=1 && strcmp(strUnlockingKey, cJSON_strUnlockingKey->valuestring)!=0) { memset(strUnlockingKey,0x00,sizeof(strUnlockingKey)); strcpy(strUnlockingKey, cJSON_strUnlockingKey->valuestring); char buf_exe[1024] = {}; readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); char exePath_temp[1024] = {}; getFilePath(buf_exe, exePath_temp, 1024); char keyPATH[1024] = { 0 }; strcpy(keyPATH, exePath_temp); strcat(keyPATH, "key.txt"); if (FileExist(keyPATH) == 1) { FILE *pFile; if ((pFile = fopen(keyPATH, "w")) != NULL) { fprintf(pFile, strUnlockingKey); fclose(pFile); } else printf("Fail to open key.txt \n"); } memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); strcpy(strLicenseStatus, "Please restart gynet to run AI with new key."); } } if (root) { cJSON_Delete(root); root = NULL; } if (g_config_root) { cJSON_Delete(g_config_root); g_config_root = NULL; } #ifdef GY_OS_AMBA /*int zone_to_preset[MAX_DETECTION_ZONE]; for (int i = 0; i < MAX_DETECTION_ZONE; i++) { zone_to_preset[i] = 0; if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) { zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); } }*/ //Update PTZ /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ if (g_IsPTZDevice == 1) { UpdatePTZConfigSetting(); SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); } #endif //Reload cold zone /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); #ifdef GY_OS_AMBA if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { if (enable_ai_mirror && ai_mirror_feature) { if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); #else sprintf(cmd, "/usr/local/bin/test_vin -m 2"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } else { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); #else sprintf(cmd, "/usr/local/bin/test_vin -m 0"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } } } } #endif return 0; } // 2021.01.21 Jim added. // 2021.05.12 Cayman fixed returned values. #if 0 int default_dataset_for_jsonfile(void) { char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char configPATH[1024] = { 0 }; char config_bakPATH[1024] = { 0 }; char eventsPATH[1024] = { 0 }; strcpy(configPATH, exePath); strcpy(config_bakPATH, exePath); strcpy(eventsPATH, exePath); strcat(configPATH, "config.json"); strcat(config_bakPATH, "config_bak.json"); strcat(eventsPATH, "events.json"); char *filename; //filename = config_bakPATH; filename = configPATH; if (!FileExist(filename)) { printf("%s doesn't exist.\n", filename); return 1; } //printf("read config.json. %s\n", filename); //size_t nfileSize = ReadFileSize(filename); char* fileBuf = ReadAllBytes(filename); if (fileBuf == NULL) { printf("fileBuf FAIL.\n"); return 1; } cJSON *root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config.json parse OK.\n"); } else { printf("config.json parse FAIL.\n"); return 1; } cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); char* JsonString = cJSON_Print(root); FILE *fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); CopyFileTo(filename, config_bakPATH); } else { printf("Fail to open Config.json \n"); return 1; } //copy config.json to config_bak.json if (JsonString != NULL) { free(JsonString); JsonString = NULL; } if (root) { cJSON_Delete(root); root = NULL; } return 0; } #endif //GY_OS_AMBA #ifdef GY_OS_AMBA static long delete_now_heatmap = 0; struct timeval delete_currtime_heatmap; void delete_heatmap_image() { gettimeofday(&delete_currtime_heatmap, NULL); delete_now_heatmap = (delete_currtime_heatmap.tv_sec * 1000) + (delete_currtime_heatmap.tv_usec / 1000); //單位為毫秒 delete_now_heatmap = delete_now_heatmap / 1000 * 1000; pthread_mutex_lock(&mutex_heatmap_jpeg); DIR *d_file; struct dirent *dir_file; d_file = opendir("/emmc/plugin/Aida_data/playback"); if (d_file) { while ((dir_file = readdir(d_file)) != NULL) { if (strlen(dir_file->d_name) >= 17) { char temp_d_name[50] = { 0 }; for (int i = 0; i < strlen(dir_file->d_name)-4; i++) { temp_d_name[i] = dir_file->d_name[i]; } if (atol(temp_d_name) <= delete_now_heatmap - 15 * 24 * 60 * 60 * 1000 / 2) {//15/2=7.5 FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); #else sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } //usSleep(10000); //printf("\n-------temp_d_name:%ld\n", atol(temp_d_name)); } } closedir(d_file); } pthread_mutex_unlock(&mutex_heatmap_jpeg); //printf("\n-------delete_now_heatmap:%ld\n", delete_now_heatmap); } #endif #if defined GY_OS_AMBA || defined GY_OS_NOVA void * delete_jpg_in_seven_days_detector(void *ptr) { pthread_detach(pthread_self()); setPthreadName("delete_seven"); int check_delete = 0; int delete_time = 1; int delete_time2 = 7; int delete_time3 = 13; int delete_time4 = 19; delete_jpg_in_seven_days(); #ifdef GY_OS_AMBA delete_heatmap_image(); #endif while (bHttpServerThreadStart) { //printf("\n------delete jpg in seven days detector start\n"); if (iFeature_lpr_layer_index >= 0) { time_t rawtime = time(0); struct tm * timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); if ((timeinfo->tm_hour == delete_time || timeinfo->tm_hour == delete_time2 || timeinfo->tm_hour == delete_time3 || timeinfo->tm_hour == delete_time4) && check_delete == 0) { if (unlockingKeyInnoFR == 1) { #ifdef GY_OS_AMBA //delete_jpg_in_seven_days_face(); #endif } else { delete_jpg_in_seven_days(); } #ifdef GY_OS_AMBA delete_heatmap_image(); #endif check_delete = 1; } else if (timeinfo->tm_hour != delete_time && timeinfo->tm_hour != delete_time2 && timeinfo->tm_hour != delete_time3 && timeinfo->tm_hour != delete_time4) { check_delete = 0; } //printf("\n------delete jpg in seven days detector end\n"); //usSleep(60000000); usSleep(1000000); } else { usSleep(10000000); } } //printf("\n---------delete jpg in seven days detector:exit\n"); pthread_exit(NULL); } #endif //CURLM* g_multi_handle; //int g_handle_count; //modified the input from file to memory based on test_detector() #ifdef TEST_DETECTOR_MEM void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, float thresh, float hier_thresh, int ext_output, int save_labels, char* model, char* target_device, int input_resizable, char* custom_cpu_library, char* custom_cldnn, int performance_counter, int IsHardwareOK) { //printf("\n[test detector mem]------------------------:1\n"); //UTF8 trans.name table char buff[MAX_MSG_LEN] = { 0 }; //char strKeyValue[MAX_MSG_LEN] = { 0 }; // Assign ini file key value char section[16] = { 0 }; #ifdef GY_OS_V_SERIES #else for (int n = 0; n < MAX_LAYER_NUM; n++) { for (int i = 0; i < MAX_SECTION_VARIABLE; i++) { //if (section) if (layerFeatureType[n] == FEATURE_LPR_MEA || layerFeatureType[n] == FEATURE_LPR_SEA || layerFeatureType[n] == FEATURE_LPR_VNM || layerFeatureType[n] == FEATURE_LPR_IDN || layerFeatureType[n] == FEATURE_LPR_USA || layerFeatureType[n] == FEATURE_LPR_JPN || layerFeatureType[n] == FEATURE_LPR_THA || layerFeatureType[n] == FEATURE_LPR_LAO || layerFeatureType[n] == FEATURE_LPR_BGD || layerFeatureType[n] == FEATURE_LPR_TWN || layerFeatureType[n] == FEATURE_LPR_EUR ) { if (layerFeatureType[n] == FEATURE_LPR_MEA && layerFeatureType[n - 1] == FEATURE_LPR_MEA && n > 0) strcpy(section, "[MEA]"); if ((layerFeatureType[n] == FEATURE_LPR_SEA && layerFeatureType[n - 1] == FEATURE_LPR_SEA && n > 0) || (layerFeatureType[n] == FEATURE_LPR_VNM && layerFeatureType[n - 1] == FEATURE_LPR_VNM && n > 0) || (layerFeatureType[n] == FEATURE_LPR_IDN && layerFeatureType[n - 1] == FEATURE_LPR_IDN && n > 0)) strcpy(section, "[SEA]"); if (layerFeatureType[n] == FEATURE_LPR_USA && layerFeatureType[n - 1] == FEATURE_LPR_USA && n > 0) strcpy(section, "[USA]"); if (layerFeatureType[n] == FEATURE_LPR_JPN && layerFeatureType[n - 1] == FEATURE_LPR_JPN && n > 0) strcpy(section, "[JPN]"); if (layerFeatureType[n] == FEATURE_LPR_THA && layerFeatureType[n - 1] == FEATURE_LPR_THA && n > 0) strcpy(section, "[THA]"); if (layerFeatureType[n] == FEATURE_LPR_LAO && layerFeatureType[n - 1] == FEATURE_LPR_LAO && n > 0) strcpy(section, "[LAO]"); if (layerFeatureType[n] == FEATURE_LPR_BGD && layerFeatureType[n - 1] == FEATURE_LPR_BGD && n > 0) strcpy(section, "[BGD]"); if (layerFeatureType[n] == FEATURE_LPR_TWN && layerFeatureType[n - 1] == FEATURE_LPR_TWN && n > 0) strcpy(section, "[TWN]"); if (layerFeatureType[n] == FEATURE_LPR_EUR && layerFeatureType[n - 1] == FEATURE_LPR_EUR && n > 0) strcpy(section, "[EUR]"); sprintf(buff, "%d", i); char* value = GetIniKeyString(section, buff, INI_FILE_PATH); if (value != NULL) { if (strlen(value) > 0) { strcpy(ppIniKeyValue[n][i], value); } else { strcpy(ppIniKeyValue[n][i], ""); } } else { strcpy(ppIniKeyValue[n][i], ""); } } else { strcpy(ppIniKeyValue[n][i], ""); } } } #endif #ifdef GY_OS_AMBA memset_snapshot_addr(); #endif //===================== //sophia add 2020/09/24 for (int i = 0; i < MAX_CLIENT_SOCKET; i++) { //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); socketRecords[i].sock = -1; //socketRecords[i].thread_id = 0; socketRecords[i].channel_id = -1; //socketRecords[i].last_recv_time = time(0); //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; socketRecords[i].isGetAlarmMotion = FALSE; //socketRecords[i].isFirstAlarmMotion = FALSE; socketRecords[i].isWebSocketConnect = FALSE; socketRecords[i].isUdpSocket = FALSE; socketRecords[i].isNvrRequest = 0; socketRecords[i].isCredentialRequest = 0; socketRecords[i].debug_type = 0; #if defined GY_OS_AMBA //socketRecords[i].iIsAIRelay = 0; #endif // //#ifdef GY_OS_WIN // socketRecords[i].prev_frame_data = NULL; /*if (socketRecords[i].prev_frame_data) free(socketRecords[i].prev_frame_data);*/ //#endif socketRecords[i].used = 0; //socketRecord_ALM[i].sock = -1; } //printf("\nKKKKKKKKKKKKKKKK:3\n"); //for (int i = 0; i < MAX_CLIENT_SOCKET; i++) //{ //socketRecord_ALM[i].sock = -1; /*socketRecord_ALM[i].head = NULL; socketRecord_ALM[i].tail = NULL;*/ //} mtrace(); set_metadata(); reset_onvif(); initial_ivs(); initial_g_PostRecorderList(); check_if_is_existing_weight = 0; //===================== // Create a HTTP thread #if 1 //printf("\nKKKKKKKKKKKKKKKK:4\n"); if (http_port > 0) { // HTTP server //printf("\nKKKKKKKKKKKKKKKK:5\n"); g_write_config_file_dirty_flag = 0; protected_sqlite_fflpr_db_close = 1; #if defined GY_OS_AMBA || defined GY_OS_NOVA fflpr_log_db_init(); #ifdef GY_OS_AMBA if(unlockingKeyInnoFR == 1) { //face_log_db_init(); } #endif #endif isGYNetReady = TRUE; //Set GYNet is ready! //printf("\nKKKKKKKKKKKKKKKK:6\n"); //run_server有做過,但是這邊要再做一次,因為要更新g_IsPTZDevice。 pthread_t thread_id_getipcamsettings; if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { printf("\ngetipcamsettings thread creation failed #1\n"); } pthread_join(thread_id_getipcamsettings, NULL); #if 1 //329個Memory not freed 正常背景值洩漏 if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) error("HTTP server thread creation failed\n"); #endif //printf("\nKKKKKKKKKKKKKKKK:8\n"); //printf("\n[test detector mem]------------------------:2\n"); #ifdef GY_OS_AMBA #if 0 if ( g_IsToFDevice == 1) { // 建立記憶體共享區 long data_size = sizeof(frameimage) + sizeof(rbuf_t); tof_depth_shmid = Initial_ShareMemory(data_size, 888); if (tof_depth_shmid == -1) { perror("Create shared memory failed !\n"); } else { // 初始化緩衝區 ringbuf_init(&tof_ring_buffer); bTofDataStart = 1; if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0)) error("thread gettofdata creation failed\n"); } } #endif #endif #ifdef GY_OS_AMBA if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); #else sprintf(cmd, "/usr/local/bin/test_vin -m 2"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } else { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); #ifdef GY_OS_AMBA sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); #else sprintf(cmd, "/usr/local/bin/test_vin -m 0"); #endif pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } } } #endif //printf("\nKKKKKKKKKKKKKKKK:7\n"); int check_if_setting_general_mode = 1; if (g_IsPTZDevice == 0) { if (strcmp(accountData[0].account_flip, "1") == 0 || strcmp(accountData[0].account_mirror, "1") == 0 || strcmp(accountData[0].account_rotate, "1") == 0) { check_if_setting_general_mode = 0; } } else if (g_IsPTZDevice == 1) { if (strcmp(accountData[0].account_rotate, "1") == 0 || strcmp(accountData[0].account_mirror, "1") == 0) { check_if_setting_general_mode = 0; } } #if 1 //除了delete_jpg_in_seven_days_detector沒開,合計10,878,464byte產生1983個記憶體洩漏(正常推播:只有一個zone,且output只設定一個虛擬輸入端,dwell time6秒) //除了delete_jpg_in_seven_days_detector和run_post_notification_thread的推播AA沒開,合計11,276,800byte產生1978個記憶體洩漏 //除了delete_jpg_in_seven_days_detector和run_post_notification_thread沒開,合計11,232,112byte產生1467個記憶體洩漏,大約1983-1467=516個記憶體洩漏是run_post_notification_thread造成的 //除了delete_jpg_in_seven_days_detector沒開,合計10,891,264byte產生1500個記憶體洩漏(暴力推播:只有一個zone,但output設定四個虛擬輸入端,dwell time6秒) //除了delete_jpg_in_seven_days_detector沒開,合計11,190,784byte產生1568個記憶體洩漏(四個zone暴力推播:4個zone,且每個output設定四個虛擬輸入端,dwell time6秒) //除了delete_jpg_in_seven_days_detector沒開,合計11,518,976byte產生1992個記憶體洩漏(四個zone暴力推播:4個zone,且每個output設定四個虛擬輸入端,dwell time1秒) //除了delete_jpg_in_seven_days_detector沒開,合計11,319,296byte產生1697個記憶體洩漏(四個zone暴力推播:4個zone,且每個output8個都開,dwell time1秒)//推不對的IP,不會影響記憶體洩漏 bHttpServerThreadStart = 1; if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL)) error("Post notification thread creation failed\n"); #endif #ifdef GY_OS_NOVA if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) error("resolution changed thread failed\n"); #else if (get_run_check_current_resolution() == -1) { set_run_check_current_resolution(0); if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) error("check current resolution thread failed\n"); } #endif if (IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1) { // printf("\n[test detector mem] IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1)\n"); check_if_is_existing_weight = 1; bHttpServerThreadStart = 1; /* if (g_IsToFDevice == 1) { system(SHELLSCRIPT_TOF_DRIVER); }*/ #if 1 if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n"); if (pthread_create(&getimage_thread, 0, thread_getimage, 0)) error("thread getimage creation failed\n"); #ifdef GY_OS_AMBA if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) error("thread getimage creation failed\n"); #endif } #endif #ifdef GY_OS_AMBA #if 0 if (g_IsRadarDevice == 1) { if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0)) 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) error("RADAR_recieve creation failed\n"); } else { if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) error("thread getimage creation failed\n"); if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) error("thread radar parser creation failed\n"); } } #endif // unlockingKeyInnoFR_success = faceengine_start_and_check_license(); // unlockingKeyInnoFR_success = 1; #if 0 if (unlockingKeyInnoFR_success == 1) { #ifdef GY_OS_AMBA faceengine_start(); #endif } #endif #if 0 //目前先關掉與faceengine的互動 if(unlockingKeyInnoFR_success == 1){ #ifdef GY_OS_AMBA if (pthread_create(&get_face_websocket_thread, 0, thread_get_face_websocket, 0)) error("thread get_face_websocket creation failed\n"); if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) error("thread parse_face creation failed\n"); #endif } #endif #endif //printf("\nKKKKKKKKKKKKKKKK:9\n"); #if 1 //test_nn_main & run_send_udp_thread & run_getalarmmotion_thread output.log 8,532,480byte -> 產生1167個記憶體洩漏 大約1167-1072=95個記憶體洩漏是run_getalarmmotion_thread造成的 if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) error("Getalarmmotion thread creation failed\n"); #endif #ifdef GY_OS_V_SERIES #else //329個Memory not freed 正常背景值洩漏 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 1 ////原本名稱是check_http_socket_thread,現在改成run_event_counter_thread if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) error("check http socket thread creation failed\n"); #endif } #endif #ifdef GY_OS_V_SERIES #else #if 1 //329個Memory not freed 正常背景值洩漏 if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { if (pthread_create(&delete_jpg_in_seven_days_detector_thread_id, 0, delete_jpg_in_seven_days_detector, NULL)) printf("create delete_jpg_in_seven_days_detector thread faile \n"); } #endif #endif //printf("\nKKKKKKKKKKKKKKKK:10\n"); // UDP thread to send getalarmotion #if 1 //test_nn_main & run_send_udp_thread output.log 8,579,969byte -> 產生1072個記憶體洩漏 大約1072-875=197個記憶體洩漏是run_send_udp_thread造成的 if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) error("check http socket thread creation failed\n"); #endif #ifdef GY_OS_AMBA //**這邊還會記憶體洩漏 //output.log 8,392,192byte ->產生934個記憶體洩漏 output.log增長幅度變成40,000byte //不開start_all_nets 105,984byte->產生343個記憶體洩漏 比背景值洩漏一點點 正常OK //不開while (live_mode_flag) 119,808byte->產生337個記憶體洩漏 比背景值洩漏一點點 正常OK //if (g_IsRadarDevice == 0) { #if 1 if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent)) 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)) error("Test nnctrl live thread creation failed\n"); #endif #if 1 //329個Memory not freed 正常背景值洩漏 //Get CPU/VPU loading & AI FPS if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) error("fps loading thread creation failed\n"); #endif #ifdef GY_OS_AMBA #if 1 //OSD server 建立 if (pthread_create(&thread_id_run_osd_server, 0, run_osd_server_thread, NULL)) { printf("\nrun osd server thread creation failed\n"); } #endif #endif #ifdef GY_OS_NOVA if (pthread_create(&thread_id_get_nova_driver, 0, thread_get_nova_driver, 0)) error("thread get nova driver creation failed\n"); #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"); //} } else bHttpServerThreadStart = 1; //printf("\nKKKKKKKKKKKKKKKK:12\n"); //printf("\n[test_detector_mem] &stAMBAcontent:%x\n", &stAMBAcontent); //printf("\n[test_detector_mem] stAMBAcontent.licenseType:%d\n", stAMBAcontent.licenseType); RefreshCheckExistingWeight(); int count_timeout = 0; while (bHttpServerThreadStart) { if (AI_fps >= 1) break; else if (count_timeout >= 30) //count_timeout 100會沒載完 { printf("\n[Error]: Not Ready to run test_nn_main\n"); break; } count_timeout++; usSleep(1000000); } } #endif //muntrace(); //這邊會影響CPU的效能Sleep不能太低// while (bHttpServerThreadStart) { //printf("while bHttpServerThreadStart :%d\n", bHttpServerThreadStart); #if defined GY_OS_NOVA usSleep(3600000000);//3600000000 #else usSleep(1500000); #endif } ////////////////////後面可能會沒有free到 printf("\n------------test detector mem:1\n"); #if 0 for (int n = 0; n < MAX_LAYER_NUM; n++) { if (layer_count > 0) { if (tcp_port > 0) free_ptrs((void**)names[n], nets[n].layers[nets[n].n - 1].classes); else if (http_port > 0) free_ptrs((void**)names[n], http_nets[n].layers[http_nets[n].n - 1].classes); #ifdef GY_OS_WIN if (tcp_port > 0) free_network(nets[n]); if (http_port > 0) free_network(http_nets[n]); #endif //free_list_contents_kvp(options[n]); free_list(options[n]); } } #endif //free_ptrs(pPosInfo, element_size); printf("\n------------test detector mem:2\n"); /* if (alphabet != NULL) //20201015 sophia add { const int nsize = 8; for (int j = 0; j < nsize; ++j) { for (int i = 32; i < 127; ++i) { free_image(alphabet[j][i]); } if (alphabet[j]) { free(alphabet[j]); alphabet[j] = NULL; } } if (alphabet) { free(alphabet); alphabet = NULL; } }*/ printf("\n[test detector mem] end\n"); stop_server(); } #endif void stop_btHttpServer() { // share_memory_stop(); #if 0 bTofDataStart = 0; #endif bHttpServerThreadStart = 0; bHttpServerMainStart = 0; //printf("\n----------stop_btHttpServer:%d\n",1); if (cgi_startTime_buff) { free(cgi_startTime_buff); cgi_startTime_buff = NULL; } if (cgi_whenTime_buff) { free(cgi_whenTime_buff); cgi_whenTime_buff = NULL; } //printf("\n----------stop_btHttpServer:%d\n", 2); #ifdef GY_OS_AMBA //if (g_IsPTZDevice == 1) { //Free_PTZ_g_curl_connect(); //} #endif //printf("\n----------stop_btHttpServer:%d\n", 3); curl_global_cleanup(); //printf("\n----------stop_btHttpServer:%d\n", 4); base64_cleanup(); //printf("\n----------stop_btHttpServer:%d\n", 5); #if defined GY_OS_AMBA || defined GY_OS_NOVA sqlite_fflpr_db_close(); #ifdef GY_OS_AMBA if (unlockingKeyInnoFR == 1) { //sqlite_face_db_close(); } #endif #endif //printf("\n----------stop_btHttpServer:%d\n", 6); //printf("Stop btHttpServer - finished. \n"); } int get_bHttpServerThreadStart() { return bHttpServerThreadStart; } void stop_server() { printf("Stop Server - started.\n"); //pthread_mutex_lock(&mutex_run_one_net); //bHttpServerThreadStart = 0; //bHttpServerMainStart = 0; //pthread_mutex_unlock(&mutex_run_one_net); stop_btHttpServer(); //printf("\n----------stop server 1\n"); #if 1 #ifdef GY_OS_AMBA StopPTZupdateStatusThread(); #endif //printf("\n----------stop server 2\n"); //#ifdef GY_OS_AMBA //close 4 threads //http server - run_http_server_thread() //post notification - run_post_notification_thread() //run event counter thread - run_event_counter_thread() //test nnctrl live - test_nn_main() //#endif //GY_OS_AMBA #endif printf("Stop Server - finished. \n"); //destroy pthread_mutex #if 1 //pthread_mutex_destroy(&mutex_post_notification); //pthread_mutex_destroy(&mutex_post_notification_push); pthread_mutex_destroy(&mutex_post_notification_pop); //printf("\n----------stop server 3\n"); pthread_mutex_destroy(&mutex_getalarmmotion); pthread_mutex_destroy(&mutex_alm); pthread_mutex_destroy(&mutex_curl); pthread_mutex_destroy(&mutex_dn); pthread_mutex_destroy(&mutex_websocket); pthread_mutex_destroy(&mutex_enable_lpr_db); #ifdef GY_OS_AMBA pthread_mutex_destroy(&mutex_enable_face_db); #endif pthread_mutex_destroy(&mutex_username); pthread_mutex_destroy(&mutex_pns); //pthread_mutex_destroy(&mutex_get_canvas); //printf("\n----------stop server 4\n"); pthread_mutex_destroy(&mutex_snap); //pthread_mutex_destroy(&mutex_cropped_roi); //pthread_mutex_destroy(&mutex_snap_hd_image); pthread_mutex_destroy(&mutex_snap_image); #ifdef GY_OS_AMBA 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); pthread_mutex_destroy(&mutex_config_json); #if defined GY_OS_AMBA //pthread_mutex_destroy(&mutex_jvc_config_json); #endif pthread_mutex_destroy(&mutex_events_json); pthread_mutex_destroy(&mutex_web); //printf("\n----------stop server 5\n"); //pthread_mutex_destroy(&mutex_http_connection_handler); pthread_mutex_destroy(&mutex_base64); pthread_mutex_destroy(&mutex_run_one_net); #ifdef GY_OS_NOVA //pthread_mutex_destroy(&mutex_run_parse_json); #endif pthread_mutex_destroy(&mutex_send_jpeg); pthread_mutex_destroy(&mutex_heatmap_jpeg); //pthread_mutex_destroy(&mutex_strsplit); #ifdef GY_OS_AMBA pthread_mutex_destroy(&mutex_perspective_transform); #endif //printf("\n----------stop server 6\n"); pthread_mutex_destroy(&mutex_get_network_input); pthread_mutex_destroy(&mutex_differ_image); pthread_mutex_destroy(&mutex_run_one_net_anpr); pthread_mutex_destroy(&mutex_check_license); pthread_mutex_destroy(&mutex_read_ipcam); pthread_mutex_destroy(&mutex_update_candidate); pthread_mutex_destroy(&mutex_send_cgi); //pthread_mutex_destroy(&mutex_parse_bbox); //pthread_mutex_destroy(&mutex_color_detect); pthread_mutex_destroy(&mutex_compute_median); //pthread_mutex_destroy(&mutex_long_term); //pthread_mutex_destroy(&mutex_short_term); //pthread_mutex_destroy(&mutex_long_term_yuv); //pthread_mutex_destroy(&mutex_short_term_yuv); pthread_mutex_destroy(&mutex_set_http_request); pthread_mutex_destroy(&mutex_reset_counter); #ifdef GY_OS_AMBA pthread_mutex_destroy(&mutex_run_osd); pthread_mutex_destroy(&mutex_get_depth); //pthread_mutex_destroy(&mutex_tof_data); pthread_mutex_destroy(&mutex_write_pcd_data); pthread_mutex_destroy(&mutex_write_pcd_data_L); pthread_mutex_destroy(&mutex_write_pcd_data_M); pthread_mutex_destroy(&mutex_write_pcd_data_S); #endif #ifdef GY_OS_NOVA pthread_mutex_destroy(&mutex_pre_bbox_receive); pthread_mutex_destroy(&mutex_pre_connection); pthread_mutex_destroy(&mutex_pre_image_receive); #endif #endif printf("Stop Server - pthread finished. #2\n"); } #ifdef GY_OS_AMBA void write_to_enable_tracking(char *enable_tracking) { //printf("\n--------------[enable tracking]-----------------: %s\n", enable_tracking); char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; //printf("exePath:%s\n", exePath); getFilePath(buf, exePath, 1024); //printf("exePath:%s\n", exePath); char configPATH[1024] = { 0 }; strcpy(configPATH, exePath); strcat(configPATH, "config.json"); char config_bakPATH[1024] = { 0 }; strcpy(config_bakPATH, exePath); strcat(config_bakPATH, "config_bak.json"); char *filename_config = configPATH; if (!FileExist(filename_config)) { printf("%s doesn't exist.\n", filename_config); } else { //size_t nfileSize_cofnig = ReadFileSize(filename_config); char *fileBuf_config = ReadAllBytes(filename_config); if (fileBuf_config) { cJSON *root = NULL; root = cJSON_Parse(fileBuf_config); if (fileBuf_config) { free(fileBuf_config); fileBuf_config = NULL; } if (root == NULL) { printf("root_config is NULL\n"); } else { cJSON *view_setting, *camera01, *ptz_enable_tracking; view_setting = cJSON_GetObjectItem(root, "view_setting"); camera01 = cJSON_GetObjectItem(view_setting, "camera01"); ptz_enable_tracking = cJSON_GetObjectItem(camera01, "ptz_enable_tracking"); if (ptz_enable_tracking) { cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); char* JsonString = cJSON_Print(root); FILE *fp; if ((fp = fopen(filename_config, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); CopyFileTo(configPATH, config_bakPATH); } else { printf("Fail to open config.json \n"); } if (JsonString) { free(JsonString); JsonString = NULL; } } } if (root) { cJSON_Delete(root); root = NULL; } } } } #endif #ifdef GY_OS_AMBA int read_bin(char *fileDir, unsigned char *addr) { //fread printf("read_bin \n"); //int rval = 0; int lSize = 0; #if 0 FILE *fp = NULL; //lSize = ftell(fileDir); lSize = 460800; printf("read_bin return\n"); return lSize; if (lSize > 0) { fp = fopen(fileDir, "r"); //char addr[500000]; //int readCnt = fread(addr, 1, lSize, fp); /* return 0*/ //int readCnt = fread(buffer,1,sizeof(buffer),fp); /* return 11 */ //printf("readCnt = %d\n", readCnt); fclose(fp); } else return 0; #endif printf("read_bin return\n"); return lSize; } int teststoreYUV(char *file, int size, void *addr) { FILE *fp = NULL; int rval = 0; do { if ((fp = fopen(file, "wb")) == NULL) { printf("\n%s\n", file); rval = -1; break; } if (fwrite(addr, 1, size, fp) != size) { printf("\nfwrite]n"); rval = -1; break; } fclose(fp); fp = NULL; } while (0); if (fp) { fclose(fp); fp = NULL; } return rval; } int testbinfile(char *filename, char *buffer) { printf("file name: %s \n", filename); int lSize = 0; FILE *fp = NULL; fp = fopen(filename, "r"); fseek(fp, 0, SEEK_END); lSize = ftell(fp); rewind(fp); //set read point to start /*size_t read_result = */fread(buffer, 1, lSize, fp); //char img_name[512] = { 0 }; //sprintf(img_name, "/emmc/plugin/Aida_data/storage/hello_tofyuv.bin"); //same ////store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); //teststoreYUV(img_name, lSize, buffer); //int readCnt = fread(buffer, 1, sizeof(buffer), fp); fclose(fp); return lSize; } #endif void move_file() { for(int i = 0 ; i < 13 ; i++) { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); if( i == 0 ) sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage"); else if( i == 1 ) sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/default.jpg"); else if( i == 2 ) sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/default.jpg"); else if (i == 3) sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/face"); else if (i == 4) sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/face/default.jpg"); else if (i == 5) sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/face/default.jpg"); else if (i == 6) sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/template"); else if (i == 7) sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/template/default.jpg"); else if (i == 8) sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/template/default.jpg"); else if (i == 9) sprintf(cmd, "mkdir /emmc/plugin/Aida_data/playback"); else if (i == 10) sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/playback/default.jpg"); else if (i == 11) sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/playback/default.jpg"); else if (i == 12) sprintf(cmd, "mkdir /emmc/plugin/Aida_data/sfe/storage"); pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } } void *start_run_python_thread(void* pythonpath) { pthread_detach(pthread_self()); setPthreadName("run_python"); char *value = get_enable_python_file_value((const char*)pythonpath); while (python_check_webstatus == 0) { // python_check_webstatus = 0 Web close // python_check_webstatus = 1 Web open printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); continue; } // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); sleep(15); // sleep 15 sec,wait Web thread open if (value == NULL) { printf("Failed to retrieve enable_python_file value\n"); pthread_exit(NULL); } // 抓取 python 檔案 if (strstr(value, ".py") != NULL) { // printf("enable_python_file is a Python file: %s\n", value); const char *prefix = "lifile_liname="; char pythonfile[256]; snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); runPython(pythonfile); } else { printf("enable_python_file is not a Python file: %s\n", value); } pthread_exit(NULL); } char* get_enable_python_file_value(const char *filename) { FILE *file = fopen(filename, "r"); if (file == NULL) { printf("Could not open file %s\n", filename); return NULL; } // 獲取文件大小 fseek(file, 0, SEEK_END); long file_size = ftell(file); fseek(file, 0, SEEK_SET); // 讀取文件內容到內存中 char *file_content = (char *)malloc(file_size + 1); if (file_content == NULL) { printf("Memory allocation failed\n"); fclose(file); return NULL; } fread(file_content, 1, file_size, file); file_content[file_size] = '\0'; fclose(file); // 解析 JSON cJSON *json = cJSON_Parse(file_content); free(file_content); if (json == NULL) { printf("Error parsing JSON file\n"); return NULL; } // 獲取 system_setting 的值 cJSON *system_setting = cJSON_GetObjectItem(json, "system_setting"); if (system_setting == NULL) { printf("system_setting not found in JSON\n"); cJSON_Delete(json); return NULL; } // 獲取 enable_python_file 的值 cJSON *enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); char *result = NULL; if (enable_python_file != NULL && cJSON_IsString(enable_python_file)) { result = strdup(enable_python_file->valuestring); // 複製字符串值 } // 清理 cJSON 對象 cJSON_Delete(json); printf("[get_enable_python_file_value] result : %s \n",result); // 返回結果 return result; } void run_server(int argc, char **argv) { //以下沒有記憶體洩漏------------------------20210803 check_if_start_run_server = 1; { char temp_msg[8192] = { 0 }; snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "The start of gynet."); write_to_logs_html(temp_msg, "run server", "INFO", "Yes"); write_to_log_for_start(temp_msg, "run server", "INFO"); } #ifdef _DEBUG_AMBA printf("\n[run_server] start\n"); for (int i = 0;i < argc;i++) printf("[run_server] argv[%d]:%s\n", i, argv[i]); #endif // _DEBUG_AMBA file_management(); initial_weight_settings(); getCameraPlugInInfo(); update_accountData(); update_accountData_port(); move_file(); g_IsRadarFake = 0; setlocale(LC_ALL, "en_US.UTF-8"); g_match_mac = 0; char init_CPU_usage[256] = "20"; char init_GPU_usage[256] = "20"; sprintf(CPU_usage, "%s", init_CPU_usage); sprintf(GPU_usage, "%s", init_GPU_usage);//psBuffer_send2 #ifdef REBOOT_BY_CPU_GPU_USAGE CPU_usage_int = atoi(CPU_usage); GPU_usage_int = atoi(GPU_usage); #endif ColdZoneInit(); /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); char buf[1024] = { 0 }; readlink("/proc/self/exe", buf, sizeof(buf)); //printf("Program binary path is: %s\n", buf); char exePath[1024] = { 0 }; getFilePath(buf, exePath, 1024); char configPATH[1024] = { 0 }; #ifdef GY_OS_NOVA char config_smallPATH[1024] = { 0 }; #endif char config_installPATH[1024] = { 0 }; #ifdef GY_OS_NOVA char config_small_installPATH[1024] = { 0 }; #endif char config_bakPATH[1024] = { 0 }; char events_installPATH[1024] = { 0 }; char eventsPATH[1024] = { 0 }; char events_bakPATH[1024] = { 0 }; char tof_installPATH[1024] = { 0 }; char tofPATH[1024] = { 0 }; char tof_bakPATH[1024] = { 0 }; char emails_installPATH[1024] = { 0 }; char emailsPATH[1024] = { 0 }; char emails_bakPATH[1024] = { 0 }; char cold_objects_installPATH[1024] = { 0 }; char cold_objectsPATH[1024] = { 0 }; strcpy(configPATH, exePath); #ifdef GY_OS_NOVA strcpy(config_smallPATH, exePath); #endif strcpy(config_installPATH, exePath); #ifdef GY_OS_NOVA strcpy(config_small_installPATH, exePath); #endif strcpy(config_bakPATH, exePath); strcpy(eventsPATH, exePath); strcpy(events_installPATH, exePath); strcpy(events_bakPATH, exePath); strcpy(tofPATH, exePath); strcpy(tof_installPATH, exePath); strcpy(tof_bakPATH, exePath); strcpy(emailsPATH, exePath); strcpy(emails_installPATH, exePath); strcpy(emails_bakPATH, exePath); strcpy(cold_objectsPATH, exePath); strcpy(cold_objects_installPATH, exePath); strcat(configPATH, "config.json"); #ifdef GY_OS_NOVA strcat(config_smallPATH, "config_small.json"); #endif strcat(config_installPATH, "config_install.json"); #ifdef GY_OS_NOVA strcat(config_small_installPATH, "config_small_install.json"); #endif strcat(config_bakPATH, "config_bak.json"); strcat(eventsPATH, "events.json"); strcat(events_installPATH, "events_install.json"); strcat(events_bakPATH, "events_bak.json"); strcat(tofPATH, "tof.json"); strcat(tof_installPATH, "tof_install.json"); strcat(tof_bakPATH, "tof_bak.json"); strcat(emailsPATH, "emails.json"); strcat(emails_installPATH, "emails_install.json"); strcat(emails_bakPATH, "emails_bak.json"); strcat(cold_objectsPATH, "cold_objects.json"); strcat(cold_objects_installPATH, "cold_objects_install.json"); //arguments dont_show = find_arg(argc, argv, "-dont_show"); show = find_arg(argc, argv, "-show"); tcp_port = find_int_arg(argc, argv, "-tcp_port", -1); //out_filename = find_char_arg(argc, argv, "-out_filename", 0); //outfile = find_char_arg(argc, argv, "-out", 0); //prefix = find_char_arg(argc, argv, "-prefix", 0); thresh = find_float_arg(argc, argv, "-thresh", .24); hier_thresh = find_float_arg(argc, argv, "-hier", .5); cam_index = find_int_arg(argc, argv, "-c", 0); frame_skip = find_int_arg(argc, argv, "-s", 0); num_of_clusters = find_int_arg(argc, argv, "-num_of_clusters", 5); yuv_width = find_int_arg(argc, argv, "-width", -1); yuv_height = find_int_arg(argc, argv, "-height", -1); ext_output = find_arg(argc, argv, "-ext_output"); save_labels = find_arg(argc, argv, "-save_labels"); http_port = find_int_arg(argc, argv, "-http_port", 0); //unlocking_key = find_char_arg(argc, argv, "-unlocking_key", 0); //char *ip_address = find_char_arg(argc, argv, "-ip_address", 0); gpu_idx = find_int_arg(argc, argv, "-gpu_idx", 0); //c_cnn_type = find_char_arg(argc, argv, "-cnn_type", 0); #if 0 radar_log = find_arg(argc, argv, "-radar_log"); // 10-19 leo #endif // radar_log = 1; // 2022-10-28 Ken for V1 classification testing info //printf("radar_log:%d\n", radar_log); //char* model = find_char_arg(argc, argv, "-m", ""); input_resizable = find_int_arg(argc, argv, "-auto_resize", 0); custom_cpu_library = find_char_arg(argc, argv, "-l", ""); custom_cldnn = find_char_arg(argc, argv, "-c", ""); performance_counter = find_int_arg(argc, argv, "-pc", 0); isGYNetReady = FALSE; //pthread_mutex_init(&mutex_post_notification, NULL); //pthread_mutex_init(&mutex_post_notification_push, NULL); pthread_mutex_init(&mutex_post_notification_pop, NULL); pthread_mutex_init(&mutex_getalarmmotion, NULL); pthread_mutex_init(&mutex_alm, NULL); pthread_mutex_init(&mutex_curl, NULL); pthread_mutex_init(&mutex_dn, NULL); pthread_mutex_init(&mutex_websocket, NULL); pthread_mutex_init(&mutex_enable_lpr_db,NULL); #ifdef GY_OS_AMBA pthread_mutex_init(&mutex_enable_face_db,NULL); #endif pthread_mutex_init(&mutex_username, NULL); pthread_mutex_init(&mutex_pns, NULL); pthread_mutex_init(&mutex_snap, NULL); //pthread_mutex_init(&mutex_get_canvas, NULL); //pthread_mutex_init(&mutex_cropped_roi, NULL); //pthread_mutex_init(&mutex_snap_hd_image, NULL); pthread_mutex_init(&mutex_snap_image, NULL); #ifdef GY_OS_AMBA pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 pthread_mutex_init(&mutex_radar_json, NULL); pthread_mutex_init(&mutex_tof_json, NULL); pthread_mutex_init(&mutex_buffer, NULL); #endif pthread_mutex_init(&mutex_get_image, NULL); pthread_mutex_init(&mutex_get_image_HD, NULL); pthread_mutex_init(&mutex_config_json, NULL); #if defined GY_OS_AMBA //pthread_mutex_init(&mutex_jvc_config_json, NULL); #endif pthread_mutex_init(&mutex_events_json, NULL); pthread_mutex_init(&mutex_web, NULL); //pthread_mutex_init(&mutex_http_connection_handler, NULL); pthread_mutex_init(&mutex_base64, NULL); pthread_mutex_init(&mutex_run_one_net, NULL); #ifdef GY_OS_NOVA //pthread_mutex_init(&mutex_run_parse_json, NULL); #endif pthread_mutex_init(&mutex_send_jpeg, NULL); pthread_mutex_init(&mutex_heatmap_jpeg, NULL); //pthread_mutex_init(&mutex_strsplit, NULL); #ifdef GY_OS_AMBA pthread_mutex_init(&mutex_perspective_transform, NULL); #endif pthread_mutex_init(&mutex_get_network_input, NULL); pthread_mutex_init(&mutex_differ_image, NULL); pthread_mutex_init(&mutex_run_one_net_anpr, NULL); pthread_mutex_init(&mutex_check_license, NULL); pthread_mutex_init(&mutex_read_ipcam, NULL); pthread_mutex_init(&mutex_update_candidate, NULL); pthread_mutex_init(&mutex_send_cgi, NULL); //pthread_mutex_init(&mutex_parse_bbox, NULL); //pthread_mutex_init(&mutex_color_detect, NULL); pthread_mutex_init(&mutex_compute_median, NULL); //pthread_mutex_init(&mutex_long_term, NULL); //pthread_mutex_init(&mutex_short_term, NULL); //pthread_mutex_init(&mutex_long_term_yuv, NULL); //pthread_mutex_init(&mutex_short_term_yuv, NULL); pthread_mutex_init(&mutex_set_http_request, NULL); pthread_mutex_init(&mutex_reset_counter, NULL); #ifdef GY_OS_AMBA pthread_mutex_init(&mutex_run_osd, NULL); pthread_mutex_init(&mutex_get_depth, NULL); //pthread_mutex_init(&mutex_tof_data, NULL); pthread_mutex_init(&mutex_write_pcd_data, NULL); 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); #endif #ifdef GY_OS_NOVA pthread_mutex_init(&mutex_pre_bbox_receive, NULL); pthread_mutex_init(&mutex_pre_connection, NULL); pthread_mutex_init(&mutex_pre_image_receive, NULL); #endif //g_multi_handle = curl_multi_init(); //Curl init //QueueLockInit(); //以上沒有記憶體洩漏------------------------20210803 //100個左右記憶體洩漏 memset(&accountData, 0, sizeof(accountData)); #if defined GY_OS_AMBA || defined GY_OS_NOVA pthread_mutex_lock(&mutex_curl); curl_global_init(CURL_GLOBAL_SSL); g_http_handle = NULL; g_http_handle = curl_easy_init(); pthread_mutex_unlock(&mutex_curl); pthread_t thread_id_getipcamsettings; if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { printf("\ngetipcamsettings thread creation failed\n"); } pthread_join(thread_id_getipcamsettings, NULL); //StartPTZupdateStatusThread(); #ifdef GY_OS_NOVA ipcam_getfeatures(); #else if (strcmp(WeightFileModeName, "mod004") == 0) { ipcam_getfeatures(); } #endif ///讀取SMTP service資料 copy_ipcam_smtp_service_to_gynet(); //printf("000 get password = %s \n", accountData[0].account_password); #if 1 //1個記憶體洩漏 if (http_port > 0) { //printf("\n**********************\n"); //printf("preload server open"); //printf("\n**********************\n"); pthread_t preload_http_thread; if (pthread_create(&preload_http_thread, 0, run_preload_http_server_thread, 0)) error("preload http server thread creation failed\n"); } //0個左右記憶體洩漏 //char returned_msg[MEMORY_SIZE] = { 0 }; //PNS_Query_Service_Status(returned_msg); #endif //**半OK記憶體洩漏 //output.log 138,240byte ->產生330個記憶體洩漏 output.log增長幅度顯著變比較慢 //get_current_events_json_data 會記憶體洩漏,但是不常進去。 g_IsPTZDevice = 0; #endif //init CGI CMD time //兩個記憶體洩漏 在stop_server才會釋放 cgi_startTime_buff = (struct tm*)malloc(sizeof(struct tm)); cgi_whenTime_buff = (struct tm*)malloc(sizeof(struct tm)); //printf("GyNet is starting......\n"); td_weight_num = 0; char customWeightPATH[1024] = { 0 }; strcpy(customWeightPATH, exePath); strcat(customWeightPATH, "customWeight.json"); cJSON* root_third, * weight_number; cJSON *third_party_weight_list, *td_party_weight, *weight_name,*anchor_name,*label_name, *encryption; //printf("111 get password = %s \n", accountData[0].account_password); if (!FileExist(customWeightPATH)) { td_weight_num = 0; printf("%s doesn't exist.\n", customWeightPATH); } else { //printf("read customWeight.json.\n"); char* fileBuf_third = ReadAllBytes(customWeightPATH); if (fileBuf_third) { root_third = cJSON_Parse(fileBuf_third); if (fileBuf_third) { free(fileBuf_third); fileBuf_third = NULL; } weight_number = cJSON_GetObjectItem(root_third, "Weight Number"); if (weight_number) td_weight_num = (short)weight_number->valueint; third_party_weight_list = cJSON_GetObjectItem(root_third, "Third party weight"); if (third_party_weight_list) { int k = 0; cJSON_ArrayForEach(td_party_weight, third_party_weight_list) { if (td_party_weight && k < MAX_LAYER_NUM) { weight_name = cJSON_GetObjectItem(td_party_weight, "Weight Name"); if (weight_name) sprintf(td_weight_info[k].weight_name, "%s", weight_name->valuestring); anchor_name = cJSON_GetObjectItem(td_party_weight, "Anchor Name"); if (anchor_name) sprintf(td_weight_info[k].anchor_name, "%s", anchor_name->valuestring); label_name = cJSON_GetObjectItem(td_party_weight, "Label Name"); if (label_name) sprintf(td_weight_info[k].label_name, "%s", label_name->valuestring); encryption = cJSON_GetObjectItem(td_party_weight, "Encryption"); if (encryption && strcmp(encryption->valuestring,"Yes")==0) td_weight_info[k].is_encryption = 1; else td_weight_info[k].is_encryption = 0; k++; } } } if (root_third) { cJSON_Delete(root_third); root_third = NULL; } } } #if 0 for (int i = 0; i < td_weight_num; i++) { printf("\nWeight Name: %s\n", td_weight_info[i].weight_name); printf("\nis_encryption: %hd\n", td_weight_info[i].is_encryption); } #endif int new_data_write_to_config_file_flag = 0; int new_data_write_to_events_file_flag = 0; int new_data_write_to_tof_file_flag = 0; //printf("\n-------------------http_port: %d\n", http_port); sprintf(accountData[0].account_aida_port, "%d", http_port); if (tcp_port > 0 || http_port > 0) { //read settings from config.json //char filename[] = config_bakPATH; char *filename = configPATH; //char *filename = config_bakPATH; if (!FileExist(filename)) { printf("%s doesn't exist.\n", filename); return; } //printf("read config.json. %s\n", filename); //size_t nfileSize = ReadFileSize(filename); char* fileBuf = ReadAllBytes(filename); if(fileBuf){ cJSON *root = cJSON_Parse(fileBuf); //g_config_root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config.json parse OK.\n"); cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); //cJSON* nic_name = cJSON_GetObjectItem(about_box, "NIC name"); cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); //printf(">>>>>>>>>>> uk key = %s \n", unlock_key->valuestring); /* if (td_weight_num >= 1) { cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("Third_party")); unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); }*/ if (unlock_key && (int)strlen(unlock_key->valuestring) == 0) { char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char keyPATH[1024] = { 0 }; strcpy(keyPATH, exePath); strcat(keyPATH, "key.txt"); if (FileExist(keyPATH) == 1) { char key_buff[1024] = { 0 };//creating char array to store data of file FILE *pFile; if ((pFile = fopen(keyPATH, "r")) != NULL) { fscanf(pFile, "%s", key_buff); fclose(pFile); cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(key_buff)); unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); char* JsonString = cJSON_Print(root); FILE *f = fopen(configPATH, "w"); if (f == NULL) { printf("Error opening config.json!\n"); } else { fprintf(f, "%s\n", JsonString); fclose(f); CopyFileTo(configPATH, config_bakPATH); } if (JsonString) { free(JsonString); JsonString = NULL; } } else printf("Fail to open key.txt \n"); } } //解碼unlockingKey - step 1:base64 decode size_t base64_decode_length = 0; unsigned char EncryptKeyData[256]; char DecryptKeyData[256]; memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); unsigned char OriEncryptData[512] = { 0 }; base64_decode(unlock_key->valuestring, strlen(unlock_key->valuestring), &base64_decode_length, OriEncryptData); memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); //printf("\n--------------OriEncryptData:%s\n", OriEncryptData); //printf("\n--------------EncryptKeyData:%s\n", EncryptKeyData); //解碼unlockingKey - step 2:AES descrytion KeyExpansion(key, expandedKey); //printf("\n---------expandedKey:%s\n", expandedKey); AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); //printf("unlocking_key descrytion OK.\n"); //printf("key info = %s \n", DecryptKeyData); //printf("\n--------------DecryptKeyData:%s\n", DecryptKeyData); //取得unlockingKey明碼資訊 cJSON *keyRoot, *fe, *fe2, *li, *ad, *st, *et, *id; keyRoot = cJSON_Parse(DecryptKeyData); fe = cJSON_GetObjectItem(keyRoot, "fe"); fe2 = cJSON_GetObjectItem(keyRoot, "fe2"); li = cJSON_GetObjectItem(keyRoot, "li"); ad = cJSON_GetObjectItem(keyRoot, "ad"); st = cJSON_GetObjectItem(keyRoot, "st"); et = cJSON_GetObjectItem(keyRoot, "et"); id = cJSON_GetObjectItem(keyRoot, "id"); unsigned char first_half_char_key[512] = { 0 }; unsigned char mykey_custom[512] = { 0 }; //unsigned char expandedmykey_custom[176] = { 0 }; char mygmail_after_ddDec[512] = { 0 }; // If lilin ID and independent face license are not consistent, the verification will fail. if (!id && unlock_key && strlen(unlock_key->valuestring) >= 4 && strncmp(unlock_key->valuestring, "face", 4) != 0) { printf("[ERROR] Null System ID\n"); //printf("\n--------------unlock_key->valuestring:%s\n", unlock_key->valuestring); memcpy(first_half_char_key, unlock_key->valuestring, 16); if ((int)strlen((char *)first_half_char_key) < 16) { for (int i = (int)strlen((char *)first_half_char_key); i < 16; i++) { first_half_char_key[i] = '0'; } } //printf("\n--------------first_half_char_key:%s\n", first_half_char_key); ddDec(unlock_key->valuestring, mygmail_after_ddDec); //printf("\n---------------mygmail_after_ddDec: %s\n", mygmail_after_ddDec); if (strstr(mygmail_after_ddDec, "@") != NULL && strstr(mygmail_after_ddDec, "email:") != NULL) { for (int i = 0; i < 16; i++) { //mykey_custom[i] = first_half_char_key[i]; sprintf((char*)mykey_custom + i * 2, "%02x", (char*)first_half_char_key[i]); } //printf("\n---------------mykey_custom: %s\n", mykey_custom); check_if_correct_mail = 1; } } else { //printf("System ID: %s\n", id->valuestring); } //取得隱藏資訊 strcpy(g_filename_TLT, TLT_FILE_NAME); //strcpy(filename2, exePath); //first time if (!FileExist(g_filename_TLT) || ReadFileSize(g_filename_TLT) == 0) { printf("TLT file doesn't exist.\n"); //create gysetting.json with current time { time_t now_time = time(0); char strLaunchTime[16] = { 0 }; snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); //將本次執行時間加密, 寫入檔案 //if (!(last_launch_time > now_time)) { KeyExpansion(key, expandedKey); unsigned char EncryptData[1 * 1024]; memset(EncryptData, 0x00, sizeof(EncryptData)); int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); size_t base64_encode_length = 0; char launchTime[1024] = { 0 }; base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); *(launchTime + base64_encode_length) = '\0'; cJSON *s_root = cJSON_CreateObject(); cJSON_AddItemToObject(s_root, "TLT code", cJSON_CreateString(launchTime)); cJSON_AddItemToObject(s_root, "VM code", cJSON_CreateString("%")); char* JsonString = cJSON_Print(s_root); FILE *f = fopen(g_filename_TLT, "w"); if (f == NULL) { printf("Error opening setting file!\n"); } else { fprintf(f, "%s\n", JsonString); fclose(f); } if (JsonString) { free(JsonString); JsonString = NULL; } if (s_root) { free(s_root); s_root = NULL; } } } } //printf("\n----------------mode: %s\n", WeightFileModeName); int bMacMatch = 0; if (g_match_mac == 1) { bMacMatch = 1; } //int nEnableNIC = 0; char * find; ///取得mac { char fetch_mac_addr[64] = { 0 }; memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); GetMACAddress(fetch_mac_addr); //printf("\n--------------------------:25\n"); //http_mac_address = fetch_mac_addr; //printf("\nfetch_mac_addr:%s\n", fetch_mac_addr); //printf("\nid->valuestring:%s\n", id->valuestring); find = strchr(fetch_mac_addr, '\n'); if (find) *find = '\0'; strcpy(g_mac_address, fetch_mac_addr); } //printf("111-9 get password = %s \n", accountData[0].account_password); // Check SDK3.0 and independent face license #ifdef GY_OS_AMBA #if 0 if (g_IsSDK_3_0 == 1 && unlock_key && strncmp(unlock_key->valuestring, "face", 4) == 0) { unlockingKeyInnoFR = 1; // printf("unlocking key : %s\n", unlock_key->valuestring); char temp_key[512] = { 0 }; //memcpy(temp_key, unlock_key->valuestring + 4, strlen(unlock_key->valuestring) - 4); char formatted_mac[30] = { 0 }; #if 0 char fetch_mac_addr[30] = { 0 }; //printf("\n--------g_mac_address:%s\n", g_mac_address); strcpy(fetch_mac_addr, g_mac_address); char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); //printf("\n--------new_mac_addr:%s\n", new_mac_addr); //sprintf(formatted_mac, "%s", new_mac_addr + 2); if (new_mac_addr) { free(new_mac_addr); new_mac_addr = NULL; } #endif getContractSignature(temp_key, formatted_mac); //printf("\n--------formatted_mac:%s\n", formatted_mac); //printf("\n--------temp_key:%s\n", temp_key); memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); strcpy(strUnlockingKey,"face"); strcat(strUnlockingKey, temp_key); char object_key[512] = { 0 }; strcpy(object_key, unlock_key->valuestring+4); if (strcmp(temp_key, object_key)!=0) { //printf("\nAAAAAAAAAA:Diff\n"); char buffer_content[1024] = { 0 }; strcpy(buffer_content,"{\"unlocking_key\":\""); strcat(buffer_content,strUnlockingKey); strcat(buffer_content,"\"}"); update_config(buffer_content); } else { //printf("\nAAAAAAAAAA:OK\n"); } unlockingKeyInnoFR_success = faceengine_start_and_check_license(); // if strat faceengine earlily(when getContractSignature), faceengine will stuck //unlockingKeyInnoFR_success = 1;//不啟動faceengine,看能不能進去網頁 //if (unlockingKeyInnoFR_success == 1) //{ //} } #endif #endif #ifdef GY_OS_AMBA if (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0 || strcmp(WeightFileModeName, "mod003") == 0 || strcmp(WeightFileModeName, "mod004") == 0) { if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring, "auto") == 0) { check_if_fe_fail = 1; } } #else if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring,"auto")==0) { check_if_fe_fail = 1; } #endif if ((fe && fe2 && li && st && et && id && td_weight_num == 0) || (td_weight_num >= 1 && check_if_correct_mail == 1) || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { //取得授權時間 time_t start_time; time_t end_time; struct tm* m_time; if (fe && fe2) { featureType = fe->valueint; featureType2 = fe2->valueint; stAMBAcontent.featureType = featureType; stAMBAcontent.featureType2 = featureType2; } /*else if (unlockingKeyInnoFR_success == 1) { featureType = FEATURE_EMPTY; featureType2 = FEATURE_AIFACE; stAMBAcontent.featureType = FEATURE_EMPTY; stAMBAcontent.featureType2 = FEATURE_AIFACE; }*/ else if (check_if_fe_fail == 1) { featureType = FEATURE_TRAF_DET; #ifdef GY_OS_V_SERIES featureType2 = FEATURE_AIFLOW; #elif defined GY_OS_NOVA featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; #else /*if (g_check_if_OK_getfeatures == 0) { featureType2 = FEATURE_AIFLOW; } else*/ featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; #endif stAMBAcontent.featureType = featureType; stAMBAcontent.featureType2 = featureType2; } else { featureType = 0x0000; featureType2 = 0x0000; stAMBAcontent.featureType = 0x0000; stAMBAcontent.featureType2 = 0x0000; } if (li && st && et && id) { start_time = st->valueint; m_time = gmtime(&start_time); m_time->tm_mday += et->valueint; end_time = mktime(m_time); g_start_time = start_time; g_end_time = end_time; } else { start_time = 0; end_time = 0; g_start_time = start_time; g_end_time = end_time; } if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIRADAR) == FEATURE_AIRADAR) { g_IsRadarDevice = 1; printf("g_IsRadarDevice : %d\n", g_IsRadarDevice); printf("g_IsRadarFake : %d\n", g_IsRadarFake); } if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AITOF) == FEATURE_AITOF) { g_IsToFDevice = 1; printf("\ng_IsToFDevice : %d\n", g_IsToFDevice); } if (td_weight_num >= 1 && check_if_correct_mail == 1) { g_IsCustomWeight = 1; printf("\ng_IsCustomWeight : %d\n", g_IsCustomWeight); //featureType = FEATURE_ACCESS_CTRL; //featureType2 = 0x0000; //stAMBAcontent.featureType = FEATURE_ACCESS_CTRL; //stAMBAcontent.featureType2 = 0x0000; } //printf("111-8 get password = %s \n", accountData[0].account_password); // printf("Check licence:\n"); //printf("--------------featureType = 0x%x \n", featureType); //printf("--------------featureType2 = 0x%x \n", featureType2); // printf("--------------li->valueint: %d\n", li->valueint); // printf("--------------st->valueint: %d\n", st->valueint); // printf("--------------et->valueint: %d\n", et->valueint); // printf("--------------id->valueint: %d\n", id->valueint); ///////////////////////////////////////////////////////以上為featuretype 取得的地方 /* if (strstr(EncryptKeyData, "@") == NULL) { printf("\nThere is no @.\n"); } else { printf("\nThere is existing @.\n"); }*/ //取得MAC Address //20201111 sophia add if (g_match_mac == 0) { char fetch_mac_addr[30] = { 0 }; strcpy(fetch_mac_addr, g_mac_address); char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); //printf("new_mac_addr = %s\n", new_mac_addr); //char* find_lilin_mac = strstr((const char*)new_mac_addr, "000FFC"); //begin 00-0f-fc //000FFC if (strstr(new_mac_addr, "000FFC") != NULL || strstr(new_mac_addr, "142FFD") != NULL) { if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { if (id && strcmp(id->valuestring, new_mac_addr) == 0) { //printf("find_lilin_mac = 0x%x\n", find_lilin_mac); bMacMatch = 1; //找到符合的MAC address g_match_mac = 1; g_bMacMatch = bMacMatch; } else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { bMacMatch = 1; g_match_mac = 1; g_bMacMatch = bMacMatch; } else { bMacMatch = 0; g_match_mac = 0; g_bMacMatch = bMacMatch; } } else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { bMacMatch = 1; g_match_mac = 1; g_bMacMatch = bMacMatch; } else if(check_if_correct_mail == 1){ bMacMatch = 1; g_match_mac = 1; g_bMacMatch = bMacMatch; } /*else if (g_IsRadarDevice == 1) {//現在有key了,就需要找到符合的MAC address bMacMatch = 1; g_match_mac = 1; } else if (g_IsToFDevice == 1)//現在有key了,就需要找到符合的MAC address { bMacMatch = 1; g_match_mac = 1; }*/ else { bMacMatch = 0; g_match_mac = 0; g_bMacMatch = bMacMatch; } } else { g_match_mac = 0; printf("\n============This is not LILIN mac address.\n"); } /* printf("\ng_match_mac: %d\n", g_match_mac); printf("\ng_mac_address: %s\n", g_mac_address); */ if (new_mac_addr) { free(new_mac_addr); new_mac_addr = NULL; } } //printf("111-711 0 get password = %s \n", accountData[0].account_password); update_system_time(); if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && g_IsRadarDevice == 0 && unlockingKeyInnoFR_success == 0) { if (li) g_li = li->valueint; else g_li = 0; if (ad) g_ad = ad->valueint; else g_ad = 0; if (ad && li) check_license(li->valueint, ad->valueint, bMacMatch, start_time, end_time, g_filename_TLT); else if(li) check_license(li->valueint, 0, bMacMatch, start_time, end_time, g_filename_TLT); else check_license(0, 0, bMacMatch, start_time, end_time, g_filename_TLT); } check_feature(); //printf("111-7 0 get password = %s \n", accountData[0].account_password); //post events setting //char filename2[] = "events.json"; char *filename2 = eventsPATH; char *filename_tof = tofPATH; if (!FileExist(filename2)) { printf("%s doesn't exist.\n", filename2); printf("Press any key to exit...\n"); getchar(); return; } if (!FileExist(filename_tof)) { printf("%s doesn't exist.\n", filename_tof); printf("Press any key to exit...\n"); getchar(); return; } //printf("111-7 1 get password = %s \n", accountData[0].account_password); cJSON *tof_root; cJSON *tof_version,*tof_debug,*tof_install_angle,*tof_enable_camera,*enable_tof_ground,*enable_tof_wall,*tof_camera; cJSON *tof_camera_ip,*tof_camera_port,*tof_camera_sub_url,*tof_auth_key,*tof_ip_setting,*tof_camera_username,*tof_camera_password; cJSON *distance_options, *distance_threshold, *height_options, *height_threshold,*distance_min_max,*height_min_max; cJSON *ground_x, *ground_y; fileBuf = ReadAllBytes(filename_tof); if (fileBuf) { tof_root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; tof_version = cJSON_GetObjectItem(tof_root, "version"); tof_debug = cJSON_GetObjectItem(tof_root, "debug"); tof_install_angle = cJSON_GetObjectItem(tof_root, "install_angle"); tof_enable_camera = cJSON_GetObjectItem(tof_root, "enable_camera"); enable_tof_ground = cJSON_GetObjectItem(tof_root, "enable_tof_ground"); enable_tof_wall = cJSON_GetObjectItem(tof_root, "enable_tof_wall"); tof_camera = cJSON_GetObjectItem(tof_root, "camera"); distance_options = cJSON_GetObjectItem(tof_root, "distance_options"); distance_threshold = cJSON_GetObjectItem(tof_root, "distance_threshold"); height_options = cJSON_GetObjectItem(tof_root, "height_options"); height_threshold = cJSON_GetObjectItem(tof_root, "height_threshold"); distance_min_max = cJSON_GetObjectItem(tof_root, "distance_min_max"); height_min_max = cJSON_GetObjectItem(tof_root, "height_min_max"); ground_x = cJSON_GetObjectItem(tof_root, "ground_x"); ground_y = cJSON_GetObjectItem(tof_root, "ground_y"); #ifdef GY_OS_AMBA if (tof_version) { tofData.tof_version = tof_version->valueint; } else { new_data_write_to_tof_file_flag = 1; tofData.tof_version = 1; } if (tof_debug) { if (cJSON_IsTrue(tof_debug)) { tofData.tof_debug = true; } else { tofData.tof_debug = false; } } else { new_data_write_to_tof_file_flag = 1; tofData.tof_debug = false; } if (tof_install_angle) { tofData.tof_install_angle = tof_install_angle->valueint; } else { new_data_write_to_tof_file_flag = 1; tofData.tof_install_angle = 90; } if (tof_enable_camera) { if (cJSON_IsTrue(tof_enable_camera)) { tofData.tof_enable_camera = true; } else { tofData.tof_enable_camera = false; } } else { new_data_write_to_tof_file_flag = 1; tofData.tof_enable_camera = false; } if (enable_tof_ground) { if (cJSON_IsTrue(enable_tof_ground)) { tofData.enable_tof_ground = true; } else { tofData.enable_tof_ground = false; } } else { new_data_write_to_tof_file_flag = 1; tofData.enable_tof_ground = false; } if (enable_tof_wall) { if (cJSON_IsTrue(enable_tof_wall)) { tofData.enable_tof_wall = true; } else { tofData.enable_tof_wall = false; } } else { new_data_write_to_tof_file_flag = 1; tofData.enable_tof_wall = false; } if (distance_options) { strcpy(tofData.distance_options, distance_options->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.distance_options, "lt"); } if (distance_min_max) { strcpy(tofData.distance_min_max, distance_min_max->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.distance_min_max, "min"); } if (distance_threshold) { strcpy(tofData.distance_threshold, distance_threshold->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.distance_threshold, "0.5"); } if (height_options) { strcpy(tofData.height_options, height_options->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.height_options, "gt"); } if (height_min_max) { strcpy(tofData.height_min_max, height_min_max->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.height_min_max, "max"); } if (ground_x) { strcpy(tofData.ground_x, ground_x->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.ground_x, "320"); } if (ground_y) { strcpy(tofData.ground_y, ground_y->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.ground_y, "240"); } if (height_threshold) { strcpy(tofData.height_threshold, height_threshold->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.height_threshold, "1.5"); } if (tof_camera) { tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); if (tof_camera_ip) { strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_ip, "192.168.50.200"); } if (tof_camera_port) { strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_port, "80"); } if (tof_camera_sub_url) { strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_sub_url, "/stream0"); } if (tof_auth_key) { strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); } if (tof_ip_setting) { if (cJSON_IsTrue(tof_ip_setting)) { tofData.tof_ip_setting = true; } else { tofData.tof_ip_setting = false; } } else { new_data_write_to_tof_file_flag = 1; tofData.tof_ip_setting = false; } if (tof_camera_username) { char temp_account[512] = { 0 }; urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); tofData.tof_camera_username[strlen(temp_account)] = '\0'; } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_username, "admin"); } if (tof_camera_password) { char temp_account[512] = { 0 }; urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); tofData.tof_camera_password[strlen(temp_account)] = '\0'; } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_password, "pass"); } } else { new_data_write_to_tof_file_flag = 1; strcpy(tofData.tof_camera_ip, "192.168.50.200"); strcpy(tofData.tof_camera_port, "80"); strcpy(tofData.tof_camera_sub_url, "/stream0"); strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); tofData.tof_ip_setting = false; strcpy(tofData.tof_camera_username, "admin"); strcpy(tofData.tof_camera_password, "pass"); } #endif } } //printf("111-7 2 get password = %s \n", accountData[0].account_password); cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content ,*post_customized_header; cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone,*counter_c_name, *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, *snmp_oid, *snmp_value, *snmp_type; cJSON *link_to_post_event_name, *post_interval; cJSON *email_setting,*email_content; cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; fileBuf = ReadAllBytes(filename2); if (fileBuf) { n_root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } notification = cJSON_GetObjectItem(n_root, "notification"); events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); enable_post = cJSON_GetObjectItem(notification, "enable_post"); http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; if (events_default_version) { strcpy(heartbeatData.events_default_version, events_default_version->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.events_default_version, "1"); } if (enable_snmp_post) activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; else { new_data_write_to_events_file_flag = 1; activeSNMPPost = _FALSE; } if (enable_heartbeat) { strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_heartbeat, "No"); } if (enable_snmp_heartbeat) { strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_snmp_heartbeat, "No"); } if (snmp_heartbeat_dwell) { strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); } if (snmp_heartbeat_link_to_post_event_name) { strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); } if (enable_check_ptz_start_autotracking) { strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); } if (enable_check_ptz_end_autotracking) { strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); } if (enable_only_once_to_post) { strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_only_once_to_post, "Yes"); } if (enable_obj_once_to_post) { strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); } if (enable_location_once_to_post) { strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_location_once_to_post, "Yes"); } if (enable_nvr_once_to_getalarmmotion) { strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); } if (enable_8592_once_to_getalarmmotion) { strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); } if (dwell_to_the_same_location) { strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.dwell_to_the_same_location, "5"); } if (heartbeat_dwell) { strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.heartbeat_dwell, "10"); } if (heatmap_max) { strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.heatmap_max, "100"); } if (enable_heatmap) { strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_heatmap, "No"); } if (heatmap_frequency) { strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.heatmap_frequency, "5"); } if (lpr_title) { strcpy(heartbeatData.lpr_title, lpr_title->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.lpr_title, "My Car Park"); } if (heartbeat_link_to_post_event_name) { strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); } if (ptz_start_autotracking_link_to_post_event_name) { strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); } if (ptz_end_autotracking_link_to_post_event_name) { strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); } if (enable_counter_snap) { strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_counter_snap, "No"); } if (enable_barcode_qr) { strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(heartbeatData.enable_barcode_qr, "No"); } int i = 0; cJSON_ArrayForEach(detect2, http_post_events) { post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); post_url = cJSON_GetObjectItem(detect2, "post_url"); post_username = cJSON_GetObjectItem(detect2, "post_username"); post_password = cJSON_GetObjectItem(detect2, "post_password"); post_content = cJSON_GetObjectItem(detect2, "post_content"); post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); char temp_account[512] = { 0 }; urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); postEventList[i].post_username[strlen(temp_account)] = '\0'; char temp_account2[512] = { 0 }; urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); postEventList[i].post_password[strlen(temp_account2)] = '\0'; strcpy(postEventList[i].post_protocol, post_protocol->valuestring); strcpy(postEventList[i].post_event_method, post_event_method->valuestring); strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); if (g_camera_white_LED == 1 && i == 2 && strcmp(postEventList[i].post_event_name, "Camera virtual 3 / White LED") != 0) { new_data_write_to_events_file_flag = 1; strcpy(postEventList[i].post_event_name, "Camera virtual 3 / White LED"); } strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); strcpy(postEventList[i].post_host_port, post_host_port->valuestring); strcpy(postEventList[i].post_url, post_url->valuestring); //strcpy(postEventList[i].post_username, post_username->valuestring); //strcpy(postEventList[i].post_password, post_password->valuestring); strcpy(postEventList[i].post_content, post_content->valuestring); strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); if (post_sequence) strcpy(postEventList[i].post_sequence, post_sequence->valuestring); else { strcpy(postEventList[i].post_sequence, ""); new_data_write_to_events_file_flag = 1; } if (post_timeout) strcpy(postEventList[i].post_timeout, post_timeout->valuestring); else { strcpy(postEventList[i].post_timeout, "5"); new_data_write_to_events_file_flag = 1; } if (post_file_format) strcpy(postEventList[i].post_file_format, post_file_format->valuestring); else { strcpy(postEventList[i].post_file_format, "text"); new_data_write_to_events_file_flag = 1; } if (post_jpeg_file_name_format) strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); else { strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); new_data_write_to_events_file_flag = 1; } if (post_jpeg_file_name) strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); else { strcpy(postEventList[i].post_jpeg_file_name, "snap"); new_data_write_to_events_file_flag = 1; } postEventList[i].check_if_delivering = 0;//其他地方不須再初始化 i++; } if (i < 9) { strcpy(postEventList[i].post_protocol, "HTTP"); strcpy(postEventList[i].post_event_method, "GET"); strcpy(postEventList[i].post_event_name, "Go to PTZ preset"); strcpy(postEventList[i].post_host_ip, "localhost"); strcpy(postEventList[i].post_host_port, accountData[0].account_aida_port); strcpy(postEventList[i].post_url, "/ptzpreset?camid=1&ai_goto_preset=1"); strcpy(postEventList[i].post_username, "admin"); strcpy(postEventList[i].post_password, "Pass1234"); strcpy(postEventList[i].post_content, ""); strcpy(postEventList[i].post_customized_header, ""); strcpy(postEventList[i].post_sequence, ""); strcpy(postEventList[i].post_file_format, "text"); strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); strcpy(postEventList[i].post_jpeg_file_name, "snap"); strcpy(postEventList[i].post_timeout, "5"); new_data_write_to_events_file_flag = 1; } #ifdef GY_OS_V_SERIES #else event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); i = 0; cJSON_ArrayForEach(detect3, event_counters) { counter_name = cJSON_GetObjectItem(detect3, "counter_name"); counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); reset_value = cJSON_GetObjectItem(detect3, "reset_value"); enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); reset_at = cJSON_GetObjectItem(detect3, "reset_at"); enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); post_interval = cJSON_GetObjectItem(detect3, "post_interval"); strcpy(eventCounterList[i].counter_name, counter_name->valuestring); if (counter_cust_name) strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); else { strcpy(eventCounterList[i].counter_cust_name, eventCounterList[i].counter_name); new_data_write_to_events_file_flag = 1; } strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); if (reset_value) eventCounterList[i].reset_value = atoi(reset_value->valuestring); else { eventCounterList[i].reset_value = 0; new_data_write_to_events_file_flag = 1; } strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); strcpy(eventCounterList[i].reset_at, reset_at->valuestring); strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); struct tm tm; strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); eventCounterList[i].timetResetAt = mktime(&tm); struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); eventCounterList[i].reset_month = resetTime->tm_mon; eventCounterList[i].reset_month_day = resetTime->tm_mday; eventCounterList[i].reset_week_day = resetTime->tm_wday; eventCounterList[i].reset_hour = resetTime->tm_hour; eventCounterList[i].reset_min = resetTime->tm_min; eventCounterList[i].reset_sec = resetTime->tm_sec; strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); eventCounterList[i].timetTimeRangeFrom = mktime(&tm); strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); eventCounterList[i].timetTimeRangeTo = mktime(&tm); if (link_to_post_event_name) { strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(eventCounterList[i].link_to_post_event_name, ""); } if (post_interval) { strcpy(eventCounterList[i].post_interval, post_interval->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(eventCounterList[i].post_interval, "5 minutes"); } if (enable_reset_only_cloud) { strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); } if (enable_linked_to_dwell_time) { strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); } i++; } if (i < 8) { new_data_write_to_events_file_flag = 1; } report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); if (report_counters) { i = 0; cJSON_ArrayForEach(a_report, report_counters) { if (a_report) { counter_a = cJSON_GetObjectItem(a_report, "counter_a"); counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); counter_b = cJSON_GetObjectItem(a_report, "counter_b"); counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); enable_report = cJSON_GetObjectItem(a_report, "enable_report"); counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); detection_output = cJSON_GetObjectItem(a_report, "detection_output"); output_icon = cJSON_GetObjectItem(a_report, "output_icon"); if (counter_a) { strcpy(reportCounterList[i].counter_a, counter_a->valuestring); } else { strcpy(reportCounterList[i].counter_a, "Counter01"); new_data_write_to_events_file_flag = 1; } if (counter_a_name) { strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); } else { strcpy(reportCounterList[i].counter_a_name, "Name"); new_data_write_to_events_file_flag = 1; } if (counter_a_zone) { strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); } else { strcpy(reportCounterList[i].counter_a_zone, "1"); new_data_write_to_events_file_flag = 1; } if (counter_b) { strcpy(reportCounterList[i].counter_b, counter_b->valuestring); } else { strcpy(reportCounterList[i].counter_b, ""); new_data_write_to_events_file_flag = 1; } if (counter_b_name) { strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); } else { strcpy(reportCounterList[i].counter_b_name, ""); new_data_write_to_events_file_flag = 1; } if (counter_b_zone) { strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); } else { strcpy(reportCounterList[i].counter_b_zone, "0"); new_data_write_to_events_file_flag = 1; } if (counter_c_name) { strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); } else { strcpy(reportCounterList[i].counter_c_name, ""); new_data_write_to_events_file_flag = 1; } if (report_max_value) { strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); } else { strcpy(reportCounterList[i].report_max_value, "100"); new_data_write_to_events_file_flag = 1; } if (enable_report) { strcpy(reportCounterList[i].enable_report, enable_report->valuestring); } else { strcpy(reportCounterList[i].enable_report, "No"); new_data_write_to_events_file_flag = 1; } if (counter_mode) { strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); } else { strcpy(reportCounterList[i].counter_mode, "0"); new_data_write_to_events_file_flag = 1; } if (initial_icon) { strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); } else { strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); new_data_write_to_events_file_flag = 1; } if (detection_output) { strcpy(reportCounterList[i].detection_output, detection_output->valuestring); } else { strcpy(reportCounterList[i].detection_output, "No entry for cars"); new_data_write_to_events_file_flag = 1; } if (output_icon) { strcpy(reportCounterList[i].output_icon, output_icon->valuestring); } else { strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); new_data_write_to_events_file_flag = 1; } i++; } } if (i < MAX_REPORT_COUNTERS) { for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { strcpy(reportCounterList[index_report].counter_a, "Counter01"); strcpy(reportCounterList[index_report].counter_a_name, "Name"); strcpy(reportCounterList[index_report].counter_a_zone, "1"); strcpy(reportCounterList[index_report].counter_b, ""); strcpy(reportCounterList[index_report].counter_b_name, ""); strcpy(reportCounterList[index_report].counter_b_zone, "0"); strcpy(reportCounterList[index_report].counter_c_name, ""); strcpy(reportCounterList[index_report].report_max_value, "100"); strcpy(reportCounterList[index_report].enable_report, "No"); strcpy(reportCounterList[index_report].counter_mode, "0"); strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); } new_data_write_to_events_file_flag = 1; } } else { for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { strcpy(reportCounterList[index_report].counter_a, "Counter01"); strcpy(reportCounterList[index_report].counter_a_name, "Name"); strcpy(reportCounterList[index_report].counter_a_zone, "1"); strcpy(reportCounterList[index_report].counter_b, ""); strcpy(reportCounterList[index_report].counter_b_name, ""); strcpy(reportCounterList[index_report].counter_b_zone, "0"); strcpy(reportCounterList[index_report].counter_c_name, ""); strcpy(reportCounterList[index_report].report_max_value, "100"); strcpy(reportCounterList[index_report].enable_report, "No"); strcpy(reportCounterList[index_report].counter_mode, "0"); strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); } new_data_write_to_events_file_flag = 1; } snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); if (snmp_management) { i = 0; cJSON_ArrayForEach(a_snmp, snmp_management) { if (a_snmp) { snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); if (snmp_event_name) { strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); } else { char temp_name[10] = { 0 }; sprintf(temp_name, "SNMP %d", i + 1); strcpy(SNMPManagementList[i].snmp_event_name, temp_name); new_data_write_to_events_file_flag = 1; } if (snmp_version) { strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); } else { strcpy(SNMPManagementList[i].snmp_version, "v1"); new_data_write_to_events_file_flag = 1; } if (snmp_group_name) { strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); } else { strcpy(SNMPManagementList[i].snmp_group_name, "public"); new_data_write_to_events_file_flag = 1; } if (snmp_host_ip) { strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); } else { strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); new_data_write_to_events_file_flag = 1; } if (snmp_host_port) { strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); } else { strcpy(SNMPManagementList[i].snmp_host_port, "161"); new_data_write_to_events_file_flag = 1; } if (snmp_oid) { strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); } else { strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); new_data_write_to_events_file_flag = 1; } if (snmp_value) { strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); } else { strcpy(SNMPManagementList[i].snmp_value, "mylocation"); new_data_write_to_events_file_flag = 1; } if (snmp_type) { strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); } else { strcpy(SNMPManagementList[i].snmp_type, "string"); new_data_write_to_events_file_flag = 1; } SNMPManagementList[i].check_if_delivering = 0;//其他地方不須再初始化 i++; } } if (i < MAX_SNMP_MANAGEMENT) { for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { char temp_name[10] = { 0 }; if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { sprintf(temp_name, "SNMP %d", index_snmp + 1); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } else { sprintf(temp_name, "%s", "Heartbeat"); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } SNMPManagementList[index_snmp].check_if_delivering = 0;//其他地方不須再初始化 } new_data_write_to_events_file_flag = 1; } } else { for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { char temp_name[10] = { 0 }; if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { sprintf(temp_name, "SNMP %d", index_snmp + 1); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } else { sprintf(temp_name, "%s", "Heartbeat"); strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); } SNMPManagementList[index_snmp].check_if_delivering = 0;//其他地方不須再初始化 } new_data_write_to_events_file_flag = 1; } #endif email_setting = cJSON_GetObjectItem(n_root, "email_setting"); if (email_setting) { email_content = cJSON_GetObjectItem(email_setting, "email_content"); if (email_content) { strcpy(emailData.email_content, email_content->valuestring); } else { new_data_write_to_events_file_flag = 1; strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); } } else { new_data_write_to_events_file_flag = 1; strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); } } //printf("111-7 3 get password = %s \n", accountData[0].account_password); //trigger events settings //cJSON* cam_ip, * http_port, * video_port, * cam_pwd, * channel_id; cJSON *view_setting, *camera, *camera_name, *enable_anpr, *enable_face, *enable_traffic, *enable_logo, *tab_view_size, *enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, *enable_track,*enable_PTZ, *ptz_tracking_fov_min, *ptz_tracking_fov_max, *ptz_enable_tracking, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, *cJSON_enable_only_show_metadata1, *count_zone, *ivs_mode, *detection_zone, *detect, *ptz_tracking_mode, *levenshtein_distance, *min_characters, *max_characters, *obj_min_proportion, *obj_max_proportion, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, *point_number, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5 = NULL, *y5, *x6 = NULL, *y6, *ptz_zone_to_preset = NULL, *enable_speed, *set_distance, *world_distance_unit, *world_distance_side1, *world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered, *unknown_object_max_proportion, *unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object, *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; //root = cJSON_Parse(fileBuf); view_setting = cJSON_GetObjectItem(root, "view_setting"); //printf("111-7 get password = %s \n", accountData[0].account_password); for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) { char CameraID[20] = { 0 }; sprintf(CameraID, "camera%02d", n + 1); camera = cJSON_GetObjectItem(view_setting, CameraID); /*cam_ip = cJSON_GetObjectItem(camera, "ip"); http_port = cJSON_GetObjectItem(camera, "http_port"); video_port = cJSON_GetObjectItem(camera, "video_port"); cam_username = cJSON_GetObjectItem(camera, "username"); cam_pwd = cJSON_GetObjectItem(camera, "password"); channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ camera_name = cJSON_GetObjectItem(camera, "camera_name"); levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); min_characters = cJSON_GetObjectItem(camera, "min_characters"); max_characters = cJSON_GetObjectItem(camera, "max_characters"); obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 confidence3 = cJSON_GetObjectItem(camera, "confidence3"); confidence4 = cJSON_GetObjectItem(camera, "confidence4"); count_zone = cJSON_GetObjectItem(camera, "count_zone"); strcpy(viewChannelData[n].camera_name, camera_name->valuestring); strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); strcpy(viewChannelData[n].min_characters, min_characters->valuestring); strcpy(viewChannelData[n].max_characters, max_characters->valuestring); strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); if (plate_filter_times) viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); else { viewChannelData[n].i_plate_filter_times = 4; new_data_write_to_config_file_flag = 1; } if (plate_filter_time) viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); else { viewChannelData[n].i_plate_filter_time = 3; new_data_write_to_config_file_flag = 1; } if (plate_free_time) viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); else { viewChannelData[n].i_plate_free_time = 3; new_data_write_to_config_file_flag = 1; } strcpy(viewChannelData[n].confidence, confidence->valuestring); strcpy(viewChannelData[n].confidence2, confidence2->valuestring); strcpy(viewChannelData[n].confidence3, confidence3->valuestring); strcpy(viewChannelData[n].confidence4, confidence4->valuestring); if (count_zone) viewChannelData[n].count_zone = count_zone->valueint; else { viewChannelData[n].count_zone = 1; new_data_write_to_config_file_flag = 1; } //printf("\nenable_lpr_db-----8\n"); pthread_mutex_lock(&mutex_enable_lpr_db); enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); if (enable_lpr_db) strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); else { strcpy(viewChannelData[n].enable_lpr_db, "Yes"); new_data_write_to_config_file_flag = 1; } pthread_mutex_unlock(&mutex_enable_lpr_db); enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); if (enable_downsized_cropped_roi) { set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); } else { set_enable_downsized_cropped_roi(1); new_data_write_to_config_file_flag = 1; } enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); if (enable_zone_crop_1) { set_enable_zone_crop_1(enable_zone_crop_1->valueint); } else { set_enable_zone_crop_1(0); new_data_write_to_config_file_flag = 1; } enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); if (enable_add_face_frequent_list) if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) viewChannelData[n].enable_add_face_frequent_list = 1; else viewChannelData[n].enable_add_face_frequent_list = 0; else { viewChannelData[n].enable_add_face_frequent_list = 1; new_data_write_to_config_file_flag = 1; } enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); if (enable_PTZ) strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); else { strcpy(viewChannelData[n].enable_PTZ, "No"); new_data_write_to_config_file_flag = 1; } enable_track = cJSON_GetObjectItem(camera, "enable_track"); if (enable_track) strcpy(viewChannelData[n].enable_track, enable_track->valuestring); else { strcpy(viewChannelData[n].enable_track, "No"); new_data_write_to_config_file_flag = 1; } ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); if (ptz_tracking_fov_min) strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); else { strcpy(viewChannelData[n].ptz_tracking_fov_min, "0"); new_data_write_to_config_file_flag = 1; } ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); if (ptz_tracking_fov_max) strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); else { strcpy(viewChannelData[n].ptz_tracking_fov_max, "40"); new_data_write_to_config_file_flag = 1; } ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); if (ptz_enable_tracking) strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); else { strcpy(viewChannelData[n].ptz_enable_tracking, "Yes"); new_data_write_to_config_file_flag = 1; } //Tracking MODE //1: First in First out //2: Bigger first //3: All ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); if (ptz_tracking_mode) viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); else { viewChannelData[n].ptz_tracking_mode = 1; new_data_write_to_config_file_flag = 1; } ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); if (ptz_tracking_by_enter_zone) { if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) viewChannelData[n].ptz_tracking_by_enter_zone = 1; else viewChannelData[n].ptz_tracking_by_enter_zone = 0; } else { viewChannelData[n].ptz_tracking_by_enter_zone = 1; new_data_write_to_config_file_flag = 1; } enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); if (enable_tracking_limits) strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); else { strcpy(viewChannelData[n].enable_tracking_limits, "No"); new_data_write_to_config_file_flag = 1; } ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); if (ptz_pan_left_limit) strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); else { strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); new_data_write_to_config_file_flag = 1; } ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); if (ptz_pan_right_limit) strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); else { strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); new_data_write_to_config_file_flag = 1; } ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); if (ptz_tilt_up_limit) strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); else { strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); new_data_write_to_config_file_flag = 1; } ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); if (ptz_tilt_down_limit) strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); else { strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); new_data_write_to_config_file_flag = 1; } ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); if (ptz_speed) strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); else { strcpy(viewChannelData[n].ptz_speed, "3"); new_data_write_to_config_file_flag = 1; } enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); if (enable_unknown_object) strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); else { strcpy(viewChannelData[n].enable_unknown_object, "No"); new_data_write_to_config_file_flag = 1; } enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); if (enable_ivs_person_detection) strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); else { strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); new_data_write_to_config_file_flag = 1; } assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); if (assign_ivs_object_to) strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); else { strcpy(viewChannelData[n].assign_ivs_object_to, ""); new_data_write_to_config_file_flag = 1; } enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); if (enable_ambulance) strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); else { strcpy(viewChannelData[n].enable_ambulance, "No"); new_data_write_to_config_file_flag = 1; } enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); if (enable_blank_plate) strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); else { strcpy(viewChannelData[n].enable_blank_plate, "No"); new_data_write_to_config_file_flag = 1; } enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); if (enable_stop_sign) strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); else { strcpy(viewChannelData[n].enable_stop_sign, "No"); new_data_write_to_config_file_flag = 1; } enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); if (enable_show_unknown_object) strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); else { strcpy(viewChannelData[n].enable_show_unknown_object, "No"); new_data_write_to_config_file_flag = 1; } enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); if (enable_ivs_fix_mode) strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); else { strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); new_data_write_to_config_file_flag = 1; } enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); if (enable_ivs_and_ai) strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); else { strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); new_data_write_to_config_file_flag = 1; } enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); if (enable_lpr_upon_triggered) strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); else { strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); new_data_write_to_config_file_flag = 1; } dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); if (dwell_lpr_upon_triggered) strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); else { strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); new_data_write_to_config_file_flag = 1; } ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); if (ivs_mode) strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); else { strcpy(viewChannelData[n].ivs_mode, "3"); new_data_write_to_config_file_flag = 1; } unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); if (unknown_object_max_proportion) strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); else { strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); new_data_write_to_config_file_flag = 1; } unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); if (unknown_object_min_proportion) strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); else { strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); new_data_write_to_config_file_flag = 1; } confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); if (confidence_unknown_object) strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); else { strcpy(viewChannelData[n].confidence_unknown_object, "0"); new_data_write_to_config_file_flag = 1; } confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); if (confidence2_unknown_object) strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); else { strcpy(viewChannelData[n].confidence2_unknown_object, "0"); new_data_write_to_config_file_flag = 1; } dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); if (dwell_unknown_object) strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); else { strcpy(viewChannelData[n].dwell_unknown_object, "30"); new_data_write_to_config_file_flag = 1; } dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); if (dwell_minute_focus_on) strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); else { strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); new_data_write_to_config_file_flag = 1; } person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); if (person_obj_fov) strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); else { strcpy(viewChannelData[n].person_obj_fov, "100"); new_data_write_to_config_file_flag = 1; } getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); if (getnetwork_buffer_id) strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); else { strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); new_data_write_to_config_file_flag = 1; } red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); if (red_light_zone) strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); else { strcpy(viewChannelData[n].red_light_zone, ""); new_data_write_to_config_file_flag = 1; } no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); if (no_give_way_zone_to_protect) strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); else { strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); new_data_write_to_config_file_flag = 1; } no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); if (no_give_way_zone_to_keep_away) strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); else { strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); new_data_write_to_config_file_flag = 1; } no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); if (no_give_way_zone_to_protect_2) strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); else { strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); new_data_write_to_config_file_flag = 1; } no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); if (no_give_way_zone_to_keep_away_2) strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); else { strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); new_data_write_to_config_file_flag = 1; } ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); if (ptz_sensitivity) viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); else { viewChannelData[n].ptz_sensitivity = 6; new_data_write_to_config_file_flag = 1; } ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); if (ptz_tracking_resume_dwell) strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); else { strcpy(viewChannelData[n].ptz_tracking_resume_dwell, "3"); new_data_write_to_config_file_flag = 1; } cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); if (cJSON_enable_only_show_metadata1) enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; else { enable_only_show_metadata1 = 0; new_data_write_to_config_file_flag = 1; } tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); //printf("\n[run_server]tab_view_size: %s\n", tab_view_size->valuestring); char outArray[2][STRSPLIT_SIZE]={0}; char temp_tab[50] = { 0 }; strcpy(temp_tab, tab_view_size->valuestring); StrSplit(temp_tab, outArray, "x"); //printf("\n------UU:16\n"); viewChannelData[n].channel_idx = n; if (outArray[0]) viewChannelData[n].tab_view_width = atoi(outArray[0]); else new_data_write_to_config_file_flag = 1; if (outArray[1]) viewChannelData[n].tab_view_height = atoi(outArray[1]); else new_data_write_to_config_file_flag = 1; enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); if (strcmp(enable_anpr->valuestring, "Yes") == 0) viewChannelData[n].enable_anpr = 1; else viewChannelData[n].enable_anpr = 0; enable_face = cJSON_GetObjectItem(camera, "enable_face"); if (enable_face) { if (strcmp(enable_face->valuestring, "Yes") == 0) viewChannelData[n].enable_face = 1; else viewChannelData[n].enable_face = 0; } else { new_data_write_to_config_file_flag = 1; viewChannelData[n].enable_face = 1; } enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); if (strcmp(enable_traffic->valuestring, "Yes") == 0) viewChannelData[n].enable_traffic = 1; else viewChannelData[n].enable_traffic = 0; enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); if (strcmp(enable_logo->valuestring, "Yes") == 0) viewChannelData[n].enable_logo = 1; else viewChannelData[n].enable_logo = 0; detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); viewChannelData[n].enable_traffic_light_zone = 0; int i = 0; cJSON_ArrayForEach(detect, detection_zone) { enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); detection_time = cJSON_GetObjectItem(detect, "detection_time"); metadata1 = cJSON_GetObjectItem(detect, "metadata1"); metadata2 = cJSON_GetObjectItem(detect, "metadata2"); metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); direction1 = cJSON_GetObjectItem(detect, "direction1"); direction2 = cJSON_GetObjectItem(detect, "direction2"); no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); parking_space = cJSON_GetObjectItem(detect, "parking_space"); parking_line = cJSON_GetObjectItem(detect, "parking_line"); set_distance = cJSON_GetObjectItem(detect, "set_distance"); world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); if (obj_max_proportion_in_zone) strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); else { strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, "80"); new_data_write_to_config_file_flag = 1; } if (obj_min_proportion_in_zone) strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); else { strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, "0"); new_data_write_to_config_file_flag = 1; } if (ptz_zone_to_preset) strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); else { strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, "0"); new_data_write_to_config_file_flag = 1; } if (enable_speed) strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); else { strcpy(viewDetectionZone[n][i].enable_speed, "No"); new_data_write_to_config_file_flag = 1; } if (enable_radar_speed) strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); else { strcpy(viewDetectionZone[n][i].enable_radar_speed, "No"); new_data_write_to_config_file_flag = 1; } if (enable_ivs_zone) strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); else { strcpy(viewDetectionZone[n][i].enable_ivs_zone, "No"); new_data_write_to_config_file_flag = 1; } if (parking_space) { viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); } else { viewDetectionZone[n][i].parking_space = 0; new_data_write_to_config_file_flag = 1; } if (parking_line) { viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); } else { viewDetectionZone[n][i].parking_line = 0; new_data_write_to_config_file_flag = 1; } if (set_distance) { viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); } else { viewDetectionZone[n][i].set_distance = 10; new_data_write_to_config_file_flag = 1; } if (world_distance_unit) strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); else { strcpy(viewDetectionZone[n][i].world_distance_unit, "meter"); new_data_write_to_config_file_flag = 1; } if (world_distance_side1) { viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); } else { viewDetectionZone[n][i].world_distance_side1 = 10; viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; new_data_write_to_config_file_flag = 1; } //printf("[%d]World dis 1 = %f \n", i, viewDetectionZone[n][i].world_distance_side1); if (world_distance_side2) { viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); } else { viewDetectionZone[n][i].world_distance_side2 = 10; viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; new_data_write_to_config_file_flag = 1; } //printf("[%d]World dis 2 = %f \n", i, viewDetectionZone[n][i].world_distance_side2); viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); if (world_time_unit) strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); else { strcpy(viewDetectionZone[n][i].world_time_unit, "KPH"); new_data_write_to_config_file_flag = 1; } trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); point_number = cJSON_GetObjectItem(detect, "point_number"); /* if (point_number) printf("load point number 2 = %d \n", point_number->valueint); */ x1 = cJSON_GetObjectItem(detect, "x1"); y1 = cJSON_GetObjectItem(detect, "y1"); x2 = cJSON_GetObjectItem(detect, "x2"); y2 = cJSON_GetObjectItem(detect, "y2"); x3 = cJSON_GetObjectItem(detect, "x3"); y3 = cJSON_GetObjectItem(detect, "y3"); x4 = cJSON_GetObjectItem(detect, "x4"); y4 = cJSON_GetObjectItem(detect, "y4"); x5 = cJSON_GetObjectItem(detect, "x5"); y5 = cJSON_GetObjectItem(detect, "y5"); x6 = cJSON_GetObjectItem(detect, "x6"); y6 = cJSON_GetObjectItem(detect, "y6"); strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); if (metadata_stop) strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); else { strcpy(viewDetectionZone[n][i].metadata_stop, ""); new_data_write_to_config_file_flag = 1; } if (no_parking_time) viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); else { viewDetectionZone[n][i].no_parking_time = 5; new_data_write_to_config_file_flag = 1; } if (no_parking_time_in_minute) viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); else { viewDetectionZone[n][i].no_parking_time_in_minute = 0; new_data_write_to_config_file_flag = 1; } if (queuing_count && strlen(queuing_count->valuestring) >= 1) viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); else { viewDetectionZone[n][i].queuing_count = 1; new_data_write_to_config_file_flag = 1; } if (point_number) viewDetectionZone[n][i].point_num = point_number->valueint; else { viewDetectionZone[n][i].point_num = 6; new_data_write_to_config_file_flag = 1; } viewDetectionZone[n][i].Points[0].x = x1->valueint; viewDetectionZone[n][i].Points[0].y = y1->valueint; viewDetectionZone[n][i].Points[1].x = x2->valueint; viewDetectionZone[n][i].Points[1].y = y2->valueint; viewDetectionZone[n][i].Points[2].x = x3->valueint; viewDetectionZone[n][i].Points[2].y = y3->valueint; viewDetectionZone[n][i].Points[3].x = x4->valueint; viewDetectionZone[n][i].Points[3].y = y4->valueint; viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); if (x5 && x6) { viewDetectionZone[n][i].Points[4].x = x5->valueint; viewDetectionZone[n][i].Points[4].y = y5->valueint; viewDetectionZone[n][i].Points[5].x = x6->valueint; viewDetectionZone[n][i].Points[5].y = y6->valueint; viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); } else new_data_write_to_config_file_flag = 1; strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) { viewChannelData[n].enable_traffic_light_zone = i + 1; //UpdateTrafficLightZone(n); } #ifdef GY_OS_AMBA if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) { int social_zone_idx = i; if (social_zone_idx >= 0) { pthread_mutex_lock(&mutex_perspective_transform); if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); pthread_mutex_unlock(&mutex_perspective_transform); } } #endif i++; if (i < MAX_DETECTION_ZONE) { } else { break; } } int original_zone_size = i; //int arraySize = cJSON_GetArraySize(detection_zone); int k = 0; for (int j = 0; j < MAX_DETECTION_ZONE && j < original_zone_size; j++) { k = 0; cJSON_ArrayForEach(detect, trigger_events[j]) { checked = cJSON_GetObjectItem(detect, "checked"); detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); counter_name = cJSON_GetObjectItem(detect, "counter_name"); counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); if (!detect_event_id || !detect_event_name || strlen(detect_event_id->valuestring) == 0 || strlen(detect_event_name->valuestring) == 0) { new_data_write_to_config_file_flag = 1; } else { viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); if (counter_increment) { if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; else viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; } else viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; } k++; } if (k < MAX_TRIGGER_EVENT) { if(k < 10) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00800000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Visitor list"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 11) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x01000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Unattended object or missing object"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 12) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x02000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "BG learning"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 13) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x04000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Tampering detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 14) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x40000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "All objects detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 15) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x80000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lack of any object detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 16) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00002000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Over speed detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 17) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00004000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lower speed detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 18) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000400"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Running red lights"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 19) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000800"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning left on red"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 20) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00001000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning right on red"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 21) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00008000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Forget to give way detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 22) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00040000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Distance violation"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } if (k < 23) { viewDetectionZone[n][j].trigger_event[k].checked = 0; strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x08000000"); strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Height detection"); strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; k++; } new_data_write_to_config_file_flag = 1; } } if (original_zone_size < MAX_DETECTION_ZONE) { for (int index_zone = original_zone_size; index_zone < MAX_DETECTION_ZONE; index_zone++) { strcpy(viewDetectionZone[n][index_zone].obj_max_proportion_in_zone, "80"); strcpy(viewDetectionZone[n][index_zone].obj_min_proportion_in_zone, "0"); strcpy(viewDetectionZone[n][index_zone].ptz_zone_to_preset, "0"); strcpy(viewDetectionZone[n][index_zone].enable_speed, "No"); strcpy(viewDetectionZone[n][index_zone].enable_radar_speed, "No"); strcpy(viewDetectionZone[n][index_zone].enable_ivs_zone, "No"); viewDetectionZone[n][index_zone].parking_space = 0; viewDetectionZone[n][index_zone].parking_line = 0; viewDetectionZone[n][index_zone].set_distance = 10; strcpy(viewDetectionZone[n][index_zone].world_distance_unit, "meter"); viewDetectionZone[n][index_zone].world_distance_side1 = 10; viewDetectionZone[n][index_zone].world_distance[0] = viewDetectionZone[n][index_zone].world_distance_side1; viewDetectionZone[n][index_zone].world_distance[2] = viewDetectionZone[n][index_zone].world_distance_side1; viewDetectionZone[n][index_zone].world_distance_side2 = 10; viewDetectionZone[n][index_zone].world_distance[1] = viewDetectionZone[n][index_zone].world_distance_side2; viewDetectionZone[n][index_zone].world_distance[3] = viewDetectionZone[n][index_zone].world_distance_side2; strcpy(viewDetectionZone[n][index_zone].world_time_unit, "KPH"); strcpy(viewDetectionZone[n][index_zone].detection_time, ""); strcpy(viewDetectionZone[n][index_zone].metadata1, ""); strcpy(viewDetectionZone[n][index_zone].metadata2, ""); strcpy(viewDetectionZone[n][index_zone].metadata_stop, ""); strcpy(viewDetectionZone[n][index_zone].link_to_counter, ""); strcpy(viewDetectionZone[n][index_zone].enable_direction1, "No"); strcpy(viewDetectionZone[n][index_zone].enable_direction2, ""); strcpy(viewDetectionZone[n][index_zone].direction1, "1"); strcpy(viewDetectionZone[n][index_zone].direction2, ""); viewDetectionZone[n][index_zone].no_parking_time = 5; viewDetectionZone[n][index_zone].no_parking_time_in_minute = 0; viewDetectionZone[n][index_zone].queuing_count = 1; viewDetectionZone[n][index_zone].point_num = 6; viewDetectionZone[n][index_zone].Points[0].x = 19; viewDetectionZone[n][index_zone].Points[0].y = 16; viewDetectionZone[n][index_zone].Points[1].x = 19; viewDetectionZone[n][index_zone].Points[1].y = 250; viewDetectionZone[n][index_zone].Points[2].x = 19; viewDetectionZone[n][index_zone].Points[2].y = 484; viewDetectionZone[n][index_zone].Points[3].x = 870; viewDetectionZone[n][index_zone].Points[3].y = 484; viewDetectionZone[n][index_zone].Points[4].x = 870; viewDetectionZone[n][index_zone].Points[4].y = 250; viewDetectionZone[n][index_zone].Points[5].x = 870; viewDetectionZone[n][index_zone].Points[5].y = 16; viewDetectionZone[n][index_zone].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].y, CANVAS_HEIGHT / 2); viewDetectionZone[n][index_zone].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].y, CANVAS_HEIGHT / 2); viewDetectionZone[n][index_zone].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].y, CANVAS_HEIGHT / 2); viewDetectionZone[n][index_zone].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].y, CANVAS_HEIGHT / 2); viewDetectionZone[n][index_zone].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].y, CANVAS_HEIGHT / 2); viewDetectionZone[n][index_zone].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].x, CANVAS_WIDTH / 2); viewDetectionZone[n][index_zone].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].y, CANVAS_HEIGHT / 2); strcpy(viewDetectionZone[n][index_zone].enable_traffic_light, ""); for (int index_trigger = 0; index_trigger < MAX_TRIGGER_EVENT; index_trigger++) { viewDetectionZone[n][index_zone].trigger_event[index_trigger].checked = 0; strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_id, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_id); strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_name, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_name); strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].post_event_name, ""); strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_name, ""); viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_increment = -2; } } new_data_write_to_config_file_flag = 1; } } //cJSON* cnn_device[MAX_LAYER_NUM]; cJSON* system_setting/*, *load_cnn_type*/, *display_dash, *display_properties,*display_OSD/*, *enable_log*/, *overlap_thresh, *confidence_thresh,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage, *enable_person_independent,*enable_onvif_profile_m, *enable_crop_mode,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language, *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran,*osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, *enable_email_notification,*enable_system_logs,*enable_email_jpeg, *send_counter_at_specific_hour,*email_reset_time_interval,*sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; system_setting = cJSON_GetObjectItem(root, "system_setting"); //cJSON* api_version = cJSON_GetObjectItem(system_setting, "api version"); //load_cnn_type = cJSON_GetObjectItem(system_setting, "cnn type"); overlap_thresh = cJSON_GetObjectItem(system_setting, "overlap thresh"); confidence_thresh = cJSON_GetObjectItem(system_setting, "confidence thresh"); enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); enable_crop_mode = cJSON_GetObjectItem(system_setting, "enable_crop_mode"); nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); language = cJSON_GetObjectItem(system_setting, "language"); enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); send_counter_at_specific_hour = cJSON_GetObjectItem(system_setting, "send_counter_at_specific_hour"); email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); if (enable_person_independent) strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); else { strcpy(SystemSetting.enable_person_independent, "No"); new_data_write_to_config_file_flag = 1; } if (enable_onvif_profile_m) strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); else { strcpy(SystemSetting.enable_onvif_profile_m, "No"); new_data_write_to_config_file_flag = 1; } if (enable_crop_mode) strcpy(SystemSetting.enable_crop_mode, enable_crop_mode->valuestring); else { strcpy(SystemSetting.enable_crop_mode, "Yes"); new_data_write_to_config_file_flag = 1; } if (nms_thres) strcpy(SystemSetting.nms_thres, nms_thres->valuestring); else { strcpy(SystemSetting.nms_thres, "10"); new_data_write_to_config_file_flag = 1; } if (tracking_id_dwell) strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); else { strcpy(SystemSetting.tracking_id_dwell, "5"); new_data_write_to_config_file_flag = 1; } if (cloud_enable_snap) strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); else { strcpy(SystemSetting.cloud_enable_snap, "Yes"); new_data_write_to_config_file_flag = 1; } if (enable_cloud) strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); else { strcpy(SystemSetting.enable_cloud, "No"); new_data_write_to_config_file_flag = 1; } if (enable_special_edition) strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); else { strcpy(SystemSetting.enable_special_edition, "No"); new_data_write_to_config_file_flag = 1; } if (enable_python) strcpy(SystemSetting.enable_python, enable_python->valuestring); else { strcpy(SystemSetting.enable_python, "No"); new_data_write_to_config_file_flag = 1; } if (enable_python_file) { // check python file if (strstr(enable_python_file->valuestring, ".py") == enable_python_file->valuestring + strlen(enable_python_file->valuestring) - 3) { strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { printf("check current runpython thread failed\n"); } } 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; } if (enable_low_cpu_usage) strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); else { strcpy(SystemSetting.enable_low_cpu_usage, "No"); new_data_write_to_config_file_flag = 1; } if (cloud_enable_notification) strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); else { strcpy(SystemSetting.cloud_enable_notification, "No"); new_data_write_to_config_file_flag = 1; } if (cloud_account) strcpy(SystemSetting.cloud_account, cloud_account->valuestring); else { strcpy(SystemSetting.cloud_account, "myaccount@mail.com"); new_data_write_to_config_file_flag = 1; } if (cloud_password) strcpy(SystemSetting.cloud_password, cloud_password->valuestring); else { strcpy(SystemSetting.cloud_password, "mypass"); new_data_write_to_config_file_flag = 1; } if (cloud_notification_dwell) strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); else { strcpy(SystemSetting.cloud_notification_dwell, "60"); new_data_write_to_config_file_flag = 1; } if (cloud_statue) strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); else { strcpy(SystemSetting.cloud_statue, ""); new_data_write_to_config_file_flag = 1; } if (cloud_v2_statue) strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); else { strcpy(SystemSetting.cloud_v2_statue, ""); new_data_write_to_config_file_flag = 1; } if (cloud_record_v2_statue) strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); else { strcpy(SystemSetting.cloud_record_v2_statue, ""); new_data_write_to_config_file_flag = 1; } if (enable_special_char) strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); else { strcpy(SystemSetting.enable_special_char, "No"); new_data_write_to_config_file_flag = 1; } if (enable_bounding_box) strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); else { strcpy(SystemSetting.enable_bounding_box, "Yes"); new_data_write_to_config_file_flag = 1; } if (enable_dwell_bounding_box) strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); else { strcpy(SystemSetting.enable_dwell_bounding_box, "No"); new_data_write_to_config_file_flag = 1; } if (force_i_to_one) strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); else { strcpy(SystemSetting.force_i_to_one, "Yes"); new_data_write_to_config_file_flag = 1; } if (force_o_to_zero) strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); else { strcpy(SystemSetting.force_o_to_zero, "Yes"); new_data_write_to_config_file_flag = 1; } if (enable_plate_angle_correction) strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); else { strcpy(SystemSetting.enable_plate_angle_correction, "No"); new_data_write_to_config_file_flag = 1; } if (enable_ai_mirror) strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); else { strcpy(SystemSetting.enable_ai_mirror, "No"); new_data_write_to_config_file_flag = 1; } if (ai_mirror_feature) strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); else { strcpy(SystemSetting.ai_mirror_feature, "0"); new_data_write_to_config_file_flag = 1; } if (enable_cloud_v2) strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); else { strcpy(SystemSetting.enable_cloud_v2, "No"); new_data_write_to_config_file_flag = 1; } if (cloud_v2_notification_dwell) strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); else { strcpy(SystemSetting.cloud_v2_notification_dwell, "60"); new_data_write_to_config_file_flag = 1; } if (cloud_v2_content) strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); else { strcpy(SystemSetting.cloud_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); new_data_write_to_config_file_flag = 1; } if (enable_cloud_record_v2) strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); else { strcpy(SystemSetting.enable_cloud_record_v2, "No"); new_data_write_to_config_file_flag = 1; } if (cloud_record_v2_notification_dwell) strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); else { strcpy(SystemSetting.cloud_record_v2_notification_dwell, "60"); new_data_write_to_config_file_flag = 1; } if (cloud_record_v2_content) strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); else { strcpy(SystemSetting.cloud_record_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); new_data_write_to_config_file_flag = 1; } if (enable_post_only_if_both_detected) strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); else { strcpy(SystemSetting.enable_post_only_if_both_detected, "No"); new_data_write_to_config_file_flag = 1; } if (enable_getalarmmotion_snap) strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); else { strcpy(SystemSetting.enable_getalarmmotion_snap, "No"); new_data_write_to_config_file_flag = 1; } if (getimage_encoder_id) strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); else { #ifdef GY_OS_NOVA strcpy(SystemSetting.getimage_encoder_id, "3"); #endif #ifdef GY_OS_AMBA strcpy(SystemSetting.getimage_encoder_id, "4"); #endif new_data_write_to_config_file_flag = 1; } if (getimage_encoder_id_HD) strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); else { #ifdef GY_OS_NOVA strcpy(SystemSetting.getimage_encoder_id_HD, "0"); #endif #ifdef GY_OS_AMBA strcpy(SystemSetting.getimage_encoder_id_HD, "4"); #endif new_data_write_to_config_file_flag = 1; } if (osd_encoder_id) strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); else { strcpy(SystemSetting.osd_encoder_id, "2"); new_data_write_to_config_file_flag = 1; } if (osd_font_size) strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); else { strcpy(SystemSetting.osd_font_size, "26"); new_data_write_to_config_file_flag = 1; } if (osd_outline_lilin) strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); else { strcpy(SystemSetting.osd_outline_lilin, "4"); new_data_write_to_config_file_flag = 1; } if (enable_osd_bottom) strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); else { strcpy(SystemSetting.enable_osd_bottom, "Yes"); new_data_write_to_config_file_flag = 1; } if (osd_bottom_bg_tran) strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); else { strcpy(SystemSetting.osd_bottom_bg_tran, "255"); new_data_write_to_config_file_flag = 1; } if (osd_bottom_content) strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); else { strcpy(SystemSetting.osd_bottom_content, "Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>"); new_data_write_to_config_file_flag = 1; } if (sensors_type) strcpy(SystemSetting.sensors_type, sensors_type->valuestring); else { strcpy(SystemSetting.sensors_type, "0"); new_data_write_to_config_file_flag = 1; } if (enable_sync_external_lpr_db) strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); else { strcpy(SystemSetting.enable_sync_external_lpr_db, "No"); new_data_write_to_config_file_flag = 1; } if (external_lpr_db_IP) strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); else { strcpy(SystemSetting.external_lpr_db_IP, "192.168.0.200"); new_data_write_to_config_file_flag = 1; } if (external_lpr_db_port) strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); else { strcpy(SystemSetting.external_lpr_db_port, accountData[0].account_aida_port); new_data_write_to_config_file_flag = 1; } if (external_lpr_db_username) strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); else { strcpy(SystemSetting.external_lpr_db_username, "admin"); new_data_write_to_config_file_flag = 1; } if (external_lpr_db_password) strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); else { strcpy(SystemSetting.external_lpr_db_password, "pass"); new_data_write_to_config_file_flag = 1; } if (enable_system_logs) strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); else { strcpy(SystemSetting.enable_system_logs, "No"); new_data_write_to_config_file_flag = 1; } if (enable_email_jpeg) strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); else { strcpy(SystemSetting.enable_email_jpeg, "Yes"); new_data_write_to_config_file_flag = 1; } if (send_counter_at_specific_hour) strcpy(SystemSetting.send_counter_at_specific_hour, send_counter_at_specific_hour->valuestring); else { strcpy(SystemSetting.send_counter_at_specific_hour, "NULL"); new_data_write_to_config_file_flag = 1; } if (email_reset_time_interval) strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); else { strcpy(SystemSetting.email_reset_time_interval, ""); new_data_write_to_config_file_flag = 1; } if (enable_ftp) strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); else { strcpy(SystemSetting.enable_ftp, "No"); new_data_write_to_config_file_flag = 1; } if (ftp_url) strcpy(SystemSetting.ftp_url, ftp_url->valuestring); else { strcpy(SystemSetting.ftp_url, "ftp.example.com"); new_data_write_to_config_file_flag = 1; } if (ftp_port) strcpy(SystemSetting.ftp_port, ftp_port->valuestring); else { strcpy(SystemSetting.ftp_port, "21"); new_data_write_to_config_file_flag = 1; } if (ftp_username) strcpy(SystemSetting.ftp_username, ftp_username->valuestring); else { strcpy(SystemSetting.ftp_username, ""); new_data_write_to_config_file_flag = 1; } if (ftp_password) strcpy(SystemSetting.ftp_password, ftp_password->valuestring); else { strcpy(SystemSetting.ftp_password, ""); new_data_write_to_config_file_flag = 1; } if (ftp_remote_directory) strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); else { strcpy(SystemSetting.ftp_remote_directory, "myfolder/myfile"); new_data_write_to_config_file_flag = 1; } if (ftp_jpeg_file_name_format) strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); else { strcpy(SystemSetting.ftp_jpeg_file_name_format, "fixed"); new_data_write_to_config_file_flag = 1; } if (ftp_jpeg_file_name) strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); else { strcpy(SystemSetting.ftp_jpeg_file_name, "snap"); new_data_write_to_config_file_flag = 1; } if (enable_email_notification) strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); else { strcpy(SystemSetting.enable_email_notification, "No"); new_data_write_to_config_file_flag = 1; } if (language) strcpy(SystemSetting.language, language->valuestring); else { strcpy(SystemSetting.language, "en_gb"); new_data_write_to_config_file_flag = 1; } display_properties = cJSON_GetObjectItem(system_setting, "display properties"); if (display_properties) strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); else { strcpy(SystemSetting.enable_display_properties, "No"); new_data_write_to_config_file_flag = 1; } display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); if (display_OSD) strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); else { strcpy(SystemSetting.enable_display_OSD, "No"); new_data_write_to_config_file_flag = 1; } //enable_log = cJSON_GetObjectItem(system_setting, "enable log"); //api_format_ver = atoi(api_version->valuestring); overlap_ratio_limit = 75; if (overlap_thresh) overlap_ratio_limit = overlap_thresh->valuedouble; confidence_limit = 0; stAMBAcontent.confidence_plate = 0; stAMBAcontent.confidence_traffic = 0; if (confidence_thresh) { confidence_limit = confidence_thresh->valuedouble; stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; } display_dash = cJSON_GetObjectItem(system_setting, "display dash"); activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; activeDisplayProperties = (strcmp(display_properties->valuestring, "Yes") == 0) ? _TRUE : _FALSE; //printf("111-6 get password = %s \n", accountData[0].account_password); //20201027 sophia add //account settings cJSON *account_setting, *account_data; account_setting = cJSON_GetObjectItem(root, "account_setting"); account_data = cJSON_GetObjectItem(account_setting, "account_data"); #if 1 { //解碼account_data - step 1:base64 decode size_t base64_decode_length = 0; unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; char DecryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); unsigned char OriEncryptData[512] = { 0 }; base64_decode(account_data->valuestring, strlen(account_data->valuestring), &base64_decode_length, OriEncryptData); memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); //解碼account_data - step 2:AES descrytion KeyExpansion(key, expandedKey); AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); //printf("account_data descrytion OK.\n"); #ifdef _DEBUG_AMBA printf("account_data = %s \n", DecryptKeyData); #endif //取得account_data明碼資訊 cJSON *keyRoot, *detect; cJSON *account_username, *account_password, *account_type, *account_status; keyRoot = cJSON_Parse(DecryptKeyData); int i = 0; cJSON_ArrayForEach(detect, keyRoot) { account_username = cJSON_GetObjectItem(detect, "account_username"); account_password = cJSON_GetObjectItem(detect, "account_password"); account_type = cJSON_GetObjectItem(detect, "account_type"); account_status = cJSON_GetObjectItem(detect, "account_status"); char temp_account[512] = { 0 }; urlencode((unsigned char *)account_username->valuestring, strlen(account_username->valuestring), (unsigned char *)temp_account, 512); memcpy(accountData[i].account_username, temp_account, strlen(temp_account)); accountData[i].account_username[strlen(temp_account)] = '\0'; char temp_account2[512] = { 0 }; urlencode((unsigned char *)account_password->valuestring, strlen(account_password->valuestring), (unsigned char *)temp_account2, 512); memcpy(accountData[i].account_password, temp_account2, strlen(temp_account2)); accountData[i].account_password[strlen(temp_account2)] = '\0'; //printf("111-6-0 get password = %s \n", account_password->valuestring); //printf("111-6-0 password size = %d \n", strlen(account_password->valuestring)); //printf("111-6-1 get password = %s \n", accountData[i].account_password); //printf("111-6-1 password size = %d \n", strlen(accountData[i].account_password)); //strcpy(accountData[i].account_username, account_username->valuestring); //strcpy(accountData[i].account_password, account_password->valuestring); accountData[i].account_type = account_type->valueint; accountData[i].account_status = account_status->valueint; //printf("111-6-2 get password = %s \n", accountData[i].account_password); #ifdef _DEBUG_AMBA printf("\naccountData[%d].account_username:%s", i, accountData[i].account_username); printf("\naccountData[%d].account_password:%s", i, accountData[i].account_password); printf("\naccountData[%d].account_type:%d", i, accountData[i].account_type); printf("\naccountData[%d].account_status:%d", i, accountData[i].account_status); #endif i++; } if (keyRoot) { cJSON_Delete(keyRoot); keyRoot = NULL; } } #endif overlap_ratio_limit = 75; if (overlap_thresh) overlap_ratio_limit = overlap_thresh->valuedouble; confidence_limit = 0; stAMBAcontent.confidence_plate = 0; stAMBAcontent.confidence_traffic = 0; if (confidence_thresh) { confidence_limit = confidence_thresh->valuedouble; stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; } { char* fileBuf = ReadAllBytes(emailsPATH); if (fileBuf) { cJSON *root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { cJSON *auth_password; auth_password = cJSON_GetObjectItem(root, "auth_password"); if (auth_password && strlen(auth_password->valuestring) >= 1) { size_t base64_decode_length = 0; char EncryptKeyData[256]; char DecryptKeyData[256]; memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); unsigned char OriEncryptData[512] = { 0 }; char temp_auth_password[256] = { 0 }; memcpy(temp_auth_password, auth_password->valuestring, strlen(auth_password->valuestring)); //KeyExpansion(key_email, expandedKey_email); //int decryptSize = AESDecryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); strcpy(IPCAMService.auth_password, EncryptKeyData); //printf("\n-------------temp_auth_password:%s\n", temp_auth_password); //printf("\n-------------DecryptKeyData:%s\n", DecryptKeyData); //printf("\n-------------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); } } if (root) { cJSON_Delete(root); root = NULL; } } else { if (fileBuf) { free(fileBuf); fileBuf = NULL; } printf("\nFail to read emailsPATH or emails.json\n"); } } //printf("\n---------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); //printf("GYNet Version=%s\n", APP_VERSION); //printf("LicenseType=%s\n", strLicenseType);// //printf("LicenseStatus=%s\n", strLicenseStatus); //printf("111-5 get password = %s \n", accountData[0].account_password); //printf("\n----------g_match_mac:%d\n", g_match_mac); if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { if (strcmp(strLicenseStatus, "Trial mismatch the system ID") != 0) { if (strcmp(strLicenseStatus, "License mismatch the system ID") != 0) { if (IsExistingWeight(featureType, featureType2)) { if (strncmp(strUnlockingKey, "face", 4) == 0) { } else { strcpy(strUnlockingKey, unlock_key->valuestring); } char buf[1024] = {}; readlink("/proc/self/exe", buf, sizeof(buf)); char exePath[1024] = {}; getFilePath(buf, exePath, 1024); char keyPATH[1024]; strcpy(keyPATH, exePath); strcat(keyPATH, "key.txt"); FILE *pFile; if ((pFile = fopen(keyPATH, "w")) != NULL) { fprintf(pFile, strUnlockingKey); fclose(pFile); } else { printf("Fail to open key.txt \n"); } } else strcpy(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type"); } else strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); } else strcpy(strUnlockingKey, "Trial_mismatch_the_system_ID"); } else { if (g_match_mac == 1) { strcpy(strUnlockingKey, "Third_party"); } else { strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); } } //printf("\nUnlockingKey=%s\n", strUnlockingKey); //printf("111-4 get password = %s \n", accountData[0].account_password); if (new_data_write_to_config_file_flag == 1 || strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") == 0 || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0 || strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") == 0 || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0) { cJSON *new_data_root, *ai_server, *view_setting, *camera01, *detection_zone, *detect, *trigger_events, *trigger, *system_setting, *account_setting, *about_box; new_data_root = cJSON_CreateObject(); ai_server = cJSON_CreateObject(); view_setting = cJSON_CreateObject(); camera01 = cJSON_CreateObject(); detection_zone = cJSON_CreateArray(); system_setting = cJSON_CreateObject(); account_setting = cJSON_CreateObject(); about_box = cJSON_CreateObject(); cJSON_AddItemToObject(new_data_root, "ai_server", ai_server); cJSON_AddItemToObject(ai_server, "ip", cJSON_CreateString("127.0.0.1")); cJSON_AddItemToObject(ai_server, "http_port", cJSON_CreateString(accountData[0].account_aida_port)); cJSON_AddItemToObject(ai_server, "video_port", cJSON_CreateString("8591")); cJSON_AddItemToObject(new_data_root, "view_setting", view_setting); cJSON_AddItemToObject(view_setting, "camera01", camera01); cJSON_AddItemToObject(camera01, "ip", cJSON_CreateString("47.176.29.11")); cJSON_AddItemToObject(camera01, "http_port", cJSON_CreateString("80")); cJSON_AddItemToObject(camera01, "video_port", cJSON_CreateString("80")); cJSON_AddItemToObject(camera01, "username", cJSON_CreateString("guest")); cJSON_AddItemToObject(camera01, "password", cJSON_CreateString("GP12345")); cJSON_AddItemToObject(camera01, "channel_id", cJSON_CreateString("")); cJSON_AddItemToObject(camera01, "enable_repeat", cJSON_CreateNumber(0)); cJSON_AddItemToObject(camera01, "camera_name", cJSON_CreateString("")); cJSON_AddItemToObject(camera01, "obj_max_proportion", cJSON_CreateString(obj_max_proportion->valuestring)); cJSON_AddItemToObject(camera01, "obj_min_proportion", cJSON_CreateString(obj_min_proportion->valuestring)); if (plate_filter_times) cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); else cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString("4")); if (plate_filter_time) cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); else cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString("3")); if (plate_free_time) cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); else cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString("3")); cJSON_AddItemToObject(camera01, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); cJSON_AddItemToObject(camera01, "enable_face", cJSON_CreateString("Yes")); cJSON_AddItemToObject(camera01, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); cJSON_AddItemToObject(camera01, "enable_logo", cJSON_CreateString("No")); cJSON_AddItemToObject(camera01, "enable_human", cJSON_CreateString("No")); cJSON_AddItemToObject(camera01, "enable_helmet", cJSON_CreateString("No")); cJSON_AddItemToObject(camera01, "levenshtein_distance", cJSON_CreateString(levenshtein_distance->valuestring)); cJSON_AddItemToObject(camera01, "min_characters", cJSON_CreateString(min_characters->valuestring)); cJSON_AddItemToObject(camera01, "max_characters", cJSON_CreateString(max_characters->valuestring)); cJSON_AddItemToObject(camera01, "confidence", cJSON_CreateString(confidence->valuestring)); cJSON_AddItemToObject(camera01, "confidence2", cJSON_CreateString(confidence2->valuestring)); cJSON_AddItemToObject(camera01, "confidence3", cJSON_CreateString(confidence3->valuestring)); cJSON_AddItemToObject(camera01, "confidence4", cJSON_CreateString(confidence4->valuestring)); cJSON_AddItemToObject(camera01, "tab_view_size", cJSON_CreateString("889x500")); cJSON_AddItemToObject(camera01, "count_zone", cJSON_CreateNumber(viewChannelData[0].count_zone)); //printf("\nenable_lpr_db-----9\n"); if (enable_lpr_db) { cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString(enable_lpr_db->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString("Yes")); } if (enable_track) { cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString(enable_track->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString("No")); } if (enable_PTZ) { cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString(enable_PTZ->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString("No")); } if (ptz_tracking_fov_min) { cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString(ptz_tracking_fov_min->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString("0")); } if (ptz_tracking_fov_max) { cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString(ptz_tracking_fov_max->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString("40")); } if (ptz_enable_tracking) { cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString(ptz_enable_tracking->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString("Yes")); } if (ptz_tracking_mode) { cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString("1")); } if (ptz_tracking_by_enter_zone) { cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString("Yes")); } if (enable_tracking_limits) { cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString(enable_tracking_limits->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString("No")); } if (ptz_pan_left_limit) { cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString(ptz_pan_left_limit->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString("0")); } if (ptz_pan_right_limit) { cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString(ptz_pan_right_limit->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString("360")); } if (ptz_tilt_up_limit) { cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString(ptz_tilt_up_limit->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString("0")); } if (ptz_tilt_down_limit) { cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString(ptz_tilt_down_limit->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString("210")); } if (ptz_speed) { cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString(ptz_speed->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString("3")); } if (ptz_sensitivity) { cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString("6")); } if (ptz_tracking_resume_dwell) { cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString(ptz_tracking_resume_dwell->valuestring)); } else { cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString("3")); } if (cJSON_enable_only_show_metadata1) { cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(cJSON_enable_only_show_metadata1->valueint)); } else { cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); } if (enable_downsized_cropped_roi) { cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); } else { cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(1)); } if (enable_zone_crop_1) { cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); } else { cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(0)); } if (enable_unknown_object) { cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString(enable_unknown_object->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString("No")); } if (enable_ivs_person_detection) { cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString(enable_ivs_person_detection->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString("No")); } if (assign_ivs_object_to) { cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString(assign_ivs_object_to->valuestring)); } else { cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString("")); } if (enable_ambulance) { cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString(enable_ambulance->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString("No")); } if (enable_blank_plate) { cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString(enable_blank_plate->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString("No")); } if (enable_stop_sign) { cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString(enable_stop_sign->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString("No")); } if (enable_show_unknown_object) { cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString(enable_show_unknown_object->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString("No")); } if (enable_ivs_fix_mode) { cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString(enable_ivs_fix_mode->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString("No")); } if (enable_ivs_and_ai) { cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString(enable_ivs_and_ai->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString("No")); } if (enable_add_face_frequent_list) { cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString("No")); } if (enable_lpr_upon_triggered) { cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString(enable_lpr_upon_triggered->valuestring)); } else { cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString("No")); } if (dwell_lpr_upon_triggered) { cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString(dwell_lpr_upon_triggered->valuestring)); } else { cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString("10")); } if (unknown_object_max_proportion) { cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString(unknown_object_max_proportion->valuestring)); } else { cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString("20")); } if (unknown_object_min_proportion) { cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString(unknown_object_min_proportion->valuestring)); } else { cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString("0")); } if (confidence_unknown_object) { cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString(confidence_unknown_object->valuestring)); } else { cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString("0")); } if (confidence2_unknown_object) { cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString(confidence2_unknown_object->valuestring)); } else { cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString("0")); } if (dwell_unknown_object) { cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString(dwell_unknown_object->valuestring)); } else { cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString("30")); } if (dwell_minute_focus_on) { cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString(dwell_minute_focus_on->valuestring)); } else { cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString("5")); } if (person_obj_fov) { cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString(person_obj_fov->valuestring)); } else { cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString("100")); } if (ivs_mode) { cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString(ivs_mode->valuestring)); } else { cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString("3")); } if (getnetwork_buffer_id) { cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString(getnetwork_buffer_id->valuestring)); } else { cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString("1")); } if (red_light_zone) { cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString(red_light_zone->valuestring)); } else { cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString("")); } if (no_give_way_zone_to_protect) { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString(no_give_way_zone_to_protect->valuestring)); } else { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString("")); } if (no_give_way_zone_to_keep_away) { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString(no_give_way_zone_to_keep_away->valuestring)); } else { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString("")); } if (no_give_way_zone_to_protect_2) { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString(no_give_way_zone_to_protect_2->valuestring)); } else { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString("")); } if (no_give_way_zone_to_keep_away_2) { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(no_give_way_zone_to_keep_away_2->valuestring)); } else { cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString("")); } cJSON_AddItemToObject(camera01, "detection_zone", detection_zone); for (int index_i = 0; index_i < MAX_DETECTION_ZONE; index_i++) { detect = cJSON_CreateObject(); cJSON_AddItemToArray(detection_zone, detect); cJSON_AddItemToObject(detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[0][index_i].enable_direction1)); cJSON_AddItemToObject(detect, "enable_direction2", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "direction1", cJSON_CreateString(viewDetectionZone[0][index_i].direction1)); cJSON_AddItemToObject(detect, "direction2", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "enable_tripwire", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "enable_traffic_light", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "enable_social_distance", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "metadata1", cJSON_CreateString(viewDetectionZone[0][index_i].metadata1)); cJSON_AddItemToObject(detect, "metadata2", cJSON_CreateString(viewDetectionZone[0][index_i].metadata2)); cJSON_AddItemToObject(detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[0][index_i].metadata_stop)); char str[25] = { 0 }; sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time); cJSON_AddItemToObject(detect, "no_parking_time", cJSON_CreateString(str)); memset(str, 0x00, sizeof(str)); sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time_in_minute); cJSON_AddItemToObject(detect, "no_parking_time_in_minute", cJSON_CreateString(str)); memset(str,0x00,sizeof(str)); sprintf(str, "%d", viewDetectionZone[0][index_i].queuing_count); cJSON_AddItemToObject(detect, "queuing_count", cJSON_CreateString(str)); cJSON_AddItemToObject(detect, "distance_violation_count", cJSON_CreateString("")); cJSON_AddItemToObject(detect, "detection_time", cJSON_CreateString(viewDetectionZone[0][index_i].detection_time)); cJSON_AddItemToObject(detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[0][index_i].link_to_counter)); if (obj_max_proportion_in_zone) cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_max_proportion_in_zone)); else { cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString("80")); } if (obj_min_proportion_in_zone) cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_min_proportion_in_zone)); else { cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString("0")); } if (ptz_zone_to_preset) cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[0][index_i].ptz_zone_to_preset)); else { cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString("0")); } if (enable_speed) cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_speed)); else { cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString("No")); } if (enable_radar_speed) cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_radar_speed)); else { cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString("No")); } if (enable_ivs_zone) cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[0][index_i].enable_ivs_zone)); else { cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString("No")); } if (parking_space) { char buf_temp[20] = { 0 }; sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_space); cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString(buf_temp)); } else { cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString("0")); } if (parking_line) { char buf_temp[20] = { 0 }; sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_line); cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString(buf_temp)); } else { cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString("0")); } if (set_distance) { char buf_temp[20] = { 0 }; sprintf(buf_temp,"%f", viewDetectionZone[0][index_i].set_distance); cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString(buf_temp)); } else { cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString("10")); } if (world_distance_unit) cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_distance_unit)); else { cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString("meter")); } if (world_distance_side1) { char buf_temp[20] = { 0 }; sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side1); cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString(buf_temp)); } else { cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString("10")); } if (world_distance_side2) { char buf_temp[20] = { 0 }; sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side2); cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString(buf_temp)); } else { cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString("10")); } if (world_time_unit) { cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_time_unit)); } else { cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString("KPH")); } trigger_events = cJSON_CreateArray(); cJSON_AddItemToObject(detect, "trigger_events", trigger_events); for (int index_j = 0; index_j < MAX_TRIGGER_EVENT; index_j++) { trigger = cJSON_CreateObject(); cJSON_AddItemToArray(trigger_events, trigger); char str_counter_increment[50] = { 0 }; if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment==1) { strcpy(str_counter_increment,"counter_increment_add"); } else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == -1) { strcpy(str_counter_increment, "counter_increment_minus"); } else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == 0) { strcpy(str_counter_increment, "counter_increment_equal"); } else { strcpy(str_counter_increment,""); } cJSON_AddItemToObject(trigger, "checked", cJSON_CreateNumber(viewDetectionZone[0][index_i].trigger_event[index_j].checked)); if (index_j == 0) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000001")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Prohibit zone (AIAREA)")); } else if (index_j == 1) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000004")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Parking violation (AIAREA/AICAP)")); } else if (index_j == 2) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00200000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Allowed list")); } else if (index_j == 3) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00400000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Denial list")); } else if (index_j == 4) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000008")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Traffic flow (AIFLOW/AICAP)")); } else if (index_j == 5) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000010")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn left (AIFLOW)")); } else if (index_j == 6) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000020")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn right (AIFLOW)")); } else if (index_j == 7) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x10000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Density detection (03AI)")); } else if (index_j == 8) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x20000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Missing object detection (01AI)")); } else if (index_j == 9) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00800000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Visitor list")); } else if (index_j == 10) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x01000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Unattended object or missing object")); } else if (index_j == 11) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x02000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("BG learning")); } else if (index_j == 12) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x04000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Tampering detection")); } else if (index_j == 13) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x40000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("All objects detection")); } else if (index_j == 14) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x80000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lack of any object detection")); } else if (index_j == 15) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00002000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Over speed detection")); } else if (index_j == 16) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00004000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lower speed detection")); } else if (index_j == 17) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000400")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Running red lights")); } else if (index_j == 18) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000800")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning left on red")); } else if (index_j == 19) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00001000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning right on red")); } else if (index_j == 20) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00008000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Forget to give way detection")); } else if (index_j == 21) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00040000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Distance violation")); } else if (index_j == 22) { cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x08000000")); cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Height detection")); } cJSON_AddItemToObject(trigger, "post_event_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].post_event_name)); cJSON_AddItemToObject(trigger, "counter_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].counter_name)); cJSON_AddItemToObject(trigger, "counter_increment", cJSON_CreateString(str_counter_increment)); } cJSON_AddItemToObject(detect, "point_number", cJSON_CreateNumber(6)); cJSON_AddItemToObject(detect, "x1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].x)); cJSON_AddItemToObject(detect, "y1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].y)); cJSON_AddItemToObject(detect, "x2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].x)); cJSON_AddItemToObject(detect, "y2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].y)); cJSON_AddItemToObject(detect, "x3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].x)); cJSON_AddItemToObject(detect, "y3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].y)); cJSON_AddItemToObject(detect, "x4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].x)); cJSON_AddItemToObject(detect, "y4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].y)); if (x5 && x6) { cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].x)); cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].y)); cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].x)); cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].y)); } else { cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(579)); cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(250)); cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(579)); cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(100)); } } cJSON_AddItemToObject(new_data_root, "system_setting", system_setting); cJSON_AddItemToObject(system_setting, "AI dataset", cJSON_CreateString("")); cJSON_AddItemToObject(system_setting, "dataset category", cJSON_CreateString("; Total 60 FPS")); cJSON_AddItemToObject(system_setting, "snapshot folder", cJSON_CreateString("D:\\\\")); if (language) { cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString(language->valuestring)); } else { cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString("en_gb")); } cJSON_AddItemToObject(system_setting, "enable log", cJSON_CreateString("No")); cJSON_AddItemToObject(system_setting, "auto reconnect", cJSON_CreateString("Yes")); cJSON_AddItemToObject(system_setting, "auto start", cJSON_CreateString("Yes")); cJSON_AddItemToObject(system_setting, "enable watchdog", cJSON_CreateString("Yes")); cJSON_AddItemToObject(system_setting, "enable watchdog UI", cJSON_CreateString("Yes")); cJSON_AddItemToObject(system_setting, "cpu usage limit", cJSON_CreateString("80")); cJSON_AddItemToObject(system_setting, "display OSD", cJSON_CreateString("No")); if (activeDisplayDash) { cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); } else { cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString("No")); } if (display_properties) cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString(display_properties->valuestring)); else { cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString("No")); } cJSON_AddItemToObject(system_setting, "display tracking ID", cJSON_CreateString("Yes")); cJSON_AddItemToObject(system_setting, "overlap thresh", cJSON_CreateNumber(70)); cJSON_AddItemToObject(system_setting, "confidence thresh", cJSON_CreateNumber(0)); cJSON_AddItemToObject(system_setting, "cnn type", cJSON_CreateString("CUDA")); cJSON_AddItemToObject(system_setting, "cnn device1", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device2", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device3", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device4", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device5", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device6", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device7", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "cnn device8", cJSON_CreateString("GPU")); cJSON_AddItemToObject(system_setting, "whitelist", cJSON_CreateString("No")); cJSON_AddItemToObject(system_setting, "blacklist", cJSON_CreateString("No")); if (enable_person_independent) { cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString(enable_person_independent->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString("No")); } if (enable_onvif_profile_m) { cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString(enable_onvif_profile_m->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString("No")); } if (enable_crop_mode) { cJSON_AddItemToObject(system_setting, "enable_crop_mode", cJSON_CreateString(enable_crop_mode->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_crop_mode", cJSON_CreateString("Yes")); } if (nms_thres) { cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString(nms_thres->valuestring)); } else { cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString("10")); } if (tracking_id_dwell) { cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString(tracking_id_dwell->valuestring)); } else { cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString("5")); } if (enable_cloud) { cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString(enable_cloud->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString("No")); } if (enable_special_edition) { cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString(enable_special_edition->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); } if (enable_python) { cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString(enable_python->valuestring)); } 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)); } else { cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); } if (enable_low_cpu_usage) { cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString(enable_low_cpu_usage->valuestring)); } else { cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString("No")); } if (cloud_enable_snap) { cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString(cloud_enable_snap->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString("Yes")); } if (cloud_enable_notification) { cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString(cloud_enable_notification->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString("No")); } if (cloud_account) { cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString(cloud_account->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString("myaccount@mail.com")); } if (cloud_password) { cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString(cloud_password->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString("mypass")); } if (cloud_notification_dwell) { cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString(cloud_notification_dwell->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString("60")); } if (cloud_statue) { cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString(cloud_statue->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString("")); } if (cloud_v2_statue) { cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString(cloud_v2_statue->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString("")); } if (cloud_record_v2_statue) { cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString(cloud_record_v2_statue->valuestring)); } else { cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString("")); } if (enable_special_char) cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString(enable_special_char->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString("No")); } if (enable_bounding_box) cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString("Yes")); } if (enable_dwell_bounding_box) cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString("No")); } if (force_i_to_one) cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString(force_i_to_one->valuestring)); else { cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString("Yes")); } if (force_o_to_zero) cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString(force_o_to_zero->valuestring)); else { cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString("Yes")); } if (enable_plate_angle_correction) cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString(enable_plate_angle_correction->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString("No")); } if (enable_ai_mirror) cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString(enable_ai_mirror->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString("No")); } if (ai_mirror_feature) cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString(ai_mirror_feature->valuestring)); else { cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString("0")); } if (enable_cloud_v2) cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString(enable_cloud_v2->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString("No")); } if (cloud_v2_notification_dwell) cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(cloud_v2_notification_dwell->valuestring)); else { cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString("60")); } if (cloud_v2_content) cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString(cloud_v2_content->valuestring)); else { cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); } if (enable_cloud_record_v2) cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString(enable_cloud_record_v2->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString("No")); } if (cloud_record_v2_notification_dwell) cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(cloud_record_v2_notification_dwell->valuestring)); else { cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString("60")); } if (cloud_record_v2_content) cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString(cloud_record_v2_content->valuestring)); else { cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); } if (enable_post_only_if_both_detected) cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(enable_post_only_if_both_detected->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString("No")); } if (enable_getalarmmotion_snap) cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(enable_getalarmmotion_snap->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString("No")); } if (getimage_encoder_id) cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString(getimage_encoder_id->valuestring)); else { #ifdef GY_OS_NOVA cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("3")); #endif #ifdef GY_OS_AMBA cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("4")); #endif } if (getimage_encoder_id_HD) cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString(getimage_encoder_id_HD->valuestring)); else { #ifdef GY_OS_NOVA cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("0")); #endif #ifdef GY_OS_AMBA cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("4")); #endif } if (osd_encoder_id) cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString(osd_encoder_id->valuestring)); else { cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString("2")); } if (osd_font_size) cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString(osd_font_size->valuestring)); else { cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString("26")); } if (osd_outline_lilin) cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString(osd_outline_lilin->valuestring)); else { cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString("4")); } if (enable_osd_bottom) cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString(enable_osd_bottom->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString("Yes")); } if (osd_bottom_bg_tran) cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString(osd_bottom_bg_tran->valuestring)); else { cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString("255")); } if (osd_bottom_content) cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString(osd_bottom_content->valuestring)); else { cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString("Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>")); } if (sensors_type) cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString(sensors_type->valuestring)); else { cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString("0")); } if (enable_sync_external_lpr_db) cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(enable_sync_external_lpr_db->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString("No")); } if (external_lpr_db_IP) cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString(external_lpr_db_IP->valuestring)); else { cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString("192.168.0.200")); } if (external_lpr_db_port) cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(external_lpr_db_port->valuestring)); else { cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(accountData[0].account_aida_port)); } if (external_lpr_db_username) cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString(external_lpr_db_username->valuestring)); else { cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString("admin")); } if (external_lpr_db_password) cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString(external_lpr_db_password->valuestring)); else { cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString("pass")); } if (enable_system_logs) cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString(enable_system_logs->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString("No")); } if (enable_email_jpeg) cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString(enable_email_jpeg->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString("Yes")); } if (send_counter_at_specific_hour) cJSON_AddItemToObject(system_setting, "send_counter_at_specific_hour", cJSON_CreateString(send_counter_at_specific_hour->valuestring)); else { cJSON_AddItemToObject(system_setting, "send_counter_at_specific_hour", cJSON_CreateString("NULL")); } if (email_reset_time_interval) cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString(email_reset_time_interval->valuestring)); else { cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString("")); } if (enable_ftp) cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString(enable_ftp->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString("No")); } if (ftp_url) cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString(ftp_url->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString("ftp.example.com")); } if (ftp_port) cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString(ftp_port->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString("21")); } if (ftp_username) cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString(ftp_username->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString("")); } if (ftp_password) cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString(ftp_password->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString("")); } if (ftp_remote_directory) cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString(ftp_remote_directory->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString("myfolder/myfile")); } if (ftp_jpeg_file_name_format) cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(ftp_jpeg_file_name_format->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString("fixed")); } if (ftp_jpeg_file_name) cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString(ftp_jpeg_file_name->valuestring)); else { cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString("snap")); } if (enable_email_notification) cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString(enable_email_notification->valuestring)); else { cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString("No")); } cJSON_AddItemToObject(new_data_root, "account_setting", account_setting); cJSON_AddItemToObject(account_setting, "account_data", cJSON_CreateString(account_data->valuestring)); cJSON_AddItemToObject(new_data_root, "about_box", about_box); cJSON_AddItemToObject(about_box, "dataset version", cJSON_CreateString("")); cJSON_AddItemToObject(about_box, "software version", cJSON_CreateString("2.0.2")); cJSON_AddItemToObject(about_box, "system id", cJSON_CreateString("")); cJSON_AddItemToObject(about_box, "NIC name", cJSON_CreateString("乙太網路")); if(strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") != 0) { if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { if (strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") != 0) { if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { if (strncmp(strUnlockingKey, "face", 4) == 0) { cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); } else { cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(unlock_key->valuestring)); } } else cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); } else cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_mismatch_the_system_ID")); } else cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); } else cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_or_license_mismatch_the_feature_type")); char *filename; filename = configPATH; int del = remove(filename); if (!del) { //printf("config is Deleted successfully."); } else { printf("config cannot be Deleted.\n"); } char* JsonString = cJSON_Print(new_data_root); FILE *fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); } else { fclose(fp); printf("Fail to open config.json \n"); } if (JsonString) { free(JsonString); JsonString = NULL; } if (new_data_root) { cJSON_Delete(new_data_root); new_data_root = NULL; } new_data_write_to_config_file_flag = 0; } //printf("111-3 get password = %s \n", accountData[0].account_password); if (new_data_write_to_events_file_flag == 1) { cJSON *new_data_root, *notification, *event_counter_setting/*,*enable_post*//*,*enable_snmp_post*/,*http_post_events,*a_http_post_event,*event_counters, *a_event_counter; cJSON *a_report, *report_counters; cJSON *a_snmp, *snmp_management; cJSON *email_setting; new_data_root = cJSON_CreateObject(); notification = cJSON_CreateObject(); event_counter_setting = cJSON_CreateObject(); email_setting = cJSON_CreateObject(); ; cJSON_AddItemToObject(new_data_root, "notification", notification); cJSON_AddItemToObject(new_data_root, "event_counter_setting", event_counter_setting); cJSON_AddItemToObject(new_data_root, "email_setting", email_setting); if(activePostNotification) cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("Yes")); else cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("No")); if (activeSNMPPost) cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("Yes")); else cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("No")); cJSON_AddItemToObject(notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); cJSON_AddItemToObject(notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); cJSON_AddItemToObject(notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); cJSON_AddItemToObject(notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); cJSON_AddItemToObject(notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); cJSON_AddItemToObject(notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); cJSON_AddItemToObject(notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); cJSON_AddItemToObject(notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); cJSON_AddItemToObject(notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); cJSON_AddItemToObject(notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); cJSON_AddItemToObject(notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); cJSON_AddItemToObject(notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); cJSON_AddItemToObject(notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); cJSON_AddItemToObject(notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); cJSON_AddItemToObject(notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); cJSON_AddItemToObject(notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); cJSON_AddItemToObject(notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); cJSON_AddItemToObject(notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); cJSON_AddItemToObject(notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); cJSON_AddItemToObject(notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); cJSON_AddItemToObject(notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); cJSON_AddItemToObject(notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); cJSON_AddItemToObject(notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); http_post_events = cJSON_CreateArray(); cJSON_AddItemToObject(notification, "http_post_events", http_post_events); for (int index_http_post = 0; index_http_post < MAX_POST_EVENTS; index_http_post++) { a_http_post_event = cJSON_CreateObject(); cJSON_AddItemToArray(http_post_events, a_http_post_event); cJSON_AddItemToObject(a_http_post_event, "post_protocol", cJSON_CreateString(postEventList[index_http_post].post_protocol)); cJSON_AddItemToObject(a_http_post_event, "post_event_method", cJSON_CreateString(postEventList[index_http_post].post_event_method)); cJSON_AddItemToObject(a_http_post_event, "post_event_name", cJSON_CreateString(postEventList[index_http_post].post_event_name)); cJSON_AddItemToObject(a_http_post_event, "post_host_ip", cJSON_CreateString(postEventList[index_http_post].post_host_ip)); cJSON_AddItemToObject(a_http_post_event, "post_host_port", cJSON_CreateString(postEventList[index_http_post].post_host_port)); cJSON_AddItemToObject(a_http_post_event, "post_url", cJSON_CreateString(postEventList[index_http_post].post_url)); cJSON_AddItemToObject(a_http_post_event, "post_content_type", cJSON_CreateString("text/html; charset=utf-8")); char buf_account[512] = { 0 }; urldecode((unsigned char *)postEventList[index_http_post].post_username, (unsigned char *)buf_account); char buf_account2[512] = { 0 }; urldecode((unsigned char *)postEventList[index_http_post].post_password, (unsigned char *)buf_account2); cJSON_AddItemToObject(a_http_post_event, "post_username", cJSON_CreateString(buf_account)); cJSON_AddItemToObject(a_http_post_event, "post_password", cJSON_CreateString(buf_account2)); cJSON_AddItemToObject(a_http_post_event, "post_customized_header", cJSON_CreateString(postEventList[index_http_post].post_customized_header)); cJSON_AddItemToObject(a_http_post_event, "post_content", cJSON_CreateString(postEventList[index_http_post].post_content)); cJSON_AddItemToObject(a_http_post_event, "post_sequence", cJSON_CreateString(postEventList[index_http_post].post_sequence)); cJSON_AddItemToObject(a_http_post_event, "post_file_format", cJSON_CreateString(postEventList[index_http_post].post_file_format)); cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name_format)); cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name)); cJSON_AddItemToObject(a_http_post_event, "post_timeout", cJSON_CreateString(postEventList[index_http_post].post_timeout)); } event_counters = cJSON_CreateArray(); cJSON_AddItemToObject(event_counter_setting, "event_counters", event_counters); report_counters = cJSON_CreateArray(); cJSON_AddItemToObject(event_counter_setting, "report_counters", report_counters); snmp_management = cJSON_CreateArray(); cJSON_AddItemToObject(event_counter_setting, "snmp_management", snmp_management); #ifdef GY_OS_V_SERIES for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { a_event_counter = cJSON_CreateObject(); cJSON_AddItemToArray(event_counters, a_event_counter); char str_name[50] = { 0 }; sprintf(str_name, "Counter0%d", index_event_counter+1); cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(str_name)); cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(str_name)); cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString("0")); cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString("Yes")); cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString("1 minute")); cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString("Camera virtual 4")); cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString("5 minutes")); cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString("No")); cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString("No")); } for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { a_report = cJSON_CreateObject(); cJSON_AddItemToArray(report_counters, a_report); cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString("Counter01")); cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString("Name")); cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString("1")); cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString("")); cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString("")); cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString("0")); cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString("")); cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString("100")); cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString("No")); cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString("0")); cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString("car_300X300_white")); cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString("No entry for cars")); cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString("car_1_300X300_red")); } for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { a_snmp = cJSON_CreateObject(); cJSON_AddItemToArray(snmp_management, a_snmp); char str_name[50] = { 0 }; if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { sprintf(str_name, "SNMP %d", index_snmp + 1); } else { sprintf(str_name, "%s", "Heartbeat"); } cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(str_name)); cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString("v1")); cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString("public")); cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString("192.168.0.200")); cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString("161")); cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(".1.3.6.1.2.1.1.6.0")); cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString("mylocation")); cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString("string")); } #else for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { a_event_counter = cJSON_CreateObject(); cJSON_AddItemToArray(event_counters, a_event_counter); char str_reset_value[50] = { 0 }; sprintf(str_reset_value,"%d", eventCounterList[index_event_counter].reset_value); cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_name)); cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_cust_name)); cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString(str_reset_value)); cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_time_interval)); cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].reset_time_interval)); cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString(eventCounterList[index_event_counter].link_to_post_event_name)); cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString(eventCounterList[index_event_counter].post_interval)); cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_only_cloud)); cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[index_event_counter].enable_linked_to_dwell_time)); } for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { a_report = cJSON_CreateObject(); cJSON_AddItemToArray(report_counters, a_report); cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString(reportCounterList[index_report].counter_a)); cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString(reportCounterList[index_report].counter_a_name)); cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[index_report].counter_a_zone)); cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString(reportCounterList[index_report].counter_b)); cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString(reportCounterList[index_report].counter_b_name)); cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[index_report].counter_b_zone)); cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString(reportCounterList[index_report].counter_c_name)); cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString(reportCounterList[index_report].report_max_value)); cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString(reportCounterList[index_report].enable_report)); cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString(reportCounterList[index_report].counter_mode)); cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString(reportCounterList[index_report].initial_icon)); cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString(reportCounterList[index_report].detection_output)); cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString(reportCounterList[index_report].output_icon)); } for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { a_snmp = cJSON_CreateObject(); cJSON_AddItemToArray(snmp_management, a_snmp); cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_event_name)); cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_version)); cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_group_name)); cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_ip)); cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_port)); cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_oid)); cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_value)); cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_type)); } #endif cJSON_AddItemToObject(email_setting, "email_content", cJSON_CreateString(emailData.email_content)); char *filename; filename = eventsPATH; int del = remove(filename); if (!del) { //printf("events is Deleted successfully."); } else { printf("events cannot be Deleted.\n"); } char* JsonString = cJSON_Print(new_data_root); FILE *fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); } else { fclose(fp); printf("Fail to open events.json \n"); } if (JsonString) { free(JsonString); JsonString = NULL; } if (new_data_root) { cJSON_Delete(new_data_root); new_data_root = NULL; } new_data_write_to_events_file_flag = 0; } //printf("111-2 get password = %s \n", accountData[0].account_password); #ifdef GY_OS_AMBA if (new_data_write_to_tof_file_flag == 1) { cJSON *new_data_root,*new_tof_camera; new_data_root = cJSON_CreateObject(); new_tof_camera = cJSON_CreateObject(); cJSON_AddItemToObject(new_data_root, "version", cJSON_CreateNumber(tofData.tof_version)); cJSON_AddItemToObject(new_data_root, "debug", cJSON_CreateBool(tofData.tof_debug)); cJSON_AddItemToObject(new_data_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); cJSON_AddItemToObject(new_data_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); cJSON_AddItemToObject(new_data_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); cJSON_AddItemToObject(new_data_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); cJSON_AddItemToObject(new_data_root, "distance_options", cJSON_CreateString(tofData.distance_options)); cJSON_AddItemToObject(new_data_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); cJSON_AddItemToObject(new_data_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); cJSON_AddItemToObject(new_data_root, "height_options", cJSON_CreateString(tofData.height_options)); cJSON_AddItemToObject(new_data_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); cJSON_AddItemToObject(new_data_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); cJSON_AddItemToObject(new_data_root, "ground_x", cJSON_CreateString(tofData.ground_x)); cJSON_AddItemToObject(new_data_root, "ground_y", cJSON_CreateString(tofData.ground_y)); cJSON_AddItemToObject(new_data_root, "camera", new_tof_camera); cJSON_AddItemToObject(new_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); cJSON_AddItemToObject(new_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); cJSON_AddItemToObject(new_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); cJSON_AddItemToObject(new_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); cJSON_AddItemToObject(new_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); char buf_account[512] = { 0 }; urldecode((unsigned char *)tofData.tof_camera_username, (unsigned char *)buf_account); char buf_account2[512] = { 0 }; urldecode((unsigned char *)tofData.tof_camera_password, (unsigned char *)buf_account2); cJSON_AddItemToObject(new_tof_camera, "camera_username", cJSON_CreateString(buf_account)); cJSON_AddItemToObject(new_tof_camera, "camera_password", cJSON_CreateString(buf_account2)); char *filename; filename = tofPATH; int del = remove(filename); if (!del) { //printf("tof is Deleted successfully."); } else { printf("tof cannot be Deleted.\n"); } char* JsonString = cJSON_Print(new_data_root); FILE *fp; if ((fp = fopen(filename, "w")) != NULL) { fprintf(fp, JsonString); fclose(fp); } else { fclose(fp); printf("Fail to open events.json \n"); } if (JsonString) { free(JsonString); JsonString = NULL; } if (new_data_root) { cJSON_Delete(new_data_root); new_data_root = NULL; } new_data_write_to_tof_file_flag = 0; } #endif //20201123 sophia add if (root) { cJSON_Delete(root); root = NULL; } if (tof_root) { cJSON_Delete(tof_root); tof_root = NULL; } if (n_root) { cJSON_Delete(n_root); n_root = NULL; } if (keyRoot) { cJSON_Delete(keyRoot); keyRoot = NULL; } //http_ip_address = (ip_address) ? ip_address : NULL; //http_http_port = http_port; http_sleep_interval = 2; //http_dataset_version = dataset_version; //set base time for reload struct tm* b_time = localtime(&start_time);; memset(b_time, 0, sizeof(struct tm)); b_time->tm_hour = 0; // 24 hour format, 0 = midnight, 23 = 11pm b_time->tm_min = 0; b_time->tm_sec = 0; b_time->tm_mon = 0; // 0 based, 0 = jan, 11 = dec b_time->tm_mday = 1; b_time->tm_year = 100; // current - 1900 //time_t base_time = mktime(b_time); //initialize socketRecords /*for (int i = 0; i < sizeof(socketRecords); i++) { socketRecords[i].sock = INVALID_SOCKET; socketRecords[i].last_recv_time = 0; }*/ int layer_idx = 0; #ifdef GY_OS_NOVA cJSON *root_weight,*net_number,*net_info_list,*net_info,*weight_name,*anc_name,*label_name,*feature_type; root_weight = cJSON_CreateObject(); net_info_list = cJSON_CreateArray(); cJSON_AddItemToObject(root_weight, "net_info_list", net_info_list); #endif /*for (int i = 0; i < MAX_LAYER_NUM; i++) { if (layerUTF8Country[i] != NULL) { free(layerUTF8Country[i]); layerUTF8Country[i] = NULL; } layerUTF8Country[i] = malloc(128); strcpy(layerUTF8Country[layer_idx], ""); }*/ ///Steven MARK TEMP ////按照license key載入不同網路 //MAX_IMG_BUFF_SIZE * MAX_CLIENT_SOCKET //printf("\nKKKKKKKKKKKKKKKK:1\n"); /* printf("\n--------------------\n"); printf("\nfeatureType: 0x%x\n", featureType); printf("\nfeatureType2: 0x%x\n", featureType2); printf("\n--------------------\n");*/ //printf("\n--------------------------:5\n"); //printf("111-1 get password = %s \n", accountData[0].account_password); if (IsExistingWeight(featureType, featureType2)) { #ifdef GY_OS_AMBA //AMBA Weight if (strcmp(WeightFileModeName, "mod004") == 0) { if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) ///Steven TEMP MARK { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_WGT.aes", "/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_ANC.aes", "/emmc/plugin/Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITHERMAL/GYNet_AITHERMAL_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITHERMAL/AMB_AITHERMAL_VER.txt,"); if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin"); } } //if (g_check_if_OK_thermal == 1 && g_IsPTZDevice == 1) if(g_dual_sensor == 1) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); } } } } } else { if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) ///Steven TEMP MARK { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); } } } else { if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { featureType = featureType | FEATURE_TRAF_DET; featureType2 = featureType2 | FEATURE_AICAP; stAMBAcontent.featureType = featureType; stAMBAcontent.featureType2 = featureType2; if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; g_IsHelm_without_car = 1; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); } } } if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || (strcmp(WeightFileModeName, "mod003") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK)) { featureType = featureType | FEATURE_TRAF_DET; featureType2 = featureType2 | FEATURE_AIFLOW; stAMBAcontent.featureType = featureType; stAMBAcontent.featureType2 = featureType2; if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; g_IsHelm_without_car = 1; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); } } } } } //AMBA Weight if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_WGT.aes", "/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_ANC.aes", "/emmc/plugin/Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGARBAGE/GYNet_AIGARBAGE_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGARBAGE/AMB_AIGARBAGE_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_LOGO) == FEATURE_LPR_LOGO) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_WGT.aes", "/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_ANC.aes", "/emmc/plugin/Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AICarMake/GYNet_LOGO_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AICarMake/AMB_LOGO_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_LOGO; layerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_LOGO; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE /*&& (featureType2 & FEATURE_DET_AIFIRE) == FEATURE_DET_AIFIRE*/) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_WGT.aes", "/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_ANC.aes", "/emmc/plugin/Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFIRE/GYNet_AIFIRE_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFIRE/AMB_AIFIRE_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_AIFIRE; layerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIFIRE; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) ///Steven TEMP MARK { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_WGT.aes", "/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_ANC.aes", "/emmc/plugin/Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAERO/GYNet_AIAERO_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAERO/AMB_AIAERO_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIAREO; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREO; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) ///Steven TEMP MARK FEATURE_HUM_DET { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_WGT.aes", "/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_ANC.aes", "/emmc/plugin/Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISAFTY/GYNet_AISAFTY_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISAFTY/AMB_AISAFTY_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AIHELM; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIHELM; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) ///Steven TEMP MARK FEATURE_HUM_DET { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_WGT.aes", "/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_ANC.aes", "/emmc/plugin/Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRAILWAY/GYNet_AIRAILWAY_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRAILWAY/AMB_AIRAILWAY_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_AIRAIL; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIRAIL; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) ///Steven TEMP MARK FEATURE_HUM_DET { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_WGT.aes", "/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_ANC.aes", "/emmc/plugin/Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISPORTS/GYNet_AISPORTS_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISPORTS/AMB_AISPORTS_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AISPORTS; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISPORTS; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) ///Steven TEMP MARK { if (layer_idx < MAX_LAYER_NUM) { if (strcmp(WeightFileModeName, "mod003") != 0) { LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_WGT.aes", "/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_ANC.aes", "/emmc/plugin/Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIHUMAN/GYNet_Human_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIHUMAN/AMB_Human_VER.txt,"); if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin"); } } else { LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_WGT.aes", "/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_ANC.aes", "/emmc/plugin/Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGENDER/GYNet_AIGENDER_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGENDER/AMB_AIGENDER_VER.txt,"); if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin"); } } layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AIMASK; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIMASK; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } } //AMBA Weight if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { if (layer_idx < MAX_LAYER_NUM) { if (strcmp(WeightFileModeName, "mod003") != 0) { LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_WGT.aes", "/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_ANC.aes", "/emmc/plugin/Aida/AIAML/anchors_GYNet_AIAML_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAML/anchors_GYNet_AIAML_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAML/GYNet_AIAML_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAML/AMB_AIAML_VER.txt,"); if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin"); } } else { LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_WGT.aes", "/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_ANC.aes", "/emmc/plugin/Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFRONTBACK/GYNet_AIFRONTBACK_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFRONTBACK/AMB_AIFRONTBACK_VER.txt,"); if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin"); } } layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AIAML; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAML; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; } } //AMBA Weight if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_WGT.aes", "/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_ANC.aes", "/emmc/plugin/Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISHIP/GYNet_AISHIP_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISHIP/AMB_AISHIP_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AISHIP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISHIP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_WGT.aes", "/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_ANC.aes", "/emmc/plugin/Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIPRODUCTION/GYNet_AIPRODUCTION_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIPRODUCTION/AMB_AIPRODUCTION_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_TWN\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/AMB_ANPR_TWN_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_TWN; layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_TWN; layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR)//20201216 Jim add { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_EUR\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/AMB_ANPR_EUR_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA || (featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM || (featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_SEA\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/AMB_ANPR_SEA_VER.txt,"); if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) { layerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } else if ((featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM) { layerFeatureType[layer_idx] = FEATURE_LPR_VNM; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_VNM; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } else if ((featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) { layerFeatureType[layer_idx] = FEATURE_LPR_IDN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_IDN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA)//20201216 Jim add { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_MEA\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/AMB_ANPR_MEA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_USA\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/AMB_ANPR_USA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) { if (layer_idx < MAX_LAYER_NUM - 1) { //printf("feature type = FEATURE_LPR_GBR\n"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/AMB_ANPR_GBR_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/AMB_ANPR_JPN_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/AMB_ANPR_THA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_BGD) == FEATURE_LPR_BGD) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_LPD_Label_BGD.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_OCR_Label_BGD.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRBGD/AMB_ANPR_BGD_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_BGD; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_BGD; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/AMB_ANPR_PHL_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_CNT) == FEATURE_LPR_CNT) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_LPD_Label_CNT.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_OCR_Label_CNT.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRCNT/AMB_ANPR_CNT_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_CNT; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_CNT; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin"); } } } //AMBA Weight if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) { if (layer_idx < MAX_LAYER_NUM - 1) { LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt", key, 0, false); LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/AMB_ANPR_AUS_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; layerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.tiny_enable[layer_idx] = 1; //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin"); cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin"); } } } //AMBA Weight if (g_IsToFDevice == 1) { if (layer_idx < MAX_LAYER_NUM) { LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_WGT.aes", "/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin", key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin,"); LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_ANC.aes", "/emmc/plugin/Aida/AITOF/anchors_GYNet_AITOF_ANC.txt", key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITOF/anchors_GYNet_AITOF_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITOF/GYNet_AITOF_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITOF/AMB_AITOF_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AITOF; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AITOF; stAMBAcontent.tiny_enable[layer_idx] = 1; layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin"); } } } //AMBA Weight if (g_IsRadarDevice == 1) { if (layer_idx < MAX_LAYER_NUM - 1) { strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRADAR/GYNet_Radar_Tiny_Label.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRADAR/AMB_AIRADAR_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_HUM_DET; layerFeatureType2[layer_idx] = FEATURE_AIRADAR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIRADAR; // stAMBAcontent.tiny_enable[layer_idx] = 1; // Radar ??????n YOLO layer_idx++; } } #endif #ifdef GY_OS_NOVA //NOVA Weight if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) { if (layer_idx < MAX_LAYER_NUM) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt")); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/NOV_Traffic_Tiny_VER.txt,"); if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIFLOW)); } else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIAREA)); } else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { layerFeatureType[layer_idx] = FEATURE_TRAF_DET; layerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 layer_idx++; cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AICAP)); } } } //NOVA Weight if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/NOV_ANPR_TWN_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_TWN; layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_TWN; layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_LPD_Label_USA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_OCR_Label_USA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/NOV_ANPR_USA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_USA; layerFeatureType2[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_USA; layerFeatureType2[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/NOV_ANPR_PHL_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_PHL; layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_PHL; layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_LPD_Label_THA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_OCR_Label_THA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/NOV_ANPR_THA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_THA; layerFeatureType2[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_THA; layerFeatureType2[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/NOV_ANPR_SEA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_SEA; layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_SEA; layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/NOV_ANPR_MEA_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_MEA; layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_MEA; layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_LPD_Label_EUR.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_OCR_Label_EUR.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/NOV_ANPR_EUR_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_EUR; layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_EUR; layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/NOV_ANPR_GBR_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_GBR; layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_GBR; layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/NOV_ANPR_JPN_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_JPN; layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_JPN; layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } //NOVA Weight if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) { if (layer_idx < MAX_LAYER_NUM - 1) { net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); net_info = cJSON_CreateObject(); cJSON_AddItemToArray(net_info_list, net_info); cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names")); cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/NOV_ANPR_AUS_VER.txt,"); layerFeatureType[layer_idx] = FEATURE_LPR_AUS; layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; //Second setting is for OCR det. layerFeatureType[layer_idx] = FEATURE_LPR_AUS; layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); layer_idx++; } } #endif } #ifdef GY_OS_NOVA cJSON_AddItemToObject(root_weight, "net_number", cJSON_CreateNumber(layer_idx)); char * JsonString_weight = cJSON_PrintUnformatted(root_weight); //(Nova: 生成授權設定檔 nova_driver_valid_weight.txt) write_driver_setting_file(JsonString_weight); if (JsonString_weight != NULL) { free(JsonString_weight); JsonString_weight = NULL; } if (root_weight) { cJSON_Delete(root_weight); root_weight = NULL; } if (IsExistingWeight(featureType, featureType2)) { pthread_t NOVA_detection/*, NOVA_listener, NOVA_listener_image*/; pthread_create(&NOVA_detection, 0, RUN_NOVA_DETECTION, NULL); //A11en create pthread to run detection printf("\n==== Gynet create nova_driver ====\n"); } #endif /* printf("\n--------------------\n"); printf("\nfeatureType: 0x%x\n", featureType); printf("\nfeatureType2: 0x%x\n", featureType2); printf("\n--------------------\n"); */ //printf("333 get password = %s \n", accountData[0].account_password); #ifdef GY_OS_AMBA //Third party weight //printf("td_weight_num: %d \n", td_weight_num); //printf("\n---------------key:%s\n",key); //printf("\n---------------mykey_custom:%s\n", mykey_custom); //printf("\n---------------first_half_char_key:%s\n", first_half_char_key); if(check_if_correct_mail == 1 && g_match_mac == 1) { for (int read_td_weight_idx = 0; read_td_weight_idx < td_weight_num; read_td_weight_idx++) { if (layer_idx < MAX_LAYER_NUM) { char ori_weight_name[MAX_MSG_LEN] = { 0 }; strcpy(ori_weight_name,"/emmc/plugin/Aida"); strcat(ori_weight_name, td_weight_info[read_td_weight_idx].weight_name); char new_weight_name[MAX_MSG_LEN] = { 0 }; strcpy(new_weight_name, "/emmc/plugin/Aida"); strcat(new_weight_name, td_weight_info[read_td_weight_idx].weight_name); new_weight_name[strlen(new_weight_name) - 3] = 'b'; new_weight_name[strlen(new_weight_name) - 2] = 'i'; new_weight_name[strlen(new_weight_name) - 1] = 'n'; //printf("\n-------------new_weight_name:%s\n", new_weight_name); if (td_weight_info[read_td_weight_idx].is_encryption == 1) { LILIN_File_Decryption(ori_weight_name, new_weight_name, first_half_char_key, 0, false); strcat(stAMBAcontent.sz_amba_NetworkNames, new_weight_name); } else strcat(stAMBAcontent.sz_amba_NetworkNames, ori_weight_name); strcat(stAMBAcontent.sz_amba_NetworkNames, ","); char ori_anchor_name[MAX_MSG_LEN] = { 0 }; strcpy(ori_anchor_name, "/emmc/plugin/Aida"); strcat(ori_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); char new_anchor_name[MAX_MSG_LEN] = { 0 }; strcpy(new_anchor_name, "/emmc/plugin/Aida"); strcat(new_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); new_anchor_name[strlen(new_anchor_name) - 3] = 't'; new_anchor_name[strlen(new_anchor_name) - 2] = 'x'; new_anchor_name[strlen(new_anchor_name) - 1] = 't'; //printf("\n-------------new_anchor_name:%s\n", new_anchor_name); if (td_weight_info[read_td_weight_idx].is_encryption == 1) { LILIN_File_Decryption(ori_anchor_name, new_anchor_name, first_half_char_key, 0, false); strcat(stAMBAcontent.sz_amba_anchor_fileNames, new_anchor_name); } else strcat(stAMBAcontent.sz_amba_anchor_fileNames, ori_anchor_name); strcat(stAMBAcontent.sz_amba_anchor_fileNames, ","); char ori_label_name[MAX_MSG_LEN] = { 0 }; strcpy(ori_label_name, "/emmc/plugin/Aida"); strcat(ori_label_name, td_weight_info[read_td_weight_idx].label_name); //printf("\n-------------ori_label_name:%s\n", ori_label_name); strcat(stAMBAcontent.sz_amba_label_fileNames, ori_label_name); strcat(stAMBAcontent.sz_amba_label_fileNames, ","); layerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; stAMBAcontent.tiny_enable[layer_idx] = 1; layer_idx++; if (g_IsSDK_3_0 == 1) { cavalry_gen_sdk_3_0(new_weight_name); } } } } #endif //printf("\n%s\n", stAMBAcontent.sz_amba_ver_fileNames); #ifdef TEST_DETECTOR_MEM //到此記憶體線漏大約1304個 //printf("\n--------------------------:6\n"); test_detector_mem(NULL, cnn_type, stAMBAcontent.sz_amba_NetworkNames, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, custom_cpu_library, custom_cldnn, performance_counter, nIsHardwareOK); #endif } else { printf("\n****************\n"); printf("No License Key"); printf("\n****************\n"); //沒有license key還是會運行http server, 可以用/server查詢伺服器狀態 //http_ip_address = (ip_address) ? ip_address : NULL; //http_http_port = http_port; licenseType = _TRIAL_LICENSE_FPS06; #ifdef TEST_DETECTOR_MEM test_detector_mem(NULL, cnn_type, NULL, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, NULL, NULL, performance_counter, nIsHardwareOK); #endif }/// if (fe && li && st && et && id) } else printf("config.json parse FAIL.\n"); } } else printf("-http_port %d not found!\n", http_port); //printf("999 get password = %s \n", accountData[0].account_password); printf("\n[run_server] end\n"); } void getCameraPlugInInfo() { //printf("\n---------------get Camera PlugIn Info start\n"); char filename[1024] = { 0 }; strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); if (!FileExist(filename)) printf("%s doesn't exist.\n", filename); else { char* fileBuf = ReadAllBytes(filename); if (fileBuf) { cJSON *plugin; plugin = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (plugin) { cJSON *description; description = cJSON_GetObjectItem(plugin, "description"); if (description) { if (strstr(description->valuestring, "LILIN") != NULL) { //printf("\n---------------get Camera PlugIn Info 1\n"); g_check_if_no_brand = 0; } else { //printf("\n---------------get Camera PlugIn Info 2\n"); g_check_if_no_brand = 1; } } else { //printf("\n---------------get Camera PlugIn Info 3\n"); g_check_if_no_brand = 0; } if (plugin) { cJSON_Delete(plugin); plugin = NULL; } } else printf("CameraPlug-in.json parse FAIL.\n"); } } //printf("\n---------------get Camera PlugIn Info end\n"); } long getCurrentTime() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * 1000 + tv.tv_usec / 1000; } static int CheckIsExistingWeight = 1; int IsExistingWeight(size_t featureType, size_t featureType2) { int nHasFeature = 0; int count_weight = 0; #ifdef GY_OS_AMBA if (strcmp(WeightFileModeName, "mod004") == 0) { if (weightfileList[30].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[30].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) { CheckIsExistingWeight = 0; } } else #endif { if (weightfileList[15].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) { #ifdef GY_OS_V_SERIES if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; } #else nHasFeature = 1; count_weight++; #endif CheckIsExistingSpeed = 1; } else if (weightfileList[15].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP )) { CheckIsExistingWeight = 0; } } if (weightfileList[27].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { nHasFeature = 1; count_weight++; } else if (weightfileList[27].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { CheckIsExistingWeight = 0; } if (weightfileList[28].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) { nHasFeature = 1; count_weight++; } else if (weightfileList[28].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) { CheckIsExistingWeight = 0; } if (weightfileList[11].enable_weight_to_run == 1 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) { nHasFeature = 1; count_weight++; } else if (weightfileList[11].enable_weight_to_run == 0 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) { CheckIsExistingWeight = 0; } if (weightfileList[13].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[13].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { CheckIsExistingWeight = 0; } if (weightfileList[22].enable_weight_to_run == 1 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[22].enable_weight_to_run == 0 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { CheckIsExistingWeight = 0; } if (weightfileList[23].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[23].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { CheckIsExistingWeight = 0; } if (strcmp(WeightFileModeName, "mod003") != 0) { if (weightfileList[12].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[12].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) { CheckIsExistingWeight = 0; } } else { if (weightfileList[25].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[25].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) { CheckIsExistingWeight = 0; } } if (weightfileList[14].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[14].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) { CheckIsExistingWeight = 0; } if (weightfileList[26].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) { nHasFeature = 1; count_weight++; } else if (weightfileList[26].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) { CheckIsExistingWeight = 0; } if (strcmp(WeightFileModeName, "mod003") != 0) { if (weightfileList[0].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[0].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { CheckIsExistingWeight = 0; } } else { if (weightfileList[29].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[29].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) { CheckIsExistingWeight = 0; } } if ((featureType & FEATURE_AIFISHTRAF) == FEATURE_AIFISHTRAF) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_POK_DET) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_HUM_POS) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_LED_DGT) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_SHOES_DET) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[10].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_LOGO) != 0) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[10].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_LOGO) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[7].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_TWN) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[7].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_TWN) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[1].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_EUR) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[1].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_EUR) != 0) { CheckIsExistingWeight = 0; } if ((weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_SEA) != 0) || (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) || (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0)) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if ((weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_SEA) != 0) || (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) || (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0)) { CheckIsExistingWeight = 0; } #if 0 if (weightfileList[9].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[9].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) { CheckIsExistingWeight = 0; } #endif /* if ((featureType & FEATURE_LPR_CNA) != 0) { CheckIsExistingWeight = 0; }*/ if (weightfileList[17].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_MEA) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[17].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_MEA) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[19].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_AUS) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[19].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_AUS) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[8].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_USA) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if(weightfileList[8].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_USA) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[2].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_GBR) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[2].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_GBR) != 0) { CheckIsExistingWeight = 0; } #if 0 if (weightfileList[24].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[24].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0) { CheckIsExistingWeight = 0; } #endif if (weightfileList[3].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_JPN) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[3].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_JPN) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_LPR_IND) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[6].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_THA) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[6].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_THA) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_LPR_LAO) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[16].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_BGD) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[16].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_BGD) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[4].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_PHL) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[4].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_PHL) != 0) { CheckIsExistingWeight = 0; } if (weightfileList[18].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_CNT) != 0) { if (g_check_if_OK_getfeatures == 0) { CheckIsExistingWeight = 0; } else { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } } else if (weightfileList[18].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_CNT) != 0) { CheckIsExistingWeight = 0; } if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && featureType2 == FEATURE_EMPTY) { CheckIsExistingWeight = 0; } if (g_IsCustomWeight == 1) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } if (weightfileList[20].enable_weight_to_run == 1 && g_IsRadarDevice == 1) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if (weightfileList[20].enable_weight_to_run == 0 && g_IsRadarDevice == 1) { CheckIsExistingWeight = 0; } if (weightfileList[21].enable_weight_to_run == 1 && g_IsToFDevice == 1) { nHasFeature = 1; count_weight++; CheckIsExistingSpeed = 1; } else if(weightfileList[21].enable_weight_to_run == 0 && g_IsToFDevice == 1){ CheckIsExistingWeight = 0; } if (unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 1) { nHasFeature = 1; count_weight++; } else if(unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 0){ CheckIsExistingWeight = 0; } if (count_weight >= 2) { #ifdef GY_OS_NOVA CheckIsExistingWeight = 0; #endif } return (CheckIsExistingWeight) > 0 && nHasFeature == 1 ? 1 : 0; } void RefreshCheckExistingWeight() { CheckIsExistingWeight = 1; } #ifdef GY_OS_AMBA void cavalry_gen_sdk_3_0(char * bin_name) { { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); sprintf(cmd, "/usr/local/bin/cavalry_gen -f %s -t /emmc/plugin/Aida/temp.bin -V 2.2.8.3", bin_name); pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); sprintf(cmd, "cp /emmc/plugin/Aida/temp.bin %s", bin_name); pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } { FILE * pPipe; char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); sprintf(cmd, "rm -f /emmc/plugin/Aida/temp.bin"); pPipe = vpopen(cmd, "r"); if (pPipe != NULL) vpclose(pPipe); } } #endif void initial_weight_settings() { //會根據設定檔,建立權重是否啟動 strcpy(weightfileList[0].weight_repository, "AIAML"); strcpy(weightfileList[1].weight_repository, "AIANPREUR"); strcpy(weightfileList[2].weight_repository, "AIANPRGBR"); strcpy(weightfileList[3].weight_repository, "AIANPRJPN"); strcpy(weightfileList[4].weight_repository, "AIANPRPHL"); strcpy(weightfileList[5].weight_repository, "AIANPRSEA"); strcpy(weightfileList[6].weight_repository, "AIANPRTHA"); strcpy(weightfileList[7].weight_repository, "AIANPRTWN"); strcpy(weightfileList[8].weight_repository, "AIANPRUSA"); strcpy(weightfileList[9].weight_repository, "AIANPRVNM"); strcpy(weightfileList[10].weight_repository, "AICarMake"); strcpy(weightfileList[11].weight_repository, "AIFIRE"); strcpy(weightfileList[12].weight_repository, "AIHUMAN"); strcpy(weightfileList[13].weight_repository, "AISAFTY"); strcpy(weightfileList[14].weight_repository, "AISHIP"); strcpy(weightfileList[15].weight_repository, "AITRAFFIC"); strcpy(weightfileList[16].weight_repository, "AIANPRBGD"); strcpy(weightfileList[17].weight_repository, "AIANPRMEA"); strcpy(weightfileList[18].weight_repository, "AIANPRCNT"); strcpy(weightfileList[19].weight_repository, "AIANPRAUS"); strcpy(weightfileList[20].weight_repository, "AIRADAR"); // Ken 2022-10-13 strcpy(weightfileList[21].weight_repository, "AITOF"); strcpy(weightfileList[22].weight_repository, "AIRAILWAY"); strcpy(weightfileList[23].weight_repository, "AISPORTS"); strcpy(weightfileList[24].weight_repository, "AIANPRIDN"); strcpy(weightfileList[25].weight_repository, "AIGENDER"); strcpy(weightfileList[26].weight_repository, "AIPRODUCTION"); strcpy(weightfileList[27].weight_repository, "AIGARBAGE"); strcpy(weightfileList[28].weight_repository, "AIAERO"); strcpy(weightfileList[29].weight_repository, "AIFRONTBACK"); strcpy(weightfileList[30].weight_repository, "AITHERMAL"); for (size_t index_weightfile = 0; index_weightfile < MAX_WEIGHT_FILE_LIST; index_weightfile++) { weightfileList[index_weightfile].enable_weight_to_run = 0; } char c_file_name_weight_setting[1024] = { 0 }; strcpy(c_file_name_weight_setting, "/emmc/plugin/Aida_data/weight_setting.json"); if (!FileExist(c_file_name_weight_setting) || ReadFileSize(c_file_name_weight_setting) == 0) { printf("weight_setting file doesn't exist.\n"); cJSON *s_root = cJSON_CreateObject(); cJSON_AddItemToObject(s_root, "mode_name", cJSON_CreateString("mode_err")); //AIAML,AIANPREUR,AIANPRGBR,AIANPRJPN,AIANPRPHL,AIANPRSEA,AIANPRTHA,AIANPRTWN,AIANPRUSA,AIANPRVNM,AICarMake,AIFIRE,AIHUMAN,AISAFTY,AISHIP,AITRAFFIC cJSON_AddItemToObject(s_root, "mode_repository", cJSON_CreateString("")); char* JsonString = cJSON_Print(s_root); FILE *f = fopen(c_file_name_weight_setting, "w"); if (f == NULL) { printf("Error opening setting file!\n"); } else { fprintf(f, "%s\n", JsonString); fclose(f); } if (JsonString) { free(JsonString); JsonString = NULL; } if (s_root) { free(s_root); s_root = NULL; } } cJSON* root_weight_setting, *mode_name, *mode_repository; if (!FileExist(c_file_name_weight_setting)) { printf("%s doesn't exist.\n", c_file_name_weight_setting); } else { char* fileBuf_weight_setting = ReadAllBytes(c_file_name_weight_setting); if (fileBuf_weight_setting) { root_weight_setting = cJSON_Parse(fileBuf_weight_setting); if (fileBuf_weight_setting) { free(fileBuf_weight_setting); fileBuf_weight_setting = NULL; } mode_name = cJSON_GetObjectItem(root_weight_setting, "mode_name"); mode_repository = cJSON_GetObjectItem(root_weight_setting, "mode_repository"); strcpy(WeightFileModeName, mode_name->valuestring); char temp_buf_mode_repository[1024] = { 0 }; strcpy(temp_buf_mode_repository, mode_repository->valuestring); if (strstr(temp_buf_mode_repository, "AIAML") != NULL) { weightfileList[0].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPREUR") != NULL) { weightfileList[1].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRGBR") != NULL) { weightfileList[2].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRJPN") != NULL) { weightfileList[3].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRPHL") != NULL) { weightfileList[4].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRSEA") != NULL) { weightfileList[5].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRTHA") != NULL) { weightfileList[6].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRTWN") != NULL) { weightfileList[7].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRUSA") != NULL) { weightfileList[8].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRVNM") != NULL) { weightfileList[9].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AICarMake") != NULL) { weightfileList[10].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIFIRE") != NULL) { weightfileList[11].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIHUMAN") != NULL) { weightfileList[12].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AISAFTY") != NULL) { weightfileList[13].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AISHIP") != NULL) { weightfileList[14].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AITRAFFIC") != NULL) { weightfileList[15].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRBGD") != NULL) { weightfileList[16].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRMEA") != NULL) { weightfileList[17].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRCNT") != NULL) { weightfileList[18].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRAUS") != NULL) { weightfileList[19].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIRADAR") != NULL) { weightfileList[20].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AITOF") != NULL) { weightfileList[21].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIRAILWAY") != NULL) { weightfileList[22].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AISPORTS") != NULL) { weightfileList[23].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIANPRIDN") != NULL) { weightfileList[24].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIGENDER") != NULL) { weightfileList[25].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIPRODUCTION") != NULL) { weightfileList[26].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIGARBAGE") != NULL) { weightfileList[27].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIAERO") != NULL) { weightfileList[28].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AIFRONTBACK") != NULL) { weightfileList[29].enable_weight_to_run = 1; } if (strstr(temp_buf_mode_repository, "AITHERMAL") != NULL) { weightfileList[30].enable_weight_to_run = 1; } if (root_weight_setting) { cJSON_Delete(root_weight_setting); root_weight_setting = NULL; } } } } void file_management() { char buf[1024] = { 0 }; readlink("/proc/self/exe", buf, sizeof(buf)); //printf("Program binary path is: %s\n", buf); char exePath[1024] = { 0 }; getFilePath(buf, exePath, 1024); char configPATH[1024] = { 0 }; #ifdef GY_OS_NOVA char config_smallPATH[1024] = { 0 }; #endif char config_installPATH[1024] = { 0 }; #ifdef GY_OS_NOVA char config_small_installPATH[1024] = { 0 }; #endif char config_bakPATH[1024] = { 0 }; char events_installPATH[1024] = { 0 }; char eventsPATH[1024] = { 0 }; char events_bakPATH[1024] = { 0 }; char tof_installPATH[1024] = { 0 }; char tofPATH[1024] = { 0 }; char tof_bakPATH[1024] = { 0 }; char emails_installPATH[1024] = { 0 }; char emailsPATH[1024] = { 0 }; char emails_bakPATH[1024] = { 0 }; char cold_objects_installPATH[1024] = { 0 }; char cold_objectsPATH[1024] = { 0 }; char face_installPATH[1024] = { 0 }; char facePATH[1024] = { 0 }; char db_fflprPATH[1024] = { 0 }; char db_fflpr_installPATH[1024] = { 0 }; char db_fflpr_bakPATH[1024] = { 0 }; char db_facePATH[1024] = { 0 }; char db_face_installPATH[1024] = { 0 }; char db_face_bakPATH[1024] = { 0 }; char face_license_PATH[1024] = { 0 }; char face_license_installPATH[1024] = { 0 }; char face_license_bakPATH[1024] = { 0 }; strcpy(configPATH, exePath); #ifdef GY_OS_NOVA strcpy(config_smallPATH, exePath); #endif strcpy(config_installPATH, exePath); #ifdef GY_OS_NOVA strcpy(config_small_installPATH, exePath); #endif strcpy(config_bakPATH, exePath); strcpy(eventsPATH, exePath); strcpy(events_installPATH, exePath); strcpy(events_bakPATH, exePath); strcpy(tofPATH, exePath); strcpy(tof_installPATH, exePath); strcpy(tof_bakPATH, exePath); strcpy(emailsPATH, exePath); strcpy(emails_installPATH, exePath); strcpy(emails_bakPATH, exePath); strcpy(cold_objectsPATH, exePath); strcpy(cold_objects_installPATH, exePath); strcpy(facePATH, exePath); strcpy(face_installPATH, exePath); strcpy(db_fflprPATH, exePath); strcpy(db_fflpr_installPATH, exePath); strcpy(db_fflpr_bakPATH, exePath); strcpy(db_facePATH, exePath); strcpy(db_face_installPATH, exePath); strcpy(db_face_bakPATH, exePath); strcpy(face_license_PATH, exePath); strcpy(face_license_installPATH, exePath); strcpy(face_license_bakPATH, exePath); strcat(configPATH, "config.json"); #ifdef GY_OS_NOVA strcat(config_smallPATH, "config_small.json"); #endif strcat(config_installPATH, "config_install.json"); #ifdef GY_OS_NOVA strcat(config_small_installPATH, "config_small_install.json"); #endif strcat(config_bakPATH, "config_bak.json"); strcat(eventsPATH, "events.json"); strcat(events_installPATH, "events_install.json"); strcat(events_bakPATH, "events_bak.json"); strcat(tofPATH, "tof.json"); strcat(tof_installPATH, "tof_install.json"); strcat(tof_bakPATH, "tof_bak.json"); strcat(emailsPATH, "emails.json"); strcat(emails_installPATH, "emails_install.json"); strcat(emails_bakPATH, "emails_bak.json"); strcat(cold_objectsPATH, "cold_objects.json"); strcat(cold_objects_installPATH, "cold_objects_install.json"); strcat(facePATH, "sfe/iengine.lic"); strcat(face_installPATH, "sfe/iengine_install.lic"); #if defined GY_OS_AMBA || defined GY_OS_NOVA strcat(db_fflprPATH, "db_fflpr.db"); strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); strcat(db_facePATH, "db_face.db"); strcat(db_face_installPATH, "db_face_install_2.db"); #endif //確認config_bak.json沒有壞掉 { char* fileBuf = ReadAllBytes(config_bakPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config_bakPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { //printf("config_bakPATH parse FAIL.0\n"); if (FileExist(config_bakPATH)) { int del = unlink(config_bakPATH); if (!del) { //printf("config_bakPATH is Deleted successfully."); } else { printf("config_bakPATH cannot be Deleted.\n"); } } } } } if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) >= 20000) { //CopyFileTo(configPATH, config_bakPATH); CopyFileTo(config_bakPATH, configPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bak to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); } else if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) < 20000) { int del = remove(config_bakPATH); if (!del) { //printf("config_bak is Deleted successfully."); } else { printf("config_bak cannot be Deleted.\n"); } } //確認config.json沒有壞掉 { char* fileBuf = ReadAllBytes(configPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config_bakPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { printf("configPATH parse FAIL.0\n"); if (FileExist(config_bakPATH)) { printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bakPATH to main_0 config <<<<<<<<<<<<<<<<<<<<<<<\n"); CopyFileTo(config_bakPATH, configPATH); } else { if (FileExist(configPATH)) { int del = unlink(configPATH); if (!del) { //printf("configPATH is Deleted successfully."); } else { printf("configPATH cannot be Deleted.\n"); } } } } } } //確認events_bak.json沒有壞掉 { char* fileBuf = ReadAllBytes(events_bakPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config_bakPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { //printf("events_bakPATH parse FAIL.0\n"); if (FileExist(events_bakPATH)) { int del = unlink(events_bakPATH); if (!del) { //printf("config_bakPATH is Deleted successfully."); } else { printf("events_bakPATH cannot be Deleted.\n"); } } } } } if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) >= 8000) { CopyFileTo(events_bakPATH, eventsPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bak to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); } else if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) < 8000) { int del = remove(events_bakPATH); if (!del) { //printf("events_bak is Deleted successfully."); } else { printf("events_bak cannot be Deleted.\n"); } } //確認events.json沒有壞掉 { char* fileBuf = ReadAllBytes(eventsPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("eventsPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { printf("eventsPATH parse FAIL.0\n"); if (FileExist(events_bakPATH)) { printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); CopyFileTo(events_bakPATH, eventsPATH); } else { if (FileExist(events_bakPATH)) { int del = unlink(events_bakPATH); if (!del) { //printf("events_bakPATH is Deleted successfully."); } else { printf("events_bakPATH cannot be Deleted.\n"); } } } } } } //確認tof_bak.json沒有壞掉 { char* fileBuf = ReadAllBytes(tof_bakPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("tof_bakPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { //printf("tof_bakPATH parse FAIL.0\n"); if (FileExist(tof_bakPATH)) { int del = unlink(tof_bakPATH); if (!del) { //printf("tof_bakPATH is Deleted successfully."); } else { printf("tof_bakPATH cannot be Deleted.\n"); } } } } } if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) >= 250) { CopyFileTo(tof_bakPATH, tofPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bak to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); } else if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) < 250) { int del = remove(tof_bakPATH); if (!del) { //printf("tof_bak is Deleted successfully."); } else { printf("tof_bak cannot be Deleted.\n"); } } //確認tof.json沒有壞掉 { char* fileBuf = ReadAllBytes(tofPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("eventsPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { printf("tofPATH parse FAIL.0\n"); if (FileExist(tof_bakPATH)) { printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bakPATH to main_0 tof <<<<<<<<<<<<<<<<<<<<<<<\n"); CopyFileTo(tof_bakPATH, tofPATH); } else { if (FileExist(tof_bakPATH)) { int del = unlink(tof_bakPATH); if (!del) { //printf("tof_bakPATH is Deleted successfully."); } else { printf("tof_bakPATH cannot be Deleted.\n"); } } } } } } //確認emails_bak.json沒有壞掉 { char* fileBuf = ReadAllBytes(emails_bakPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("config_bakPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { //printf("emails_bakPATH parse FAIL.0\n"); if (FileExist(emails_bakPATH)) { int del = unlink(emails_bakPATH); if (!del) { //printf("emails_bakPATH is Deleted successfully."); } else { printf("emails_bakPATH cannot be Deleted.\n"); } } } } } //確認emails.json沒有壞掉 { char* fileBuf = ReadAllBytes(emailsPATH); if (fileBuf) { cJSON* root; root = cJSON_Parse(fileBuf); if (fileBuf) { free(fileBuf); fileBuf = NULL; } if (root) { //printf("eventsPATH parse OK\n"); cJSON_Delete(root); root = NULL; } else { printf("emailsPATH parse FAIL.0\n"); if (FileExist(emails_bakPATH)) { printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_bakPATH to main_0 emails <<<<<<<<<<<<<<<<<<<<<<<\n"); CopyFileTo(emails_bakPATH, emailsPATH); } else { if (FileExist(emails_bakPATH)) { int del = unlink(emails_bakPATH); if (!del) { //printf("emails_bakPATH is Deleted successfully."); } else { printf("emails_bakPATH cannot be Deleted.\n"); } } } } } } #if defined GY_OS_AMBA || defined GY_OS_NOVA //確認是不是剛update LPKG,如果是則刪除舊的db,以符合新的db格式。 { char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; if (FileExist(NEW_UPDATE_PATH)) { int del = unlink(NEW_UPDATE_PATH); if (!del) { //printf("txt is Deleted successfully."); } else { printf("NEW UPDATE PATH cannot be Deleted.\n"); } /*char DB_FFLPR_PATH[1024] = "/emmc/plugin/Aida_data/db_fflpr.db"; if (FileExist(DB_FFLPR_PATH)) { int del = unlink(DB_FFLPR_PATH); if (!del) { //printf("db is Deleted successfully."); } else { printf("DB FFLPR PATH cannot be Deleted.\n"); } }*/ char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; if (FileExist(DB_FACE_PATH)) { int del = unlink(DB_FACE_PATH); if (!del) { //printf("db is Deleted successfully."); } else { printf("DB FACE PATH cannot be Deleted.\n"); } } delete_file("/emmc/plugin/Aida_data/sfe/storage/entities.rec"); delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.map"); delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.rec"); delete_file("/emmc/plugin/Aida_data/sfe/storage/labels.rec"); } } { //face db char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; if (FileExist(NEW_UPDATE_PATH)) { int del = unlink(NEW_UPDATE_PATH); if (!del) { //printf("txt is Deleted successfully."); } else { printf("NEW UPDATE PATH cannot be Deleted.\n"); } char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; if (FileExist(DB_FACE_PATH)) { int del = unlink(DB_FACE_PATH); if (!del) { //printf("db is Deleted successfully."); } else { printf("DB FACE PATH cannot be Deleted.\n"); } } } } #endif if (FileExist(config_installPATH) == 1 && (FileExist(configPATH) == 0 || ReadFileSize(configPATH) == 0)) { CopyFileTo(config_installPATH, configPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(config_installPATH) == 1 && (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) == 0)) { CopyFileTo(config_installPATH, config_bakPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to back config <<<<<<<<<<<<<<<<<<<<<<<\n"); } #ifdef GY_OS_NOVA if (FileExist(config_small_installPATH) == 1 && (FileExist(config_smallPATH) == 0 || ReadFileSize(config_smallPATH) == 0)) { CopyFileTo(config_small_installPATH, config_smallPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_small_installPATH to main config_small <<<<<<<<<<<<<<<<<<<<<<<\n"); } #endif if (FileExist(events_installPATH) == 1 && (FileExist(eventsPATH) == 0 || ReadFileSize(eventsPATH) == 0)) { CopyFileTo(events_installPATH, eventsPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(events_installPATH) == 1 && (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) == 0)) { CopyFileTo(events_installPATH, events_bakPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to back events <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(tof_installPATH) == 1 && (FileExist(tofPATH) == 0 || ReadFileSize(tofPATH) == 0)) { CopyFileTo(tof_installPATH, tofPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(tof_installPATH) == 1 && (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) == 0)) { CopyFileTo(tof_installPATH, tof_bakPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to back tof <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(emails_installPATH) == 1 && (FileExist(emailsPATH) == 0 || ReadFileSize(emailsPATH) == 0)) { CopyFileTo(emails_installPATH, emailsPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to main emails <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(emails_installPATH) == 1 && (FileExist(emails_bakPATH) == 1 && ReadFileSize(emails_bakPATH) == 0)) { CopyFileTo(emails_installPATH, emails_bakPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to back emails <<<<<<<<<<<<<<<<<<<<<<<\n"); } #if defined GY_OS_AMBA || defined GY_OS_NOVA if (FileExist(db_fflpr_installPATH) == 1 && (FileExist(db_fflprPATH) == 0 || ReadFileSize(db_fflprPATH) == 0)) { CopyFileTo(db_fflpr_installPATH, db_fflprPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_fflpr_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(db_face_installPATH) == 1 && (FileExist(db_facePATH) == 0 || ReadFileSize(db_facePATH) == 0)) { CopyFileTo(db_face_installPATH, db_facePATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_face_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); } #endif if (FileExist(face_installPATH) == 1 && (FileExist(facePATH) == 0 || ReadFileSize(facePATH) == 0)) { CopyFileTo(face_installPATH, facePATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy face_install to main face <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist(cold_objects_installPATH) == 1 && (FileExist(cold_objectsPATH) == 0 || ReadFileSize(cold_objectsPATH) == 0)) { CopyFileTo(cold_objects_installPATH, cold_objectsPATH); printf(">>>>>>>>>>>>>>>>>>>>>> Copy cold_objects_install to main cold_objects <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_bak to main heatmap_data <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_1_bak.js", "/emmc/plugin/Aida/heatmap_data_1.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_1_bak to main heatmap_data_1 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_2_bak.js", "/emmc/plugin/Aida/heatmap_data_2.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_2_bak to main heatmap_data_2 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_3_bak.js", "/emmc/plugin/Aida/heatmap_data_3.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_3_bak to main heatmap_data_3 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_4_bak.js", "/emmc/plugin/Aida/heatmap_data_4.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_4_bak to main heatmap_data_4 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_5_bak.js", "/emmc/plugin/Aida/heatmap_data_5.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_5_bak to main heatmap_data_5 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_6_bak.js", "/emmc/plugin/Aida/heatmap_data_6.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_6_bak to main heatmap_data_6 <<<<<<<<<<<<<<<<<<<<<<<\n"); } if (FileExist("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") >= 1) { CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_7_bak.js", "/emmc/plugin/Aida/heatmap_data_7.js"); printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_7_bak to main heatmap_data_7 <<<<<<<<<<<<<<<<<<<<<<<\n"); } #ifdef GY_OS_AMBA char sdk_versionPATH[1024] = { 0 }; strcpy(sdk_versionPATH, exePath); strcat(sdk_versionPATH, "sdk_version.txt"); { char *filename = sdk_versionPATH; if (FileExist(filename)) { char* fileBuf = ReadAllBytes(filename); //printf("\n[run server]----sdk version:%s\n", fileBuf); if (strstr(fileBuf, "3.0") != NULL) { g_IsSDK_3_0 = 1; } if (fileBuf) { free(fileBuf); fileBuf = NULL; } } } #endif } #ifdef GY_OS_NOVA int get_pid_nova_driver() { char *temp = NULL; int size_psBuffer = 512; char psBuffer[512] = { 0 }; { char cmd[256] = { 0 }; memset(cmd, 0x00, sizeof(cmd)); sprintf(cmd, "pidof nova_driver"); FILE * pPipe; pPipe = vpopen(cmd, "r"); if (pPipe != NULL) { temp = fgets(psBuffer, size_psBuffer, pPipe); if (pPipe != NULL) vpclose(pPipe); } } if (temp != NULL && (int)strlen(psBuffer) >= 1) { /* printf("\n-------------------------------\n"); printf("\psBuffer: %d\n", atoi(psBuffer)); printf("\n-------------------------------\n"); */ return atoi(psBuffer); } return -1; } int g_check_run_nova_detection = 0; void *RUN_NOVA_DETECTION(void *ptr) { //A11en pthread_detach(pthread_self()); setPthreadName("RUN_NOVA"); usSleep(1000000); system("killall -15 nova_driver"); usSleep(15000000); char cmd[256] = { 0 }; sprintf(cmd,"/emmc/plugin/Aida_data/nova_driver server -http_port %s &", accountData[0].account_aida_port); g_check_run_nova_detection = 1; system(cmd); usSleep(2000000); if (get_live_mode_flag() == 1 && g_check_run_nova_detection == 1) { if (get_pid_nova_driver() == -1) { char temp_msg[8192] = { 0 }; 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"); pthread_t auto_reboot_thread_id; if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) { printf("\ncreate auto reboot thread faile \n"); } } } pthread_exit(NULL); } #endif