Opencv LBPH人脸识别算法详解
2019-05-21 07:07
1721 查看
简要:
LBPH(Local Binary PatternsHistograms)局部二进制编码直方图,建立在LBPH基础之上的人脸识别法基本思想如下:首先以每个像素为中心,判断与周围像素灰度值大小关系,对其进行二进制编码,从而获得整幅图像的LBP编码图像;再将LBP图像分为个区域,获取每个区域的LBP编码直方图,继而得到整幅图像的LBP编码直方图,通过比较不同人脸图像LBP编码直方图达到人脸识别的目的,其优点是不会受到光照、缩放、旋转和平移的影响。
#include<opencv2\opencv.hpp> #include<opencv2\face.hpp> using namespace cv; using namespace face; using namespace std; char win_title[40] = {}; int main(int arc, char** argv) { //namedWindow("input",CV_WINDOW_AUTOSIZE); //读入模型需要输入的数据,用来训练的图像vector<Mat>images和标签vector<int>labels string filename = string("path.txt"); ifstream file(filename); if (!file) { printf("could not load file"); } vector<Mat>images; vector<int>labels; char separator = ';'; string line,path, classlabel; while (getline(file,line)) { stringstream lines(line); getline(lines, path, separator); getline(lines, classlabel); //printf("%d\n", atoi(classlabel.c_str())); images.push_back(imread(path, 0)); labels.push_back(atoi(classlabel.c_str()));//atoi(ASCLL to int)将字符串转换为整数型 } int height = images[0].rows; int width = images[0].cols; printf("height:%d,width:%d\n", height, width); //将最后一个样本作为测试样本 Mat testSample = images[images.size() - 1]; int testLabel = labels[labels.size() - 1]; //删除列表末尾的元素 images.pop_back(); labels.pop_back(); //加载,训练,预测 Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create(); model->train(images, labels); int predictedLabel = model->predict(testSample); printf("actual label:%d,predict label :%d\n", testLabel, predictedLabel); int radius = model->getRadius(); int neibs = model->getNeighbors(); int grad_x = model->getGridX(); int grad_y = model->getGridY(); double t = model->getThreshold(); printf("radius:%d\n", radius); printf("neibs:%d\n", neibs); printf("grad_x:%d\n", grad_x); printf("grad_y:%d\n", grad_y); printf("threshold:%.2f\n", t); waitKey(0); return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 人脸识别算法-LBP算法及python实现
- OpenCV运动检测跟踪(blob track)框架组成模块详解
- OpenCV之亮度、对比度详解
- OpenCV矩阵的归一化和欧式距离详解
- OpenCV学习之CvMat的用法详解及实例(三)
- 【OpenCV3】cv::Mat类成员函数详解
- 关于opencv中人脸识别主函数的部分注释详解。
- OpenCV中的RANSAC详解
- win10下vs2015配置Opencv3.1.0过程详解
- Opencv研读笔记:haartraining程序之cvCreateMTStumpClassifier函数详解(弱分类器创建)~
- OpenCV学习之CvMat的用法详解及实例
- OpenCV学习笔记——数据结构Mat详解
- 【转】OpenCV中Mat的详解
- OpenCV Mat类详解和用法
- 【OpenCV】CvMat的用法详解及实例
- zz 详解linux下安装opencv2.4.1(eclipse)
- OpenCV参考手册之Mat类详解
- OpenCV参考手册之Mat类详解1
- 【opencv】 opencv之Mat详解
- opencv-dark channel -实现暗通道去雾详解