资讯 小学 初中 高中 语言 会计职称 学历提升 法考 计算机考试 医护考试 建工考试 教育百科
栏目分类:
子分类:
返回
空麓网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
空麓网 > 计算机考试 > 软件开发 > 后端开发 > C/C++/C#

Opencv LBPH人脸识别算法详解

C/C++/C# 更新时间: 发布时间: 计算机考试归档 最新发布

Opencv LBPH人脸识别算法详解

简要: 

LBPH(Local Binary PatternsHistograms)局部二进制编码直方图,建立在LBPH基础之上的人脸识别法基本思想如下:首先以每个像素为中心,判断与周围像素灰度值大小关系,对其进行二进制编码,从而获得整幅图像的LBP编码图像;再将LBP图像分为个区域,获取每个区域的LBP编码直方图,继而得到整幅图像的LBP编码直方图,通过比较不同人脸图像LBP编码直方图达到人脸识别的目的,其优点是不会受到光照、缩放、旋转和平移的影响。

#include
#include
using namespace cv;
using namespace face;
using namespace std;
char win_title[40] = {};
 
int main(int arc, char** argv) { 
 //namedWindow("input",CV_WINDOW_AUTOSIZE);
 
 //读入模型需要输入的数据,用来训练的图像vectorimages和标签vectorlabels
 string filename = string("path.txt");
 ifstream file(filename);
 if (!file) { printf("could not load file"); }
 vectorimages;
 vectorlabels;
 char separator = ';';
 string line,path, classlabel;
 while (getline(file,line)) {
 stringstream lines(line);
 getline(lines, path, separator);
 getline(lines, classlabel);
 //printf("%dn", 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:%dn", height, width);
 //将最后一个样本作为测试样本
 Mat testSample = images[images.size() - 1];
 int testLabel = labels[labels.size() - 1];
 //删除列表末尾的元素
 images.pop_back();
 labels.pop_back();
 
 //加载,训练,预测
 Ptr model = LBPHFaceRecognizer::create();
 model->train(images, labels);
 int predictedLabel = model->predict(testSample);
 printf("actual label:%d,predict label :%dn", 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:%dn", radius);
 printf("neibs:%dn", neibs);
 printf("grad_x:%dn", grad_x);
 printf("grad_y:%dn", grad_y);
 printf("threshold:%.2fn", t);
 
 waitKey(0);
 return 0;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持趣学号。

转载请注明:文章转载自 http://www.konglu.com/
本文地址:http://www.konglu.com/it/62420.html
免责声明:

我们致力于保护作者版权,注重分享,被刊用文章【Opencv LBPH人脸识别算法详解】因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理,本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即通知我们,情况属实,我们会第一时间予以删除,并同时向您表示歉意,谢谢!

我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2023 成都空麓科技有限公司

ICP备案号:蜀ICP备2023000828号-2