#include "mvpt_process_assist.h" #include "../common/logger.hpp" //******** 判断位置是否合法函数 **********// // 目的:剔除掉靠近摄像头时,面积最大,但是检测物体已经不完整的情况 // 1. 设定阈值,靠近边缘不要了(阈值目前设定为自身宽高的20%) //bool sy_legal_pos(bitset flags, int left, int top, int right, int bottom, int img_height, int img_width) //{ // int pos[4] = { left, top, right, bottom }; // int edges[4] = { 0, 0, img_width, img_height }; // // for (int i = 0; i < EDGESIZE; i++) // { // if (flags[i]) //是需要判断的边 // { // if (abs(pos[i] - edges[i]) < minDistance[i]) // return false; // } // } // return true; //} bool LegalMinArea(int width, int height, sy_rect min_box) { return (width >= min_box.width_ && height >= min_box.height_); } //******** 判断面积是否合法函数 **********// // 目的:选取框最大最完整的那帧 // 1. 比之前面积小的不要 // 2. 突变的面积不要 bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom) { //不需要通过MINBOX来判断,直接返回true int newArea = (bottom - top)*(right - left); if (lastArea == 0) return true; if (newArea < maxArea) return false; else if ((newArea - lastArea) / lastArea > 0.5) //阈值测试之后再确定,看是否需要分种类来确定不同的阈值 return false; else return true; } //******** 辅助函数:根据目标运动的轨迹,判断需要特别外扩的方向 **********// // 目的:因为跳帧的存在,目标运动较快时,框会有一定的滞后的情况(车向前运动,车头被裁掉的情况尤其明显),框滞后的方向需要额外外扩 void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h, int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom) { if (abs(direction_x) > abs(direction_y)) { if (direction_x > 0) { boundary_right = 2.5 * boundary_w; } else { boundary_left = 2.5 * boundary_w; } } else { if (direction_y > 0) { boundary_bottom = 2.5 * boundary_h; } else { boundary_top = 2.5 * boundary_h; } } /*int max_dis = max(max(max(dis_left, dis_right), dis_top), dis_bottom); if (max_dis == dis_left) boundary_left = 3 * boundary_w; else if (max_dis == dis_right) boundary_right = 3 * boundary_w; else if (max_dis == dis_top) boundary_top = 3 * boundary_h; else boundary_bottom = 3 * boundary_h;*/ } int CreateDir(char *pszDir) { int i = 0; int iRet; int iLen = strlen(pszDir); if (pszDir[iLen - 1] != '\\' && pszDir[iLen - 1] != '/') { pszDir[iLen] = '/'; pszDir[iLen + 1] = '\0'; } iLen = strlen(pszDir); if (iLen > 2 && ((pszDir[i] == '\\' && pszDir[i + 1] == '\\') || (pszDir[i] == '/' && pszDir[i + 1] == '/'))) { i = 2; for (; i <= iLen; i++) if (pszDir[i] == '\\' || pszDir[i] == '/') break; i++; for (; i <= iLen; i++) { if (pszDir[i] == '\\' || pszDir[i] == '/') { pszDir[i] = '\0'; //printf("file access %s\n", pszDir); iRet = ACCESS(pszDir, 0); //printf("file access %d\n", iRet); if (iRet != 0) { //printf("file mkdir %s\n", pszDir); iRet = MKDIR(pszDir); //printf("file mkdir %d\n", iRet); if (iRet != 0) { LOG_ERROR("Create Folder Failed!"); return -1; } } pszDir[i] = '/'; } } return 0; } if (pszDir[i] != '\\' && pszDir[i] != '/') i = 0; else i = 1; for (; i <= iLen; i++) { if (pszDir[i] == '\\' || pszDir[i] == '/') { pszDir[i] = '\0'; iRet = ACCESS(pszDir, 0); if (iRet != 0) { iRet = MKDIR(pszDir); if (iRet != 0) { return -1; } } pszDir[i] = '/'; } } return 0; } void CreateResultFolder(char* resultFolder, const char* jointFolder) { if (strlen(resultFolder) > 240) //?too long { LOG_ERROR("Folder Name is too Long!"); return; } else if (strlen(resultFolder) < 1) //?too short { LOG_ERROR("Folder Name is too Short!"); return; } char dir[260]; sprintf(dir, "%s%s/", resultFolder, jointFolder); if (CreateDir(dir) != 0) { LOG_ERROR("Create Folder Failed!"); return; } } bool snapshot_judge_algor(int index, int width, int height) { return snapshot_legal_minarea(index, width, height) //判断最小面积 && snapshot_legal_inarea(width, height); //判断在有效区域 //&& snapshot_algor_open_config(obj_key); //判断算法开启,调整不用在此处判断,检测出来会进行过滤 } bool snapshot_legal_minarea(int index, int width, int height) { return (width >= m_boxsize[index].width_ && height >= m_boxsize[index].height_); } bool snapshot_legal_pos(bitset flags, int left, int top, int right, int bottom, int image_width, int image_height) { int pos[4] = { left, top, right, bottom }; int edges[4] = { 0, 0, image_width, image_height }; for (int i = 0; i < EDGESIZE; i++) { if (flags[i]) //是需要判断的边 { if (abs(pos[i] - edges[i]) < minDistance[i]) return false; } } return true; } //******** 判断面积是否合法函数 **********// // 目的:选取框最大最完整的那帧 // 1. 比之前面积小的不要 // 2. 突变的面积不要 bool snapshot_legal_area(int max_area, int last_area, int left, int top, int right, int bottom) { //不需要通过MINBOX来判断,直接返回true int new_area = (bottom - top)*(right - left); if (last_area == 0) return true; if (new_area < max_area) return false; // else if ((new_area - last_area) / last_area > 0.5) //阈值测试之后再确定,看是否需要分种类来确定不同的阈值 else if ((new_area - max_area) / max_area > 0.5) //阈值测试之后再确定,看是否需要分种类来确定不同的阈值 modified by zsh return false; else return true; } bool snapshot_legal_inarea(sy_rect algor_area, int left, int top, int right, int bottom) { if (left < algor_area.left_ || top < algor_area.top_ || right>(algor_area.left_ + algor_area.width_) || bottom >(algor_area.top_ + algor_area.height_)) return false; return true; } bool snapshot_legal_inarea(int width, int height) { return true; } // added by zsh 220719 判断人脸姿态角是否满足要求 float convert_score(float attitude_angle) { if(fabs(attitude_angle) > 30) // 超过设置角度则过滤---暂未用到 return 180; else return fabs(attitude_angle); } bool snapshot_legal_pose(float last_roll, float last_yaw, float last_pitch, float roll, float yaw, float pitch) { if(fabs(roll) > 30 || fabs(yaw) > 30 || fabs(pitch) > 30) return false; float last_score = convert_score(last_roll) + convert_score(last_yaw) + convert_score(last_pitch); float cur_score = convert_score(roll) + convert_score(yaw) + convert_score(pitch); if(last_score > cur_score) return false; return true; }