#include "snapshot_reprocessing.h" #include "ImageSaveGPU.h" #include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" #include "helpers/logger.hpp" snapshot_reprocessing::snapshot_reprocessing() { m_task_param_manager = task_param_manager::getInstance(); algor_index_table["human"] = { (int)det_class_label_t::HUMAN }; algor_index_table["nonmotor_vehicle"] = { (int)det_class_label_t::BICYCLE, (int)det_class_label_t::MOTOCYCLE, (int)det_class_label_t::TRICYCLE }; algor_index_table["vehicle"] = { (int)det_class_label_t::SMALL_CAR, (int)det_class_label_t::LARGE_CAR, (int)det_class_label_t::TRUCK, (int)det_class_label_t::TRACTOR, (int)det_class_label_t::MEDIUM_BUS }; } /* 获取人车物目标快照图 */ map * snapshot_reprocessing::get_total_snapshot_info() { return &total_snapshot_info; } /* 获取所有人脸目标快照图 */ map * snapshot_reprocessing::get_total_face_snapshot_info() { return &total_face_snapshot_info; } /* 获取人车物目标快照图 */ int snapshot_reprocessing::update_bestsnapshot(set& task_in_play_id, sy_img* images, vector &ol_det_result, vector>& delete_object_id) { int idx = 0; for (auto iter: task_in_play_id) { if (0 == ol_det_result[idx].obj_count) { #ifdef MTASK_DEBUG_ LOG_DEBUG("task_id {} ckpt:0", iter); #endif ++idx; continue; } int frame_height = images[idx].h_; int frame_width = images[idx].w_; int copy_obj_count = 0; // 用于记录该路有多少个目标需要进行显存图像的更新 for (int c = 0; c < ol_det_result[idx].obj_count; c++) { int index = 0; OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id }; /* 投票确定目标index */ if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()) { index = ol_det_result[idx].obj[c].index; } else { index = total_snapshot_info[new_obj].index.index; } int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left); int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); int cur_real_index = ol_det_result[idx].obj[c].index; int expansion_width = cur_real_width * EXPANSION_PROPORTION; int expansion_height = cur_real_height * EXPANSION_PROPORTION; // DEBUG----------------------------------------------------------------- // 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴 if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可 expansion_width = 10; expansion_height = 10; } // DEBUG END------------------------------------------------------------- /* 若该目标第一次出现 */ if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()) { /* manager insert new object. */ /* 判断目标合法 */ if (!snapshot_judge_algor(index, cur_real_width, cur_real_height)) { #ifdef MTASK_DEBUG_ LOG_DEBUG("task_id {} ckpt:1", iter); #endif continue; } /* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */ total_snapshot_info[new_obj].index.count++; total_snapshot_info[new_obj].index.index = cur_real_index; total_snapshot_info[new_obj].confidence = ol_det_result[idx].obj[c].confidence; total_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1; //left total_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1; //top total_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right total_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom /* 存入抠图参数 */ snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- // total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩 int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); // total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; // 推出的坐标不外扩,只存在本地的快照外扩 //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame; CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShot.frame, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char))); CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_snapshot_info[new_obj].snapShot.height = frame_height; total_snapshot_info[new_obj].snapShot.width = frame_width; total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } else /* 若目标不是第一次出现 */ { total_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); /* 判断该目标是否优于之前的目标(判断策略可以自定义) */ if (!best_snapshot_judge_algor(new_obj, total_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, cur_real_width, cur_real_height, frame_width, frame_height)) { continue; } /* 若更优于之前的快照 做快照的更新 */ if (total_snapshot_info[new_obj].index.count == 0) { total_snapshot_info[new_obj].index.count++; total_snapshot_info[new_obj].index.index = cur_real_index; } else { if (total_snapshot_info[new_obj].index.index == cur_real_index) total_snapshot_info[new_obj].index.count++; else total_snapshot_info[new_obj].index.count--; } snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; //DEBUG-------------------------------------------------------------------------------------------------------------------------------------- // total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩 int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); // total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; //debug by zsh 推出的坐标不外扩,只存在本地的快照外扩 //DEBUG END---------------------------------------------------------------------------------------------------------------------------------- if (total_snapshot_info[new_obj].snapShotLittle.frame != nullptr) { CHECK(cudaFree(total_snapshot_info[new_obj].snapShotLittle.frame)); CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); } total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame; CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_snapshot_info[new_obj].snapShot.height = frame_height; total_snapshot_info[new_obj].snapShot.width = frame_width; total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } } /* 根据上面对目标的依次判断 存在需要抠图的目标 进行批量的抠图 同时做resize操作 */ if (0 != copy_obj_count) { PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); } idx++; } return 0; } /* 获取人车物目标快照图 */ int snapshot_reprocessing::update_bestsnapshot2(vector& task_in_play_id, sy_img* images, vector &ol_det_result, vector>& delete_object_id) { int idx = 0; for (auto iter: task_in_play_id) { if (0 == ol_det_result[idx].obj_count) { #ifdef MTASK_DEBUG_ LOG_DEBUG("task_id {} ckpt:0", iter); #endif ++idx; continue; } int frame_height = images[idx].h_; int frame_width = images[idx].w_; int copy_obj_count = 0; // 用于记录该路有多少个目标需要进行显存图像的更新 for (int c = 0; c < ol_det_result[idx].obj_count; c++) { int index = 0; OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id }; /* 投票确定目标index */ if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()) { index = ol_det_result[idx].obj[c].index; } else { index = total_snapshot_info[new_obj].index.index; } int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left); int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); int cur_real_index = ol_det_result[idx].obj[c].index; int expansion_width = cur_real_width * EXPANSION_PROPORTION; int expansion_height = cur_real_height * EXPANSION_PROPORTION; // DEBUG----------------------------------------------------------------- // 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴 if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可 expansion_width = 10; expansion_height = 10; } // DEBUG END------------------------------------------------------------- /* 若该目标第一次出现 */ if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()) { /* manager insert new object. */ /* 判断目标合法 */ if (!snapshot_judge_algor(index, cur_real_width, cur_real_height)) { #ifdef MTASK_DEBUG_ LOG_DEBUG("task_id {} ckpt:1", iter); #endif continue; } /* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */ total_snapshot_info[new_obj].index.count++; total_snapshot_info[new_obj].index.index = cur_real_index; total_snapshot_info[new_obj].confidence = ol_det_result[idx].obj[c].confidence; total_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1; //left total_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1; //top total_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right total_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom /* 存入抠图参数 */ snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- // total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩 int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); // total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; // 推出的坐标不外扩,只存在本地的快照外扩 //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame; CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShot.frame, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char))); CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_snapshot_info[new_obj].snapShot.height = frame_height; total_snapshot_info[new_obj].snapShot.width = frame_width; total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } else /* 若目标不是第一次出现 */ { total_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); /* 判断该目标是否优于之前的目标(判断策略可以自定义) */ if (!best_snapshot_judge_algor(new_obj, total_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, cur_real_width, cur_real_height, frame_width, frame_height)) { continue; } /* 若更优于之前的快照 做快照的更新 */ if (total_snapshot_info[new_obj].index.count == 0) { total_snapshot_info[new_obj].index.count++; total_snapshot_info[new_obj].index.index = cur_real_index; } else { if (total_snapshot_info[new_obj].index.index == cur_real_index) total_snapshot_info[new_obj].index.count++; else total_snapshot_info[new_obj].index.count--; } snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; //DEBUG-------------------------------------------------------------------------------------------------------------------------------------- // total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩 int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); // total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; //debug by zsh 推出的坐标不外扩,只存在本地的快照外扩 //DEBUG END---------------------------------------------------------------------------------------------------------------------------------- if (total_snapshot_info[new_obj].snapShotLittle.frame != nullptr) { CHECK(cudaFree(total_snapshot_info[new_obj].snapShotLittle.frame)); CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); } total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame; CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_snapshot_info[new_obj].snapShot.height = frame_height; total_snapshot_info[new_obj].snapShot.width = frame_width; total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } } /* 根据上面对目标的依次判断 存在需要抠图的目标 进行批量的抠图 同时做resize操作 */ if (0 != copy_obj_count) { PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); } idx++; } return 0; } //人脸快照保存更新 int snapshot_reprocessing::update_face_bestsnapshot(set& task_in_play_id, sy_img* images, vector &ol_det_result, vector>& delete_object_id) { int idx = 0; for (auto iter : task_in_play_id) { LOG_TRACE("[info]: {}: {}",iter,ol_det_result[idx].obj_count); if (0 == ol_det_result[idx].obj_count) { ++idx; continue; } int frame_height = images[idx].h_; int frame_width = images[idx].w_; int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 for (int c = 0; c < ol_det_result[idx].obj_count; c++) { OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id }; int index = 1; // 分类判断,人脸不需要 int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left); int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); int cur_real_index = ol_det_result[idx].obj[c].index; LOG_TRACE("[info]00000: {}: {} roll:{} yaw:{} pitch:{}",iter,ol_det_result[idx].obj[c].id, fabs(ol_det_result[idx].obj[c].roll),fabs(ol_det_result[idx].obj[c].yaw),fabs(ol_det_result[idx].obj[c].pitch)); // 该目标的第一张 if (total_face_snapshot_info.find(new_obj) == total_face_snapshot_info.end()) { /* manager insert new object. */ // 有效区域和最小面积过滤 if (cur_real_width * cur_real_height < 30 * 30) { continue; } LOG_TRACE("[info]11111: {}: {}",iter,ol_det_result[idx].obj[c].id); total_face_snapshot_info[new_obj].index.count++; total_face_snapshot_info[new_obj].index.index = cur_real_index; //debug by zsh total_face_snapshot_info[new_obj].confidence = ol_det_result[idx].obj[c].confidence; // 人脸姿态角 added by zsh 220719------------------------------------------- total_face_snapshot_info[new_obj].roll = ol_det_result[idx].obj[c].roll; total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw; total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch; //------------------------------------------------------------------------- //判断是否有余地外扩 total_face_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1; //left total_face_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1; //top total_face_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right total_face_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom // 外扩 //人脸 按长边2倍外扩 --modified by zsh------------------------------------------------------- int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height; int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION; int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION; //------------------------------------------------------------------------------------------ // int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION; // int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION; snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // 存参数 //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); // total_face_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- // total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame; // 存人脸关键点、检测框及大图 memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25); total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; total_face_snapshot_info[new_obj].snapShot.height = frame_height; total_face_snapshot_info[new_obj].snapShot.width = frame_width; total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; const unsigned nbytes = total_face_snapshot_info[new_obj].snapShot.size * sizeof(unsigned char); CHECK(cudaMalloc(&total_face_snapshot_info[new_obj].snapShot.frame, nbytes)); //// CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, images[idx].data_, nbytes, cudaMemcpyDeviceToDevice));//// } else { // 该目标非第一张 total_face_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); // 最佳快照判断 // if (!best_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, // cur_real_width, cur_real_height, frame_width, frame_height)) // modified by zsh // if (!best_face_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, // cur_real_width, cur_real_height, frame_width, frame_height)) // modified by zsh 220719 加入姿态角 if (!best_face_snapshot_judge_algor_v2(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, cur_real_width, cur_real_height, frame_width, frame_height, ol_det_result[idx].obj[c].roll, ol_det_result[idx].obj[c].yaw, ol_det_result[idx].obj[c].pitch )) continue; // 满足更新条件则进行更新 if (total_face_snapshot_info[new_obj].index.count == 0) { total_face_snapshot_info[new_obj].index.count++; total_face_snapshot_info[new_obj].index.index = cur_real_index; } else { if (total_face_snapshot_info[new_obj].index.index == cur_real_index) total_face_snapshot_info[new_obj].index.count++; else total_face_snapshot_info[new_obj].index.count--; } // 人脸姿态角 added by zsh 220719------------------------------------------- total_face_snapshot_info[new_obj].roll = ol_det_result[idx].obj[c].roll; total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw; total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch; //------------------------------------------------------------------------- //人脸 按长边2倍外扩 --modified by zsh------------------------------------------------------- int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height; int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION; int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION; //------------------------------------------------------------------------------------------ // int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION; // int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION; snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); // total_face_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- // total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; if (total_face_snapshot_info[new_obj].snapShotLittle.frame != nullptr) { CHECK(cudaFree(total_face_snapshot_info[new_obj].snapShotLittle.frame)); //释放显存 CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); } total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame; //存人脸关键点、检测框及大图 memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25); total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_face_snapshot_info[new_obj].snapShot.height = frame_height; total_face_snapshot_info[new_obj].snapShot.width = frame_width; total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } } //对一张图片统一抠图 if (0 != copy_obj_count) { PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); } ++idx; } return 0; } //人脸快照保存更新 int snapshot_reprocessing::update_face_bestsnapshot2(vector& task_in_play_id, sy_img* images, vector &ol_det_result, vector>& delete_object_id) { int idx = 0; for (auto iter : task_in_play_id) { LOG_TRACE("[info]: {}: {}",iter,ol_det_result[idx].obj_count); if (0 == ol_det_result[idx].obj_count) { ++idx; continue; } int frame_height = images[idx].h_; int frame_width = images[idx].w_; int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 for (int c = 0; c < ol_det_result[idx].obj_count; c++) { OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id }; int index = 1; // 分类判断,人脸不需要 int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left); int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); int cur_real_index = ol_det_result[idx].obj[c].index; LOG_TRACE("[info]00000: {}: {} roll:{} yaw:{} pitch:{}",iter,ol_det_result[idx].obj[c].id, fabs(ol_det_result[idx].obj[c].roll),fabs(ol_det_result[idx].obj[c].yaw),fabs(ol_det_result[idx].obj[c].pitch)); // 该目标的第一张 if (total_face_snapshot_info.find(new_obj) == total_face_snapshot_info.end()) { /* manager insert new object. */ // 有效区域和最小面积过滤 if (cur_real_width * cur_real_height < 30 * 30) { continue; } LOG_TRACE("[info]11111: {}: {}",iter,ol_det_result[idx].obj[c].id); total_face_snapshot_info[new_obj].index.count++; total_face_snapshot_info[new_obj].index.index = cur_real_index; //debug by zsh total_face_snapshot_info[new_obj].confidence = ol_det_result[idx].obj[c].confidence; // 人脸姿态角 added by zsh 220719------------------------------------------- total_face_snapshot_info[new_obj].roll = ol_det_result[idx].obj[c].roll; total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw; total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch; //------------------------------------------------------------------------- //判断是否有余地外扩 total_face_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1; //left total_face_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1; //top total_face_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right total_face_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom // 外扩 //人脸 按长边2倍外扩 --modified by zsh------------------------------------------------------- int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height; int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION; int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION; //------------------------------------------------------------------------------------------ // int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION; // int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION; snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; // 存参数 //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); // total_face_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- // total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame; // 存人脸关键点、检测框及大图 memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25); total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; total_face_snapshot_info[new_obj].snapShot.height = frame_height; total_face_snapshot_info[new_obj].snapShot.width = frame_width; total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; const unsigned nbytes = total_face_snapshot_info[new_obj].snapShot.size * sizeof(unsigned char); CHECK(cudaMalloc(&total_face_snapshot_info[new_obj].snapShot.frame, nbytes)); //// CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, images[idx].data_, nbytes, cudaMemcpyDeviceToDevice));//// } else { // 该目标非第一张 total_face_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top); // 最佳快照判断 // if (!best_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, // cur_real_width, cur_real_height, frame_width, frame_height)) // modified by zsh // if (!best_face_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, // cur_real_width, cur_real_height, frame_width, frame_height)) // modified by zsh 220719 加入姿态角 if (!best_face_snapshot_judge_algor_v2(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, cur_real_width, cur_real_height, frame_width, frame_height, ol_det_result[idx].obj[c].roll, ol_det_result[idx].obj[c].yaw, ol_det_result[idx].obj[c].pitch )) continue; // 满足更新条件则进行更新 if (total_face_snapshot_info[new_obj].index.count == 0) { total_face_snapshot_info[new_obj].index.count++; total_face_snapshot_info[new_obj].index.index = cur_real_index; } else { if (total_face_snapshot_info[new_obj].index.index == cur_real_index) total_face_snapshot_info[new_obj].index.count++; else total_face_snapshot_info[new_obj].index.count--; } // 人脸姿态角 added by zsh 220719------------------------------------------- total_face_snapshot_info[new_obj].roll = ol_det_result[idx].obj[c].roll; total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw; total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch; //------------------------------------------------------------------------- //人脸 按长边2倍外扩 --modified by zsh------------------------------------------------------- int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height; int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION; int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION; //------------------------------------------------------------------------------------------ // int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION; // int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION; snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0); snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0); snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1); snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1); snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count]; snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count]; //DEBUG-------modified by zsh----------------------------------------------------------------------------------------------------------------- int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0); int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0); int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1); int cur_bottom = min(ol_det_result[idx].obj[c].bottom + 10, frame_height - 1); // total_face_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); //DEBUG END----------------------------------------------------------------------------------------------------------------------------------- // total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; if (total_face_snapshot_info[new_obj].snapShotLittle.frame != nullptr) { CHECK(cudaFree(total_face_snapshot_info[new_obj].snapShotLittle.frame)); //释放显存 CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char))); } total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count]; total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count]; snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame; //存人脸关键点、检测框及大图 memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25); total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice)); total_face_snapshot_info[new_obj].snapShot.height = frame_height; total_face_snapshot_info[new_obj].snapShot.width = frame_width; total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS; } } //对一张图片统一抠图 if (0 != copy_obj_count) { PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); } ++idx; } return 0; } /* 过滤不感兴趣的目标 */ void snapshot_reprocessing::screen_effective_snapshot(const set &taskid_inplay, vector &_onelevel_det_result) { map algor_param = m_task_param_manager->get_task_algor_params(); int task_count = _onelevel_det_result.size(); int task_idx = 0; for (auto taskid : taskid_inplay) { int effective_count = 0; int effective_idx = 0; det_objinfo *tmp_det_objinfo = _onelevel_det_result[task_idx].obj; for (int c = 0; c < _onelevel_det_result[task_idx].obj_count; c++) { // if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end() // && (!algor_param[taskid].human_algors.empty() || !algor_param[taskid].human_face_algors.empty())) // 此处行人和人脸存在耦合,若同一路任务配置了人脸没有配置行人,存抓拍图时会出错 if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end() && (!algor_param[taskid].human_algors.empty())) // modified by zsh 220714 { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } if (algor_index_table["nonmotor_vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["nonmotor_vehicle"].end() && !algor_param[taskid].nonmotor_vehicle_algors.empty()) { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } if (algor_index_table["vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["vehicle"].end() && !algor_param[taskid].vehicle_algors.empty()) { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } } _onelevel_det_result[task_idx++].obj_count = effective_count; } } void snapshot_reprocessing::screen_effective_snapshot2(const vector &taskid_inplay, vector &_onelevel_det_result){ map algor_param = m_task_param_manager->get_task_algor_params(); int task_count = _onelevel_det_result.size(); int task_idx = 0; for (auto taskid : taskid_inplay) { int effective_count = 0; int effective_idx = 0; det_objinfo *tmp_det_objinfo = _onelevel_det_result[task_idx].obj; for (int c = 0; c < _onelevel_det_result[task_idx].obj_count; c++) { // if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end() // && (!algor_param[taskid].human_algors.empty() || !algor_param[taskid].human_face_algors.empty())) // 此处行人和人脸存在耦合,若同一路任务配置了人脸没有配置行人,存抓拍图时会出错 if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end() && (!algor_param[taskid].human_algors.empty())) // modified by zsh 220714 { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } if (algor_index_table["nonmotor_vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["nonmotor_vehicle"].end() && !algor_param[taskid].nonmotor_vehicle_algors.empty()) { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } if (algor_index_table["vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["vehicle"].end() && !algor_param[taskid].vehicle_algors.empty()) { tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c]; effective_count++; } } _onelevel_det_result[task_idx++].obj_count = effective_count; } } /* 快照判定辅助函数 */ bool snapshot_reprocessing::best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height) { return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) && snapshot_legal_minarea(obj_value.index.index, width, height) && snapshot_legal_inarea(width, height) && snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height); return true; } bool snapshot_reprocessing::best_face_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height) { return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) /*&& snapshot_legal_minarea(obj_value.index.index, width, height)*/ && snapshot_legal_inarea(width, height) && snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height); return true; } // added by zsh 220719 bool snapshot_reprocessing::best_face_snapshot_judge_algor_v2(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height, float roll, float yaw, float pitch) { return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) /*&& snapshot_legal_minarea(obj_value.index.index, width, height)*/ && snapshot_legal_inarea(width, height) && snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height) && snapshot_legal_pose(obj_value.roll, obj_value.yaw, obj_value.pitch, roll, yaw, pitch); return true; } bool snapshot_reprocessing::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); //判断算法开启,调整不用在此处判断,检测出来会进行过滤 } /* 删除指定快照 清空资源占用(使用场景:任务结束删除该路任务所有缓存快照;目标轨迹结束,分析保存完,删除该目标快照缓存)*/ void snapshot_reprocessing::delete_finishtask_snapshot(const string taskid, const int objid) { if (objid != -1) { OBJ_KEY cur_key = { taskid , objid }; auto &ss = total_snapshot_info[cur_key]; if (ss.snapShot.frame != nullptr) { cudaFree(ss.snapShot.frame); ss.snapShot.frame = nullptr; } if (ss.snapShotLittle.frame != nullptr) { cudaFree(ss.snapShotLittle.frame); ss.snapShotLittle.frame = nullptr; } total_snapshot_info.erase(cur_key); return; } for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end(); ) { if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) { if (ss->second.snapShot.frame != nullptr){ CHECK(cudaFree(ss->second.snapShot.frame)); ss->second.snapShot.frame = nullptr; } if (ss->second.snapShotLittle.frame != nullptr) { CHECK(cudaFree(ss->second.snapShotLittle.frame)); ss->second.snapShotLittle.frame = nullptr; } total_snapshot_info.erase(ss++); } else ss++; } for (auto f_ss = total_face_snapshot_info.begin(); f_ss != total_face_snapshot_info.end(); ) { if (strcmp(f_ss->first.video_id.c_str(), taskid.c_str()) == 0) { if (f_ss->second.snapShot.frame != nullptr) { CHECK(cudaFree(f_ss->second.snapShot.frame)); f_ss->second.snapShot.frame = nullptr; } if (f_ss->second.snapShotLittle.frame != nullptr) { CHECK(cudaFree(f_ss->second.snapShotLittle.frame)); f_ss->second.snapShotLittle.frame = nullptr; } total_face_snapshot_info.erase(f_ss++); } else f_ss++; } } void snapshot_reprocessing::snapshot_reprocessing_release() { }