FaceRecognition_SDK_hisiv300_A7
所属分类:模式识别(视觉/语音等)
开发工具:C++
文件大小:57013KB
下载次数:0
上传日期:2018-11-27 09:51:31
上 传 者:
sh-1993
说明: 人脸识别_SDK_hisiv300_A7,,
(FaceRecognition_SDK_hisiv300_A7,,)
文件列表:
3rdpartylibs (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3 (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cv.h (3153, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cv.hpp (2649, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cvaux.h (2523, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cvaux.hpp (2374, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cvwimage.h (2176, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cxcore.h (2424, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cxcore.hpp (2443, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cxeigen.hpp (2257, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\cxmisc.h (129, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\highgui.h (2226, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv\ml.h (2145, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2 (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core.hpp (150773, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\affine.hpp (21525, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\base.hpp (31336, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\bufferpool.hpp (845, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\check.hpp (6769, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\core.hpp (2366, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\core_c.h (130799, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda.hpp (36890, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda.inl.hpp (13916, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\block.hpp (8327, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\border_interpolate.hpp (24756, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\color.hpp (15518, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\common.hpp (3814, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\datamov_utils.hpp (4720, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail (0, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\color_detail.hpp (222523, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\reduce.hpp (15400, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\reduce_key_val.hpp (23329, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\transform_detail.hpp (17825, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\type_traits_detail.hpp (8599, 2018-11-27)
3rdpartylibs\opencv-3.4.3\include\opencv2\core\cuda\detail\vec_distance_detail.hpp (5219, 2018-11-27)
... ...
# FaceRecognition SDK A7 edition, cross compiled by Ubuntu16.04LTS 32bit
### SDK授权
SDK采用软授权,执行`example`,可以获取机器码。调用SetLicenseFile函数,可以设置授权文件的名称。
### 人脸比对一般流程
```flow
st=>start: 开始
op1=>operation: cv::imread,读取图片1和图片2(in BGR format)
op2=>operation: VisionFaceDetect,获取图片1和图片2中的人脸位置
op3=>operation: VisionFaceAlignment,归一化图片1和图片2中的人脸
op4=>operation: VisionFaceFeature,获取图片1和图片2中的人脸特征
op5=>operation: VisionFaceFeature,比对两人脸特征,获取相似度
e=>end: 结束
st->op1->op2->op3->op4->op5->e
```
### 1. 人脸检测
```c++
namespace vision {
class VISION_API VisionFaceDetect
{
public:
/* 默认析构函数 */
virtual ~VisionFaceDetect() {}
/* 初始化,输入参数文件param_path和所要使用的GPU编号device_id */
virtual bool Init(std::string param_path = "models/face_detect_cascade.json", int device_id = 0) = 0;
/* 输入一张图像img,获取人脸信息(包括人脸框和关键点);在输入视频的情况下,将is_video_stream设置为true,能够极大提升检测速度 */
virtual std::vector GetFaces(const cv::Mat& img, bool is_video_stream = false) = 0;
/* 输入一张图像img,返回所有的人脸框以及对应的人脸关键点(引用形式返回) */
virtual std::vector GetFaces(const cv::Mat& img, std::vector>& key_pts, bool is_video_stream = false) = 0;
/* 获取图像img中最大人脸的人脸框 */
virtual std::vector GetMaximumFace(const cv::Mat& img, bool is_video_stream = false) = 0;
/* 输入一张图像img,图像img中最大人脸的人脸框以及对应的人脸关键点(引用形式返回) */
virtual std::vector GetMaximumFace(const cv::Mat& img, std::vector>& key_pts, bool is_video_stream = false) = 0;
};
/* 构造对象,默认使用GPU 0 */
VISION_API VisionFaceDetect* instantiateVisionFaceDetect(int device_id = 0);
/* 销毁对象 */
VISION_API void destroyVisionFaceDetect(VisionFaceDetect* ptr);
}
```
示例代码
```c++
// 摄像头测试
void CameraTest()
{
VisionFaceDetect *face_detect = instantiateVisionFaceDetect();
cv::VideoCapture capture(0);
Mat img;
while (true)
{
capture >> img;
if (!img.empty()) {
Mat img_show = img.clone();
double start = cv::getTickCount();
std::vector face_rects;
std::vector> key_pts;
face_rects = face_detect->GetFaces(img, key_pts); // 获取人脸框位置同时获取每张脸的5个关键点
for (int i = 0; i < face_rects.size(); i++)
{
face_detect->DrawFaceRect(img_show, face_rects.at(i));
}
cv::imshow("img_show", img_show);
if (cv::waitKey(5) == 27)
{
break;
}
}
}
vision::destroyVisionFaceDetect(face_detect);
}
```
----
### 2. 关键点定位和归一化
```c++
namespace vision {
class VISION_API VisionFaceAlignment
{
public:
/* 默认析构函数 */
virtual ~VisionFaceAlignment() {}
/* 初始化,输入参数文件param_path和所要使用的GPU编号device_id */
virtual bool Init(std::string param_path = "models/face_align.json", int device_id = 0) = 0;
/* 输入一张图像img和人脸框face_rect,输出人脸的关键点位置 */
virtual std::vector GetKeyPoints(const cv::Mat& img, const cv::Rect& face_rect) = 0;
/* 批量获取人脸的关键点位置 */
virtual std::vector> GetKeyPoints(const cv::Mat& img, const std::vector& face_rects) = 0;
/* 输入一张图像img和人脸框face_rect,输出一张归一化人脸(180x220)。若padding是true,则在图像变换的时候采用周边的像素进行补充 */
virtual cv::Mat GetAlignedFace(const cv::Mat& img, const cv::Rect& face_rect, bool padding = false) = 0;
/* 批量获取归一化人脸 */
virtual std::vector GetAlignedFace(const cv::Mat& img, const std::vector& face_rect, bool padding = false) = 0;
/* 输入一张图像img和人脸关键点key_pts,输出一张归一化人脸 */
virtual cv::Mat GetAlignedFace(const cv::Mat& img, const std::vector& key_pts, bool padding = false) = 0;
/* 批量获取归一化人脸 */
virtual std::vector GetAlignedFace(const cv::Mat& img, const std::vector>& key_pts, bool padding = false) = 0;
};
/* 构造对象,新增变量device_id,默认使用GPU 0 */
VISION_API VisionFaceAlignment* instantiateVisionFaceAlignment(int device_id = 0);
/* 销毁对象 */
VISION_API void destroyVisionFaceAlignment(VisionFaceAlignment* ptr);
}
```
示例代码
```c++
void CameraTest()
{
VisionFaceDetect* face_detect = instantiateVisionFaceDetect();
VisionFaceAlignment* face_align = instantiateVisionFaceAlignment();
cv::VideoCapture capture(0);
Mat img;
while (true)
{
capture >> img;
std::vector> key_pts;
std::vector face_rects = face_detect->GetFaces(img, key_pts);
// warning: CPU模式下,人脸检测不会返回关键点,需要通过VisionFaceAlignment获取关键点
if (key_pts.size() == 0)
{
key_pts = face_align->GetKeyPoints(img, face_rects);
}
for (int i = 0; i < key_pts.size(); i++)
{
for (int j = 0; j < key_pts.at(i).size(); j++)
{
cv::circle(img, key_pts.at(i).at(j), 2, cv::Scalar(255, 0, 0), 2);
}
}
std::vector norm_faces = face_align->GetAlignedFace(img, key_pts);
if (norm_faces.size() > 0)
{
cv::imshow("norm_face", norm_faces[0]);
}
cv::imshow("alignment result", img);
if (cv::waitKey(5) == 27)
{
break;
}
}
vision::destroyVisionFaceDetect(face_detect);
vision::destroyVisionFaceAlignment(face_align);
}
```
----
### 3. 人脸特征提取与比对
```c++
namespace vision {
class VISION_API VisionFaceFeature
{
public:
/* 默认析构函数 */
virtual ~VisionFaceFeature() {}
/* 初始化,输入参数文件param_path和所要使用的GPU编号device_id */
virtual bool Init(std::string param_path = "models/face_feature.json", int device_id = 0) = 0;
/* 初始化,输入参数文件param_path和所要使用的GPU编号device_id,针对V3的模型【推荐使用】 */
virtual bool InitV3(std::string param_path = "face_feature_v3.param", int device_id = 0) = 0;
/* 获取输入归一化人脸图像img的特征 */
virtual std::vector GetFeature(const cv::Mat& img) = 0;
/* 批量获取归一化人脸图像特征 */
virtual std::vector> GetFeature(const std::vector& imgs) = 0;
/* 获取两张人脸特征的相似度 */
virtual float GetScore(const std::vector& fea1, const std::vector& fea2, bool origin_score = false) = 0;
};
/* 构造对象, 默认使用GPU 0 */
VISION_API VisionFaceFeature* instantiateVisionFaceFeature(int device_id = 0);
/* 销毁对象 */
VISION_API void destroyVisionFaceFeature(VisionFaceFeature* ptr);
}
```
人脸比对示例代码
```c++
int main(int argc, char** argv) {
//vision::SetLicenseFile("d:/dip/license.lic");
if (argc == 4) {
std::string model_name = std::string(argv[1]);
std::string image1_name = std::string(argv[2]);
std::string image2_name = std::string(argv[3]);
vision::VisionFaceDetect * face_detect = vision::instantiateVisionFaceDetect(); // 包含默认初始化参数,无需再次初始化
face_detect->SetMaxWidthGlobal(480);
face_detect->SetMinFaceSize(80);
vision::VisionFaceAlignment *face_alignment = vision::instantiateVisionFaceAlignment(); // 包含默认初始化参数,无需再次初始化
vision::VisionFaceFeature * face_feature = vision::instantiateVisionFaceFeature(); // 针对不同的使用场景,需要用特定的模型进行初始化
face_feature->InitV3(model_name);
cv::Mat img1 = cv::imread(image1_name);
cv::Mat img2 = cv::imread(image2_name);
// Perform Face Detect First
std::vector faces1 = face_detect->GetMaximumFace(img1);
if (faces1.size() < 1) {
std::cout << "Failed to detect a face in " << image1_name << ", exit." << std::endl;
exit(-1);
} else {
std::cout << "Face rectangle in " << image1_name << " is: " << faces1[0].bbox << std::endl;
}
std::vector faces2 = face_detect->GetMaximumFace(img2);
if (faces2.size() < 1) {
std::cout << "Failed to detect a face in " << image2_name << ", exit." << std::endl;
exit(-1);
} else {
std::cout << "Face rectangle in " << image2_name << " is: " << faces2[0].bbox << std::endl;
}
// Face Alignment
cv::Mat norm_face1 = face_alignment->GetAlignedFace(img1, faces1.at(0).key_pts);
cv::Mat norm_face2 = face_alignment->GetAlignedFace(img2, faces2.at(0).key_pts);
// Extract Face Feature
std::vector fea1 = face_feature->GetFeature(norm_face1);
std::vector fea2 = face_feature->GetFeature(norm_face2);
// Feature Comapre
std::cout << "Similarity: " << face_feature->GetScore(fea1, fea2) << std::endl;
vision::destroyVisionFaceDetect(face_detect);
vision::destroyVisionFaceAlignment(face_alignment);
vision::destroyVisionFaceFeature(face_feature);
} else {
std::string cmd = std::string(argv[0]);
std::cout << "Usage: " << cmd << " model_name image1 image2" << std::endl;
}
return 0;
}
```
### 使用建议及注意事项
- 根据业务场景使用`SetMinFaceSize`接口设置合理的最小人脸大小,以获取更快的人脸检测速度
- 根据业务场景使用`SetMaxWidthGlobal`接口设置合理的检测图像最长边大小,以获取更快的人脸检测速度
- 在嵌入式平台使用该模块,建议同比例减小`MinFaceSize`和`MaxWidthGlobal`,减少IO,加速人脸检测
- 两张人脸的相似度结果(比分0.5以上,说明像;比分0.65以上,比较像;比分0.75以上,非常像;该值的设定具体要参照业务场景)
----
## Contact
chendd14
近期下载者:
相关文件:
收藏者: