You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
4992 lines
152 KiB
4992 lines
152 KiB
|
|
|
|
//#include <curl/curl.h> |
|
//#include <curl/easy.h> |
|
|
|
#include "setting.h" |
|
#include "ptz.h" |
|
#include "network.h" |
|
#include <math.h> |
|
#include <pthread.h> |
|
#include "cgicmd.h" |
|
#ifdef GY_OS_AMBA |
|
|
|
#ifdef GY_OS_WIN |
|
#include "curl.h" |
|
#include "easy.h" |
|
#endif |
|
|
|
#if defined GY_OS_AMBA || defined GY_OS_NOVA |
|
#include "curl/curl.h" |
|
#include "curl/easy.h" |
|
#endif |
|
|
|
#define USE_CURL |
|
#define USE_SOCKET |
|
|
|
|
|
//PTZ_HANDLE g_stPTZSetting; |
|
pthread_t ptz_status_thread; |
|
pthread_t ptz_tracking_thread; |
|
|
|
pthread_t ptz_zoom_thread; |
|
|
|
PTZ_HANDLE g_stPTZ_Handle; |
|
PTZ_ZONE_INFO g_stPTZ_Zone_info[MAX_DETECTION_ZONE]; |
|
|
|
//CURL *g_curl_Handle; |
|
//struct curl_slist *g_pList = NULL; |
|
|
|
int g_IsShipTracking; |
|
|
|
int g_PTZ_model = -1; |
|
|
|
|
|
//PTZ_HANDLE *CreatePTZHandle() |
|
//{ |
|
// PTZ_HANDLE *p_ptzHandle = (struct PTZ_HANDLE *) malloc(sizeof(struct PTZ_HANDLE)); |
|
|
|
// return p_ptzHandle; |
|
//} |
|
|
|
//void DeletePTZHandle(PTZ_HANDLE *pInPTZHandle) |
|
//{ |
|
// if (pInPTZHandle) |
|
// free(pInPTZHandle); |
|
//} |
|
|
|
#ifndef pmax |
|
#define pmax(a,b) (((a) > (b)) ? (a) : (b)) |
|
#endif |
|
|
|
#ifndef pmin |
|
#define pmin(a,b) (((a) < (b)) ? (a) : (b)) |
|
#endif |
|
|
|
/*float object_iou(PTZ_VIRTUAL_BOX *box1, PTZ_VIRTUAL_BOX *box2) |
|
{ |
|
if (box1->left_x > box2->left_x + box2->width) { return 0.0; } |
|
if (box1->top_y > box2->top_y + box2->height) { return 0.0; } |
|
if (box1->left_x + box1->width < box2->left_x) { return 0.0; } |
|
if (box1->top_y + box1->height < box2->top_y) { return 0.0; } |
|
float colInt = abs(pmin(box1->left_x + box1->width, box2->left_x + box2->width) - pmax(box1->left_x, box2->left_x)); |
|
float rowInt = abs(pmin(box1->top_y + box1->height, box2->top_y + box2->height) - pmax(box1->top_y, box2->top_y)); |
|
float overlapArea = colInt * rowInt; //相交處面積 |
|
float area1 = box1->width * box1->height; |
|
float area2 = box2->width * box2->height; |
|
float smallerArea = (area1 > area2) ? area2 : area1; |
|
return overlapArea / smallerArea; //相交處面積占較小物件比例 |
|
//return overlapArea / (area1 + area2 - overlapArea); //相交處面積比例占大小物件加總比例 |
|
}*/ |
|
|
|
void SetPtzWaitDwellTime(int iDwellTime) |
|
{ |
|
g_stPTZ_Handle.iTracking_resume_dwell = iDwellTime; |
|
} |
|
|
|
void SetPtzSensitivity(int iSensitivity) |
|
{ |
|
//g_stPTZ_Handle.iTimer_send_count = 0; |
|
|
|
g_stPTZ_Handle.iPTZ_speed = iSensitivity; |
|
|
|
g_stPTZ_Handle.iZoomFreqCount = 1; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 1; |
|
g_stPTZ_Handle.iGoCenterFreqCount = 1; |
|
|
|
#if 0 |
|
if (iSensitivity >= 1 |
|
&& iSensitivity <= 6) |
|
g_stPTZ_Handle.iPTZ_sensitivity = 6 - iSensitivity + 1; |
|
else |
|
g_stPTZ_Handle.iPTZ_sensitivity = PTZ_DEFAULT_SENSITIVITY; |
|
|
|
if (g_stPTZ_Handle.iPTZ_sensitivity < 0) |
|
g_stPTZ_Handle.iPTZ_sensitivity = 0; |
|
#endif |
|
} |
|
|
|
|
|
|
|
|
|
int MirrorBondingBox(int x, int w) |
|
{ |
|
int dwMirror_X = 0; |
|
|
|
if (w > 0 && x >= 0 && x < w) |
|
{ |
|
dwMirror_X = 0 + w - (x + 1); |
|
} |
|
else |
|
{ |
|
if (x > 0) |
|
dwMirror_X = x; |
|
else |
|
dwMirror_X = 0; |
|
} |
|
|
|
//g_iScaledBoundingBoxWidth, g_iScaledBoundingBoxHeight, |
|
|
|
return dwMirror_X; |
|
} |
|
|
|
int FlipBondingBox(int y, int h) |
|
{ |
|
int dwFlip_Y = 0; |
|
|
|
if (h > 0 && y >= 0 && y < h) |
|
{ |
|
dwFlip_Y = 0 + h - (y + 1); |
|
} |
|
else |
|
{ |
|
if (y > 0) |
|
dwFlip_Y = y; |
|
else |
|
dwFlip_Y = 0; |
|
} |
|
|
|
//g_iScaledBoundingBoxWidth, g_iScaledBoundingBoxHeight, |
|
|
|
return dwFlip_Y; |
|
} |
|
|
|
void Mirror_Flip_posInfo(detection_pos *PosInfo, int iTotalElementSize, int iIm_width, int iIm_height, int iMirrorFlag, int iFlipFlag) |
|
{ |
|
detection_pos *pNext = NULL; |
|
|
|
if (iMirrorFlag == 1 || iFlipFlag == 1) |
|
{ |
|
for (int i = 0; i < iTotalElementSize; i++) |
|
{ |
|
pNext = PosInfo + i; |
|
|
|
if (iMirrorFlag == 1) |
|
{ |
|
pNext->left_x = MirrorBondingBox((int)pNext->left_x, iIm_width) - pNext->width; |
|
pNext->center_x = MirrorBondingBox((int)pNext->center_x, iIm_width); |
|
//pNext->box_x = selected_detections[i].det.bbox.x; |
|
} |
|
|
|
if (iFlipFlag == 1) |
|
{ |
|
pNext->top_y = FlipBondingBox((int)pNext->top_y, iIm_height) - pNext->height; |
|
pNext->center_y = FlipBondingBox((int)pNext->center_y, iIm_height); |
|
//pNext->box_y = selected_detections[i].det.bbox.y; |
|
} |
|
} |
|
} |
|
} |
|
|
|
size_t ptz_cmd_curl_callback(void *ptr, size_t size, size_t nmemb, void *stream) { |
|
/* |
|
time_t timep; |
|
struct tm * timeinfo; |
|
time(&timep); |
|
timeinfo = localtime(&timep); |
|
*/ |
|
size_t realsize = size * nmemb; |
|
//cJSON *r_root, *r_tstamp; |
|
|
|
//time_t r_timep; |
|
//struct tm * r_timeinfo; |
|
//time(&timep); |
|
if (stream) |
|
{ |
|
//printf("Magic: %s \n", (char *)stream); |
|
//free(stream); |
|
|
|
sprintf((char *)stream, "%s", (char *)ptr); |
|
return realsize; |
|
} |
|
else |
|
{ |
|
return 0; |
|
} |
|
|
|
//printf(">>>>>>>>>>>>> Get PTZ Curl resp:\n %s \n", (char *)ptr); |
|
//printf(">>>>>>>>>>>>> Response Time: %d-%02d-%02d ", (1900 + timeinfo->tm_year), (1 + timeinfo->tm_mon), timeinfo->tm_mday); |
|
//printf("%02d:%02d:%02d\n\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
|
|
|
} |
|
#if 0 |
|
int net_socket_ptz_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, |
|
char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) |
|
{ |
|
int l_ret = 0; |
|
pthread_mutex_lock(&mutex_send_cgi); |
|
SetHttpRequest_ptz(sUrl, sOutputData, sUserNmae, sPassWord); |
|
//SetHttpRequest_ptz_re(sUrl, sOutputData, sUserNmae, sPassWord); |
|
pthread_mutex_unlock(&mutex_send_cgi); |
|
return l_ret; |
|
} |
|
#endif |
|
//extern CURLM* g_multi_handle; |
|
//extern int g_handle_count; |
|
extern amba_content stAMBAcontent; |
|
|
|
#if 0 |
|
int net_curl_ptz_cmd_multi_interface(const char *sUrl, const char *sData, void *callback_data, char *method, |
|
char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) |
|
{ |
|
pthread_mutex_lock(&mutex_curl); |
|
CURL *curl = g_http_handle; |
|
CURLcode l_res; |
|
int l_ret = -1; |
|
//const int timeout = 30000; |
|
const int timeout = 100; |
|
//char *sBuffer; |
|
char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; |
|
curl = curl_easy_init(); |
|
|
|
//char response_data[512] = { 0 }; |
|
//char *response_data; |
|
//response_data = malloc(512); |
|
//strcat(response_data, "mmmmmmmmmmmmmmagic"); |
|
|
|
if (curl != NULL) |
|
{ |
|
struct curl_slist *pList = NULL; |
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
//pList = curl_slist_append(pList, "Content-Type:application/json"); |
|
pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); |
|
//Connection: close |
|
} |
|
pList = curl_slist_append(pList, "charset: utf-8"); |
|
pList = curl_slist_append(pList, "Connection: close"); |
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); |
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3); |
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3); |
|
|
|
time_t s_timep = time(0); |
|
struct tm *s_timeinfo = localtime(&s_timep); |
|
//printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); |
|
//printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); |
|
|
|
char test_countent[25] = { 0 }; |
|
strncpy(test_countent, sData, 20); |
|
//printf("Curl send content: \n %s\n", test_countent); |
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, sUrl); |
|
|
|
//printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); |
|
char buf_account[512] = { 0 }; |
|
urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); |
|
char buf_account2[512] = { 0 }; |
|
urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); |
|
curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); |
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); |
|
curl_easy_setopt(curl, CURLOPT_PORT, iPort); |
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); |
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); |
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); |
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); |
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); |
|
|
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); |
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); |
|
|
|
curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); |
|
|
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); |
|
curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
} |
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 |
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); |
|
|
|
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). |
|
|
|
|
|
#if 0 |
|
l_res = curl_easy_perform(curl); |
|
if (l_res != CURLE_OK) |
|
{ |
|
//printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); |
|
l_ret = -1; |
|
} |
|
else |
|
l_ret = 0; |
|
#else |
|
curl_multi_add_handle(g_multi_handle, curl); |
|
curl_multi_perform(g_multi_handle, &g_handle_count); |
|
#endif |
|
curl_easy_reset(curl); |
|
if (pList != NULL) |
|
curl_slist_free_all(pList); |
|
} |
|
|
|
pthread_mutex_unlock(&mutex_curl); |
|
|
|
return l_ret; |
|
} |
|
#endif |
|
|
|
int net_curl_ptz_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, |
|
char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) |
|
{ |
|
#if 1 |
|
if (stAMBAcontent.licenseType != _NO_LICENSE && stAMBAcontent.afsCode == _LICENSED) |
|
{ |
|
} |
|
else |
|
{ |
|
printf("Trial has expired or mismatch the system ID."); |
|
return -1; |
|
} |
|
#endif |
|
|
|
//pthread_mutex_lock(&mutex_send_cgi); |
|
pthread_mutex_lock(&mutex_curl); |
|
CURL *curl = NULL; |
|
CURLcode l_res; |
|
int l_ret = -1; |
|
//const int timeout = 30000; |
|
//const int timeout = 100; |
|
//char *sBuffer; |
|
//char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; |
|
|
|
if (g_http_handle == NULL) { |
|
g_http_handle = curl_easy_init(); |
|
} |
|
|
|
curl = g_http_handle; |
|
|
|
struct curl_slist *pList = NULL; |
|
|
|
//char response_data[512] = { 0 }; |
|
//char *response_data; |
|
//response_data = malloc(512); |
|
//strcat(response_data, "mmmmmmmmmmmmmmagic"); |
|
|
|
char temp_sOutputData[60000] = { 0 }; |
|
|
|
if (curl != NULL) |
|
{ |
|
|
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
//pList = curl_slist_append(pList, "Content-Type:application/json"); |
|
pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); |
|
//Connection: close |
|
} |
|
pList = curl_slist_append(pList, "charset: utf-8"); |
|
pList = curl_slist_append(pList, "Connection: close"); |
|
pList = curl_slist_append(pList, "Content-Type: application/json"); |
|
pList = curl_slist_append(pList, "Expect:"); |
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); |
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
|
|
|
//time_t s_timep = time(0); |
|
//struct tm *s_timeinfo = localtime(&s_timep); |
|
//printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); |
|
//printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); |
|
|
|
//char test_countent[25] = { 0 }; |
|
//strncpy(test_countent, sData, 20); |
|
//printf("Curl send content: \n %s\n", test_countent); |
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, sUrl); |
|
|
|
//printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); |
|
char buf_account[512] = { 0 }; |
|
urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); |
|
char buf_account2[512] = { 0 }; |
|
urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); |
|
if ((int)strlen(buf_account) >= 1 && (int)strlen(buf_account2) >= 1) |
|
{ |
|
curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); |
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); |
|
} |
|
curl_easy_setopt(curl, CURLOPT_PORT, iPort); |
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); |
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, temp_sOutputData); |
|
|
|
//為了在UpdateRecoveryTimer 中拿到所有的資料(>57000) |
|
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 60000); |
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); |
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); |
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); |
|
|
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); |
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); |
|
|
|
curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); |
|
|
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
if (strlen(sData) >= 1) { |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); |
|
} |
|
curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
} |
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 |
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//1000 |
|
|
|
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). |
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); |
|
|
|
l_res = CURLE_FAILED_INIT; |
|
|
|
TRY |
|
{ |
|
l_res = curl_easy_perform(curl); |
|
} |
|
CATCH |
|
{ |
|
l_res = CURLE_FAILED_INIT; |
|
} |
|
ETRY; |
|
|
|
if (l_res != CURLE_OK) |
|
{ |
|
//printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); |
|
char temp_msg[8192] = { 0 }; |
|
snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); |
|
write_to_logs_html(temp_msg, "curl to ptz", "ERROR", SystemSetting.enable_system_logs); |
|
l_ret = -1; |
|
} |
|
else { |
|
strcpy(sOutputData, temp_sOutputData); |
|
//char temp_msg[8192] = { 0 }; |
|
//snprintf(temp_msg,sizeof(temp_msg), "%s:%s","OK", function_id); |
|
//write_to_logs_html(temp_msg, "curl to ptz", "DEBUG", SystemSetting.enable_system_logs); |
|
l_ret = 0; |
|
} |
|
|
|
curl_easy_reset(curl); |
|
if (pList != NULL) |
|
curl_slist_free_all(pList); |
|
pList = NULL; |
|
} |
|
|
|
|
|
pthread_mutex_unlock(&mutex_curl); |
|
//pthread_mutex_unlock(&mutex_send_cgi); |
|
|
|
return l_ret; |
|
} |
|
|
|
int net_curl_status_cmd(const char *sUrl, const char *sData, void *callback_data, char *method, |
|
char *sUserNmae, char *sPassWord, int iPort, char *sOutputData, char* function_id) |
|
{ |
|
//pthread_mutex_lock(&mutex_send_cgi); |
|
pthread_mutex_lock(&mutex_curl); |
|
CURL *curl = NULL; |
|
CURLcode l_res; |
|
int l_ret = -1; |
|
//const int timeout = 30000; |
|
//const int timeout = 100; |
|
//char *sBuffer; |
|
//char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; |
|
|
|
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(); |
|
} |
|
|
|
curl = g_http_handle; |
|
|
|
struct curl_slist *pList = NULL; |
|
|
|
//char response_data[512] = { 0 }; |
|
//char *response_data; |
|
//response_data = malloc(512); |
|
//strcat(response_data, "mmmmmmmmmmmmmmagic"); |
|
|
|
char temp_sOutputData[60000] = { 0 }; |
|
|
|
if (curl != NULL) |
|
{ |
|
|
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
//pList = curl_slist_append(pList, "Content-Type:application/json"); |
|
pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); |
|
//Connection: close |
|
} |
|
pList = curl_slist_append(pList, "charset: utf-8"); |
|
pList = curl_slist_append(pList, "Connection: close"); |
|
pList = curl_slist_append(pList, "Content-Type: application/json"); |
|
pList = curl_slist_append(pList, "Expect:"); |
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); |
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
|
|
|
//time_t s_timep = time(0); |
|
//struct tm *s_timeinfo = localtime(&s_timep); |
|
//printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); |
|
//printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); |
|
|
|
//char test_countent[25] = { 0 }; |
|
//strncpy(test_countent, sData, 20); |
|
//printf("Curl send content: \n %s\n", test_countent); |
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, sUrl); |
|
|
|
//printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); |
|
char buf_account[512] = { 0 }; |
|
urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); |
|
char buf_account2[512] = { 0 }; |
|
urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); |
|
if ((int)strlen(buf_account) >= 1 && (int)strlen(buf_account2) >= 1) |
|
{ |
|
curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); |
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); |
|
} |
|
curl_easy_setopt(curl, CURLOPT_PORT, iPort); |
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); |
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, temp_sOutputData); |
|
|
|
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 60000); |
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); |
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); |
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); |
|
|
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); |
|
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); |
|
|
|
curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); |
|
|
|
if (strcmp(method, "POST") == 0) |
|
{ |
|
if (strlen(sData) >= 1) { |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); |
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); |
|
} |
|
curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
} |
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 |
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//1000 |
|
|
|
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). |
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); |
|
|
|
l_res = CURLE_FAILED_INIT; |
|
|
|
TRY |
|
{ |
|
l_res = curl_easy_perform(curl); |
|
} |
|
CATCH |
|
{ |
|
l_res = CURLE_FAILED_INIT; |
|
} |
|
ETRY; |
|
|
|
if (l_res != CURLE_OK) |
|
{ |
|
//printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); |
|
char temp_msg[8192] = { 0 }; |
|
snprintf(temp_msg,sizeof(temp_msg), "%s:%s", curl_easy_strerror(l_res), function_id); |
|
write_to_logs_html(temp_msg, "curl to ptz status", "ERROR", SystemSetting.enable_system_logs); |
|
l_ret = -1; |
|
} |
|
else { |
|
strcpy(sOutputData, temp_sOutputData); |
|
//char temp_msg[8192] = { 0 }; |
|
//snprintf(temp_msg,sizeof(temp_msg), "%s:%s", "OK", function_id); |
|
//write_to_logs_html(temp_msg, "curl to ptz status", "DEBUG", SystemSetting.enable_system_logs); |
|
l_ret = 0; |
|
} |
|
|
|
curl_easy_reset(curl); |
|
if (pList != NULL) |
|
curl_slist_free_all(pList); |
|
pList = NULL; |
|
} |
|
|
|
|
|
pthread_mutex_unlock(&mutex_curl); |
|
//pthread_mutex_unlock(&mutex_send_cgi); |
|
|
|
return l_ret; |
|
} |
|
|
|
#if 0 |
|
void create_g_curl_connect() |
|
{ |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
//int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
/*CURLcode l_res; |
|
const int timeout = 100; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char sOutputData[1024]; |
|
|
|
|
|
|
|
char *method = "POST";*/ |
|
|
|
g_curl_Handle = g_http_handle; |
|
|
|
if (g_curl_Handle != NULL) |
|
{ |
|
//if (strcmp(method, "POST") == 0) |
|
if (1) |
|
{ |
|
//pList = curl_slist_append(pList, "Content-Type:application/json"); |
|
//pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); |
|
//Connection: close |
|
} |
|
|
|
g_pList = curl_slist_append(g_pList, "Connection: Keep-Alive"); |
|
//pList = curl_slist_append(pList, "Connection: close"); |
|
curl_easy_setopt(g_curl_Handle, CURLOPT_HTTPHEADER, g_pList); |
|
|
|
// //time_t s_timep = time(0); |
|
// //struct tm *s_timeinfo = localtime(&s_timep); |
|
|
|
// //curl_easy_setopt(curl, CURLOPT_URL, sUrl); |
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_URL, "http://127.0.0.1/server"); |
|
// //strcat(ptz_curl_url, "http://127.0.0.1/server"); |
|
|
|
//printf("%s, %s, %d \n", ptz_curl_username, ptz_curl_password, ptz_port); |
|
//curl_easy_setopt(g_curl_Handle, CURLOPT_USERNAME, ptz_curl_username); |
|
//curl_easy_setopt(g_curl_Handle, CURLOPT_PASSWORD, ptz_curl_password); |
|
//curl_easy_setopt(g_curl_Handle, CURLOPT_PORT, ptz_port); |
|
|
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); |
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_WRITEDATA, sOutputData); |
|
|
|
curl_easy_setopt(g_curl_Handle, CURLOPT_SSL_VERIFYPEER, 0L); |
|
curl_easy_setopt(g_curl_Handle, CURLOPT_SSL_VERIFYHOST, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); |
|
curl_easy_setopt(g_curl_Handle, CURLOPT_USERAGENT, "IPVideo"); |
|
|
|
curl_easy_setopt(g_curl_Handle, CURLOPT_LOW_SPEED_LIMIT, 1L); |
|
curl_easy_setopt(g_curl_Handle, CURLOPT_LOW_SPEED_TIME, 10L); |
|
|
|
curl_easy_setopt(g_curl_Handle, CURLOPT_TCP_FASTOPEN, 1L); |
|
|
|
//if (strcmp(method, "POST") == 0) |
|
//if (1) |
|
//{ |
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_POSTFIELDS, ptz_curl_sendbuf); |
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_POSTFIELDSIZE, strlen(ptz_curl_sendbuf)); |
|
// curl_easy_setopt(g_curl_Handle, CURLOPT_POST, 1L); |
|
//} |
|
|
|
curl_easy_setopt(g_curl_Handle, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 |
|
curl_easy_setopt(g_curl_Handle, CURLOPT_TIMEOUT, 1000); |
|
|
|
curl_easy_setopt(g_curl_Handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). |
|
|
|
// printf("11111 \n"); |
|
|
|
// l_res = curl_easy_perform(g_curl_Handle); |
|
// if (l_res != CURLE_OK) |
|
// { |
|
// //printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); |
|
// //l_ret = -1; |
|
// } |
|
// else |
|
// { |
|
// //l_ret = 0; |
|
// } |
|
|
|
// printf("22222 \n"); |
|
|
|
// curl_easy_reset(g_curl_Handle); |
|
} |
|
} |
|
|
|
void Free_PTZ_g_curl_connect() { |
|
curl_easy_reset(g_curl_Handle); |
|
curl_slist_free_all(g_pList); |
|
g_pList = NULL; |
|
} |
|
#endif |
|
|
|
#if 0 |
|
int net_curl_ptz_cmd_ghandle(const char *sUrl, const char *sData, void *callback_data, char *method, |
|
char *sUserNmae, char *sPassWord, int iPort, char *sOutputData) |
|
{ |
|
CURL *curl = NULL; |
|
CURLcode l_res; |
|
int l_ret = -1; |
|
//const int timeout = 30000; |
|
//const int timeout = 100; |
|
//char *sBuffer; |
|
//char outputmessage[] = "{\"data\":[{\"camera_id\": \"12A\",\"tstamp\":598,\"person_total\":799}]}"; |
|
//curl = curl_easy_init(); |
|
curl = g_curl_Handle; |
|
//char sOutputTEST[1024]; |
|
|
|
//struct curl_slist *pList = NULL; |
|
|
|
if (g_curl_Handle != NULL) |
|
{ |
|
|
|
//if (strcmp(method, "POST") == 0) |
|
//{ |
|
// //pList = curl_slist_append(pList, "Content-Type:application/json"); |
|
// pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); |
|
// //Connection: close |
|
//} |
|
//pList = curl_slist_append(pList, "Connection: close"); |
|
//curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pList); |
|
|
|
//time_t s_timep = time(0); |
|
//struct tm *s_timeinfo = localtime(&s_timep); |
|
//printf(">>>>>>>>>>>>> CURL Send Time: %d-%02d-%02d ", (1900 + s_timeinfo->tm_year), (1 + s_timeinfo->tm_mon), s_timeinfo->tm_mday); |
|
//printf("%02d:%02d:%02d\n\n", s_timeinfo->tm_hour, s_timeinfo->tm_min, s_timeinfo->tm_sec); |
|
|
|
//char test_countent[25] = { 0 }; |
|
//strncpy(test_countent, sData, 20); |
|
//printf("Curl send content: \n %s\n", test_countent); |
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, sUrl); |
|
|
|
//printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); |
|
char buf_account[512] = { 0 }; |
|
urldecode((unsigned char *)sUserNmae, (unsigned char *)buf_account); |
|
char buf_account2[512] = { 0 }; |
|
urldecode((unsigned char *)sPassWord, (unsigned char *)buf_account2); |
|
curl_easy_setopt(curl, CURLOPT_USERNAME, buf_account); |
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, buf_account2); |
|
curl_easy_setopt(curl, CURLOPT_PORT, iPort); |
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ptz_cmd_curl_callback); |
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, sOutputData); |
|
|
|
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); |
|
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "IPVideo"); |
|
|
|
//curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); |
|
//curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); |
|
|
|
//curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); |
|
|
|
//if (strcmp(method, "POST") == 0) |
|
//{ |
|
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData); |
|
// curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(sData)); |
|
// curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
//} |
|
|
|
//curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5); // 設定連線超時,單位秒 |
|
//curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1000); |
|
|
|
//curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). |
|
|
|
l_res = curl_easy_perform(curl); |
|
if (l_res != CURLE_OK) |
|
{ |
|
//printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(l_res)); |
|
char temp_msg[8192] = { 0 }; |
|
snprintf(temp_msg,sizeof(temp_msg), "%s", curl_easy_strerror(l_res)); |
|
write_to_logs_html(temp_msg, "curl to ptz ghandle", "ERROR", SystemSetting.enable_system_logs); |
|
l_ret = -1; |
|
} |
|
else |
|
l_ret = 0; |
|
} |
|
|
|
//curl_easy_cleanup(curl); |
|
curl_easy_reset(curl); |
|
//if (pList != NULL) |
|
//curl_slist_free_all(pList); |
|
//pList = NULL; |
|
|
|
return l_ret; |
|
} |
|
#endif |
|
|
|
void UpdatePTZsourceWH(int iVideo_source_w, int iVideo_source_h) |
|
{ |
|
if (iVideo_source_w != 0 && iVideo_source_h != 0) |
|
{ |
|
g_stPTZ_Handle.iIMG_source_w = iVideo_source_w; |
|
g_stPTZ_Handle.iIMG_source_h = iVideo_source_h; |
|
} |
|
} |
|
|
|
//void UpdatePTZConfigSetting(char *sEnable_ptz, char *sEnable_tracking, char *sTracking_fov_min, |
|
// char *sTracking_fov_max, char *sConfidence2, int iPTZMode, int iIsTrackingEnterZone, char *sTracking_resume_dwell, |
|
// char *sInMetadata1, int iZoneToPreset[]) |
|
void UpdatePTZConfigSetting() |
|
{ |
|
///initial setting storege |
|
g_stPTZ_Handle.iIsAtHomePOS = 0; |
|
g_stPTZ_Handle.iIsFlip = 0; |
|
g_stPTZ_Handle.iIsMirror = 0; |
|
g_stPTZ_Handle.iIsInAutopan = 0; |
|
g_stPTZ_Handle.iIsInAutoTracking = 1; |
|
g_stPTZ_Handle.iIsInPreset = 0; |
|
g_stPTZ_Handle.iHomePreset = 0; |
|
|
|
//g_stPTZ_Handle.iIsStayHomePos = 0; |
|
//g_stPTZ_Handle.iSwitchTrackOnOff = 0; |
|
|
|
g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; |
|
g_stPTZ_Handle.iRunPTZZoomThread_flag = 0; |
|
|
|
|
|
//g_stPTZ_Handle.iIs_enable_alarm = 0; |
|
|
|
g_stPTZ_Handle.iTraffic_cnfidence = 0; |
|
|
|
g_stPTZ_Handle.iEnable_PTZ = 0; |
|
g_stPTZ_Handle.iTracking_fov_min = 0; |
|
g_stPTZ_Handle.iTracking_fov_max = 0; |
|
g_stPTZ_Handle.iEnable_tracking = 0; |
|
g_stPTZ_Handle.iTracking_mode = 1; //Default 1 |
|
g_stPTZ_Handle.iTracking_entering_zone = 1; //Default 1 |
|
//g_stPTZ_Handle.iTracking_resume_dwell = 5; //Default 5 |
|
g_stPTZ_Handle.iIMG_source_w = 0; |
|
g_stPTZ_Handle.iIMG_source_h = 0; |
|
|
|
g_stPTZ_Handle.iPanABS = 0; |
|
g_stPTZ_Handle.iTiltABS = 0; |
|
g_stPTZ_Handle.iZoomABS = 0; |
|
|
|
g_stPTZ_Handle.iRT_min = 0; |
|
g_stPTZ_Handle.iRT_sec = 0; |
|
|
|
|
|
//ptz_zone_to_preset |
|
//printf("===============================================> %d, %d, %d, %d \n", iZoneToPreset[0], iZoneToPreset[1], iZoneToPreset[2], iZoneToPreset[3]); |
|
|
|
/*if (viewDetectionZone[0][0].ptz_zone_to_preset == 0 |
|
&& viewDetectionZone[0][1].ptz_zone_to_preset == 0 |
|
&& viewDetectionZone[0][2].ptz_zone_to_preset == 0 |
|
&& viewDetectionZone[0][3].ptz_zone_to_preset == 0) |
|
{ |
|
g_stPTZ_Handle.iZoneToPresetAnyOne = 0; |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iZoneToPresetAnyOne = 1; |
|
|
|
for (int i = 0; i < MAX_DETECTION_ZONE; i++) |
|
{ |
|
g_stPTZ_Handle.iZoneToPreset[i] = 0; |
|
|
|
if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL |
|
&& strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) |
|
{ |
|
g_stPTZ_Handle.iZoneToPreset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); |
|
} |
|
} |
|
}*/ |
|
|
|
//printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne); |
|
|
|
|
|
|
|
//Update PTZ config setting |
|
if (viewChannelData[0].confidence2) //confidece2 = for Traffic |
|
g_stPTZ_Handle.iTraffic_cnfidence = atoi(viewChannelData[0].confidence2); |
|
|
|
//viewChannelData[0].enable_PTZ |
|
if (viewChannelData[0].enable_PTZ) |
|
{ |
|
if (strcmp(viewChannelData[0].enable_PTZ, "Yes") == 0) |
|
g_stPTZ_Handle.iEnable_PTZ = 1; |
|
else |
|
g_stPTZ_Handle.iEnable_PTZ = 0; |
|
} |
|
|
|
//viewChannelData[0].ptz_tracking_fov_min |
|
if (viewChannelData[0].ptz_tracking_fov_min) |
|
{ |
|
g_stPTZ_Handle.iTracking_fov_min = atoi(viewChannelData[0].ptz_tracking_fov_min); |
|
} |
|
|
|
//viewChannelData[0].ptz_tracking_fov_max |
|
if (viewChannelData[0].ptz_tracking_fov_max) |
|
{ |
|
g_stPTZ_Handle.iTracking_fov_max = atoi(viewChannelData[0].ptz_tracking_fov_max); |
|
} |
|
|
|
//viewChannelData[0].ptz_enable_tracking |
|
if (viewChannelData[0].ptz_enable_tracking) |
|
{ |
|
if (strcmp(viewChannelData[0].ptz_enable_tracking, "Yes") == 0) |
|
g_stPTZ_Handle.iEnable_tracking = 1; |
|
else |
|
g_stPTZ_Handle.iEnable_tracking = 0; |
|
} |
|
|
|
if (viewChannelData[0].ptz_tracking_mode) |
|
{ |
|
g_stPTZ_Handle.iTracking_mode = viewChannelData[0].ptz_tracking_mode; |
|
} |
|
|
|
if (viewChannelData[0].ptz_tracking_by_enter_zone) |
|
{ |
|
g_stPTZ_Handle.iTracking_entering_zone = viewChannelData[0].ptz_tracking_by_enter_zone; |
|
} |
|
|
|
if (viewChannelData[0].ptz_tracking_resume_dwell |
|
&& strlen(viewChannelData[0].ptz_tracking_resume_dwell) > 0) |
|
{ |
|
g_stPTZ_Handle.iTracking_resume_dwell = atoi(viewChannelData[0].ptz_tracking_resume_dwell); |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iTracking_resume_dwell = 5; |
|
} |
|
|
|
{ |
|
//char msg_temp[512] = { 0 }; |
|
//sprintf(msg_temp, "UpdatePTZConfigSetting g_stPTZ_Handle.iTracking_resume_dwell:%d,,,%s", g_stPTZ_Handle.iTracking_resume_dwell, viewChannelData[0].ptz_tracking_resume_dwell); |
|
//write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); |
|
} |
|
|
|
//Parse Metadata |
|
|
|
//char MetaOut1[20][50] = { 0 }; |
|
//memset(&(g_stPTZ_Handle.sMetaOut1), 0x00, sizeof(SecData)); |
|
|
|
g_stPTZ_Handle.iZoneToPresetAnyOne = 0; |
|
|
|
for (int j = 0; j < viewChannelData[0].count_zone; j++) |
|
{ |
|
char MetaData1[BUFSIZE] = { 0 }; |
|
char s_metadata1[512][STRSPLIT_SIZE] = { 0 }; //for filter |
|
for (int i = 0; i < PTZ_TRACKING_OBJ_NUMBER; i++) |
|
{ |
|
//memset(&(g_stPTZ_Handle.sMetaOut1[i]), 0x00, sizeof(g_stPTZ_Handle.sMetaOut1[i])); |
|
memset(g_stPTZ_Zone_info[j].sMetaOut1[i], 0x00, 50); //目前未用到, 以防萬一 |
|
} |
|
|
|
g_stPTZ_Zone_info[j].iMetadata1_num = 0; |
|
|
|
int iZoneIdx = j; |
|
if (viewDetectionZone[0][iZoneIdx].metadata1 |
|
&& strlen(viewDetectionZone[0][iZoneIdx].metadata1) > 0) |
|
{ |
|
//strcpy(MetaData1, viewDetectionZone[0][iZoneIdx].metadata1); |
|
strcpy(MetaData1, viewDetectionZone[0][iZoneIdx].metadata1); |
|
|
|
//g_stPTZ_Handle.iMetadata1_num = StrSplit(MetaData1, s_metadata1, ","); |
|
g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num = StrSplit(MetaData1, s_metadata1, ","); //strsplit = (strtok_r): replace ","->"\0" |
|
|
|
int count_num = 0; |
|
for (int k = 0; k < g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num; k++) |
|
{ |
|
int iMetadataIdx = k; |
|
UpperToLower(s_metadata1[iMetadataIdx]); |
|
|
|
if (k == 0 && strcmp(s_metadata1[iMetadataIdx], "null") == 0) { |
|
break; |
|
} |
|
else { |
|
TrimSpace(g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx], sizeof(g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx]), s_metadata1[iMetadataIdx], 0); |
|
printf("[%d][%d] metadata: %s\n", iZoneIdx, iMetadataIdx, g_stPTZ_Zone_info[iZoneIdx].sMetaOut1[iMetadataIdx]); |
|
count_num++; |
|
} |
|
} |
|
g_stPTZ_Zone_info[iZoneIdx].iMetadata1_num = count_num; |
|
} |
|
|
|
//get zone to preset point |
|
g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset = 0; |
|
|
|
if (viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset != NULL |
|
&& strlen(viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset) > 0) |
|
{ |
|
g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset = atoi(viewDetectionZone[0][iZoneIdx].ptz_zone_to_preset); |
|
|
|
if (g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset > 0) |
|
g_stPTZ_Handle.iZoneToPresetAnyOne = 1; |
|
} |
|
} |
|
|
|
//g_stPTZ_Handle.iMetadata1_num = 0; |
|
|
|
//Zone 0 |
|
//不可跟上面共用參數 |
|
char MetaData1_temp[BUFSIZE] = { 0 }; |
|
char s_metadata1_temp[512][STRSPLIT_SIZE] = { 0 }; //for filter |
|
|
|
if (viewDetectionZone[0][0].metadata1 |
|
&& strlen(viewDetectionZone[0][0].metadata1) > 0) |
|
{ |
|
strcpy(MetaData1_temp, viewDetectionZone[0][0].metadata1); |
|
|
|
g_stPTZ_Handle.iMetadata1_num = StrSplit(MetaData1_temp, s_metadata1_temp, ","); |
|
for (int i = 0; i < g_stPTZ_Handle.iMetadata1_num; i++) |
|
{ |
|
UpperToLower(s_metadata1_temp[i]); |
|
|
|
TrimSpace(g_stPTZ_Handle.sMetaOut1[i], sizeof(g_stPTZ_Handle.sMetaOut1[i]), s_metadata1_temp[i], 0); |
|
//printf("[%d] metadata: %s \n", i, MetaOut1[i]); |
|
} |
|
} |
|
//printf("\n------UpdatePTZConfigSetting end\n"); |
|
} |
|
|
|
|
|
void* ptz_stop_thread(void * ptr) { |
|
pthread_detach(pthread_self()); |
|
setPthreadName("ptz_stop"); |
|
usSleep(2000000); |
|
StopPtz(); |
|
pthread_exit(NULL); |
|
|
|
} |
|
|
|
int move_PTZ_in_the_direction(int new_pan,int new_tilt) |
|
{ |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
int curl_ret = 0; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
|
|
|
|
if (g_stPTZ_Handle.iIsPTZ == 1) { |
|
if (new_pan != 0 && new_tilt != 0) { |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rpan=%d&rtilt=%d", new_pan, new_tilt); |
|
} |
|
else if (new_pan == 0 && new_tilt != 0) { |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rtilt=%d", new_tilt); |
|
} |
|
else if (new_pan != 0 && new_tilt == 0) { |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rpan=%d", new_pan); |
|
} |
|
else { |
|
curl_ret = -1; |
|
} |
|
} |
|
else { |
|
curl_ret = -1; |
|
} |
|
|
|
if (curl_ret >= 0) { |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
//int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
//char *arr_sOutputDataList[MAX_PTZ_INFO]; |
|
//int iPTZInfoCount = 0; |
|
//char *del = ","; |
|
//float iGetValue = 0; |
|
|
|
curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "move PTZ in the direction"); |
|
} |
|
return curl_ret; |
|
} |
|
|
|
int SetPTZNewTilt(int new_tilt) |
|
{ |
|
int curl_ret = -1; |
|
if (g_stPTZ_Handle.iIsPTZ == 1) { |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?tiltposdegree=%d", new_tilt); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
//int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
//char *arr_sOutputDataList[MAX_PTZ_INFO]; |
|
//int iPTZInfoCount = 0; |
|
//char *del = ","; |
|
//float iGetValue = 0; |
|
|
|
curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "Set PTZ new tilt"); |
|
} |
|
return curl_ret; |
|
} |
|
|
|
int SetPTZNewPan(int new_pan) |
|
{ |
|
int curl_ret = -1; |
|
if (g_stPTZ_Handle.iIsPTZ == 1) { |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?panposdegree=%d", new_pan); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
//int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
//char *arr_sOutputDataList[MAX_PTZ_INFO]; |
|
//int iPTZInfoCount = 0; |
|
//char *del = ","; |
|
//float iGetValue = 0; |
|
|
|
curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData, "Set PTZ new pan"); |
|
} |
|
return curl_ret; |
|
} |
|
|
|
//CGI http://127.0.0.1/control?getcurpos=1 |
|
//Get pan, tilt and zoom absolute value |
|
int UpdatePTZCurPos() |
|
{ |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
strcat(ptz_curl_url, "http://127.0.0.1/control?getcurpos=1"); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
//int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; |
|
int iPTZInfoCount = 0; |
|
char *del = ","; |
|
float iGetValue = 0; |
|
|
|
int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update PTZ CurPos"); |
|
|
|
if (strlen(outputData) > 0) |
|
{ |
|
//printf("getcurpos=%s \n", outputData); |
|
iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); |
|
if (iPTZInfoCount >= 3) { |
|
if (arr_sOutputDataList[0]) |
|
{ |
|
iGetValue = atof(arr_sOutputDataList[0]); |
|
g_stPTZ_Handle.iPanABS = (int)iGetValue; |
|
//printf("Pan ABS = %d \n", iGetValue); |
|
} |
|
|
|
if (arr_sOutputDataList[1]) |
|
{ |
|
iGetValue = atof(arr_sOutputDataList[1]); |
|
g_stPTZ_Handle.iTiltABS = (int)iGetValue; |
|
//printf("Tilt ABS = %d \n", iGetValue); |
|
} |
|
|
|
if (arr_sOutputDataList[2]) |
|
{ |
|
iGetValue = atof(arr_sOutputDataList[2]); |
|
g_stPTZ_Handle.iZoomABS = (int)iGetValue; |
|
//printf("Zoom ABS = %d \n", iGetValue); |
|
} |
|
} |
|
} |
|
|
|
return curl_ret; |
|
} |
|
|
|
//CGI http://127.0.0.1/control?getcurpos=1 |
|
//Get pan, tilt and zoom absolute value |
|
int StoreHomePresetPos() |
|
{ |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
strcat(ptz_curl_url, "http://127.0.0.1/control?getcurpos=1"); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
//int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE] = { 0 }; |
|
int iPTZInfoCount = 0; |
|
char *del = ","; |
|
int iGetValue = 0; |
|
|
|
int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Store Home PresetPos"); |
|
|
|
if (strlen(outputData) > 0) |
|
{ |
|
//printf("getcurpos=%s \n", outputData); |
|
iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); |
|
if (iPTZInfoCount >= 3) { |
|
if (arr_sOutputDataList[0]) |
|
{ |
|
iGetValue = atoi(arr_sOutputDataList[0]); |
|
g_stPTZ_Handle.iHomePanABS = iGetValue; |
|
//printf("Pan ABS = %d \n", iGetValue); |
|
} |
|
|
|
if (arr_sOutputDataList[1]) |
|
{ |
|
iGetValue = atoi(arr_sOutputDataList[1]); |
|
g_stPTZ_Handle.iHomeTiltABS = iGetValue; |
|
//printf("Tilt ABS = %d \n", iGetValue); |
|
} |
|
|
|
if (arr_sOutputDataList[2]) |
|
{ |
|
iGetValue = atoi(arr_sOutputDataList[2]); |
|
g_stPTZ_Handle.iHomeZoomABS = iGetValue; |
|
//printf("Zoom ABS = %d \n", iGetValue); |
|
} |
|
} |
|
} |
|
|
|
return curl_ret; |
|
} |
|
|
|
|
|
int ParseReadLine(char* allbuf, int level, char* linebuf) |
|
{ |
|
int len = strlen(allbuf); |
|
for (; level < len; ++level) |
|
{ |
|
if (allbuf[level] == '\r' && allbuf[level + 1] == '\n') |
|
return level + 2; |
|
else |
|
*(linebuf++) = allbuf[level]; |
|
} |
|
return -1; |
|
} |
|
|
|
//CGI http://127.0.0.1/ptzcamera?get=all |
|
//Get Recovery Time |
|
int UpdateRecoveryTime() |
|
{ |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = atoi(accountData[0].account_port); |
|
|
|
strcpy(ptz_curl_username, accountData[0].account_username); |
|
strcpy(ptz_curl_password, accountData[0].account_password); |
|
|
|
strcpy(ptz_curl_url, "http://"); |
|
strcat(ptz_curl_url, "127.0.0.1:"); |
|
strcat(ptz_curl_url, accountData[0].account_port); |
|
strcat(ptz_curl_url, "/ptzcamera?get=all"); |
|
|
|
int ret = 0; |
|
|
|
//recv buffer |
|
char outputData[60000] = { 0 }; //>57000 |
|
//a line data |
|
char sParselinebuf[256] = { 0 }; |
|
//next line's point num |
|
int iParselevel = 0; |
|
char *field; |
|
|
|
char sRTmin[32] = { 0 }; |
|
char sRTsec[32] = { 0 }; |
|
|
|
//char *arr_sOutputDataList[MAX_PTZ_INFO]; |
|
//int iPTZInfoCount = 0; |
|
//char *del = ","; |
|
//int iGetValue = 0; |
|
|
|
/*int curl_ret = */net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update Recovery Time"); |
|
|
|
if (strlen(outputData) > 0) |
|
{ |
|
//printf("size of getall=%d \n", strlen(outputData)); |
|
|
|
do { |
|
memset(sParselinebuf, 0, 256); |
|
iParselevel = ParseReadLine(outputData, iParselevel, sParselinebuf); |
|
|
|
if (strncasecmp(sParselinebuf, "SELF_RT=", 8) == 0) |
|
{ |
|
field = (sParselinebuf + 8); |
|
field += strspn(field, " \t"); |
|
memcpy(sRTmin, (sParselinebuf + 8), strlen(sParselinebuf + 8)); |
|
|
|
if (strlen(sRTmin) > 0) |
|
g_stPTZ_Handle.iRT_min = atoi(sRTmin); |
|
} |
|
else if (strncasecmp(sParselinebuf, "SELF_RT_SEC=", 12) == 0) |
|
{ |
|
field = (sParselinebuf + 12); |
|
field += strspn(field, " \t"); |
|
memcpy(sRTsec, (sParselinebuf + 12), strlen(sParselinebuf + 12)); |
|
|
|
if (strlen(sRTsec) > 0) |
|
g_stPTZ_Handle.iRT_sec = atoi(sRTsec); |
|
|
|
break; |
|
} |
|
|
|
} while ((outputData[iParselevel] != '\r' || outputData[iParselevel + 1] != '\n') && iParselevel != -1); |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
//CGI http://127.0.0.1/control?get=aiptz |
|
//Response的部份是 |
|
//status = success |
|
//image.mirror = 0 |
|
//image.flip = 0 |
|
//ptz.athomepos = 0 |
|
//ptz.inpreset = 0 |
|
//ptz.inautopan = 0 |
|
//ptz.isautotracking = 0 |
|
int UpdatePTZIPcamSetting() |
|
{ |
|
//printf("iEnable_PTZ: %d \n", g_stPTZ_Handle.iEnable_PTZ); |
|
//printf("iTracking_fov_min: %d \n", g_stPTZ_Handle.iTracking_fov_min); |
|
//printf("iTracking_fov_max: %d \n", g_stPTZ_Handle.iTracking_fov_max); |
|
//printf("iEnable_tracking: %d \n", g_stPTZ_Handle.iEnable_tracking); |
|
//printf("iTracking_resume_dwell: %d \n", g_stPTZ_Handle.iTracking_resume_dwell); |
|
//printf("iIMG_source_w: %d \n", g_stPTZ_Handle.iIMG_source_w); |
|
//printf("iIMG_source_h: %d --------------------------------\n", g_stPTZ_Handle.iIMG_source_h); |
|
|
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
//int ptz_port = 80; |
|
|
|
//strcat(ptz_curl_url, "http://192.168.8.151/server"); |
|
//strcat(ptz_curl_url, "http://192.168.8.151/ptzcamera?get=AUTO_MODE_STATUS"); |
|
strcat(ptz_curl_url, "http://127.0.0.1/control?get=aiptz"); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
//Update PTZ Ipcam info |
|
int ret = 0; |
|
|
|
char outputData[60000] = { 0 }; |
|
|
|
char arr_sOutputDataList[MAX_PTZ_INFO][STRSPLIT_SIZE]={0}; |
|
//char **arr_sOutputDataList; |
|
int iPTZInfoCount = 0; |
|
char *del = "\r\n"; |
|
|
|
#if 0 |
|
/*int curl_ret = */net_curl_ptz_cmd_ghandle(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
accountData[0].account_username, accountData[0].account_password, atoi(accountData[0].account_port), outputData); |
|
#endif |
|
|
|
#if 1 |
|
/*int curl_ret = */net_curl_status_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData,"Update PTZ IPcam Setting"); |
|
//int curl_ret = net_curl_ptz_cmd(ptz_curl_url, ptz_curl_sendbuf, NULL, method, |
|
// ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData); |
|
#endif |
|
|
|
#if 0 |
|
/*int curl_ret =*/ net_socket_ptz_cmd(ptz_url, ptz_curl_sendbuf, NULL, method, |
|
ptz_curl_username, ptz_curl_password, atoi(accountData[0].account_port), outputData); |
|
#endif |
|
|
|
#if 1 |
|
if (strlen(outputData) > 0 && strstr(outputData,"image.mirror")!=NULL |
|
&& strstr(outputData, "image.flip") != NULL |
|
&& strstr(outputData, "ptz.athomepos") != NULL |
|
&& strstr(outputData, "ptz.inpreset") != NULL |
|
&& strstr(outputData, "ptz.inautopan") != NULL |
|
&& strstr(outputData, "ptz.isautotracking") != NULL |
|
&& strstr(outputData, "ptz.homepreset") != NULL) |
|
{ |
|
//printf("Get curl size: %d, content: %s \n", strlen(outputData), outputData); |
|
|
|
iPTZInfoCount = StrSplit(outputData, arr_sOutputDataList, del); |
|
|
|
for (int i = 0; i < iPTZInfoCount; i++) |
|
{ |
|
if (arr_sOutputDataList[i]) |
|
{ |
|
//printf("[%d]: %s \n", i, arr_sOutputDataList[i]); |
|
|
|
char outArray[2][STRSPLIT_SIZE]={0}; |
|
StrSplit(arr_sOutputDataList[i], outArray, "="); |
|
|
|
int iGetValue = 0; |
|
if (outArray[0] && outArray[1]) |
|
{ |
|
if (strstr(outArray[0], "image.mirror")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("mirror= %d \n", iGetValue); |
|
sprintf(accountData[0].account_mirror, "%d", iGetValue); |
|
g_stPTZ_Handle.iIsMirror = iGetValue; |
|
} |
|
else if (strstr(outArray[0], "image.flip")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("flip= %d \n", iGetValue); |
|
sprintf(accountData[0].account_flip, "%d", iGetValue); |
|
g_stPTZ_Handle.iIsFlip = iGetValue; |
|
} |
|
else if (strstr(outArray[0], "ptz.athomepos")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("athomepos= %d \n", iGetValue); |
|
g_stPTZ_Handle.iIsAtHomePOS = iGetValue; |
|
g_stPTZ_Handle.iPauseTrackFlag = 0; |
|
} |
|
else if (strstr(outArray[0], "ptz.inpreset")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("inpreset= %d \n", iGetValue); |
|
g_stPTZ_Handle.iIsInPreset = iGetValue; |
|
} |
|
else if (strstr(outArray[0], "ptz.inautopan")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("inautopan= %d \n", iGetValue); |
|
g_stPTZ_Handle.iIsInAutopan = iGetValue; |
|
} |
|
else if (strstr(outArray[0], "ptz.isautotracking")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
//printf("isautotracking= %d \n", iGetValue); |
|
g_stPTZ_Handle.iIsInAutoTracking = iGetValue; |
|
} |
|
else if (strstr(outArray[0], "ptz.homepreset")) |
|
{ |
|
iGetValue = atoi(outArray[1]); |
|
if (iGetValue >= 0 && iGetValue <= 256) |
|
g_stPTZ_Handle.iHomePreset = iGetValue; |
|
else |
|
g_stPTZ_Handle.iHomePreset = 0; |
|
} |
|
}//if (outArray[0] && outArray[1]) |
|
}//if (arr_sOutputDataList[i]) |
|
}//for (int i = 0; i < iPTZInfoCount; i++) |
|
//free(arr_sOutputDataList); |
|
|
|
//"ptz.athomepos" 不可信 20220113, 使用此法解套 |
|
if (g_stPTZ_Handle.iIsInPreset == g_stPTZ_Handle.iHomePreset) |
|
{ |
|
g_stPTZ_Handle.iIsAtHomePOS = 1; |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iIsAtHomePOS = 0; |
|
} |
|
}//if (strlen(outputData) > 0) |
|
#endif |
|
|
|
#if 0 //TEMP TEST |
|
g_stPTZ_Handle.iIsMirror = 0; |
|
g_stPTZ_Handle.iIsFlip = 0; |
|
//g_stPTZ_Handle.iIsAtHomePOS = 1; |
|
//g_stPTZ_Handle.iIsInPreset = 1; |
|
g_stPTZ_Handle.iIsInAutopan = 1; |
|
g_stPTZ_Handle.iIsInAutoTracking = 1; |
|
g_stPTZ_Handle.iHomePreset = 1; |
|
#endif |
|
#if 0 |
|
g_stPTZ_Handle.iIsMirror = 0; |
|
g_stPTZ_Handle.iIsFlip = 0; |
|
g_stPTZ_Handle.iIsInAutopan = 1; |
|
g_stPTZ_Handle.iIsInAutoTracking = 1; |
|
#endif |
|
|
|
//printf("flip, mirror = %s, %s \n", accountData[0].account_flip, accountData[0].account_mirror); |
|
|
|
return ret; |
|
} |
|
|
|
//0 = not ptz, 1 = ptz |
|
int IsPTZ() |
|
{ |
|
return g_stPTZ_Handle.iIsPTZ; |
|
} |
|
|
|
int get_g_PTZ_model() { |
|
return g_PTZ_model; |
|
} |
|
|
|
// CGI http://127.0.0.1/server |
|
// 判斷 SysFeature = 0x4000000 check_ptz |
|
int check_ptz(char *outputData/*char* sUrl, char* sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort*/) |
|
{ |
|
int ret = 0; |
|
|
|
//char outputData[60000] = { 0 }; |
|
|
|
//int curl_ret = net_curl_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, |
|
//sUsername, sPassword, iPort, outputData); |
|
|
|
/*int curl_ret = *///net_curl_status_cmd(sUrl, sSendbuf, NULL, sMethod, sUsername, sPassword, iPort, outputData, "check ptz"); |
|
|
|
char *sFindStr_Start = NULL; |
|
char *sFindStr_End = NULL; |
|
char sSysFeature[128] = { '\0' }; |
|
//int iSysFeature = 0; |
|
|
|
char *sFindModel_Start = NULL; |
|
char *sFindModel_End = NULL; |
|
char sModel[128] = { '\0' }; |
|
//int iModel = 0; |
|
//printf("\nTTTTTTTTTTTT\n"); |
|
|
|
/*{ |
|
char temp_msg[8192] = { 0 }; |
|
snprintf(temp_msg,sizeof(temp_msg), "%s", outputData); |
|
write_to_logs_html(temp_msg, "check ptz", "INFO", "Yes"); |
|
write_to_log_if_error(temp_msg, "check ptz", "INFO"); |
|
}*/ |
|
|
|
if (strlen(outputData) > 0 && g_IsPTZDevice != 1) |
|
{ |
|
//printf("Get curl size: %d, content: %s \n", strlen(outputData), outputData); |
|
sFindStr_Start = strstr(outputData, "SysFeature="); |
|
sFindModel_Start = strstr(outputData, "Model="); |
|
|
|
if (sFindStr_Start && sFindModel_Start) |
|
{ |
|
sFindStr_Start = sFindStr_Start + strlen("SysFeature="); |
|
sFindModel_Start = sFindModel_Start + strlen("Model="); |
|
//printf("start: 0x%x \n", sFindStr_Start); |
|
|
|
sFindStr_End = strstr(sFindStr_Start, "\n"); |
|
sFindModel_End = strstr(sFindModel_Start, "\n"); |
|
|
|
if (sFindStr_End && sFindModel_End) |
|
{ |
|
//printf("start: 0x%x \n", sFindStr_End); |
|
|
|
if ((sFindStr_End - sFindStr_Start) > 0 && (sFindModel_End - sFindModel_Start) > 0) |
|
{ |
|
memcpy(sSysFeature, sFindStr_Start, (sFindStr_End - sFindStr_Start)); |
|
memcpy(sModel, sFindModel_Start, (sFindModel_End - sFindModel_Start)); |
|
|
|
unsigned long long int val = strtoull(sSysFeature, NULL, 10); |
|
unsigned long long int iModel = strtoull(sModel, NULL, 10); |
|
g_PTZ_model = (int)iModel; |
|
|
|
//printf("\n-------iModel:%d\n", iModel); |
|
if ((val & SYS_FEATURE_PTZ) == SYS_FEATURE_PTZ && iModel != 659 && iModel != 715 && iModel != 714 && iModel != 731 && iModel != 716) |
|
{ |
|
//printf("Is ptz 1\n"); |
|
g_IsPTZDevice = 1; |
|
ret = 1; |
|
} |
|
else |
|
{ |
|
//printf("Is ptz 2\n"); |
|
//printf("\n-------sSysFeature: %s, 0x%x\n", sSysFeature, val); |
|
ret = 0; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
void DefaultFocusSetting() |
|
{ |
|
//TEMP TEST 20211122 |
|
//return; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
char outputData[1024] = { 0 }; |
|
|
|
//sprintf(ptz_curl_url, "/control?airzoom=%d", 7); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/camera?lensfocus=3&focussen=2&autofocussearch=0&nearlimit=1&ptmovefocusmode=0"); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Default Focus Setting"); |
|
} |
|
|
|
//CGI http://127.0.0.1/image?get=image.mirror |
|
//Response的部份是 |
|
//status=success |
|
//image.mirror=1 |
|
//int IsPTZMirror(char* sUrl, char* sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort) |
|
int IsPTZMirror() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsMirror; |
|
|
|
return ret; |
|
} |
|
|
|
//CGI http://127.0.0.1/image?get=image.flip |
|
//Response的部份是 |
|
//status=success |
|
//image.flip=1 |
|
int IsPTZFlip() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsFlip; |
|
|
|
return ret; |
|
} |
|
|
|
int IsPTZMirrowFlip() |
|
{ |
|
int ret = -1; |
|
|
|
if (g_stPTZ_Handle.iIsMirror == 1 && g_stPTZ_Handle.iIsFlip == 1) |
|
ret = 1; |
|
else |
|
ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
//檢查是否在Home點cgi為 /check_home_position |
|
//回覆為Check Home Position = 0,表示不在Home點 |
|
//回覆為Check Home Position = 1,表示在Home點 |
|
int IsPTZatHomePos() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsAtHomePOS; |
|
|
|
if (ret == 0 || ret == -1) |
|
{ |
|
ret = 0; |
|
} |
|
|
|
//double check |
|
if (ret == 1) |
|
{ |
|
//Get cur pos |
|
//UpdatePTZCurPos(); |
|
if (g_stPTZ_Handle.iPanABS != g_stPTZ_Handle.iHomePanABS |
|
|| g_stPTZ_Handle.iTiltABS != g_stPTZ_Handle.iHomeTiltABS |
|
|| g_stPTZ_Handle.iZoomABS != g_stPTZ_Handle.iHomeZoomABS) |
|
{ |
|
ret = 0; |
|
} |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
//Home Preset >= 0 && <= 256 |
|
int GetHomePreset() |
|
{ |
|
int ret = 0; |
|
|
|
ret = g_stPTZ_Handle.iHomePreset; |
|
|
|
return ret; |
|
} |
|
|
|
//檢查是否在預設點cgi為 /check_preset_position |
|
//回覆為Preset Position = 0,表示目前不在任何預設點 |
|
//回覆為Preset Position = 1,表示目前在預設點1,最多到255 |
|
int IsPTZinPreset() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsInPreset; |
|
|
|
return ret; |
|
} |
|
|
|
|
|
//檢查是否在預設點cgi為 /ptzcamera ? get = AUTO_MODE_STATUS |
|
//回覆為AUTO_MODE_STATUS=0,表示目前 不在AutoPan 模式. |
|
//回覆為AUTO_MODE_STATUS=1,表示目前 開啟AutoPan 模式. |
|
int IsPTZinAutoPan() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsInAutopan; |
|
|
|
return ret; |
|
} |
|
|
|
//回覆為AUTO_MODE_STATUS=0,表示目前 不在AutoPan 模式. |
|
//回覆為AUTO_MODE_STATUS=1,表示目前 開啟AutoPan 模式. |
|
int IsPTZinAutoTracking() |
|
{ |
|
int ret = -1; |
|
|
|
ret = g_stPTZ_Handle.iIsInAutoTracking; |
|
|
|
return ret; |
|
} |
|
|
|
//0 = Not in tracking mode, 1 = In tracking mode |
|
int IsTracking() |
|
{ |
|
int ret = -1; |
|
|
|
//time_t tCheckAutoTrackingTimeStart = time(0); |
|
//time_t tCheckAutoTrackingTimeCurrent = time(0); |
|
//double dwDeltaCheckTime = 0.0; |
|
|
|
//int diffOperatSecs = difftime(tCheckAutoTrackingTimeCurrent, g_stPTZ_Handle.tChangAutoPanTime); |
|
|
|
|
|
//if (dwDeltaCheckTime ) |
|
if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) |
|
{ |
|
//g_stPTZ_Handle.tChangAutoPanTime = time(0); |
|
ret = 1; |
|
} |
|
else if (g_stPTZ_Handle.iIsInAutopan == 0 && g_stPTZ_Handle.iIsInAutoTracking == 0) |
|
{ |
|
//dwDeltaCheckTime = difftime(tCheckAutoTrackingTimeCurrent, g_stPTZ_Handle.tChangAutoPanTime); |
|
//if (dwDeltaCheckTime >= PTZ_IS_TRACKING_TIMER) |
|
//{ |
|
ret = 0; |
|
//} |
|
//else |
|
//{ |
|
// ret = 1; |
|
//} |
|
} |
|
else if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 0) |
|
{ |
|
ret = 0; |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
|
|
int GetPTZActionState() |
|
{ |
|
int ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
int StartTracking() |
|
{ |
|
int ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
int StopTracking() |
|
{ |
|
int ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
int EnableAlarmQuaue() |
|
{ |
|
int ret = 0; |
|
|
|
|
|
|
|
return ret; |
|
} |
|
|
|
int DisableAlarmQueue() |
|
{ |
|
int ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
int GetPTZStatus() |
|
{ |
|
int ret = 0; |
|
|
|
return ret; |
|
} |
|
|
|
typedef struct point { double x, y; } point; |
|
|
|
double getAngleBetween(point p1, point p2) |
|
{ |
|
double x = p2.x - p1.x, y = p2.y - p1.y; |
|
double angle = asin(y / sqrt(x * x + y * y)) * (180 / MATH_PI); |
|
angle = x < 0 ? angle - 90 : 90 - angle; |
|
return angle < 0 ? angle + 360 : angle; |
|
} |
|
|
|
void send_request(char *szIP, char *sUrl, char *sSendbuf, char *sUsername, char *sPassword, char *sMethod, int iPort, char *sOutputData, char* function_id) |
|
{ |
|
//int ret = 0; |
|
|
|
//char *arr_sOutputDataList[MAX_PTZ_INFO]; |
|
//int iPTZInfoCount = 0; |
|
//char *del = "\r\n"; |
|
|
|
#if 0 |
|
FILE * pPipe; |
|
char cmd[512] = { 0 }; |
|
//memset(cmd, 0x00, sizeof(cmd)); |
|
sprintf(cmd, "curl %s", sUrl); |
|
pPipe = vpopen(cmd, "r"); |
|
if (pPipe != NULL) |
|
vpclose(pPipe); |
|
#endif |
|
|
|
//strcat(ptz_curl_username, accountData[0].account_username); |
|
//strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
#if 0 |
|
/*int curl_ret = */net_curl_ptz_cmd_ghandle(sUrl, sSendbuf, NULL, sMethod, |
|
accountData[0].account_username, accountData[0].account_password, iPort, sOutputData); |
|
#endif |
|
|
|
#if 1 |
|
/*int curl_ret = */net_curl_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, |
|
sUsername, sPassword, iPort, sOutputData, function_id); |
|
#endif |
|
|
|
#if 0 |
|
/*int curl_ret = */net_socket_ptz_cmd(sUrl, sSendbuf, NULL, sMethod, |
|
sUsername, sPassword, iPort, sOutputData); |
|
#endif |
|
|
|
#if 0 |
|
/*int curl_ret = */net_curl_ptz_cmd_multi_interface(sUrl, sSendbuf, NULL, sMethod, |
|
sUsername, sPassword, iPort, sOutputData); |
|
#endif |
|
|
|
#if 0 |
|
SendCGIHighSpeed_B(sUsername, sPassword, szIP, iPort, sUrl); |
|
//SendCGIHighSpeed(sUsername, sPassword, szIP, iPort, sUrl); |
|
#endif |
|
|
|
} |
|
|
|
void GetLockObjFOV(int iResW, int iResH) |
|
{ |
|
int OutBox_w = g_stPTZ_Handle.stPTZOutsideBox.width; |
|
int OutBox_h = g_stPTZ_Handle.stPTZOutsideBox.height; |
|
int OutBox_Scale_w = 0, OutBox_Scale_h = 0; |
|
|
|
int iLimitW = (int)(iResW * PTZ_ZOOMIN_LIMIT) / 100; |
|
int iLimitH = (int)(iResH * PTZ_ZOOMIN_LIMIT) / 100; |
|
|
|
g_stPTZ_Handle.iLockObjFOV = 0; |
|
|
|
if ((OutBox_w > 0 && OutBox_w < iResW) |
|
&& (OutBox_h > 0 && OutBox_h < iResH) |
|
) |
|
{ |
|
//printf("rw, rh: %d, %d \n", iResW, iResH); |
|
//printf("O_w, O_h: %d, %d \n", OutBox_w, OutBox_h); |
|
|
|
OutBox_Scale_w = ((OutBox_w * 1000) / iLimitW) / 10; |
|
OutBox_Scale_h = ((OutBox_h * 1000) / iLimitH) / 10; |
|
|
|
|
|
if (OutBox_Scale_w > OutBox_Scale_h) |
|
g_stPTZ_Handle.iLockObjFOV = OutBox_Scale_w; |
|
else |
|
g_stPTZ_Handle.iLockObjFOV = OutBox_Scale_h; |
|
|
|
//printf("s_w / s_h: %d, %d, %d \n", OutBox_Scale_w, OutBox_Scale_h, g_stPTZ_Handle.iLockObjFOV); |
|
} |
|
|
|
//return g_stPTZ_Handle.iLockObjFOV; |
|
} |
|
|
|
int IfDoZoom(int iResW, int iResH, int iInZoomScale) |
|
{ |
|
int iZoomScale = 0; |
|
|
|
if (g_stPTZ_Handle.iLockObjFOV != 0) |
|
{ |
|
|
|
if (g_stPTZ_Handle.iLockObjFOV > (g_stPTZ_Handle.iTracking_fov_max + 5)) |
|
{ |
|
iZoomScale = g_stPTZ_Handle.iLockObjFOV; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV < (g_stPTZ_Handle.iTracking_fov_max - 5)) |
|
{ |
|
iZoomScale = g_stPTZ_Handle.iLockObjFOV; |
|
} |
|
} |
|
else |
|
iZoomScale = 0; |
|
|
|
|
|
#if 0 |
|
int iZoomScale = 0; |
|
|
|
int OutBox_w = g_stPTZ_Handle.stPTZOutsideBox.width; |
|
int OutBox_h = g_stPTZ_Handle.stPTZOutsideBox.height; |
|
int OutBox_Scale_w = 0, OutBox_Scale_h = 0; |
|
int MINZoomScale = g_stPTZ_Handle.iTracking_fov_min; //iInZoomScale |
|
int MAXZoomScale = g_stPTZ_Handle.iTracking_fov_max; |
|
|
|
int iLimitW = (int)(iResW * PTZ_ZOOMIN_LIMIT) / 100; |
|
int iLimitH = (int)(iResH * PTZ_ZOOMIN_LIMIT) / 100; |
|
|
|
//Check Outbox avaliable |
|
if ((OutBox_w > 0 && OutBox_w < iResW) |
|
&& (OutBox_h > 0 && OutBox_h < iResH) |
|
) |
|
{ |
|
//printf("rw, rh: %d, %d \n", iResW, iResH); |
|
//printf("O_w, O_h: %d, %d \n", OutBox_w, OutBox_h); |
|
|
|
OutBox_Scale_w = ((OutBox_w * 1000) / iLimitW) / 10; |
|
OutBox_Scale_h = ((OutBox_h * 1000) / iLimitH) / 10; |
|
|
|
//printf("s_w / s_h: %d, %d, %d \n", OutBox_Scale_w, OutBox_Scale_h, iInZoomScale); |
|
//printf("iInZoomScale = %d \n", iInZoomScale); |
|
|
|
if (OutBox_Scale_w > OutBox_Scale_h) |
|
iZoomScale = OutBox_Scale_w; |
|
else |
|
iZoomScale = OutBox_Scale_h; |
|
|
|
#if 0 |
|
if ((OutBox_Scale_w > (iInZoomScale + 10)) |
|
|| (OutBox_Scale_h > (iInZoomScale + 10)) |
|
) |
|
{ |
|
//Zoom out |
|
iZoomScale = 2; |
|
//printf("Scale 3: %d \n", iZoomScale); |
|
} |
|
else if ( (OutBox_Scale_w < (iInZoomScale-10)) |
|
&& (OutBox_Scale_h < (iInZoomScale-10)) ) |
|
{ |
|
//Zoom in |
|
iZoomScale = -2; |
|
|
|
//printf("Scale 3: %d \n", iZoomScale); |
|
} |
|
else |
|
{ |
|
iZoomScale = 0; |
|
} |
|
#endif |
|
} |
|
else |
|
iZoomScale = 0; |
|
|
|
#endif |
|
|
|
return iZoomScale; |
|
} |
|
|
|
int IfStopZoom() |
|
{ |
|
int ret = 0; |
|
|
|
if (g_stPTZ_Handle.stPTZOutsideBox.center_x == 0 |
|
&& g_stPTZ_Handle.stPTZOutsideBox.center_y == 0) |
|
{ |
|
ret = 1; |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
int GetOutsideAllBox() |
|
{ |
|
int ret = 1; |
|
float left_x = 999999, top_y = 999999; |
|
float right_x = -1, bottom_y = -1; |
|
//float iCenter_x = 0, iCenter_y = 0; |
|
|
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
if (g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y <= top_y) |
|
top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y; |
|
|
|
if (g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x <= left_x) |
|
left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x; |
|
|
|
if ((g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y + g_stPTZ_Handle.stPTZCandidateBoxTable[i].height) >= bottom_y) |
|
bottom_y = (g_stPTZ_Handle.stPTZCandidateBoxTable[i].top_y + g_stPTZ_Handle.stPTZCandidateBoxTable[i].height); |
|
|
|
if ((g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x + g_stPTZ_Handle.stPTZCandidateBoxTable[i].width) >= right_x) |
|
right_x = (g_stPTZ_Handle.stPTZCandidateBoxTable[i].left_x + g_stPTZ_Handle.stPTZCandidateBoxTable[i].width); |
|
} |
|
|
|
//printf("-------------> x, y, x, y = %f, %f, %f, %f \n", left_x, top_y, right_x, bottom_y); |
|
|
|
if (left_x < 999999 && top_y < 999999 && right_x > -1 && bottom_y > -1) |
|
{ |
|
g_stPTZ_Handle.stPTZOutsideBox.left_x = left_x; |
|
g_stPTZ_Handle.stPTZOutsideBox.top_y = top_y; |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.width = right_x - left_x; |
|
g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZOutsideBox.left_x + ((right_x - left_x) / 2); |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.height = bottom_y - top_y; |
|
g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZOutsideBox.top_y + ((bottom_y - top_y) / 2); |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.class_id = 9999; |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
//int GetOutsideBox(detection_pos *posInfo, int iTotalElementSize, int iResW, int iResH) |
|
//{ |
|
// detection_pos *pNext = NULL; |
|
// //point p1, p2; |
|
// //char *sTrackClass = "bus"; |
|
// //1920 / 1080 |
|
// int ret = 1; |
|
// |
|
// float left_x = 999999, top_y = 999999; |
|
// float right_x = -1, bottom_y = -1; |
|
// //float iCenter_x = 0, iCenter_y = 0; |
|
// //int diff_x = 0, diff_y = 0; |
|
// |
|
// //int iPercentage_W = 50, iPercentage_H = 50; |
|
// |
|
// int iFilter_confidence = 0; |
|
// |
|
// if (g_stPTZ_Handle.iTraffic_cnfidence != 0) |
|
// iFilter_confidence = g_stPTZ_Handle.iTraffic_cnfidence; |
|
// //printf("PTZ TRAFFIC CONFIDENCE: %d \n", iFilter_confidence); |
|
// |
|
// for (int i = 0; i < iTotalElementSize; i++) |
|
// { |
|
// pNext = posInfo + i; |
|
// |
|
// if (pNext->confidence >= iFilter_confidence) |
|
// { |
|
// for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) |
|
//{ |
|
// if (strcmp(pNext->name, g_stPTZ_Handle.sMetaOut1[j]) == 0) |
|
// { |
|
// //printf("[%d]ori x/y, w/h = %f, %f, %f, %f \n", i, pNext->left_x, pNext->top_y, pNext->width, pNext->height); |
|
// |
|
// if (pNext->top_y <= top_y) |
|
// top_y = pNext->top_y; |
|
// |
|
// if (pNext->left_x <= left_x) |
|
// left_x = pNext->left_x; |
|
// |
|
// if ((pNext->top_y + pNext->height) >= bottom_y) |
|
// bottom_y = (pNext->top_y + pNext->height); |
|
// |
|
// if ((pNext->left_x + pNext->width) >= right_x) |
|
// right_x = (pNext->left_x + pNext->width); |
|
// |
|
// //printf("outside box_x/y/ x/y: %f, %f, %f, %f \n\n", left_x, top_y, right_x, bottom_y); |
|
//} |
|
// } |
|
// } |
|
// } |
|
// |
|
// //printf("outside box_x/y/ x/y: %f, %f, %f, %f \n\n", left_x, top_y, right_x, bottom_y); |
|
// |
|
// if (left_x < 999999 && top_y < 99999 && right_x > -1 && bottom_y > -1) |
|
// { |
|
// if (g_stPTZ_Handle.stPTZOutsideBox.left_x == -1 |
|
// && g_stPTZ_Handle.stPTZOutsideBox.top_y == -1) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.iFirstTrackingFlag = 3; |
|
// g_stPTZ_Handle.iZoomFreqCount -= 10; |
|
//} |
|
// |
|
// g_stPTZ_Handle.stPTZOutsideBox.left_x = left_x; |
|
// g_stPTZ_Handle.stPTZOutsideBox.top_y = top_y; |
|
// |
|
// if (right_x > left_x) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.width = right_x - left_x; |
|
// g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZOutsideBox.left_x + ((right_x - left_x) / 2); |
|
// |
|
// //加入預測提前量 |
|
// //{ |
|
// //} |
|
// } |
|
// else |
|
// { |
|
// ret = -1; |
|
// } |
|
// |
|
// if (bottom_y > top_y) |
|
// { |
|
// g_stPTZ_Handle.stPTZOutsideBox.height = bottom_y - top_y; |
|
// g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZOutsideBox.top_y + ((bottom_y - top_y) / 2); |
|
// |
|
// //加入預測提前量 |
|
// //{ |
|
// //} |
|
// } |
|
// else |
|
// { |
|
// ret = -1; |
|
// } |
|
// |
|
//#if 0 |
|
// //計算角度位置 |
|
// diff_x = g_stPTZ_Handle.stPTZOutsideBox.center_x - (iResW / 2); |
|
// diff_y = (iResH / 2) - g_stPTZ_Handle.stPTZOutsideBox.center_y; |
|
// |
|
// p1.x = 0; |
|
// p1.y = 0; |
|
// p2.x = diff_x; |
|
// p2.y = diff_y; |
|
// |
|
// g_stPTZ_Handle.dwMoveAngel = getAngleBetween(p1, p2); |
|
// |
|
// //計算移動速度 |
|
// g_stPTZ_Handle.iMoveSpeed_x = diff_x / (iResW / 14); |
|
// g_stPTZ_Handle.iMoveSpeed_y = diff_y / (iResH / 14); |
|
// |
|
// //if (g_stPTZ_Handle.iMoveSpeed_y < 0) |
|
// //{ |
|
// // g_stPTZ_Handle.iMoveSpeed_y = (g_stPTZ_Handle.iMoveSpeed_y * 2) % 7; |
|
// //} |
|
// |
|
// if (g_stPTZ_Handle.iMoveSpeed_x > 7) |
|
// g_stPTZ_Handle.iMoveSpeed_x = 7; |
|
// |
|
// if (g_stPTZ_Handle.iMoveSpeed_x < -7) |
|
// g_stPTZ_Handle.iMoveSpeed_x = -7; |
|
// |
|
// if (g_stPTZ_Handle.iMoveSpeed_y > 7) |
|
// g_stPTZ_Handle.iMoveSpeed_y = 7; |
|
// |
|
// if (g_stPTZ_Handle.iMoveSpeed_y < -7) |
|
// g_stPTZ_Handle.iMoveSpeed_y = -7; |
|
// |
|
// //if (g_stPTZ_Handle.iMoveSpeed_x > 7 || g_stPTZ_Handle.iMoveSpeed_x < -7) |
|
// // g_stPTZ_Handle.iMoveSpeed_x = 0; |
|
// |
|
// //if (g_stPTZ_Handle.iMoveSpeed_y > 7 || g_stPTZ_Handle.iMoveSpeed_y < -7) |
|
// // g_stPTZ_Handle.iMoveSpeed_y = 0; |
|
//#endif |
|
// } |
|
// else |
|
// { |
|
// g_stPTZ_Handle.stPTZOutsideBox.center_x = 0; |
|
// g_stPTZ_Handle.stPTZOutsideBox.center_y = 0; |
|
// g_stPTZ_Handle.stPTZOutsideBox.width = -1; |
|
// g_stPTZ_Handle.stPTZOutsideBox.height = -1; |
|
// //g_stPTZ_Handle.iTimer_send_count = 0; |
|
// //g_stPTZ_Handle.dwMoveAngel = 0; |
|
// //g_stPTZ_Handle.iMoveSpeed_x = 0; |
|
// //g_stPTZ_Handle.iMoveSpeed_y = 0; |
|
// g_stPTZ_Handle.stPTZOutsideBox.iFirstTrackingFlag = 0; |
|
// |
|
// ret = -1; |
|
// } |
|
// |
|
// return ret; |
|
//} |
|
|
|
int GetOutsideLockBox(int iResW, int iResH) |
|
{ |
|
int ret = 1; |
|
|
|
//1: 只追第一次鎖定的物件, 遺失後改追範圍內最接近的 |
|
//2: 追較大的物件 |
|
//3: 追第一次鎖定的物件, 遺失後改追周遭同類型最大的 |
|
|
|
//if (g_stPTZ_Handle.iTracking_mode == 1 || g_stPTZ_Handle.iTracking_mode == 2) |
|
//{ |
|
g_stPTZ_Handle.stPTZOutsideBox.left_x = g_stPTZ_Handle.stPTZLockTrackingBox.left_x; |
|
g_stPTZ_Handle.stPTZOutsideBox.top_y = g_stPTZ_Handle.stPTZLockTrackingBox.top_y; |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.center_x = g_stPTZ_Handle.stPTZLockTrackingBox.left_x + (g_stPTZ_Handle.stPTZLockTrackingBox.width / 2); |
|
g_stPTZ_Handle.stPTZOutsideBox.center_y = g_stPTZ_Handle.stPTZLockTrackingBox.top_y + (g_stPTZ_Handle.stPTZLockTrackingBox.height / 2); |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.width = g_stPTZ_Handle.stPTZLockTrackingBox.width; |
|
g_stPTZ_Handle.stPTZOutsideBox.height = g_stPTZ_Handle.stPTZLockTrackingBox.height; |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.class_id = g_stPTZ_Handle.stPTZLockTrackingBox.class_id; |
|
//} |
|
//else if (g_stPTZ_Handle.iTracking_mode == 3) |
|
//{ |
|
// ret = GetOutsideAllBox(); |
|
//printf("outside box_x/y/ x/y: %d, %fd, %d, %d \n\n", g_stPTZ_Handle.stPTZOutsideBox.left_x, g_stPTZ_Handle.stPTZOutsideBox.top_y, g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); |
|
//} |
|
|
|
|
|
|
|
return ret; |
|
} |
|
|
|
int OutsideBoxChange() |
|
{ |
|
int ret = 0; |
|
int iRecordCount; |
|
|
|
iRecordCount = g_stPTZ_Handle.iRecordOldOutsideBoxCount; |
|
|
|
//If same with last one |
|
if (iRecordCount > 0) |
|
{ |
|
if (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x == g_stPTZ_Handle.stPTZOutsideBox.center_x |
|
&& g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y == g_stPTZ_Handle.stPTZOutsideBox.center_y) |
|
{ |
|
ret = 0; |
|
} |
|
else |
|
{ |
|
ret = 1; |
|
} |
|
} |
|
else |
|
{ |
|
ret = 1; |
|
} |
|
|
|
//Store record |
|
iRecordCount++; |
|
|
|
if (iRecordCount > MAX_RECORD_BOX_SIZE) |
|
{ |
|
iRecordCount = MAX_RECORD_BOX_SIZE; |
|
g_stPTZ_Handle.iRecordOldOutsideBoxCount = iRecordCount; |
|
|
|
for (int n = 0; n < iRecordCount - 1; n++) |
|
{ |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].left_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].left_x; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].top_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].top_y; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].center_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].center_x; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].center_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].center_y; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].width = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].width; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].height = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].height; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[n].class_id = g_stPTZ_Handle.stPTZRecordOldOutsideBox[n + 1].class_id; |
|
|
|
} |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iRecordOldOutsideBoxCount = iRecordCount; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].left_x = g_stPTZ_Handle.stPTZOutsideBox.left_x; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].top_y = g_stPTZ_Handle.stPTZOutsideBox.top_y; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x = g_stPTZ_Handle.stPTZOutsideBox.center_x; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y = g_stPTZ_Handle.stPTZOutsideBox.center_y; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].width = g_stPTZ_Handle.stPTZOutsideBox.width; |
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].height = g_stPTZ_Handle.stPTZOutsideBox.height; |
|
|
|
g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].class_id = g_stPTZ_Handle.stPTZOutsideBox.class_id; |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
|
|
int IfGoCenter(int iResW, int iResH) |
|
{ |
|
int ret = 1; |
|
|
|
ret = OutsideBoxChange(); |
|
//printf("If Outside Box Change = %d \n", ret); |
|
|
|
//Outside box not change |
|
if (ret == 0) |
|
{ |
|
return -1; |
|
} |
|
#if 1 |
|
int iPercentage_W = ((g_stPTZ_Handle.stPTZOutsideBox.center_x * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); |
|
int iPercentage_H = ((g_stPTZ_Handle.stPTZOutsideBox.center_y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); |
|
|
|
//printf("CKW / CKH: %d, %d \n", iPercentage_W, iPercentage_H); |
|
if (iPercentage_W > PTZ_CENTER_AREA_X2_MIN |
|
&& iPercentage_W < PTZ_CENTER_AREA_X2_MAX |
|
&& iPercentage_H > PTZ_CENTER_AREA_X2_MIN |
|
&& iPercentage_H < PTZ_CENTER_AREA_X2_MAX) |
|
{ |
|
ret = -1; |
|
} |
|
else |
|
{ |
|
ret = 1; |
|
} |
|
|
|
//中心3%太靈敏, 會晃 |
|
#if 0 |
|
if (g_stPTZ_Handle.iPTZ_speed == 1) |
|
{ |
|
if (iPercentage_W > 49 |
|
&& iPercentage_W < 51 |
|
&& iPercentage_H > 49 |
|
&& iPercentage_H < 51) |
|
{ |
|
ret = -1; |
|
} |
|
else |
|
{ |
|
ret = 1; |
|
} |
|
} |
|
#endif |
|
|
|
#endif |
|
|
|
//避免擺盪 去提前量 取中心點 |
|
#if 0 |
|
int iRecordCount = g_stPTZ_Handle.iRecordOldOutsideBoxCount; |
|
|
|
if (iRecordCount >= 2) |
|
{ |
|
if (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].obj_tracking_id == g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].obj_tracking_id) |
|
{ |
|
//X |
|
float iMidCenter_X = (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].center_x + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x) / 2; |
|
int iPercentage_X = ((iMidCenter_X * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); |
|
|
|
if (iPercentage_X > PTZ_FILTER_AREA_MIN |
|
&& iPercentage_X < PTZ_FILTER_AREA_MAX) |
|
{ |
|
g_stPTZ_Handle.stPTZOutsideBox.center_x = iMidCenter_X; |
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_x = iMidCenter_X; |
|
|
|
//g_stPTZ_Handle.stPTZOutsideBox.left_x = iMidCenter_X - (g_stPTZ_Handle.stPTZOutsideBox.width / 2); |
|
//g_stPTZ_Handle.stPTZOutsideBox.right_x = iMidCenter_X + (g_stPTZ_Handle.stPTZOutsideBox.width / 2); |
|
|
|
//if (g_stPTZ_Handle.stPTZOutsideBox.left_x < 0) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.left_x = 0; |
|
//} |
|
//else if (g_stPTZ_Handle.stPTZOutsideBox.right_x > g_stPTZ_Handle.iIMG_source_w) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.right_x = g_stPTZ_Handle.iIMG_source_w; |
|
//} |
|
|
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].right_x = g_stPTZ_Handle.stPTZOutsideBox.right_x; |
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].right_x = g_stPTZ_Handle.stPTZOutsideBox.right_x; |
|
} |
|
|
|
//Y |
|
float iMidCenter_Y = (g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 2].center_y + g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y) / 2; |
|
int iPercentage_Y = ((iMidCenter_Y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); |
|
|
|
if (iPercentage_Y > PTZ_FILTER_AREA_MIN |
|
&& iPercentage_Y < PTZ_FILTER_AREA_MAX) |
|
{ |
|
g_stPTZ_Handle.stPTZOutsideBox.center_y = iMidCenter_Y; |
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].center_y = iMidCenter_Y; |
|
|
|
//g_stPTZ_Handle.stPTZOutsideBox.top_y = iMidCenter_Y - (g_stPTZ_Handle.stPTZOutsideBox.height / 2); |
|
//g_stPTZ_Handle.stPTZOutsideBox.bottom_y = iMidCenter_Y + (g_stPTZ_Handle.stPTZOutsideBox.height / 2); |
|
|
|
//if (g_stPTZ_Handle.stPTZOutsideBox.top_y < 0) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.top_y = 0; |
|
//} |
|
//else if (g_stPTZ_Handle.stPTZOutsideBox.bottom_y > g_stPTZ_Handle.iIMG_source_h) |
|
//{ |
|
// g_stPTZ_Handle.stPTZOutsideBox.bottom_y = g_stPTZ_Handle.iIMG_source_h; |
|
//} |
|
|
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].top_y = g_stPTZ_Handle.stPTZOutsideBox.top_y; |
|
//g_stPTZ_Handle.stPTZRecordOldOutsideBox[iRecordCount - 1].bottom_y = g_stPTZ_Handle.stPTZOutsideBox.bottom_y; |
|
} |
|
} |
|
} |
|
#endif |
|
|
|
#if 0 |
|
int iKeepArea_left_x, iKeepArea_top_y; |
|
int iKeepArea_right_x, iKeepArea_bottom_y; |
|
int iKeepArea_w, iKeepArea_h; |
|
|
|
//PTZ_CENTER_AREA % |
|
if (g_stPTZ_Handle.iZoomABS >= 10) |
|
{ |
|
iKeepArea_w = iResW * PTZ_CENTER_AREA_X8 / 100; |
|
iKeepArea_h = iResH * PTZ_CENTER_AREA_X8 / 100; |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS >= 5 && g_stPTZ_Handle.iZoomABS < 10) |
|
{ |
|
iKeepArea_w = iResW * PTZ_CENTER_AREA_X5 / 100; |
|
iKeepArea_h = iResH * PTZ_CENTER_AREA_X5 / 100; |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS < 5) |
|
{ |
|
iKeepArea_w = iResW * PTZ_CENTER_AREA_X2 / 100; |
|
iKeepArea_h = iResH * PTZ_CENTER_AREA_X2 / 100; |
|
} |
|
|
|
iKeepArea_left_x = (iResW / 2) - (iKeepArea_w / 2); |
|
iKeepArea_top_y = (iResH / 2) - (iKeepArea_h / 2); |
|
|
|
iKeepArea_right_x = (iResW / 2) + (iKeepArea_w / 2); |
|
iKeepArea_bottom_y = (iResH / 2) + (iKeepArea_h / 2); |
|
|
|
//printf("k_x, k_x2, k_y, k_y2: %d, %d, %d, %d \n", iKeepArea_left_x, iKeepArea_right_x, iKeepArea_top_y, iKeepArea_bottom_y); |
|
//printf("o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); |
|
|
|
if (g_stPTZ_Handle.stPTZOutsideBox.center_x != 0 && g_stPTZ_Handle.stPTZOutsideBox.center_y != 0) |
|
{ |
|
if (g_stPTZ_Handle.stPTZOutsideBox.center_x >= iKeepArea_left_x |
|
&& g_stPTZ_Handle.stPTZOutsideBox.center_x <= iKeepArea_right_x |
|
&& g_stPTZ_Handle.stPTZOutsideBox.center_y >= iKeepArea_top_y |
|
&& g_stPTZ_Handle.stPTZOutsideBox.center_y <= iKeepArea_bottom_y |
|
) |
|
{ |
|
//printf("k_x, k_x2, k_y, k_y2: %d, %d, %d, %d \n", iKeepArea_left_x, iKeepArea_right_x, iKeepArea_top_y, iKeepArea_bottom_y); |
|
//printf("AAA o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); |
|
|
|
ret = -1; |
|
} |
|
else |
|
{ |
|
//printf("BBB o_cx, o_cy: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); |
|
ret = 1; |
|
} |
|
} |
|
else |
|
ret = -1; |
|
#endif |
|
|
|
return ret; |
|
} |
|
|
|
int IfGetLockBox() |
|
{ |
|
int ret = 0; |
|
|
|
ret = g_stPTZ_Handle.iIsGetLockTrackingBox; |
|
|
|
return ret; |
|
} |
|
|
|
int FindNearestBox() |
|
{ |
|
int iNearestDis = 9999; |
|
int iNearestIdx = -1; |
|
float fDist = 0; |
|
|
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
fDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); |
|
|
|
if (fDist < iNearestDis) |
|
{ |
|
iNearestDis = fDist; |
|
iNearestIdx = i; |
|
} |
|
} |
|
|
|
return iNearestIdx; |
|
} |
|
|
|
int FindBiggestBox() |
|
{ |
|
//int iResult = 0; |
|
int iMax_area = 0; |
|
int iBox_area = 0; |
|
int iMaxAreaIdx = -1; |
|
int iBoxW = 0; |
|
int iBoxH = 0; |
|
|
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
iBoxW = g_stPTZ_Handle.stPTZCandidateBoxTable[i].width; |
|
iBoxH = g_stPTZ_Handle.stPTZCandidateBoxTable[i].height; |
|
iBox_area = iBoxW * iBoxH; |
|
|
|
if (iBox_area > iMax_area) |
|
{ |
|
iMax_area = iBox_area; |
|
iMaxAreaIdx = i; |
|
} |
|
} |
|
|
|
return iMaxAreaIdx; |
|
} |
|
|
|
int GetSingleLockTrackingBox(int iResW, int iResH) |
|
{ |
|
int iLockBoxIdx = -1; |
|
//time_t tCurrentTime = time(0); |
|
|
|
|
|
//AI_fps: 根據目前FPS, 決定當鎖定物件消失時, 要等多久才放棄. |
|
|
|
pthread_mutex_lock(&mutex_update_candidate); |
|
|
|
{ |
|
//char msg_temp[512] = { 0 }; |
|
//sprintf(msg_temp, "g_stPTZ_Handle.iCandidateBoxCount:%d", g_stPTZ_Handle.iCandidateBoxCount); |
|
//write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); |
|
} |
|
|
|
#if 1 |
|
if (g_stPTZ_Handle.iCandidateBoxCount > 0) |
|
{ |
|
if (g_stPTZ_Handle.iTracking_mode == 3) |
|
{ |
|
if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) |
|
{ |
|
if (g_stPTZ_Handle.iCandidateBoxCount == 1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = 0; |
|
} |
|
else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find biggest box |
|
{ |
|
int iBiggestBoxIdx = FindBiggestBox(); |
|
if (iBiggestBoxIdx != -1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iBiggestBoxIdx; |
|
} |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 1) |
|
{ |
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
if (g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id == g_stPTZ_Handle.stPTZCandidateBoxTable[i].obj_tracking_id |
|
/*&& strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, pNext1->name) == 0*/) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = i; |
|
break; |
|
} |
|
} |
|
|
|
#if 1 |
|
//Lose lock obj => fine nearst obj (半徑範圍內尋找) |
|
if (iLockBoxIdx == -1) |
|
{ |
|
//容許遺失次數, 暫時不動作 |
|
|
|
|
|
int iClosestBoxIDX = -1; |
|
float fClosestDistense = 999999; |
|
float fCurDist = 0.0; |
|
float fRadius = 0.0; |
|
|
|
fRadius = (float)(3 * FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZLockTrackingBox.left_x, g_stPTZ_Handle.stPTZLockTrackingBox.top_y)); |
|
|
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
fCurDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); |
|
|
|
if (fCurDist < fClosestDistense && fCurDist <= fRadius) |
|
{ |
|
fClosestDistense = fCurDist; |
|
iClosestBoxIDX = i; |
|
} |
|
|
|
if (iClosestBoxIDX != -1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iClosestBoxIDX; |
|
} |
|
} |
|
} |
|
#endif |
|
//iLockBoxIdx = 2; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iTracking_mode == 2) |
|
{ |
|
int iBiggestBoxIdx = FindBiggestBox(); |
|
if (iBiggestBoxIdx != -1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iBiggestBoxIdx; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iTracking_mode == 1) |
|
{ |
|
if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) //first |
|
{ |
|
g_stPTZ_Handle.iMissObjMomnentCount = 0; |
|
if (g_stPTZ_Handle.iCandidateBoxCount == 1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = 0; |
|
} |
|
else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find Biggest box |
|
{ |
|
#if 1 |
|
int iBiggestBoxIdx = FindBiggestBox(); |
|
if (iBiggestBoxIdx != -1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iBiggestBoxIdx; |
|
} |
|
else |
|
{ |
|
//強制給予第一個 |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = 0; |
|
} |
|
#endif |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 1) //have been lock |
|
{ |
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
if (g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id == g_stPTZ_Handle.stPTZCandidateBoxTable[i].obj_tracking_id |
|
&& strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, g_stPTZ_Handle.stPTZCandidateBoxTable[i].name) == 0) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = i; |
|
break; |
|
} |
|
} |
|
|
|
#if 1 |
|
//Lose lock obj => fine nearst obj (半徑範圍內尋找) |
|
if (iLockBoxIdx == -1) |
|
{ |
|
//容許遺失次數, 暫時不動作 |
|
//若小於遺失次數限制 && 不再原點, 則暫時不指定ClosestBox |
|
int iMissingTimeLimit = 0; |
|
if (g_IsShipTracking) |
|
iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_LONG; |
|
else |
|
iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_SHORT; |
|
|
|
if (g_stPTZ_Handle.iLoseLockObjCount < iMissingTimeLimit) |
|
{ |
|
iLockBoxIdx = PTZ_MISS_OBJ_MAGIC_FLAG; |
|
if (g_IsShipTracking) |
|
usSleep(100000); |
|
} |
|
else |
|
{ |
|
int iClosestBoxIDX = -1; |
|
float fClosestDistense = 999999; |
|
float fCurDist = 0.0; |
|
float fRadius = 0.0; |
|
|
|
fRadius = (float)(3 * FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZLockTrackingBox.left_x, g_stPTZ_Handle.stPTZLockTrackingBox.top_y)); |
|
|
|
for (int i = 0; i < g_stPTZ_Handle.iCandidateBoxCount; i++) |
|
{ |
|
fCurDist = FindPointDistance(g_stPTZ_Handle.stPTZLockTrackingBox.center_x, g_stPTZ_Handle.stPTZLockTrackingBox.center_y, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_x, g_stPTZ_Handle.stPTZCandidateBoxTable[i].center_y); |
|
|
|
if (fCurDist < fClosestDistense && fCurDist <= fRadius) |
|
{ |
|
fClosestDistense = fCurDist; |
|
iClosestBoxIDX = i; |
|
} |
|
|
|
if (iClosestBoxIDX != -1) |
|
{ |
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iClosestBoxIDX; |
|
break; |
|
} |
|
} |
|
} //if (g_stPTZ_Handle.iLoseLockObjCount < 7) |
|
} |
|
|
|
//Still = -1 //取消, 外部會判斷錯誤 |
|
//if (iLockBoxIdx == -1) |
|
//{ |
|
// g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
// iLockBoxIdx = 0; |
|
//} |
|
#endif |
|
} |
|
} |
|
} // iCandidateBoxCount > 0 |
|
else |
|
{ |
|
int iMissingTimeLimit = 0; |
|
if (g_IsShipTracking) |
|
iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_LONG; |
|
else |
|
iMissingTimeLimit = PTZ_MISSING_OBJ_LIMIT_SHORT; |
|
|
|
if (g_stPTZ_Handle.iLoseLockObjCount < iMissingTimeLimit) |
|
{ |
|
iLockBoxIdx = PTZ_MISS_OBJ_MAGIC_FLAG; |
|
} |
|
else |
|
{ |
|
iLockBoxIdx = -1; |
|
} |
|
} |
|
|
|
//g_stPTZ_Handle.iCandidateBoxCount = 0; //Reset every time parse end |
|
|
|
pthread_mutex_unlock(&mutex_update_candidate); |
|
|
|
#if 0 |
|
printf("lockbox id = %d \n", iLockBoxIdx); |
|
printf("lock box %s, x, y, w, h = %d, %d, %d, %d \n", |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name, |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x, |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y, |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width, |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height); |
|
#endif |
|
|
|
#if 1 |
|
//Assign lock box data |
|
if (iLockBoxIdx >= 0 && iLockBoxIdx != PTZ_MISS_OBJ_MAGIC_FLAG) |
|
{ |
|
g_stPTZ_Handle.stPTZLockTrackingBox.left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.width = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.height = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height; |
|
|
|
if (g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name) |
|
{ |
|
snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, |
|
sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name); |
|
} |
|
|
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_tracking_id; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.class_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].class_id; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_type = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_type; |
|
|
|
#if 0 |
|
printf("lockbox id = %d \n", iLockBoxIdx); |
|
printf("lock box %s, x, y, w, h = %d, %d, %d, %d \n", |
|
g_stPTZ_Handle.stPTZLockTrackingBox.name, |
|
g_stPTZ_Handle.stPTZLockTrackingBox.left_x, |
|
g_stPTZ_Handle.stPTZLockTrackingBox.top_y, |
|
g_stPTZ_Handle.stPTZLockTrackingBox.width, |
|
g_stPTZ_Handle.stPTZLockTrackingBox.height); |
|
#endif |
|
} |
|
#endif |
|
|
|
|
|
|
|
#endif |
|
|
|
#if 0 |
|
if (g_stPTZ_Handle.iCandidateBoxCount == 1) |
|
{ |
|
g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = 0; |
|
} |
|
else if (g_stPTZ_Handle.iCandidateBoxCount > 1)//Find biggest box |
|
{ |
|
int iBiggestBoxIdx = FindBiggestBox(); |
|
if (iBiggestBoxIdx != -1) |
|
{ |
|
g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 1; |
|
iLockBoxIdx = iBiggestBoxIdx; |
|
} |
|
} |
|
|
|
//Assign lock box data |
|
if (iLockBoxIdx >= 0) |
|
{ |
|
g_stPTZ_Handle.stPTZLockTrackingBox.left_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].left_x; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.top_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].top_y; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.width = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].width; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.height = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].height; |
|
|
|
g_stPTZ_Handle.stPTZLockTrackingBox.center_x = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].center_x; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.center_y = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].center_y; |
|
|
|
if (g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name) |
|
{ |
|
snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, |
|
sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].name); |
|
} |
|
|
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_tracking_id; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.class_id = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].class_id; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_type = g_stPTZ_Handle.stPTZCandidateBoxTable[iLockBoxIdx].obj_type; |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.stPTZLockTrackingBox.left_x = 99999; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.top_y = 99999; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.width = -1; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.height = -1; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.center_x = 0; |
|
g_stPTZ_Handle.stPTZLockTrackingBox.center_y = 0; |
|
|
|
g_stPTZ_Handle.iLoseLockObjCount = 0; //Reset lock obj lose count |
|
} |
|
#endif |
|
|
|
#if 0 |
|
//沒有物件時等待時間 iTracking_resume_dwell |
|
if (g_stPTZ_Handle.iCandidateBoxCount <= 0) |
|
{ |
|
int dwNotUpdateLockBoxSecs = difftime(tCurrentTime, g_stPTZ_Handle.tUpdateLockBoxTime); |
|
//printf("currTime: %d, lastUpdateTime: %d \n", tCurrentTime, g_stPTZ_Handle.tUpdateLockBoxTime); |
|
//printf("Not alive time: %d sec \n", dwNotUpdateLockBoxSecs); |
|
//Wait time out. |
|
if (dwNotUpdateLockBoxSecs > g_stPTZ_Handle.iTracking_resume_dwell) |
|
{ |
|
|
|
g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
tCurrentTime = time(0); |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
|
|
snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, |
|
sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", "\0"); |
|
|
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = -1; |
|
|
|
if (IsPTZatHomePos() == 0 |
|
|| IsPTZinPreset() != GetHomePreset() |
|
) |
|
{ |
|
int iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
//usSleep(3000000); |
|
} |
|
|
|
//Go home position at out side level. |
|
} |
|
} |
|
#endif |
|
|
|
//printf("[%d]Lock box name: %s, tracking_id: %d \n", iLockBoxIdx, g_stPTZ_Handle.stPTZLockTrackingBox.name, g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id); |
|
|
|
|
|
|
|
return iLockBoxIdx; |
|
} |
|
|
|
float FindPointDistance(int x1, int y1, int x2, int y2) |
|
{ |
|
float fDist = 0; |
|
|
|
fDist = sqrt(pow( (x1 - x2) , 2) + pow( (y1 - y2), 2)); |
|
|
|
return fDist; |
|
} |
|
|
|
#if 1 |
|
int IsShipObj() |
|
{ |
|
if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) |
|
{ |
|
return 1; |
|
} |
|
else |
|
return 0; |
|
} |
|
|
|
void GetCandidateBoxTable(detection_pos *posInfo, int iTotalElementSize) |
|
{ |
|
detection_pos* pNext1; |
|
int iCandidateBoxTableIdx = 0; |
|
|
|
int iFilter_confidence = 0; |
|
if (g_stPTZ_Handle.iTraffic_cnfidence != 0) |
|
iFilter_confidence = g_stPTZ_Handle.iTraffic_cnfidence; |
|
|
|
pthread_mutex_lock(&mutex_update_candidate); |
|
|
|
g_stPTZ_Handle.iCandidateBoxCount = 0; |
|
|
|
//if (g_stPTZ_Handle.iPauseTrackFlag == 0) |
|
if (1) |
|
{ |
|
// 是否有設定zone to preset - Yes |
|
if (g_stPTZ_Handle.iZoneToPresetAnyOne == 1) |
|
{ |
|
//是否在Preset點 |
|
//是否該Preset點有設定 Map to zone //先不做, 未來看看 |
|
|
|
//在home preset點時, 就看zone to preset所對應的zone的metadata |
|
if ((g_stPTZ_Handle.iIsInPreset != 0) |
|
&& (g_stPTZ_Handle.iTracking_entering_zone == 1) |
|
&& g_stPTZ_Handle.iIsInPreset == g_stPTZ_Handle.iHomePreset) |
|
{ |
|
//根據preset點, 找到對應的zone info, //通常都是zone[0] |
|
//此時, preset點應該為home點. |
|
//iZoneToPreset = g_stPTZ_Zone_info[iZoneIdx].iZoneToPreset |
|
int iMapZoneIdx = 0; |
|
int ifAddTable = 0; |
|
|
|
//等待追蹤, 收集在zone內 |
|
for (int i = 0; i < iTotalElementSize; i++) |
|
{ |
|
iMapZoneIdx = 0; |
|
ifAddTable = 0; |
|
|
|
pNext1 = posInfo + i; |
|
if ((int)pNext1->confidence >= iFilter_confidence) |
|
{ |
|
for (int k = 0; k < viewChannelData[0].count_zone; k++) |
|
{ |
|
if (ifAddTable == 1) |
|
break; |
|
|
|
if (g_stPTZ_Handle.iIsInPreset == g_stPTZ_Zone_info[k].iZoneToPreset) |
|
{ |
|
iMapZoneIdx = k; |
|
} |
|
else |
|
continue; |
|
|
|
//if (pNext1->IsInsideZone[0] == 1) |
|
if (pNext1->IsInsideZone[iMapZoneIdx] != 0) |
|
{ |
|
//for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) |
|
for (int j = 0; j < g_stPTZ_Zone_info[iMapZoneIdx].iMetadata1_num; j++) |
|
{ |
|
//if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0) |
|
if (strcmp(pNext1->name, g_stPTZ_Zone_info[iMapZoneIdx].sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) |
|
{ |
|
ifAddTable = 1; |
|
|
|
//printf("Step 666 [%d]_ \n", i); |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = (int)pNext1->height; |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); |
|
|
|
//printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); |
|
|
|
if (strlen(pNext1->name)>=1) |
|
{ |
|
snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, |
|
sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); |
|
} |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; |
|
|
|
iCandidateBoxTableIdx++; |
|
//printf("Step 555 [%d]_ count: %d\n", i, iCandidateBoxTableIdx); |
|
break; // box只計算一次, 當出現在多個zone內. |
|
} //add to stPTZCandidateBoxTable |
|
} //cmp each metadata |
|
} //is inside zone |
|
}// scan each zone |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
//該preset點 沒有Map到任何zone |
|
//或 該preset點 不是home點 |
|
//追蹤中, 收集全畫面的 |
|
for (int i = 0; i < iTotalElementSize; i++) |
|
{ |
|
pNext1 = posInfo + i; |
|
|
|
if ((int)pNext1->confidence >= iFilter_confidence) |
|
{ |
|
for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) |
|
{ |
|
if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) |
|
{ |
|
//printf("Step 666 [%d]_ \n", i); |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = pNext1->height; |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); |
|
|
|
//printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); |
|
|
|
if (strlen(pNext1->name)>=1) |
|
{ |
|
snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, |
|
sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); |
|
} |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; |
|
|
|
iCandidateBoxTableIdx++; |
|
|
|
break; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
else // Check if set zone to preset - No |
|
{ |
|
//沒設定任何Map to zone |
|
//參考全畫面object |
|
//依據第一個zone設定的metadata為主 |
|
|
|
int iIfInAnyZone = 0; |
|
|
|
//等待追蹤, 收集在任何zone內 |
|
for (int i = 0; i < iTotalElementSize; i++) |
|
{ |
|
pNext1 = posInfo + i; |
|
if ((int)pNext1->confidence >= iFilter_confidence) |
|
{ |
|
/*iIfInAnyZone = 0; |
|
for (int k = 0; k < MAX_DETECTION_ZONE; k++) |
|
{ |
|
if (pNext1->IsInsideZone[k] != 0) |
|
{ |
|
iIfInAnyZone = 1; |
|
break; |
|
} |
|
}*/ |
|
|
|
//參考全畫面object |
|
iIfInAnyZone = 1; |
|
|
|
//if (pNext1->IsInsideZone[0] == 1) |
|
//if (pNext1->IsInsideZone[0] != 0) |
|
if (iIfInAnyZone == 1) |
|
{ |
|
for (int j = 0; j < g_stPTZ_Handle.iMetadata1_num; j++) |
|
{ |
|
if (strcmp(pNext1->name, g_stPTZ_Handle.sMetaOut1[j]) == 0 && iCandidateBoxTableIdx < MAX_DETECT_OBJECTS) |
|
{ |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x = (int)pNext1->left_x; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y = (int)pNext1->top_y; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].width = (int)pNext1->width; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].height = (int)pNext1->height; |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_x = pNext1->left_x + (pNext1->width / 2); |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].center_y = pNext1->top_y + (pNext1->height / 2); |
|
|
|
//printf("can[%d] x/y = %d, %d \n", iCandidateBoxTableIdx, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].left_x, g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].top_y); |
|
|
|
if (strlen(pNext1->name)>=1) |
|
{ |
|
snprintf(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name, |
|
sizeof(g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].name), "%s", pNext1->name); |
|
} |
|
|
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_tracking_id = pNext1->obj_tracking_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].class_id = pNext1->class_id; |
|
g_stPTZ_Handle.stPTZCandidateBoxTable[iCandidateBoxTableIdx].obj_type = pNext1->obj_type; |
|
|
|
iCandidateBoxTableIdx++; |
|
//printf("Step 555 [%d]_ count: %d\n", i, iCandidateBoxTableIdx); |
|
break; // box只計算一次, 當出現在多個zone內. |
|
} |
|
} |
|
} |
|
} |
|
} |
|
}// Check if set zone to preset |
|
} // Track Pause = 0 |
|
|
|
|
|
g_stPTZ_Handle.iCandidateBoxCount = iCandidateBoxTableIdx; |
|
|
|
//printf("iCandidateBoxCount = %d / %d \n", iCandidateBoxTableIdx, iTotalElementSize); |
|
|
|
//g_stPTZ_Handle.tUpdateCandidateTableTime = time(0); |
|
|
|
pthread_mutex_unlock(&mutex_update_candidate); |
|
} |
|
#endif |
|
|
|
|
|
void PTZUpdateTrackingInfo(detection_pos *posInfo, int iTotalElementSize, int iResW, int iResH) |
|
{ |
|
//g_stPTZ_Handle.iUpdateOutsideBox = 0; |
|
|
|
//判斷有無lock obj的時間不可在這個function做 |
|
//這個function只有當有辨識到obj時, 才會進來 |
|
|
|
#if 0 |
|
if (g_stPTZ_Handle.iEnable_tracking != 1 |
|
|| !IsPTZinAutoTracking() |
|
) |
|
{ |
|
return; |
|
} |
|
#endif |
|
|
|
//This hardcold for TEST |
|
//g_stPTZ_Handle.iTracking_mode = 3; |
|
|
|
//Check tracking MODE |
|
//int iTrackingMODE = g_stPTZ_Handle.iTracking_mode; |
|
|
|
//int iLockBoxIdxRet = -1; |
|
|
|
//Tracking MODE |
|
//1: First in First out |
|
//2: Bigger first |
|
//3: All |
|
|
|
//if (iTrackingMODE == 1 || iTrackingMODE == 2) |
|
//{ |
|
if (IsTracking() == 1) |
|
{ |
|
GetCandidateBoxTable(posInfo, iTotalElementSize); |
|
} |
|
|
|
//iLockBoxIdxRet = GetSingleLockTrackingBox(iResW, iResH); |
|
|
|
//int ret = GetOutsideLockBox(iResW, iResH); |
|
//g_stPTZ_Handle.iUpdateOutsideBox = 1; |
|
//} |
|
//else if (iTrackingMODE == 3) |
|
//{ |
|
//Get Outside Box |
|
// int ret = GetOutsideBox(posInfo, iTotalElementSize, iResW, iResH); |
|
//g_stPTZ_Handle.iUpdateOutsideBox = 1; |
|
//} |
|
} |
|
|
|
int IsPTZEnableAlarm(int iInZoneToPreset) |
|
{ |
|
int ret = 0; |
|
|
|
if (IsPTZ() == 1) |
|
{ |
|
if (IsPTZinPreset() != 0) |
|
{ |
|
//printf("***** IsPTZinPreset() = %d \n", IsPTZinPreset()); |
|
if (IsPTZinPreset() == iInZoneToPreset) |
|
ret = 1; |
|
else |
|
ret = 0; //not trigger |
|
} |
|
else |
|
{ |
|
ret = 0; //not trigger |
|
} |
|
} |
|
else |
|
{ |
|
ret = 1; |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
//void PerformDetection() |
|
//{ |
|
// g_stPTZ_Handle.iIs_enable_alarm = 1; |
|
//} |
|
|
|
|
|
/* |
|
void *ptz_do_zoom_thread(char *url) |
|
{ |
|
pthread_detach(pthread_self()); |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
char outputData[1024] = { 0 }; |
|
|
|
|
|
//sprintf(ptz_curl_url, "/control?airzoom=%d", 7); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", 7); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
usSleep(1000000); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
|
|
//exit thread |
|
pthread_exit(NULL); |
|
} |
|
*/ |
|
|
|
void *ptz_do_zoom_thread(void *ptr) |
|
{ |
|
pthread_detach(pthread_self()); |
|
setPthreadName("ptz_zoom"); |
|
char outputData[1024] = { 0 }; |
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
int iZoom_number = 0; |
|
int iZoom_value = 0; |
|
g_stPTZ_Handle.iZoomRunning = 0; |
|
g_stPTZ_Handle.iZoomFreqMod = 4; |
|
|
|
int iObjMoveDirection_y = 0; |
|
int iObjMoveDirection_x = 0; |
|
|
|
int iPtzTiltZoomOut = 0; |
|
|
|
while (g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1) |
|
{ |
|
if (g_stPTZ_Handle.iIsGoingHome == 1) |
|
{ |
|
usSleep(1000000); |
|
continue; |
|
} |
|
|
|
iPtzTiltZoomOut = 0; |
|
|
|
#if 1 |
|
///Check Tilt |
|
if (g_stPTZ_Handle.iTiltABS <= 135 |
|
&& g_stPTZ_Handle.iTiltABS >= 45 |
|
&& (strcmp(g_stPTZ_Handle.stPTZLockTrackingBox.name, "person") == 0)) |
|
{ |
|
iPtzTiltZoomOut = 1; |
|
} |
|
//else if (g_stPTZ_Handle.iTiltABS <= 160 |
|
// && g_stPTZ_Handle.iTiltABS >= 20) |
|
//{ |
|
// |
|
//} |
|
#endif |
|
|
|
//if (g_stPTZ_Handle.) |
|
// g_stPTZ_Handle.iZoomRunning = 0; |
|
//if (g_stPTZ_Handle.iPauseTrackFlag) |
|
// g_stPTZ_Handle.iZoomRunning = 0; |
|
|
|
//printf("Zoom chlockid = %d \n", g_stPTZ_Handle.iLockBoxIdx); |
|
if (iPtzTiltZoomOut == 1) |
|
{ |
|
if (g_stPTZ_Handle.iZoomRunning == 0) |
|
{ |
|
if (g_stPTZ_Handle.iZoomFreqCount >= 0 |
|
&& g_stPTZ_Handle.iZoomFreqCount % 4 == 0) |
|
{ |
|
iZoom_value = 7; |
|
|
|
//Zoom out |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"ptz do zoom thread 1"); |
|
|
|
g_stPTZ_Handle.iZoomFreqCount = 1; |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount++; |
|
} |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iLockBoxIdx != -1 |
|
&& g_stPTZ_Handle.iLockBoxIdx != PTZ_MISS_OBJ_MAGIC_FLAG |
|
&& g_stPTZ_Handle.iTracking_fov_max > 0 |
|
&& g_stPTZ_Handle.iIsGetLockTrackingBox > 0 |
|
&& g_stPTZ_Handle.iCandidateBoxCount > 0 |
|
&& iPtzTiltZoomOut == 0) |
|
{ |
|
iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.iTracking_fov_max); |
|
|
|
if (g_stPTZ_Handle.iRecordOldOutsideBoxCount > 2) |
|
{ |
|
iObjMoveDirection_y = g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 1].center_y - g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 2].center_y; |
|
iObjMoveDirection_x = g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 1].center_x - g_stPTZ_Handle.stPTZRecordOldOutsideBox[g_stPTZ_Handle.iRecordOldOutsideBoxCount - 2].center_x; |
|
} |
|
|
|
if (iObjMoveDirection_y > (g_stPTZ_Handle.iIMG_source_h / 20) |
|
|| iObjMoveDirection_x > (g_stPTZ_Handle.iIMG_source_w / 20)) |
|
{ |
|
if (g_stPTZ_Handle.iZoomRunning == 0) |
|
{ |
|
iZoom_value = 7; |
|
|
|
if (g_stPTZ_Handle.iZoomFreqCount >= 0 |
|
&& g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount = 1; |
|
|
|
//Zoom out |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 2"); |
|
|
|
//usSleep(500000); |
|
|
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
// usSleep(300000); |
|
|
|
// sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
// send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount++; |
|
} |
|
|
|
//g_stPTZ_Handle.iZoomRunning = 1; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iZoomRunning == 0 && iZoom_number != 0) |
|
{ |
|
if (iZoom_number < (g_stPTZ_Handle.iTracking_fov_max - 5)) |
|
{ |
|
iZoom_value = -3; |
|
|
|
if (g_stPTZ_Handle.iZoomFreqCount >= 0 |
|
&& g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount = 1; |
|
//Zoom in |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 3"); |
|
|
|
//usSleep(500000); |
|
|
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
// usSleep(300000); |
|
|
|
// sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
// send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount++; |
|
} |
|
|
|
//g_stPTZ_Handle.iZoomRunning = 1; |
|
} |
|
else if (iZoom_number > (g_stPTZ_Handle.iTracking_fov_max + 5)) |
|
{ |
|
iZoom_value = 3; |
|
|
|
if (g_stPTZ_Handle.iZoomFreqCount >= 0 |
|
&& g_stPTZ_Handle.iZoomFreqCount % g_stPTZ_Handle.iZoomFreqMod == 0) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount = 1; |
|
//Zoom out |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_value); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do zoom thread 4"); |
|
|
|
//usSleep(500000); |
|
|
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
// usSleep(300000); |
|
|
|
// sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
// send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iZoomFreqCount++; |
|
} |
|
//g_stPTZ_Handle.iZoomRunning = 1; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iZoomRunning == 1) |
|
{ |
|
if ((iZoom_number >= 58 && iZoom_number <= 62) |
|
|| iZoom_number == 0) |
|
{ |
|
//Stop |
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
//usSleep(300000); |
|
|
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
g_stPTZ_Handle.iZoomRunning = 0; |
|
} |
|
} |
|
} |
|
else if ((g_stPTZ_Handle.iLockBoxIdx == -1) |
|
//|| (g_stPTZ_Handle.iPauseTrackFlag == 1) |
|
) |
|
{ |
|
//Stop |
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
g_stPTZ_Handle.iZoomRunning = 0; |
|
} |
|
|
|
usSleep(300000); |
|
//printf("[%d] Zoom num = %d \n", g_stPTZ_Handle.iZoomRunning, iZoom_number); |
|
} |
|
|
|
pthread_exit(NULL); |
|
} |
|
|
|
int AdaptedGoCenterSpeed(int iSpeedBase, int obj_class_id) |
|
{ |
|
int iAdaptedSpeed = iSpeedBase; |
|
|
|
if (g_stPTZ_Handle.iZoomABS <= 10) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqMod = 4; |
|
//FOV大, 速度要快 |
|
//FOV小, 不可太快 |
|
if (g_stPTZ_Handle.iLockObjFOV <= 20) |
|
{ |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 20 && g_stPTZ_Handle.iLockObjFOV <= 40) |
|
{ |
|
iAdaptedSpeed += 3; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 40) |
|
{ |
|
iAdaptedSpeed += 4; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS > 10 && g_stPTZ_Handle.iZoomABS <= 15) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqMod = 6; |
|
|
|
//根據中心點距離與FOV, 適度加快 |
|
if (g_stPTZ_Handle.iLockObjFOV <= 15) |
|
{ |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 15 && g_stPTZ_Handle.iLockObjFOV <= 30) |
|
{ |
|
iAdaptedSpeed += 2; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 30) |
|
{ |
|
iAdaptedSpeed += 1; |
|
} |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS > 15) |
|
{ |
|
g_stPTZ_Handle.iZoomFreqMod = 8; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
|
|
//g_stPTZ_Handle.iLockBoxArea_min = 35; |
|
//g_stPTZ_Handle.iLockBoxArea_max = 65; |
|
|
|
//不考慮FOV, |
|
//速度需放慢, |
|
if (g_stPTZ_Handle.iLockObjFOV <= 10) //OBJ過小, 暫時不改變速度 |
|
{ |
|
iAdaptedSpeed = 3; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 15 && g_stPTZ_Handle.iLockObjFOV <= 50) |
|
{ |
|
iAdaptedSpeed = 3; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV > 50) |
|
{ |
|
iAdaptedSpeed = 3; |
|
} |
|
} |
|
|
|
|
|
if (g_stPTZ_Handle.iTiltABS >= 30 && g_stPTZ_Handle.iTiltABS <= 120) |
|
{ |
|
iAdaptedSpeed += 3; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
} |
|
else if (g_stPTZ_Handle.iTiltABS >= 45 && g_stPTZ_Handle.iTiltABS <= 135) |
|
{ |
|
iAdaptedSpeed += 10; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 1; |
|
} |
|
|
|
if (iAdaptedSpeed <= 0) |
|
iAdaptedSpeed = 1; |
|
|
|
//printf("classid = %d \n", obj_class_id); |
|
|
|
if (obj_class_id == 0) |
|
{ |
|
|
|
iAdaptedSpeed = 25; |
|
} |
|
|
|
//printf("iAdaptedSpeed = %d \n", iAdaptedSpeed); |
|
|
|
return iAdaptedSpeed; |
|
} |
|
|
|
void *ptz_do_tracking_thread(void *ptr) |
|
{ |
|
pthread_detach(pthread_self()); |
|
setPthreadName("ptz_track"); |
|
char outputData[1024] = { 0 }; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[1024] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
g_stPTZ_Handle.iCandidateBoxCount = 0; |
|
|
|
g_stPTZ_Handle.stPTZOutsideBox.center_x = 0; |
|
g_stPTZ_Handle.stPTZOutsideBox.center_y = 0; |
|
g_stPTZ_Handle.stPTZOutsideBox.width = -1; |
|
g_stPTZ_Handle.stPTZOutsideBox.height = -1; |
|
//g_stPTZ_Handle.dwMoveAngel = 0; |
|
|
|
//g_stPTZ_Handle.iTimer_send_count = 0; |
|
//g_stPTZ_Handle.iIs_enable_alarm = 0; |
|
|
|
g_stPTZ_Handle.iRecordOldOutsideBoxCount = 0; |
|
|
|
|
|
//int iDisPercent_W = 50, iDisPercent_H = 50; |
|
int iPercentage_W = 50, iPercentage_H = 50; |
|
//int iZoomActiveFlag = 0; |
|
//int iGoCenterFlag = 0; |
|
//int iZoomCheckTimerCount = 0; |
|
//int iZoomStopPerMSEC = 100; |
|
//int iZoomStopTimerCount = 0; |
|
//int iZoomStopTimerDefineSet = 20; //2 sec |
|
int iGoCenterSpeed = 2; |
|
|
|
time_t tCurrentTrackingTime = time(0); |
|
time_t tCheckResumeTime = time(0); |
|
time_t tLoseTrackingTime = time(0); |
|
time_t tOldTrackingTime = time(0); |
|
//time_t tCurrentZoomTime = time(0); |
|
//int tDiffTrackingSecond = 0; |
|
g_stPTZ_Handle.tDiffTrackingSecond = 0; |
|
//int tDiffZoomSecond = 0; |
|
//double dwNotUpdateLockBoxSecs = 0.0; |
|
|
|
//g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
g_stPTZ_Handle.iPauseTrackFlag = 0; |
|
|
|
//g_stPTZ_Handle.iLockBoxArea_min = PTZ_CENTER_AREA_X2_MIN; |
|
//g_stPTZ_Handle.iLockBoxArea_max = PTZ_CENTER_AREA_X2_MAX; |
|
|
|
//double dwDiffUpdateCandiDateTableSecs = 0.0; |
|
//g_stPTZ_Handle.tUpdateCandidateTableTime = time(0); //Init |
|
|
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
//g_stPTZ_Handle.tChangAutoPanTime = time(0); |
|
//g_stPTZ_Handle.tOperatZoomTime = time(0); |
|
|
|
int iHomePos = 0; |
|
int iRunningFlag = 0; |
|
|
|
//int iMoveFlag = 0; |
|
//int iMoveCounter = 0; |
|
|
|
int iLockBoxIdxRet = -1; |
|
|
|
int iIfGoCenter_ret = 0; |
|
|
|
//init store of ptz home preset pos |
|
g_stPTZ_Handle.iHomePanABS = -1; |
|
g_stPTZ_Handle.iHomeTiltABS = -1; |
|
g_stPTZ_Handle.iHomeZoomABS = -1; |
|
|
|
|
|
if (IsPTZatHomePos() == 0 |
|
&& g_stPTZ_Handle.iZoneToPresetAnyOne == 1 |
|
&& IsPTZinAutoTracking() |
|
&& g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1 |
|
) |
|
{ |
|
g_stPTZ_Handle.iIsGoingHome = 1; |
|
iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
//usSleep(GO_HOME_SLEEP*1000); |
|
} |
|
|
|
usSleep(GO_HOME_SLEEP*1000); |
|
|
|
//Store Home preset x, y, zoom pos |
|
StoreHomePresetPos(); |
|
//UpdatePTZCurPos(); |
|
|
|
usSleep(GO_HOME_SLEEP*1000); |
|
|
|
g_stPTZ_Handle.iIsGoingHome = 0; |
|
|
|
//PTZ zoom |
|
if (pthread_create(&ptz_zoom_thread, 0, ptz_do_zoom_thread, NULL)) |
|
printf("\nPTZ zoom thread creation failed\n"); |
|
|
|
int iOldPresetPoint = 0; |
|
int iCurrentPresetPoint = 0; |
|
|
|
while (g_stPTZ_Handle.iRunPTZTrackingThread_flag == 1) |
|
{ |
|
if (g_stPTZ_Handle.iIsGoingHome == 1) |
|
{ |
|
usSleep(1000000); |
|
continue; |
|
} |
|
|
|
//Test cgi freq |
|
#if 0 |
|
if (1) |
|
{ |
|
iMoveCounter++; |
|
|
|
if (iMoveCounter >= 20) |
|
{ |
|
if (iMoveFlag == 0) |
|
{ |
|
iMoveFlag = 1; |
|
//printf("1111111111 \n"); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 55, 55, 2); |
|
//sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
} |
|
else if (iMoveFlag == 1) |
|
{ |
|
iMoveFlag = 0; |
|
//printf("2222222222222 \n"); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 55, 45, 2); |
|
//sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
} |
|
|
|
iMoveCounter = 0; |
|
} |
|
|
|
usSleep(10000); |
|
} |
|
#endif |
|
|
|
//檢查AutoPan & AutoTracking flag |
|
if (!IsPTZinAutoTracking()) |
|
{ |
|
usSleep(1000000); |
|
continue; |
|
} |
|
|
|
iLockBoxIdxRet = GetSingleLockTrackingBox(999, 999); //1: found lock, -1: not lock |
|
|
|
|
|
{ |
|
//char msg_temp[512] = { 0 }; |
|
//sprintf(msg_temp, "iLockBoxIdxRet:%d", iLockBoxIdxRet); |
|
//write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); |
|
} |
|
//g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; |
|
|
|
iPercentage_W = 49; |
|
iPercentage_H = 49; |
|
|
|
if (iLockBoxIdxRet < 0) |
|
{ |
|
//write_to_logs_html("3-1", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); |
|
g_stPTZ_Handle.iLockObjFOV = 0; |
|
|
|
g_stPTZ_Handle.iLoseLockObjCount++; |
|
if (g_stPTZ_Handle.iLoseLockObjCount > PTZ_LOSE_OBJ_LIMIT) |
|
{ |
|
//write_to_logs_html("3-1-1", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); |
|
g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; |
|
} |
|
else |
|
{ |
|
//write_to_logs_html("3-1-2", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); |
|
tOldTrackingTime = time(0); |
|
tCurrentTrackingTime = time(0); |
|
//g_stPTZ_Handle.iLockBoxIdx = -1; |
|
continue; |
|
} |
|
#if 0 |
|
//檢查Candidate Table 更新時間 |
|
//比較tCurrentTrackingTime 與 g_stPTZ_Handle.tUpdateCandidateTableTime |
|
tCurrentTrackingTime = time(0); |
|
|
|
int dwNotUpdateLockBoxSecs = difftime(tCurrentTrackingTime, g_stPTZ_Handle.tUpdateLockBoxTime); |
|
|
|
if (dwNotUpdateLockBoxSecs > g_stPTZ_Handle.iTracking_resume_dwell) |
|
{ |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
|
|
snprintf(g_stPTZ_Handle.stPTZLockTrackingBox.name, |
|
sizeof(g_stPTZ_Handle.stPTZLockTrackingBox.name), "%s", "\0"); |
|
|
|
g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id = -1; |
|
|
|
if (IsPTZatHomePos() == 0 |
|
|| IsPTZinPreset() != GetHomePreset() |
|
) |
|
{ |
|
int iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
usSleep(3000000); |
|
} |
|
|
|
g_stPTZ_Handle.tUpdateLockBoxTime = time(0); |
|
} |
|
|
|
usSleep(300000); |
|
continue; |
|
#endif |
|
} |
|
else if (iLockBoxIdxRet == PTZ_MISS_OBJ_MAGIC_FLAG) |
|
{ |
|
//write_to_logs_html("3-2", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); |
|
g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; |
|
//針對Miss lock box容許狀況 |
|
g_stPTZ_Handle.iLoseLockObjCount++; //if iLoseLockObjCount < 10 |
|
|
|
//tOldTrackingTime = time(0); |
|
tCurrentTrackingTime = time(0); |
|
|
|
//g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
//if (g_stPTZ_Handle.iGoCenterFreqCount >= g_stPTZ_Handle.iGoCenterFreqFrame) |
|
//{ |
|
// g_stPTZ_Handle.iGoCenterFreqCount = 0; |
|
|
|
// //Center |
|
// sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", 50, 50, 1); |
|
// //sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
// //g_stPTZ_Handle.tOperatTime = time(0); |
|
// send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
//} |
|
//else |
|
//{ |
|
// g_stPTZ_Handle.iGoCenterFreqCount++; |
|
//} |
|
|
|
} |
|
else if (iLockBoxIdxRet > -1) |
|
{ |
|
//write_to_logs_html("3-3", "AAAAAAAAAAAAA", "DEBUG", SystemSetting.enable_system_logs); |
|
g_stPTZ_Handle.iLoseLockObjCount = 0; |
|
g_stPTZ_Handle.iLockBoxIdx = iLockBoxIdxRet; |
|
|
|
/*int ret = */GetOutsideLockBox(999, 999); |
|
|
|
GetLockObjFOV(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h); |
|
|
|
//ret = OutsideBoxChange(); |
|
|
|
//IF BACK TO HOMEPOS, sleep 2 sec. |
|
|
|
/*if (g_stPTZ_Handle.iIsStayHomePos == 0 |
|
&& IsPTZatHomePos() == 1) |
|
{ |
|
g_stPTZ_Handle.iIsStayHomePos = IsPTZatHomePos(); |
|
usSleep(1000000); |
|
}*/ |
|
|
|
|
|
|
|
|
|
//Check: If go home pos. after 6 second |
|
//tCurrentTrackingTime = time(0); |
|
//tDiffTrackingSecond = 0.0; |
|
//tDiffTrackingSecond = difftime(tCurrentTrackingTime, g_stPTZ_Handle.tOperatTime); |
|
|
|
//printf("tDiffTrackingSecond = %f \n", tDiffTrackingSecond); |
|
|
|
//if (tDiffTrackingSecond >= 5) |
|
//{ |
|
// //Go Home and wait ipcam recovery function turn on "autopen" & "autotracking" |
|
// GoPreset(iHomePos); |
|
// g_stPTZ_Handle.tOperatTime = time(0); |
|
//} |
|
|
|
|
|
iIfGoCenter_ret = IfGoCenter(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h); |
|
//printf("ck ret = %d \n", iIfGoCenter_ret); |
|
|
|
|
|
|
|
//printf("%d / %d \n", g_stPTZ_Handle.iTimer_send_count, g_stPTZ_Handle.iPTZ_sensitivity); |
|
|
|
//int iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.g_ptz_zoom_iou); |
|
|
|
//int iZoom_number = IfDoZoom(g_stPTZ_Handle.iIMG_source_w, g_stPTZ_Handle.iIMG_source_h, g_stPTZ_Handle.iTracking_fov_max); |
|
//int iZoom_number = 0; |
|
|
|
//g_stPTZ_Handle.iPTZ_sensitivity = 0; |
|
|
|
#if 0 |
|
//if (g_stPTZ_Handle.iTimer_send_count < g_stPTZ_Handle.iPTZ_sensitivity) |
|
if (1) |
|
{ |
|
g_stPTZ_Handle.iTimer_send_count++; |
|
} |
|
else |
|
#endif |
|
if (1) |
|
{ |
|
//g_stPTZ_Handle.iTimer_send_count = 0; |
|
|
|
if (iRunningFlag > 99999) |
|
iRunningFlag = 0; |
|
else |
|
iRunningFlag++; |
|
g_stPTZ_Handle.iThreadRunningFlag = iRunningFlag; |
|
|
|
//if (g_stPTZ_Handle.iTracking_mode == 3) |
|
// g_stPTZ_Handle.iCandidateBoxCount = 1; |
|
|
|
if (iIfGoCenter_ret == 1 |
|
/*&& g_stPTZ_Handle.iCandidateBoxCount != 0*/ |
|
) |
|
{ |
|
/* |
|
if (g_stPTZ_Handle.iMoveSpeed_x >= 4 |
|
|| g_stPTZ_Handle.iMoveSpeed_x <= -4 |
|
|| g_stPTZ_Handle.iMoveSpeed_y >= 4 |
|
|| g_stPTZ_Handle.iMoveSpeed_y <= -4)*/ |
|
if (1) |
|
{ |
|
#if 1 |
|
iPercentage_W = ((g_stPTZ_Handle.stPTZOutsideBox.center_x * 1000 / (g_stPTZ_Handle.iIMG_source_w)) / 10); |
|
|
|
iPercentage_H = ((g_stPTZ_Handle.stPTZOutsideBox.center_y * 1000 / (g_stPTZ_Handle.iIMG_source_h)) / 10); |
|
|
|
///Lock box distance |
|
//int iDisPercent_W = 50, iDisPercent_H = 50; |
|
|
|
//iDisPercent_W = abs(g_stPTZ_Handle.stPTZOutsideBox.center_x - ((g_stPTZ_Handle.iIMG_source_w) / 2)); |
|
//iDisPercent_H = abs(g_stPTZ_Handle.stPTZOutsideBox.center_y - ((g_stPTZ_Handle.iIMG_source_h) / 2)); |
|
|
|
//iDisPercent_W = ((iDisPercent_W * 1000 / ((g_stPTZ_Handle.iIMG_source_w) / 2)) / 10); |
|
//iDisPercent_H = ((iDisPercent_H * 1000 / ((g_stPTZ_Handle.iIMG_source_h) / 2)) / 10); |
|
|
|
//printf("percent W, H = %d, %d \n", iDisPercent_W, iDisPercent_H); |
|
|
|
//dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); |
|
|
|
|
|
///Lock box iou |
|
/* |
|
PTZ_VIRTUAL_BOX Lock_area_box; |
|
|
|
int iLockBox_left_x, iLockBox_right_x; |
|
iLockBox_left_x = g_stPTZ_Handle.iIMG_source_w * PTZ_CENTER_AREA_X2_MIN / 100; |
|
iLockBox_right_x = g_stPTZ_Handle.iIMG_source_w * PTZ_CENTER_AREA_X2_MAX / 100; |
|
|
|
Lock_area_box.left_x = iLockBox_left_x; |
|
Lock_area_box.right_x = iLockBox_right_x; |
|
Lock_area_box.width = iLockBox_right_x - iLockBox_left_x; |
|
|
|
int iLockBox_top_y, iLockBox_bottom_y; |
|
iLockBox_top_y = g_stPTZ_Handle.iIMG_source_h * PTZ_CENTER_AREA_X2_MIN / 100; |
|
iLockBox_bottom_y = g_stPTZ_Handle.iIMG_source_h * PTZ_CENTER_AREA_X2_MAX / 100; |
|
|
|
Lock_area_box.top_y = iLockBox_top_y; |
|
Lock_area_box.bottom_y = iLockBox_bottom_y; |
|
Lock_area_box.height = iLockBox_bottom_y - iLockBox_top_y; |
|
|
|
printf("lockbox: [%d, %d], [%d, %d] \n", iLockBox_left_x, iLockBox_top_y, Lock_area_box.width, Lock_area_box.height); |
|
//printf("outsidebox: [%d, %d], [%d, %d] \n", g_stPTZ_Handle.stPTZOutsideBox.left_x, g_stPTZ_Handle.stPTZOutsideBox.top_y, g_stPTZ_Handle.stPTZOutsideBox.right_x, g_stPTZ_Handle.stPTZOutsideBox.bottom_y); |
|
|
|
float fIOU_tmp; |
|
fIOU_tmp = object_iou(&g_stPTZ_Handle.stPTZOutsideBox, &Lock_area_box); |
|
*/ |
|
|
|
|
|
|
|
#if 1 ///Define MOVE SPEED |
|
switch (g_stPTZ_Handle.iPTZ_speed) |
|
{ |
|
case 0: |
|
iGoCenterSpeed = 3; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 1: |
|
iGoCenterSpeed = 2; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
//12 frame |
|
break; |
|
case 2: |
|
iGoCenterSpeed = 2; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
//10 frame |
|
break; |
|
case 3: |
|
iGoCenterSpeed = 2; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
//8 frame |
|
break; |
|
case 4: |
|
iGoCenterSpeed = 6; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
//6 frame |
|
break; |
|
case 5: |
|
iGoCenterSpeed = 8; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
//4 frame |
|
break; |
|
case 6: |
|
iGoCenterSpeed = 2; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 7: |
|
iGoCenterSpeed = 3; |
|
|
|
//if (g_stPTZ_Handle.iLockObjFOV ) |
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
break; |
|
case 8: |
|
iGoCenterSpeed = 4; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 9: |
|
iGoCenterSpeed = 5; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 3; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 10: |
|
iGoCenterSpeed = 6; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 11: |
|
iGoCenterSpeed = 7; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
case 12: |
|
iGoCenterSpeed = 8; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
default: |
|
iGoCenterSpeed = 3; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
|
|
iGoCenterSpeed = AdaptedGoCenterSpeed(iGoCenterSpeed, g_stPTZ_Handle.stPTZOutsideBox.class_id); |
|
|
|
break; |
|
} |
|
|
|
#endif |
|
#if 0 ///Define MOVE SPEED |
|
if (g_stPTZ_Handle.iLockObjFOV != 0) |
|
{ |
|
if (g_stPTZ_Handle.iLockObjFOV > 50) |
|
{ |
|
iGoCenterSpeed = 2; |
|
} |
|
else if (g_stPTZ_Handle.iLockObjFOV < 25) |
|
{ |
|
iGoCenterSpeed = 2; |
|
} |
|
else |
|
{ |
|
iGoCenterSpeed = 2; |
|
} |
|
} |
|
else |
|
iGoCenterSpeed = 2; |
|
#endif |
|
|
|
#if 0 |
|
int iDoubleGoCenterFlag = 0; |
|
|
|
if (g_stPTZ_Handle.iZoomABS >= 1 && g_stPTZ_Handle.iZoomABS <= 4) |
|
{ |
|
iGoCenterSpeed = 4; |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS >= 5 && g_stPTZ_Handle.iZoomABS <= 7) |
|
{ |
|
iGoCenterSpeed = 4; |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS >= 8 && g_stPTZ_Handle.iZoomABS <= 10) |
|
{ |
|
iGoCenterSpeed = 4; |
|
} |
|
else if (g_stPTZ_Handle.iZoomABS >= 11) |
|
{ |
|
iGoCenterSpeed = 2; |
|
} |
|
else |
|
iGoCenterSpeed = 5; |
|
#endif |
|
|
|
|
|
|
|
//printf("CenX / CenY: %d, %d \n", g_stPTZ_Handle.stPTZOutsideBox.center_x, g_stPTZ_Handle.stPTZOutsideBox.center_y); |
|
//printf("PerW / PerH: %d, %d \n", iPercentage_W, iPercentage_H); |
|
|
|
#if 0 |
|
if (g_stPTZ_Handle.iTiltABS <= 140 |
|
&& g_stPTZ_Handle.iTiltABS >= 20) |
|
{ |
|
iGoCenterSpeed = 255; |
|
//iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 2); |
|
if (iPercentage_W >= 50) |
|
iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 3); |
|
else if (iPercentage_W < 50) |
|
iPercentage_W = iPercentage_W - ((iPercentage_W) / 3); |
|
|
|
iPercentage_H = iPercentage_H + ((100 - iPercentage_H) / 3); |
|
} |
|
else if (g_stPTZ_Handle.iTiltABS <= 160 |
|
&& g_stPTZ_Handle.iTiltABS >= 20) |
|
{ |
|
iGoCenterSpeed = 125; |
|
//iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 2); |
|
if (iPercentage_W >= 50) |
|
iPercentage_W = iPercentage_W + ((100 - iPercentage_W) / 3); |
|
else if (iPercentage_W < 50) |
|
iPercentage_W = iPercentage_W - ((iPercentage_W) / 3); |
|
|
|
iPercentage_H = iPercentage_H + ((100 - iPercentage_H) / 3); |
|
} |
|
#endif |
|
|
|
if (iPercentage_W == 50) |
|
iPercentage_W = 49; |
|
|
|
if (iPercentage_H == 50) |
|
iPercentage_H = 49; |
|
|
|
//if engine type = AISHIP |
|
//g_stPTZ_Handle.iGoCenterFreqCount = g_stPTZ_Handle.iGoCenterFreqFrame |
|
//iGoCenterSpeed = 1 |
|
if (g_stPTZ_Handle.iPTZ_speed == 1) |
|
{ |
|
iGoCenterSpeed = 1; |
|
g_stPTZ_Handle.iGoCenterFreqFrame = 2; |
|
} |
|
|
|
|
|
if (g_stPTZ_Handle.iGoCenterFreqCount >= g_stPTZ_Handle.iGoCenterFreqFrame) |
|
{ |
|
g_stPTZ_Handle.iGoCenterFreqCount = 1; |
|
|
|
//Center |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
//sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"ptz do tracking thread 1"); |
|
} |
|
else |
|
{ |
|
g_stPTZ_Handle.iGoCenterFreqCount++; |
|
} |
|
|
|
|
|
//printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx GO Center \n"); |
|
|
|
#if 0 |
|
//會造成由右往左的交錯速度太快 |
|
//if (iDoubleGoCenterFlag) |
|
{ |
|
//iPercentage_H = (int)((iPercentage_H + 50) / 2); |
|
//iPercentage_W = (int)((iPercentage_W + 50) / 2); |
|
|
|
if (iPercentage_H <= 10) |
|
iPercentage_H = (int)(50 - ((50 - iPercentage_H) / 3)); |
|
|
|
if (iPercentage_H >= 90) |
|
iPercentage_H = (int)(50 + ((iPercentage_H - 50) / 3)); |
|
|
|
if (iPercentage_W <= 10) |
|
iPercentage_W = (int)(50 - ((50 - iPercentage_W) / 3)); |
|
|
|
if (iPercentage_W >= 90) |
|
iPercentage_W = (int)(50 + ((iPercentage_W - 50) / 3)); |
|
|
|
|
|
//iGoCenterSpeed = 3; |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
//sprintf(ptz_curl_url, "/ptzcenter?stream=0&startx=%d&starty=%d&speed=%d", iPercentage_W, iPercentage_H, iGoCenterSpeed); |
|
usSleep(150000); |
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "ptz do tracking thread 2"); |
|
} |
|
#endif |
|
#endif |
|
} |
|
else |
|
{ |
|
#if 0 |
|
g_stPTZ_Handle.iMoveSpeed_y = (g_stPTZ_Handle.iMoveSpeed_y * 2) % 8; |
|
g_stPTZ_Handle.iMoveSpeed_x = (g_stPTZ_Handle.iMoveSpeed_x * 2) % 8; |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?camid=1&rtilt=%d&rpan=%d", g_stPTZ_Handle.iMoveSpeed_y, g_stPTZ_Handle.iMoveSpeed_x); |
|
//sprintf(ptz_curl_url, "/control?camid=1&rtilt=%d&rpan=%d", g_stPTZ_Handle.iMoveSpeed_y, g_stPTZ_Handle.iMoveSpeed_x); |
|
|
|
//Set operat time stamp |
|
g_stPTZ_Handle.tOperatTime = time(0); |
|
|
|
send_request(ptz_ip ,ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
usSleep(200000); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); |
|
//sprintf(ptz_curl_url, "/control?stop=1"); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
#endif |
|
} |
|
//if (iZoom_number < 0 || iZoom_number > 0) |
|
//{ |
|
// usSleep(120000); |
|
//} |
|
} |
|
|
|
/* |
|
if (g_stPTZ_Handle.iMoveSpeed_x != 0 |
|
&& g_stPTZ_Handle.iMoveSpeed_y != 0 |
|
&& (g_stPTZ_Handle.iMoveSpeed_y <= 2 || g_stPTZ_Handle.iMoveSpeed_y >= -2) |
|
&& (g_stPTZ_Handle.iMoveSpeed_x <= 2 || g_stPTZ_Handle.iMoveSpeed_x >= -2) |
|
&& (iZoom_number < 0 || iZoom_number > 0)) |
|
*/ |
|
//if (iGoCenterSpeed == 2 |
|
// && (iZoom_number < 0 || iZoom_number > 0)) |
|
|
|
//if (g_stPTZ_Handle.iTracking_mode == 3) |
|
// g_stPTZ_Handle.iCandidateBoxCount = 1; |
|
#if 0 |
|
if ((iPercentage_H >= 20 && iPercentage_H <= 80) |
|
&& (iPercentage_W >= 20 && iPercentage_W <= 80) |
|
/*&& (g_stPTZ_Handle.iCandidateBoxCount != 0)*/ |
|
) |
|
{ |
|
|
|
if (iZoom_number < 0 || iZoom_number > 0) |
|
{ |
|
//tCurrentZoomTime = time(0); |
|
//tDiffZoomSecond = difftime(tCurrentZoomTime, g_stPTZ_Handle.tOperatZoomTime); |
|
|
|
//if (tDiffZoomSecond >= 2) |
|
//{ |
|
//printf("=======================================> do zoom %d \n", iZoom_number); |
|
|
|
#if 0 |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", iZoom_number); |
|
//sprintf(ptz_curl_url, "/control?airzoom=%d", iZoom_number); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
//g_stPTZ_Handle.tOperatTime = time(0); |
|
//g_stPTZ_Handle.tOperatZoomTime = time(0); |
|
|
|
usSleep(200000); |
|
|
|
//printf("=======================================> do stop\n"); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
#endif |
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//sprintf(ptz_curl_url, "/control?stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
//} |
|
} |
|
|
|
} |
|
else if(g_stPTZ_Handle.iZoomABS > 6) |
|
{ |
|
#if 0 |
|
g_stPTZ_Handle.tOperatTime = time(0); |
|
g_stPTZ_Handle.tOperatZoomTime = time(0); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?airzoom=%d", 7); |
|
//sprintf(ptz_curl_url, "/control?airzoom=%d", iZoom_number); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
usSleep(200000); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
|
|
//usSleep(100000); |
|
|
|
//sprintf(ptz_curl_url, "http://127.0.0.1/control?zoom_stop=1"); |
|
//send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData); |
|
#endif |
|
} |
|
#endif |
|
} |
|
|
|
}// if(iFindLockObj) |
|
else |
|
{ |
|
g_stPTZ_Handle.iLockBoxIdx = -1; |
|
g_stPTZ_Handle.iLockObjFOV = 0; |
|
iLockBoxIdxRet = -1; |
|
}// if(iFindLockObj) |
|
|
|
#if 1 |
|
g_stPTZ_Handle.iCandidateBoxCount = 0; |
|
//printf("%d, %d, %d\n", iPercentage_H, iPercentage_W, g_stPTZ_Handle.iCandidateBoxCount); |
|
//Check if object (car, traffic, etc....) stay long time (300 sec). |
|
//The range of box center point change keep in 5%, at center of window. |
|
if ((iPercentage_H > 45 |
|
&& iPercentage_H < 65 |
|
&& iPercentage_W > 45 |
|
&& iPercentage_W < 65 |
|
&& iLockBoxIdxRet > -1 |
|
) |
|
) |
|
{ |
|
//物體幾乎是原地狀態 |
|
//進入"看太久計時"階段 |
|
|
|
tCurrentTrackingTime = time(0); |
|
//printf("iCandidateBoxCount > 0, T_cur = %ld \n", tCurrentTrackingTime); |
|
|
|
} |
|
else |
|
{ |
|
//追蹤有大幅移動, 更新計時器tOldTrackingTime |
|
|
|
tOldTrackingTime = time(0); |
|
tCurrentTrackingTime = time(0); |
|
//printf("iCandidateBoxCount = 0, T_cur = %ld, T_old = %ld \n", tCurrentTrackingTime, tOldTrackingTime); |
|
} |
|
|
|
iCurrentPresetPoint = IsPTZinPreset(); |
|
|
|
//if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0) |
|
if (iLockBoxIdxRet == -1 |
|
&& g_stPTZ_Handle.iZoneToPresetAnyOne == 1 |
|
&& (IsPTZinPreset() != GetHomePreset()) |
|
&& iOldPresetPoint == iCurrentPresetPoint) |
|
{ |
|
//遺失追蹤物件, 進入遺失計時階段 |
|
tLoseTrackingTime = time(0); |
|
} |
|
else |
|
{ |
|
//有追蹤物建, 更新遺失計時器tCheckResumeTime |
|
|
|
iOldPresetPoint = iCurrentPresetPoint; |
|
tLoseTrackingTime = time(0); |
|
tCheckResumeTime = time(0); |
|
} |
|
|
|
//printf("iIsGetLockTrackingBox = %d \n", g_stPTZ_Handle.iIsGetLockTrackingBox); |
|
|
|
g_stPTZ_Handle.tDiffTrackingSecond = 0; |
|
//tDiffTrackingSecond = difftime(tCurrentTrackingTime, tOldTrackingTime); |
|
|
|
|
|
//printf("diff track sec = %f \n", tDiffTrackingSecond); |
|
//g_stPTZ_Handle.ResumTime = tDiffTrackingSecond; |
|
|
|
//printf("iPauseTrackFlag = %d \n", g_stPTZ_Handle.iPauseTrackFlag); |
|
|
|
if (g_stPTZ_Handle.iLockBoxIdx != -1 |
|
//&& g_stPTZ_Handle.iPauseTrackFlag == 0 |
|
) |
|
{ |
|
g_stPTZ_Handle.tDiffTrackingSecond = tCurrentTrackingTime - tOldTrackingTime; |
|
} |
|
//else if (g_stPTZ_Handle.iIsGetLockTrackingBox == 0 |
|
else if (iLockBoxIdxRet == -1 |
|
&& g_stPTZ_Handle.iZoneToPresetAnyOne == 1 |
|
&& (IsPTZinPreset() != GetHomePreset())) |
|
{ |
|
//遺失追蹤物 |
|
//有任何zone設定了link preset點 |
|
//目前不在home點上 |
|
|
|
//從遺失那刻起開始計算時間 |
|
g_stPTZ_Handle.tDiffTrackingSecond = tLoseTrackingTime - tCheckResumeTime; |
|
} |
|
|
|
//printf("tDiffTrackingSecond = %d \n", tDiffTrackingSecond); |
|
|
|
int iTryGoHomeCount = 0; |
|
|
|
int iPTZRecoveryTimeSec = 300; |
|
|
|
|
|
iPTZRecoveryTimeSec = g_stPTZ_Handle.iRT_sec + (g_stPTZ_Handle.iRT_min * 60); |
|
|
|
if (iPTZRecoveryTimeSec <= 0) |
|
iPTZRecoveryTimeSec = 300;//300 |
|
|
|
/* |
|
if (viewChannelData[0].ptz_tracking_resume_dwell |
|
&& strlen(viewChannelData[0].ptz_tracking_resume_dwell) > 0) |
|
{ |
|
g_stPTZ_Handle.iTracking_resume_dwell = atoi(viewChannelData[0].ptz_tracking_resume_dwell); |
|
}*/ |
|
|
|
|
|
{ |
|
//char msg_temp[512] = { 0 }; |
|
//sprintf(msg_temp, "tDiffTrackingSecond:%d,iTracking_resume_dwell:%d,iLockBoxIdx:%d,iZoneToPresetAnyOne:%d,iPTZRecoveryTimeSec:%d", |
|
//g_stPTZ_Handle.tDiffTrackingSecond, |
|
//g_stPTZ_Handle.iTracking_resume_dwell, |
|
//g_stPTZ_Handle.iLockBoxIdx, |
|
//g_stPTZ_Handle.iZoneToPresetAnyOne, |
|
//iPTZRecoveryTimeSec); |
|
//write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); |
|
} |
|
|
|
{ |
|
//char msg_temp[512] = { 0 }; |
|
//sprintf(msg_temp, "iTraffic_cnfidence:%d,iEnable_PTZ:%d,iTracking_fov_min:%d,iTracking_fov_max:%d,iEnable_tracking:%d,iTracking_mode:%d,iTracking_entering_zone:%d", |
|
//g_stPTZ_Handle.iTraffic_cnfidence, |
|
//g_stPTZ_Handle.iEnable_PTZ, |
|
//g_stPTZ_Handle.iTracking_fov_min, |
|
//g_stPTZ_Handle.iTracking_fov_max, |
|
//g_stPTZ_Handle.iEnable_tracking, |
|
//g_stPTZ_Handle.iTracking_mode, |
|
//g_stPTZ_Handle.iTracking_entering_zone); |
|
//write_to_logs_html(msg_temp, "Get Single Lock Tracking Box", "DEBUG", SystemSetting.enable_system_logs); |
|
} |
|
|
|
//printf("[%d][%d]>>>>>>>>>>>>>>>>>> %d, %d \n", g_stPTZ_Handle.iLockBoxIdx, g_stPTZ_Handle.iPauseTrackFlag, g_stPTZ_Handle.tDiffTrackingSecond, iPTZRecoveryTimeSec); |
|
|
|
if (g_stPTZ_Handle.tDiffTrackingSecond > iPTZRecoveryTimeSec //看太久, 要回去 300s |
|
&& g_stPTZ_Handle.iLockBoxIdx != -1 |
|
//&& g_stPTZ_Handle.iPauseTrackFlag == 0 |
|
&& g_stPTZ_Handle.iZoneToPresetAnyOne == 1) |
|
{ |
|
tOldTrackingTime = time(0); |
|
tCurrentTrackingTime = time(0); |
|
|
|
//Set Pause Flag |
|
g_stPTZ_Handle.iPauseTrackFlag = 1; |
|
|
|
//if (!IsPTZatHomePos()) |
|
//{ |
|
#if 0 |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
usSleep(GO_HOME_SLEEP*1000); |
|
#endif |
|
|
|
#if 1 |
|
iHomePos = GetHomePreset(); |
|
g_stPTZ_Handle.iIsGoingHome = 1; |
|
while (IsPTZatHomePos() == 0) |
|
{ |
|
GoPreset(iHomePos); |
|
usSleep(1000000); |
|
|
|
if (iTryGoHomeCount >= 5) |
|
break; |
|
else |
|
iTryGoHomeCount++; |
|
} |
|
g_stPTZ_Handle.iIsGoingHome = 0; |
|
#endif |
|
//} |
|
} |
|
else if (g_stPTZ_Handle.tDiffTrackingSecond > g_stPTZ_Handle.iTracking_resume_dwell //PTZ_IS_TRACKING_TIMER //g_stPTZ_Handle.iTracking_resume_dwell |
|
&& g_stPTZ_Handle.iLockBoxIdx == -1 |
|
//&& g_stPTZ_Handle.iPauseTrackFlag == 0 |
|
) |
|
{ |
|
tLoseTrackingTime = time(0); |
|
tCheckResumeTime = time(0); |
|
|
|
//Set Pause Flag |
|
g_stPTZ_Handle.iPauseTrackFlag = 1; |
|
|
|
|
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
|
|
#if 0 |
|
if (g_stPTZ_Handle.iIsAtHomePOS == 0) |
|
{ |
|
iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
usSleep(GO_HOME_SLEEP*1000); |
|
} |
|
#endif |
|
#if 1 |
|
iHomePos = GetHomePreset(); |
|
g_stPTZ_Handle.iIsGoingHome = 1; |
|
while (IsPTZatHomePos() == 0 |
|
&& g_stPTZ_Handle.iZoneToPresetAnyOne == 1) |
|
{ |
|
GoPreset(iHomePos); |
|
usSleep(1000000); |
|
|
|
if (iTryGoHomeCount >= 5) |
|
break; |
|
else |
|
iTryGoHomeCount++; |
|
} |
|
g_stPTZ_Handle.iIsGoingHome = 0; |
|
#endif |
|
} |
|
//if (g_stPTZ_Handle.iIsAtHomePOS == 1) |
|
else if (g_stPTZ_Handle.iIsInPreset != 0) |
|
{ |
|
if (g_stPTZ_Handle.iLockBoxIdx == -1) |
|
{ |
|
g_stPTZ_Handle.tDiffTrackingSecond = 0; |
|
g_stPTZ_Handle.iIsGetLockTrackingBox = 0; |
|
|
|
tLoseTrackingTime = time(0); |
|
} |
|
//tCheckResumeTime = time(0); |
|
|
|
tOldTrackingTime = time(0); |
|
tCurrentTrackingTime = time(0); |
|
} |
|
|
|
/*tDiffTrackingSecond = 0.0; |
|
tDiffTrackingSecond = difftime(tLoseTrackingTime, tCheckResumeTime); |
|
|
|
g_stPTZ_Handle.LostTime = tDiffTrackingSecond; |
|
|
|
if (tDiffTrackingSecond >= 6) |
|
{ |
|
tCheckResumeTime = time(0); |
|
tLoseTrackingTime = time(0); |
|
|
|
iHomePos = GetHomePreset(); |
|
GoPreset(iHomePos); |
|
}*/ |
|
#endif |
|
|
|
//g_stPTZ_Handle.iIsStayHomePos = IsPTZatHomePos(); |
|
usSleep(200000); |
|
} //while (1) |
|
|
|
g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; |
|
|
|
//exit thread |
|
pthread_exit(NULL); |
|
} |
|
|
|
void SwitchRecoveryMode(int iSwitch) |
|
{ |
|
char outputData[1024] = { 0 }; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
//char ptz_curl_url_sec[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
if (iSwitch == 1) |
|
{ |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returntime_flag=1&returntime_min=0&returntime_sec=5"); |
|
} |
|
else if (iSwitch == 0) |
|
{ |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returntime_flag=0&returntime_min=0&returntime_sec=0"); |
|
} |
|
|
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Switch Recovery Mode 1"); |
|
usSleep(100000); |
|
|
|
|
|
if (iSwitch == 1) |
|
{ |
|
memset(ptz_curl_url, 0, sizeof(ptz_curl_url)); |
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?returnmode_flag=1&returnmode_mode=51"); |
|
|
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "Switch Recovery Mode 2"); |
|
usSleep(100000); |
|
} |
|
} |
|
|
|
void StartPTZtrackingThread() |
|
{ |
|
//Set recovery mode = on |
|
//SwitchRecoveryMode(1); |
|
|
|
g_IsShipTracking = IsShipObj(); |
|
|
|
if (g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag == 1 |
|
&& g_stPTZ_Handle.iRunPTZTrackingThread_flag == 0) |
|
{ |
|
g_stPTZ_Handle.iRunPTZTrackingThread_flag = 1; |
|
g_stPTZ_Handle.iIsGoingHome = 0; |
|
|
|
//if (IsPTZatHomePos() == 1) |
|
//{ |
|
|
|
//Get PTZ Info |
|
if (pthread_create(&ptz_tracking_thread, 0, ptz_do_tracking_thread, NULL)) |
|
printf("\nPTZ info thread creation failed\n"); |
|
|
|
//} |
|
//else |
|
//{ |
|
//Go home |
|
|
|
|
|
//while(IsPTZatHomePos()) |
|
//Get PTZ Info |
|
// if (pthread_create(&ptz_tracking_thread, 0, ptz_do_tracking_thread, NULL)) |
|
// printf("\nPTZ info thread creation failed\n"); |
|
//} |
|
} |
|
} |
|
|
|
void StopPTZtrackingThread() |
|
{ |
|
//Set recovery mode = off |
|
//SwitchRecoveryMode(0); |
|
|
|
g_stPTZ_Handle.iRunPTZTrackingThread_flag = 0; |
|
} |
|
|
|
void update_PTZ_limits() { |
|
if (strcmp(viewChannelData[0].enable_tracking_limits, "Yes") == 0) { |
|
int check_if_set_new_pos = 0; |
|
if ((int)atof(viewChannelData[0].ptz_pan_left_limit) <= (int)atof(viewChannelData[0].ptz_pan_right_limit)) { |
|
if (g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit)) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
else { |
|
if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit) && g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { |
|
int differ_temp_right = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_right_limit); |
|
int differ_temp_left = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_left_limit); |
|
|
|
if (differ_temp_right <= differ_temp_left) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
else { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
} |
|
if ((int)atof(viewChannelData[0].ptz_tilt_up_limit) <= (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
else { |
|
if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
|
|
if (check_if_set_new_pos == 1) |
|
{ |
|
UpdatePTZCurPos(); |
|
} |
|
} |
|
} |
|
|
|
void *ptz_update_status_thread(void *str) |
|
{ |
|
pthread_detach(pthread_self()); |
|
setPthreadName("ptz_status"); |
|
//int iUpdate_PTZ_setting_times_count = TIMER_UPDATE_PTZ_SETTING; |
|
int iGoHomeSecTimer = 0; |
|
int iHomePreset = -1; |
|
|
|
while (g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag) |
|
{ |
|
//printf("get w/h = %d, %d \n", stChannelInfo->iVideo_source_w, stChannelInfo->iVideo_source_h); |
|
//Update PTZ status |
|
//if (iUpdate_PTZ_setting_times_count >= TIMER_UPDATE_PTZ_SETTING) |
|
{ |
|
//UpdatePTZIPcamSetting(); |
|
//UpdatePTZCurPos(); |
|
/*if (strcmp(viewChannelData[0].enable_tracking_limits, "Yes") == 0) { |
|
|
|
int check_if_set_new_pos = 0; |
|
if ((int)atof(viewChannelData[0].ptz_pan_left_limit) <= (int)atof(viewChannelData[0].ptz_pan_right_limit)) { |
|
if (g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit)) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
else { |
|
if (g_stPTZ_Handle.iPanABS > (int)atof(viewChannelData[0].ptz_pan_right_limit) && g_stPTZ_Handle.iPanABS < (int)atof(viewChannelData[0].ptz_pan_left_limit)) { |
|
int differ_temp_right = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_right_limit); |
|
int differ_temp_left = g_stPTZ_Handle.iPanABS - (int)atof(viewChannelData[0].ptz_pan_left_limit); |
|
|
|
if (differ_temp_right <= differ_temp_left) { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_right_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
else { |
|
SetPTZNewPan((int)atof(viewChannelData[0].ptz_pan_left_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
} |
|
if ((int)atof(viewChannelData[0].ptz_tilt_up_limit) <= (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
else { |
|
if (g_stPTZ_Handle.iTiltABS > (int)atof(viewChannelData[0].ptz_tilt_up_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_up_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
|
|
if (g_stPTZ_Handle.iTiltABS < (int)atof(viewChannelData[0].ptz_tilt_down_limit)) { |
|
SetPTZNewTilt((int)atof(viewChannelData[0].ptz_tilt_down_limit)); |
|
check_if_set_new_pos = 1; |
|
} |
|
} |
|
|
|
if (check_if_set_new_pos == 1) |
|
{ |
|
//UpdatePTZCurPos(); |
|
} |
|
|
|
}*/ |
|
|
|
//UpdateRecoveryTime(); |
|
|
|
//printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> min:sec= %d, %d \n", g_stPTZ_Handle.iRT_min, g_stPTZ_Handle.iRT_sec); |
|
//iUpdate_PTZ_setting_times_count = 0; |
|
} |
|
|
|
//iUpdate_PTZ_setting_times_count++; |
|
|
|
if (g_stPTZ_Handle.iEnable_tracking != 1) |
|
{ |
|
//usSleep(2000000); |
|
usSleep(3000000); |
|
continue; |
|
} |
|
|
|
//Check PerformDetection, |
|
//-1 = error, 0 = not in preset, 1~255 = in x preset point |
|
if (IsTracking() == 1) |
|
{ |
|
StartPTZtrackingThread(); |
|
} |
|
else if (IsTracking() != 1) |
|
{ |
|
StopPTZtrackingThread(); |
|
} |
|
|
|
//for test |
|
//StartPTZtrackingThread(); |
|
|
|
//Go Home Preset Every 10 min, when position at home. |
|
if (IsPTZatHomePos() == 1)////Start check |
|
{ |
|
iGoHomeSecTimer++; |
|
|
|
//check |
|
if (iGoHomeSecTimer > TIMER_GO_HOME_PRESET) |
|
{ |
|
//go home preset |
|
iHomePreset = GetHomePreset(); |
|
GoPreset(iHomePreset); |
|
|
|
//reset timer |
|
iGoHomeSecTimer = 0; |
|
} |
|
} |
|
else |
|
{ |
|
//reset timer |
|
iGoHomeSecTimer = 0; |
|
} |
|
|
|
|
|
//usSleep(PTZ_UPDATE_STATUS_TIMER*1000); |
|
usSleep(1000000); |
|
} |
|
//exit thread |
|
pthread_exit(NULL); |
|
} |
|
|
|
int StartPTZupdateStatusThread() |
|
{ |
|
g_stPTZ_Handle.iIsPTZ = 0; |
|
g_stPTZ_Handle.iLoseLockObjCount = 0; |
|
|
|
usSleep(100000); |
|
|
|
//Init curl handle; |
|
//g_curl_Handle = curl_easy_init(); |
|
//create_g_curl_connect(); |
|
|
|
//Create_ptz_socket(); |
|
|
|
//Check if ptz device. |
|
|
|
if (g_IsPTZDevice == 1) |
|
{ |
|
//printf("This is PTZ device. \n"); |
|
g_stPTZ_Handle.iIsPTZ = 1; //for IsPTZ() callback. |
|
|
|
DefaultFocusSetting(); |
|
|
|
#if 1 |
|
g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag = 1; |
|
//Get PTZ Info |
|
if (pthread_create(&ptz_status_thread, 0, ptz_update_status_thread, NULL)) |
|
{ |
|
//printf("\nPTZ update status thread creation failed\n"); |
|
return 0; |
|
} |
|
#endif |
|
return 1; |
|
} |
|
else |
|
{ |
|
//printf("This is not PTZ device. \n"); |
|
return 0; |
|
} |
|
} |
|
|
|
void StopPTZupdateStatusThread() |
|
{ |
|
g_stPTZ_Handle.iRunPTZUpdateStatusThread_flag = 0; |
|
StopPTZtrackingThread(); |
|
} |
|
|
|
void GoPreset(int iPresetNumber) |
|
{ |
|
//if (g_stPTZ_Handle.iIsPTZ == 1) |
|
if (1) |
|
{ |
|
if (MIN_PRESET_NUMBER <= iPresetNumber |
|
&& iPresetNumber <= MAX_PRESET_NUMBER) |
|
{ |
|
char outputData[1024] = { 0 }; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?ai_goto_preset=%d", iPresetNumber); |
|
//sprintf(ptz_curl_url, "/ptzpreset?camid=1&goto_preset=%d", iPresetNumber); |
|
//http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 |
|
|
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData, "Go Preset"); |
|
usSleep(100000); |
|
} |
|
else |
|
{ |
|
//printf("Can only support 0~16 preset number \n"); |
|
} |
|
} |
|
else |
|
{ |
|
//printf("Device not support PTZ CMD #1\n"); |
|
} |
|
} |
|
|
|
void StopPtz() |
|
{ |
|
if (g_stPTZ_Handle.iIsPTZ == 1) |
|
{ |
|
char outputData[1024] = { 0 }; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/control?stop=1"); |
|
//sprintf(ptz_curl_url, "/control?stop=1"); |
|
//http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 |
|
|
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Stop Ptz"); |
|
} |
|
else |
|
{ |
|
//printf("Device not support PTZ CMD #2\n"); |
|
} |
|
} |
|
|
|
void StartStopAutopan(int iStartStopFlag) |
|
{ |
|
if (g_stPTZ_Handle.iIsPTZ == 1) |
|
{ |
|
char outputData[1024] = { 0 }; |
|
|
|
char *ptz_ip = "http://127.0.0.1"; |
|
char ptz_curl_url[512] = { 0 }; |
|
char ptz_curl_sendbuf[1] = { 0 }; |
|
char ptz_curl_username[128] = { 0 }; |
|
char ptz_curl_password[128] = { 0 }; |
|
char *method = "GET"; |
|
int ptz_port = atoi(accountData[0].account_port); |
|
strcat(ptz_curl_username, accountData[0].account_username); |
|
strcat(ptz_curl_password, accountData[0].account_password); |
|
|
|
int iOpenFlag = 0; |
|
if (iStartStopFlag == 1) |
|
iOpenFlag = 1; |
|
|
|
sprintf(ptz_curl_url, "http://127.0.0.1/ptzpreset?autopan=%d", iOpenFlag); |
|
//sprintf(ptz_curl_url, "/ptzpreset?autopan=%d", iOpenFlag); |
|
//http://192.168.8.151/ptzpreset?camid=1&goto_preset=1 |
|
|
|
send_request(ptz_ip, ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port, outputData,"Start Stop Autopan"); |
|
} |
|
else |
|
{ |
|
//printf("Device not support PTZ CMD #3\n"); |
|
} |
|
} |
|
|
|
#endif |