1 Star 1 Fork 0

LinYe2830/face_camera

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
my_dlib.h 4.32 KB
一键复制 编辑 原始数据 按行查看 历史
LinYe2830 提交于 2023-06-04 18:58 . 第一次上传
#ifndef MY_DLIB_H
#define MY_DLIB_H
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/dnn.h>
#include <opencv2/opencv.hpp>
#include<QVector>
using namespace dlib;
/*
* my_dlib类 包含所有对dlib库的操作包括:
* 1,生成csv文件
* 2,读取cvs文件内容
*
*/
/*
* # 要读取人脸图像文件的路径
path_images_from_camera = "D:/QT_file/opencv_test/face_camera/data"
# Dlib 正向人脸检测器
detector = dlib.get_frontal_face_detector()
# Dlib 人脸预测器
predictor = dlib.shape_predictor("./model/shape_predictor_68_face_landmarks.dat")
# Dlib 人脸识别模型
# Face recognition model, the object maps human faces into 128D vectors
face_rec = dlib.face_recognition_model_v1("./model/dlib_face_recognition_resnet_model_v1.dat")
*/
// anet_type的声明
//----------------------------------------------------------------
template <template <int, template<typename>class, int, typename> class block, int N, template<typename>class BN, typename SUBNET>
using residual = dlib::add_prev1<block<N, BN, 1, dlib::tag1<SUBNET>>>;
template <template <int, template<typename>class, int, typename> class block, int N, template<typename>class BN, typename SUBNET>
using residual_down = dlib::add_prev2<dlib::avg_pool<2, 2, 2, 2, dlib::skip1<dlib::tag2<block<N, BN, 2, dlib::tag1<SUBNET>>>>>>;
template <int N, template <typename> class BN, int stride, typename SUBNET>
using block = BN<dlib::con<N, 3, 3, 1, 1, dlib::relu<BN<dlib::con<N, 3, 3, stride, stride, SUBNET>>>>>;
template <int N, typename SUBNET> using ares = dlib::relu<residual<block, N, dlib::affine, SUBNET>>;
template <int N, typename SUBNET> using ares_down = dlib::relu<residual_down<block, N, dlib::affine, SUBNET>>;
template <typename SUBNET> using alevel0 = ares_down<256, SUBNET>;
template <typename SUBNET> using alevel1 = ares<256, ares<256, ares_down<256, SUBNET>>>;
template <typename SUBNET> using alevel2 = ares<128, ares<128, ares_down<128, SUBNET>>>;
template <typename SUBNET> using alevel3 = ares<64, ares<64, ares<64, ares_down<64, SUBNET>>>>;
template <typename SUBNET> using alevel4 = ares<32, ares<32, ares<32, SUBNET>>>;
using anet_type = dlib::loss_metric<dlib::fc_no_bias<128, dlib::avg_pool_everything<
alevel0<
alevel1<
alevel2<
alevel3<
alevel4<
dlib::max_pool<3, 3, 2, 2, dlib::relu<dlib::affine<dlib::con<32, 7, 7, 2, 2,
dlib::input_rgb_image_sized<150>
>>>>>>>>>>>>;
//----------------------------------------------------------------
//一张人脸的信息
typedef struct FaceDescribe_S {
cv::Rect rect; //矩形框
std::string name = ""; //人脸姓名
float similarity = 0.f;
std::vector<cv::Point> marks; //脸部标记点
dlib::matrix<dlib::rgb_pixel> face; //脸部图片
dlib::matrix<float, 0, 1> desc; //脸部数据
}FaceDescribe;
typedef std::vector<FaceDescribe> FaceDescribes;
class my_dlib
{
public:
my_dlib();
//读取所有人脸数据,并保存为csv
void read_all_file(); //设置为静态,在input_face里面使用
// //将计算出来的数据保存到csv中
// bool save_to_csv(std::vector<std::vector<matrix<float, 0, 1>>>&);
//Mat转化为 faceDesc
bool read_imag_of_Name(const QString);
//接受人脸mat 返回是否是指定人脸的姓名
QString recognition_face(const cv::Mat &cap);
private:
QVector<QVector<float>> data_csv; //存放读取的csv
//std::vector<matrix<float, 0, 1>> vec; //定义一个向量组,用于存放每一个人脸的编码
QVector<QString> folder_name; //存放人脸文件夹名
//三个模型
anet_type net; //model
dlib::frontal_face_detector detector ;
dlib::shape_predictor sp; // landmarks
};
#endif // MY_DLIB_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linye2830/face_camera.git
git@gitee.com:linye2830/face_camera.git
linye2830
face_camera
face_camera
master

搜索帮助