#include "FaceDetModule.h" #include #include "opencv2/highgui/highgui.hpp" #include #include #include #include "CropImg.h" auto sy_process_param_check = [](void *handle, sy_img* img, int batchsize)->bool { if (handle == nullptr) { printf("error: face det handle nullptr!"); return FAILED; } if (batchsize == 0) { printf("error: face det batchsize zore!"); return FAILED; } for (int i = 0; i < batchsize; i++) { if (img[i].data_ == nullptr || img[i].h_ == 0 || img[i].w_ == 0 || img[i].c_ == 0) { printf("error: face det image nullptr!"); return FAILED; } } }; int face_det_module::face_det_module_init(int gpuid, char* auth_license) { m_face_det_handle = nullptr; fd_param param; param.thresld = 0.6; param.gpuid = 0; param.mode = DEVICE_GPU; param.log = SY_CONFIG_OPEN; param.facial_fea_point_config = SY_CONFIG_OPEN; //�Ƿ������ؼ����� param.pose_config = SY_CONFIG_OPEN; //�Ƿ�������̬�� param.quality_config = SY_CONFIG_OPEN; //�Ƿ������������ param.score_config = SY_CONFIG_OPEN; //�Ƿ������������Ŷ� //SY_CONFIG_OPEN SY_CONFIG_CLOSE param.max_result_count = 100; param.auth_license = "sy_va_sub_sdk_2023"; // param.max_batch_size_detect = 10; // param.max_batch_size_ldmk = 10; // param.max_batch_size_pose = 10; // param.max_batch_size_score = 10; // param.max_batch_size_blurglass = 10; // //param.max_batch_size_hat = 4; // param.max_batch_size_occlusion = 10; param.serialize_file = "./serialize_file/FD"; int flagFD = fd_init(&m_face_det_handle, param); if(flagFD != 0) { printf("fd_init failed\n"); return FAILED; } //return SUCCESS; const int batchsize = 20; fd_result result[batchsize]; for (int fd_i = 0; fd_i < batchsize; fd_i++) { result[fd_i].info = new fd_info[10]; //�ڴ����ⲿ���� } cv::Mat img[batchsize]; sy_img syimg[batchsize]; for (int i = 0; i < batchsize; i++) { cv::Mat tmp_img(224, 112, CV_8UC3); img[i] = tmp_img.clone(); syimg[i].set_data(img[i].cols, img[i].rows, img[i].channels(), img[i].data); } int ret = 0; ret = fd_detect_batch(m_face_det_handle, syimg, SY_FORMAT_BGR888, batchsize, result); printf("end fd init\n"); return SUCCESS; } int face_det_module::face_det_module_process(sy_img* img, int batchsize, fd_result *face_det_result, sy_point* original_size) { if (sy_process_param_check(m_face_det_handle, img, batchsize) == FAILED) return FAILED; sy_img *cpu_img = new sy_img[batchsize]; for (int b = 0; b < batchsize; b++) { cpu_img[b].c_ = 3; cpu_img[b].w_ = original_size[b].x_; cpu_img[b].h_ = original_size[b].y_; cudaMalloc(&cpu_img[b].data_, sizeof(uchar)*cpu_img[b].c_*cpu_img[b].w_*cpu_img[b].h_); cudacommon::ResizeImgGpu_int8(img[b].data_, img[b].w_ , img[b].h_, cpu_img[b].data_, cpu_img[b].w_, cpu_img[b].h_); } for (int ii = 0; ii < batchsize; ii++) { face_det_result[ii].count = 0; for (int c = 0; c < 10; c++) { memset((void*)&face_det_result[ii].info[c], 0, sizeof(fd_info)); } } int ret = fd_detect_batch(m_face_det_handle, cpu_img, SY_FORMAT_BGR888, batchsize, face_det_result); for (int b = 0; b < batchsize; b++) { int real_count = 0; for (int c = 0; c < face_det_result[b].count; c++) { if (face_det_result[b].info[c].score >= 0.5) { memcpy((void*)&face_det_result[b].info[real_count], (void*)&face_det_result[b].info[c], sizeof(fd_info)); real_count++; } } face_det_result[b].count = real_count; } for (int b = 0; b < batchsize; b++) { if(cpu_img[b].data_) { cudaFree(cpu_img[b].data_); } } if (cpu_img) delete[] cpu_img; return ret; } void face_det_module::face_det_module_release() { fd_release(&m_face_det_handle); }