diff --git a/3rdparty/model/face_detect/libface_det_vdec.so b/3rdparty/model/face_detect/libface_det_vdec.so new file mode 100644 index 0000000..20eb303 --- /dev/null +++ b/3rdparty/model/face_detect/libface_det_vdec.so diff --git a/3rdparty/model/face_detect/models/face_det_yolov5s_310p.om b/3rdparty/model/face_detect/models/face_det_yolov5s_310p.om new file mode 100644 index 0000000..31ceac5 --- /dev/null +++ b/3rdparty/model/face_detect/models/face_det_yolov5s_310p.om diff --git a/3rdparty/model/face_detect/models/face_fuzzy_310p.om b/3rdparty/model/face_detect/models/face_fuzzy_310p.om new file mode 100644 index 0000000..e358f43 --- /dev/null +++ b/3rdparty/model/face_detect/models/face_fuzzy_310p.om diff --git a/3rdparty/model/face_detect/models/face_ldmk_310p.om b/3rdparty/model/face_detect/models/face_ldmk_310p.om new file mode 100644 index 0000000..77aef02 --- /dev/null +++ b/3rdparty/model/face_detect/models/face_ldmk_310p.om diff --git a/3rdparty/model/face_detect/models/face_occlusion_310p.om b/3rdparty/model/face_detect/models/face_occlusion_310p.om new file mode 100644 index 0000000..a54db8a --- /dev/null +++ b/3rdparty/model/face_detect/models/face_occlusion_310p.om diff --git a/3rdparty/model/face_detect/models/face_pose_310p.om b/3rdparty/model/face_detect/models/face_pose_310p.om new file mode 100644 index 0000000..f520940 --- /dev/null +++ b/3rdparty/model/face_detect/models/face_pose_310p.om diff --git a/3rdparty/model/face_detect/models/face_score_310p.om b/3rdparty/model/face_detect/models/face_score_310p.om new file mode 100644 index 0000000..52ec236 --- /dev/null +++ b/3rdparty/model/face_detect/models/face_score_310p.om diff --git a/3rdparty/model/face_detect/readme.txt b/3rdparty/model/face_detect/readme.txt new file mode 100644 index 0000000..ea04494 --- /dev/null +++ b/3rdparty/model/face_detect/readme.txt @@ -0,0 +1,25 @@ +人脸检测组件_x86_vdec_v0.0.2.20230704_withfixed_license + +支持系统: + Atlas x86 linux +文件清单: + face_detect.h: 接口文件 + libface_det_vdec.so: 依赖库文件 + models: 各模型文件 + test/: 测试文件 + test.cpp: 调用示例 + imgs:测试数据 + list.txt: 测试图片列表 + +更新内容: + -2023.06.15 编译ascend310p x86版本 + -2023.07.04 修复宽高对齐因素导致的精度不足问题 + -2023.07.12 宽高对齐约束与vdec一致 + + +注意事项说明: + -auth_license = "sy_tongtu_aiplatform_sdk_2023" + +中科院自动化所 模式识别实验室图像视频组 + +2023年07月12日 \ No newline at end of file diff --git a/3rdparty/model/face_detect/test/face_detect.h b/3rdparty/model/face_detect/test/face_detect.h new file mode 100644 index 0000000..cddb023 --- /dev/null +++ b/3rdparty/model/face_detect/test/face_detect.h @@ -0,0 +1,159 @@ +/************************************************************ +* Version: face_detect_v1.4.1.20201221.x86_64.gpu +* CopyRight: 中科视语(北京)科技有限公司 +* UpdateDate: 20201221 +* Content: +************************************************************/ +#ifndef FACEDETECT_H_ +#define FACEDETECT_H_ + +#ifdef _MSC_VER +#ifdef FACEDETECT_EXPORTS +#define FACEDETECT_API __declspec(dllexport) +#else +#define FACEDETECT_API __declspec(dllimport) +#endif +#else +#define FACEDETECT_API __attribute__ ((visibility ("default"))) +#endif +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "sy_common.h" //通用数据结构体定义 + +// #define GPUIMG_PROCESS + +#ifndef FACIALFEAPOINTSIZE //关键点检测支持25个点 +#define FACIALFEAPOINTSIZE 25 +#endif + + +#ifndef __FD_INFO__ +#define __FD_INFO__ + typedef struct fd_info { + sy_rect face_position; //人脸位置 + float face_pos_score; //人脸框置信度 + sy_point facial_fea_point[FACIALFEAPOINTSIZE]; //人脸关键点位置信息 + int occlusion; //人脸遮挡度,范围值为0-100,越大表示人脸遮挡程度越高 + int clarity; //人脸清晰度,范围值为0-100,越大表示图像越清晰,人脸清晰度判别建议阈值为30 + int brightness; //人脸亮度,只有3种可能的值:[-1->太暗,0->正常,1->太亮],亮度结果会受亮度阈值参数brightness_min和brightness_max影响 + //int hat; //带帽子,范围为0-100,越大表示越可能有佩戴帽子,建议判别阈值为50 + //int glass; //带眼镜,范围为0-100,越大表示越可能有戴眼镜,建议判别阈值为70 + float roll; //姿态角 + float yaw; //姿态角 + float pitch; //姿态角 + float score; //人脸置信度 + } fd_info; +#endif + +#ifndef __FD_RESULT__ +#define __FD_RESULT__ + typedef struct fd_result { //结果结构体 + fd_info *info; //内存由外部申请 + int count; //人脸个数 + } fd_result; +#endif + +#ifndef __FD_PARAM__ +#define __FD_PARAM__ + typedef struct fd_param + { + sy_command facial_fea_point_config; //是否启动关键点检测 + sy_command pose_config; //是否启动姿态角 + sy_command quality_config; //是否启动质量检测 + sy_command score_config; //是否启动人脸置信度 + // int log; //日志 + // int mode; //运行模式(DEVICE_GPU / DEVICE_CPU) + int devId; //指定显卡id + float thresld; //检测阈值 建议0.7 + + int max_result_count; //检测结果目标数上限 + // int max_batch_size_detect; //检测批处理检测数量上限 + // int max_batch_size_ldmk; //关键点批处理检测数量上限 + // int max_batch_size_pose; //姿态角批处理检测数量上限 + // int max_batch_size_score; //置信度批处理检测数量上限 + // int max_batch_size_blurglass; //质量(模糊)批处理检测数量上限 + // //int max_batch_size_hat; //质量(帽子)批处理检测数量上限 + // int max_batch_size_occlusion; //质量(遮挡)批处理检测数量上限 + + char * auth_license; + char* det_modelNames; //人脸检测 + char* ldmk_modelNames; //人脸关键点 + char* pose_modelNames; //人脸姿态 + char* score_modelNames; //人脸置信度 + char* fuzzy_modelNames; //人脸质量_模糊 + char* occlusion_modelNames; //人脸质量_遮挡 + + fd_param() : facial_fea_point_config(SY_CONFIG_OPEN), pose_config(SY_CONFIG_OPEN), \ + quality_config(SY_CONFIG_OPEN), score_config(SY_CONFIG_OPEN), thresld(0.6), devId(0), max_result_count(20), auth_license("") {}; //默认功能全部启动 + }fd_param; +#endif + + /************************************************************************* + * function: fd_init + * purpose: init resources + * param: + [in] handle - handle + [in] param - init param + * return: success(0) or error code(<0) + * notes: null + *************************************************************************/ + FACEDETECT_API int fd_init(void ** handle, fd_param param); + + + /************************************************************************* + * function: fd_release + * purpose: release sources + * param: + [in] handle - handle + * return: null + * notes: null + *************************************************************************/ + FACEDETECT_API void fd_release(void ** handle); + + /************************************************************************* + * function: fd_get_version + * purpose: get sdk version + * param: null + * return: null + * notes: null + *************************************************************************/ + FACEDETECT_API const char * fd_get_version(); + + /************************************************************************* + * function: fd_detect_batch + * purpose: detect faces + * param: + [in] handle - handle + [in] img_data_array - data array + [in] format - data format + [in] batch_size - batch size + [in] result - face detect result + * return: success(0) or error code(<0) + * notes: null + *************************************************************************/ + //FACEDETECT_API int fd_detect_batch(void * handle, sy_img * img_data_array, sy_format format, int batch_size, fd_result *result); + + /************************************************************************* + * function: fd_detect + * purpose: detect faces + * param: + [in] handle - handle + [in] img_data_array - data array + [in] format - data format + [in] result - face detect result + * return: success(0) or error code(<0) + * notes: null + *************************************************************************/ + FACEDETECT_API int fd_detect(void * handle, sy_img img_data, sy_format format, fd_result *result); + + + FACEDETECT_API int fd_detect_batch(void * handle, sy_img * img_data_array, sy_format format, int batch_size, fd_result *result); +#ifdef __cplusplus +}; +#endif + +#endif + diff --git a/3rdparty/model/face_detect/test/imgs/202205071457080003_146.jpg b/3rdparty/model/face_detect/test/imgs/202205071457080003_146.jpg new file mode 100644 index 0000000..9f789aa --- /dev/null +++ b/3rdparty/model/face_detect/test/imgs/202205071457080003_146.jpg diff --git a/3rdparty/model/face_detect/test/imgs/202205071527200001_1.jpg b/3rdparty/model/face_detect/test/imgs/202205071527200001_1.jpg new file mode 100644 index 0000000..ed107bc --- /dev/null +++ b/3rdparty/model/face_detect/test/imgs/202205071527200001_1.jpg diff --git a/3rdparty/model/face_detect/test/imgs/202205071527400003_2.jpg b/3rdparty/model/face_detect/test/imgs/202205071527400003_2.jpg new file mode 100644 index 0000000..95861ea --- /dev/null +++ b/3rdparty/model/face_detect/test/imgs/202205071527400003_2.jpg diff --git a/3rdparty/model/face_detect/test/list.txt b/3rdparty/model/face_detect/test/list.txt new file mode 100644 index 0000000..f18e3d3 --- /dev/null +++ b/3rdparty/model/face_detect/test/list.txt @@ -0,0 +1,3 @@ +202205071457080003_146.jpg +202205071527200001_1.jpg +202205071527400003_2.jpg diff --git a/3rdparty/model/face_detect/test/makefile b/3rdparty/model/face_detect/test/makefile new file mode 100644 index 0000000..bbc6c22 --- /dev/null +++ b/3rdparty/model/face_detect/test/makefile @@ -0,0 +1,86 @@ +XX = g++ + + +PROJECT_ROOT= /data/cmhu/vpt_ascend + +DEPEND_DIR = $(PROJECT_ROOT)/bin +SRC_ROOT = $(PROJECT_ROOT)/src + +TARGET= $(PROJECT_ROOT)/bin/face_test + +THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty +SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release +# OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1 +OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv-4.5.4/release +JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release +FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release +RABBITMQ_CLIENT_ROOT = $(THIRDPARTY_ROOT)/rabbitmq-c-0.11.0/release +BOOST_ROOT = $(THIRDPARTY_ROOT)/boost_1_81_0/release +WEBSOCKETPP_ROOT = $(THIRDPARTY_ROOT)/websocketpp-0.8.2/release/include \ + +JRTP_ROOT = $(THIRDPARTY_ROOT)/gb28181_3rd/jrtp_export + +DEFS = -DENABLE_DVPP_INTERFACE -DWITH_FACE_DET_SS +# DEFS = -DENABLE_DVPP_INTERFACE -DUSE_VILLAGE -DPOST_USE_RABBITMQ + +include_dir=-I/usr/local/Ascend/ascend-toolkit/latest/include \ + -I $(SRC_ROOT)/common \ + -I $(SPDLOG_ROOT)/include \ + -I $(OPENCV_ROOT)/include/opencv4 \ + -I $(JSON_ROOT)/include \ + -I $(FFMPEG_ROOT)/include \ + -I $(RABBITMQ_CLIENT_ROOT)/include \ + -I $(JRTP_ROOT)/jrtplib/include/jrtplib3 \ + -I $(SRC_ROOT)/decoder/gb28181/rtp \ + -I $(SRC_ROOT)/decoder/gb28181 \ + -I $(WEBSOCKETPP_ROOT) \ + -I $(BOOST_ROOT)/include \ + -I $(SRC_ROOT)/common \ + -I $(SRC_ROOT)/common/dvpp \ + + +LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ + -L $(DEPEND_DIR) -lface_det_vdec \ + -L $(OPENCV_ROOT)/lib -lopencv_world\ + -L $(JSON_ROOT)/lib -l:libjsoncpp.a \ + -L $(FFMPEG_ROOT)/lib -l:libavformat.a -l:libavcodec.a -l:libswscale.a -l:libavutil.a -l:libavfilter.a -l:libswresample.a -l:libavdevice.a -l:libx264.a\ + -L $(RABBITMQ_CLIENT_ROOT)/lib/x86_64-linux-gnu -l:librabbitmq.a \ + -L $(JRTP_ROOT)/jrtplib/lib -l:libjrtp.a \ + -L/usr/local/Ascend/ascend-toolkit/latest/runtime/lib64 -lacl_dvpp -lascendcl \ + -L $(BOOST_ROOT)/lib -lboost_system \ + + + +CXXFLAGS= -g -O0 -fPIC $(include_dir) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl + + + +SRCS:=$(wildcard $(THIRDPARTY_ROOT)/model/face_detect/test/*.cpp) \ + $(wildcard $(SRC_ROOT)/common/*.cpp) \ + $(wildcard $(SRC_ROOT)/common/dvpp/*.cpp) \ + + +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) + + +$(TARGET):$(OBJS) + rm -f $(TARGET) + $(XX) -o $@ $^ $(CXXFLAGS) + rm -f *.o + +%.o:$(THIRDPARTY_ROOT)/model/face_detect/test/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/common/dvpp/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/common/%.cpp + $(XX) $(CXXFLAGS) -c $< + + +clean: + rm -f *.o $(TARGET) + + +cleano: + rm -f *.o \ No newline at end of file diff --git a/3rdparty/model/face_detect/test/stream_data.h b/3rdparty/model/face_detect/test/stream_data.h new file mode 100644 index 0000000..5b3131b --- /dev/null +++ b/3rdparty/model/face_detect/test/stream_data.h @@ -0,0 +1,15 @@ +#ifndef _STREAM_DATA_H_ +#define _STREAM_DATA_H_ + +#include + +struct ImageData { + uint32_t width = 0; + uint32_t height = 0; + uint32_t alignWidth = 0; + uint32_t alignHeight = 0; + uint32_t size = 0; + std::shared_ptr data; +}; + +#endif \ No newline at end of file diff --git a/3rdparty/model/face_detect/test/test.cpp b/3rdparty/model/face_detect/test/test.cpp new file mode 100644 index 0000000..17b585d --- /dev/null +++ b/3rdparty/model/face_detect/test/test.cpp @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#include +#include "face_detect.h" +#include "opencv2/opencv.hpp" +#include "opencv2/imgcodecs/legacy/constants_c.h" +#include "opencv2/imgproc/types_c.h" +#include "time.h" +#include "sys/time.h" +#include "sy_errorinfo.h" +#include "utils.h" +#include "dvpp_process.h" + +using namespace std; +using namespace cv; + +double msecond() { + struct timeval tv; + gettimeofday(&tv, 0); + return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0); +} + + +void getAllNm(std::string pthNm, std::vector& fileList) +{ + DIR *dir; + struct dirent *ptr; + dir = opendir(pthNm.c_str()); ///open the dir + int filenum = 0; + while((ptr = readdir(dir)) != NULL) ///read the list of this dir + { + // char* to string + std::string curNm = ptr->d_name; + if(curNm != "." && curNm != "..") + { + filenum++; + fileList.push_back(curNm); + //printf("file %d name: %s\n", filenum, curNm.c_str()); + } + } + closedir(dir); +} + +void CvBGR2NV21(Mat& bgr, unsigned char* yuv) { + int stride = (bgr.cols + 15) / 16 * 16; + int strideH = (bgr.rows + 1) / 2 * 2; + for (int i = 0; i < bgr.rows; i++) { + for (int j = 0; j < bgr.cols; j++) { + int B = bgr.at(i, j)[0]; + int G = bgr.at(i, j)[1]; + int R = bgr.at(i, j)[2]; + + int Y = (77 * R + 150 * G + 29 * B) >> 8; + yuv[i * stride + j] = (Y < 0) ? 0 : ((Y > 255) ? 255 : Y); + if (i % 2 == 0 && j % 2 == 0) { + int V = ((-44 * R - 87 * G + 131 * B) >> 8) + 128; /// + int U = ((131 * R - 110 * G - 21 * B) >> 8) + 128; /// + yuv[strideH * stride + i / 2 * stride + j] = (V < 0) ? 0 : ((V > 255) ? 255 : V); + yuv[strideH * stride + i / 2 * stride + j + 1] = (U < 0) ? 0 : ((U > 255) ? 255 : U); + } + } + } +} + +int main() { + cout << fd_get_version() << endl; + + fd_param param; + param.det_modelNames = "./models/face_detect/face_det_yolov5s_310p.om"; + param.ldmk_modelNames = "./models/face_detect/face_ldmk_310p.om"; + param.pose_modelNames = "./models/face_detect/face_pose_310p.om"; + param.score_modelNames = "./models/face_detect/face_score_310p.om"; + param.fuzzy_modelNames = "./models/face_detect/face_fuzzy_310p.om"; + param.occlusion_modelNames = "./models/face_detect/face_occlusion_310p.om"; + param.thresld = 0.2; + param.devId = 0; + param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; + 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; + + void* handle = nullptr; + cout << "init start " << endl; + ACL_CALL(aclInit(nullptr), ACL_SUCCESS, SY_FAILED); + ACL_CALL(aclrtSetDevice(param.devId), ACL_SUCCESS, SY_FAILED); + aclrtContext ctx; + ACL_CALL(aclrtCreateContext(&ctx, param.devId), ACL_SUCCESS, SY_FAILED); + aclrtStream stream = nullptr; + ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED); + DvppProcess* dvpp = new DvppProcess(); + dvpp->InitResource(stream); + int ret = fd_init(&handle, param); + + if (ret == 0) { + cout << "init success " << endl; + const char* img_file_path="imgs/"; + + ifstream infile("list.txt"); + string file; + while (infile >> file) { + string filename = "imgs/" + file; + cout << "img path: " << filename << endl; + const int batchsize = 1; + Mat cvImg = imread(filename.c_str()); + sy_img imgs[batchsize]; + + /* + ImageData src[batchsize], dvpp_data[batchsize]; + for (int b = 0; b < batchsize; b++) { + Utils::ReadImageFile(src[b], filename); //将二进制图像读入内存,并读取宽高信息 + ACL_CALL(dvpp->CvtJpegToYuv420sp(dvpp_data[b], src[b]), SY_SUCCESS, SY_FAILED); //解码 + imgs[b].w_ = dvpp_data[b].width; + imgs[b].h_ = dvpp_data[b].height; + imgs[b].data_ = dvpp_data[b].data.get(); + cout << dvpp_data[b].size << endl; + }*/ + + uint32_t alignWidth = (cvImg.cols + 15) / 16 * 16; + uint32_t alignHeight = (cvImg.rows + 1) / 2 * 2; + uint32_t size = alignWidth * alignHeight * 1.5; + cout << "opencv:"< data = shared_ptr((new uint8_t[size]), + [](uint8_t* p) {delete [] p;}); + CvBGR2NV21(cvImg, data.get()); + + for (int i = 0; i < batchsize; i++) { + imgs[i].w_ = cvImg.cols; + imgs[i].h_ = cvImg.rows; + imgs[i].data_ = data.get(); + } + + fd_result results[batchsize]; + for (int fd_i = 0; fd_i < batchsize; fd_i++) { + results[fd_i].info = new fd_info[50]; //内存由外部申请 + } + double t1, t2; + t1 = msecond(); + int ret = fd_detect_batch(handle, imgs, SY_FORMAT_BGR888, batchsize, results); + t2 = msecond(); + printf("debug mean process time: %.2f\n", (t2 - t1)/batchsize); + if (SY_SUCCESS != ret) { + printf("vpr detection process failed!"); + return SY_FAILED; + } + + // draw results + for(int b = 0; b < batchsize; b ++){ + printf("debug det num:%d\n",results[b].count); + for (int j = 0; j < results[b].count; j++) { + printf("fd_detect_batch %d - %d %d %d %d %d\n", b, j, results[b].info[j].face_position.left_, results[b].info[j].face_position.top_, results[b].info[j].face_position.width_, results[b].info[j].face_position.height_); + rectangle(cvImg, Rect(results[b].info[j].face_position.left_, results[b].info[j].face_position.top_, results[b].info[j].face_position.width_, results[b].info[j].face_position.height_), Scalar(0, 0, 255), 3); + for (int f = 0; f < 25; f++) { + cv::circle(cvImg, cv::Point(results[b].info[j].facial_fea_point[f].x_, results[b].info[j].facial_fea_point[f].y_), 1, Scalar(0, 0, 255), 1); + } + + cout << "detect_score:" << results[b].info[j].face_pos_score << endl; + printf("angle: pitch: %.2f, roll: %.2f, yaw: %.2f, score = %.2f \n", results[b].info[j].pitch, results[b].info[j].roll, results[b].info[j].yaw, results[b].info[j].score); + printf("occlusion: %d clarity: %d brightness: %d\n", results[b].info[j].occlusion, results[b].info[j].clarity, results[b].info[j].brightness/*, results[b].info[j].hat, results[b].info[j].glass*/); + printf("----- ldmk = (%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", results[b].info[j].facial_fea_point[0].x_, results[b].info[j].facial_fea_point[0].y_, results[b].info[j].facial_fea_point[1].x_, results[b].info[j].facial_fea_point[1].y_, results[b].info[j].facial_fea_point[2].x_, results[b].info[j].facial_fea_point[2].y_, results[b].info[j].facial_fea_point[3].x_, results[b].info[j].facial_fea_point[3].y_); + printf("----- ldmk eye center = (%d,%d) ldmk lip up center = (%d,%d)\n", results[b].info[j].facial_fea_point[6].x_, results[b].info[j].facial_fea_point[6].y_, results[b].info[j].facial_fea_point[8].x_, results[b].info[j].facial_fea_point[8].y_); + + } + } + string jpgSaveName = "result/" + file; + cv::imwrite(jpgSaveName, cvImg); + + for (int fd_i = 0; fd_i < batchsize; fd_i++) { + delete[] results[fd_i].info; + results[fd_i].info = NULL; + } + + } + } + + dvpp->DestroyResource(); + fd_release(&handle); + aclFinalize(); + + return 0; +}