opencv3.0使用Eigen方法进行人脸识别的方法
2016-05-08 01:34
561 查看
直接上代码
#include <opencv2\core.hpp> #include <opencv2\face.hpp> #include <opencv2\highgui.hpp> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <algorithm> #include <vector> #include <list> #include <set> #include <iostream> using namespace cv; using namespace cv::face; using namespace std; void read_csv(const char *filename, vector<Mat>& images, vector<int>labels, char separator = ';') { FILE *fp = fopen(filename, "r"); if (fp == NULL) { cout << "File not valid.\n"; return; } char path[128]; int lab; while (memset(path,0,sizeof(path)),fscanf(fp, "%s;%d", path, &lab) != EOF) { images.push_back(imread(path)); labels.push_back(lab); } return; } int main() { vector<Mat>images; vector<int>labels; char *filename = "C:\\faces\\csv.txt"; read_csv(filename, images, labels); if (images.size() <= 1) { cout << "Need More pics\n"; return 0; } int height = images[0].rows; Mat testSample = images[images.size() - 1]; int testLable = labels[labels.size() - 1]; images.pop_back(); labels.pop_back(); Ptr<FaceRecognizer> model = createEigenFaceRecognizer(); model->train(images, labels); int prediclabel; double confidence; model->predict(testSample, prediclabel, confidence); imshow("test",testSample); cout << testLable << "\t" << confidence << endl; waitKey(0); return 0; }
相关文章推荐
- linux------虚拟机的桥接模式和NAT模式的区别
- [记录]几个cheatsheet网站
- 网站渗透思路
- Linux TroubleShooting
- Linux的常用操作命令
- Linux 下的复制cp命令
- OperationalError:(1054 - "Unknown column 'game.lable1' in 'field list' ")解决办法
- Ubuntu 14.04 安装和配置Tomcat
- 正确设置php-fpm子进程用户 提高网站安全性
- php 在centos7 apache中的安装配置
- linux下如何用GDB调试c++程序
- mvware虚拟机安装ubuntu
- 钓鱼网站排名出炉:“建设银行”成榜首
- 开源新闻速递:Linux 内核 4.6 即将发布
- CentOS7 编译 Gradle
- Linux命令总结
- Spark定制班第3课:通过案例对SparkStreaming透彻理解三板斧之三:解密Spark Streaming运行机制和架构进阶之Job和容错
- linux文件系统简介
- tomcat报内存溢出解决方案
- Nginx搭建负载环境