资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

OpencvLBPH人脸识别算法详解-创新互联

简要: 

创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于网站建设、做网站、河北网络推广、微信小程序开发、河北网络营销、河北企业策划、河北品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;创新互联建站为所有大学生创业者提供河北建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

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("%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 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;
}

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:OpencvLBPH人脸识别算法详解-创新互联
当前地址:http://cdkjz.cn/article/depogg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220