SeetaFaceDetection识别人脸

  1. #pragma warning(disable: 4819)
  2.  
  3. #include <seeta/FaceEngine.h>
  4.  
  5. #include <seeta/Struct_cv.h>
  6. #include <seeta/Struct.h>
  7.  
  8. #include <opencv2/highgui/highgui.hpp>
  9. #include <opencv2/imgproc/imgproc.hpp>
  10. #include <array>
  11. #include <map>
  12. #include <iostream>
  13.  
  14. #include <qdebug.h>
  15. #include <QDateTime>
  16.  
  17. int main()
  18. {
  19. seeta::ModelSetting::Device device = seeta::ModelSetting::CPU;
  20. int id = ;
  21. seeta::ModelSetting FD_model("E:\\SeetaFaceEngine2\\SeetaFace2_install\\model\\fd_2_00.dat", device, id);
  22. seeta::ModelSetting PD_model("E:\\SeetaFaceEngine2\\SeetaFace2_install\\model\\pd_2_00_pts5.dat", device, id);
  23. seeta::ModelSetting FR_model("E:\\SeetaFaceEngine2\\SeetaFace2_install\\model\\fr_2_10.dat", device, id);
  24. seeta::FaceEngine engine(FD_model, PD_model, FR_model, , );
  25.  
  26. // recognization threshold
  27. float threshold = 0.5f;
  28.  
  29. //set face detector's min face size
  30. engine.FD.set(seeta::FaceDetector::PROPERTY_MIN_FACE_SIZE, );
  31.  
  32. //std::vector<std::string> GalleryImageFilename = { "E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\5.jpg" };
  33. std::vector<std::string> GalleryImageFilename = { "E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\1.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\2.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\3.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\4.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\5.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\6.jpg","E:\\SeetaFaceEngine2\\SeetaFace2_install\\data\\7.jpg" };
  34.  
  35. std::vector<int64_t> GalleryIndex(GalleryImageFilename.size());
  36. for (size_t i = ; i < GalleryImageFilename.size(); ++i)
  37. {
  38. //register face into facedatabase
  39. std::string &filename = GalleryImageFilename[i];
  40. int64_t &index = GalleryIndex[i];
  41. std::cerr << "Registering... " << filename << std::endl;
  42. seeta::cv::ImageData image = cv::imread(filename);
  43. auto id = engine.Register(image);
  44. index = id;
  45. std::cerr << "Registered id = " << id << std::endl;
  46. }
  47. std::map<int64_t, std::string> GalleryIndexMap;
  48. for (size_t i = ; i < GalleryIndex.size(); ++i)
  49. {
  50. // save index and name pair
  51. if (GalleryIndex[i] < ) continue;
  52. GalleryIndexMap.insert(std::make_pair(GalleryIndex[i], GalleryImageFilename[i]));
  53. }
  54.  
  55. std::cout << "----open camera----" << std::endl;
  56. // Open default USB camera
  57. cv::VideoCapture capture;
  58. capture.open();
  59.  
  60. cv::Mat frame;
  61.  
  62. int width1 = ;
  63. int height1 = ;
  64. while (capture.isOpened())
  65. {
  66. capture >> frame;
  67. if (frame.empty()) continue;
  68.  
  69. width1 = frame.cols;
  70. height1 = frame.rows;
  71. cv::resize(frame, frame, cv::Size(width1 / , height1 / ));
  72. seeta::cv::ImageData image = frame;
  73.  
  74. // Detect all faces
  75. std::vector<SeetaFaceInfo> faces = engine.DetectFaces(image);
  76.  
  77. for (SeetaFaceInfo &face : faces)
  78. {
  79. // Query top 1
  80. int64_t index = -;
  81. float similarity = ;
  82.  
  83. qDebug() << "-----------------------------------";
  84. //auto points = engine.DetectPoints(image, face);
  85. std::vector<SeetaPointF> points = engine.DetectPoints(image, face);
  86. std::vector<SeetaPointF>::iterator iter_1;
  87. for (iter_1 = points.begin(); iter_1 != points.end();++iter_1)
  88. {
  89. SeetaPointF sp1 = *iter_1;
  90. qDebug() << "x:" << sp1.x << " y:" << sp1.y;
  91. }
  92. qDebug() << "-----------------------------------";
  93.  
  94. auto queried = engine.QueryTop(image, points.data(), , &index, &similarity);
  95.  
  96. cv::rectangle(frame, cv::Rect(face.pos.x, face.pos.y, face.pos.width, face.pos.height), CV_RGB(, , ), );
  97. for (int i = ; i < ; ++i)
  98. {
  99. auto &point = points[i];
  100. cv::circle(frame, cv::Point(int(point.x), int(point.y)), , CV_RGB(, , ), -);
  101. }
  102.  
  103. // no face queried from database
  104. if (queried < ) continue;
  105.  
  106. std::cout << "similarity:" << similarity << std::endl;
  107. // similarity greater than threshold, means recognized
  108. if (similarity > threshold)
  109. {
  110. std::cout << "person:" << GalleryIndexMap[index] << std::endl;
  111. cv::putText(frame, GalleryIndexMap[index], cv::Point(face.pos.x, face.pos.y - ), , , CV_RGB(, , ));
  112.  
  113. /////////
  114. QDateTime qdt1 = QDateTime::currentDateTime();
  115. QString timeStr = qdt1.toString("yyyyMMddhhmmsszzz");
  116. QString picStr = timeStr.append(".jpg");
  117.  
  118. cv::imwrite(picStr.toStdString(), frame);
  119. }
  120. }
  121.  
  122. cv::imshow("Frame", frame);
  123.  
  124. auto key = cv::waitKey();
  125. if (key == )
  126. {
  127. break;
  128. }
  129. }
  130. }

SeetaFaceDetection识别人脸的更多相关文章

  1. 转:基于开源项目OpenCV的人脸识别Demo版整理(不仅可以识别人脸,还可以识别眼睛鼻子嘴等)【模式识别中的翘楚】

    文章来自于:http://blog.renren.com/share/246648717/8171467499 基于开源项目OpenCV的人脸识别Demo版整理(不仅可以识别人脸,还可以识别眼睛鼻子嘴 ...

  2. 写给程序员的机器学习入门 (十) - 对象识别 Faster-RCNN - 识别人脸位置与是否戴口罩

    每次看到大数据人脸识别抓逃犯的新闻我都会感叹技术发展的太快了,国家治安水平也越来越好了

  3. 写给程序员的机器学习入门 (十一) - 对象识别 YOLO - 识别人脸位置与是否戴口罩

    这篇将会介绍目前最流行的对象识别模型 YOLO,YOLO 的特征是快,识别速度非常快

  4. 使用Python结合Face++ API识别人脸

    Face++是北京旷视科技旗下的视觉服务平台,可以进行人脸识别.检测等功能.其人脸识别技术据悉在目前准确率较高,其API非常友好,免费使用,功能众多,而且调用几乎没有限制.这里我使用了Python调用 ...

  5. 使用OpenCV训练好的级联分类器识别人脸

    一.使用OpenCV训练好的级联分类器来识别图像中的人脸 当然还有很多其他的分类器,例如表情识别,鼻子等,具体可在这里下载: OpenCV分类器 import cv2 # 矩形颜色和描边 color ...

  6. 指纹识别人脸识别 iOS

    //1.判断iOS8及以后的版本 if([UIDevice currentDevice].systemVersion.doubleValue >= 8.0){ //从iPhone5S开始,出现指 ...

  7. 用Azure上Cognitive Service的Face API识别人脸

    Azure在China已经发布了Cognitive Service,包括人脸识别.计算机视觉识别和情绪识别等服务. 本文将介绍如何用Face API识别本地或URL的人脸. 一 创建Cognitive ...

  8. 4、基于JZ2440之编写测试代码处理(处理图片识别人脸)

    1.代码如下: void detectAndDisplay(Mat image) { CascadeClassifier ccf; //创建脸部对象 //ccf.load(xmlPath); //导入 ...

  9. OpenCV人脸识别Eigen算法源码分析

    1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...

随机推荐

  1. 1216 Vue基础

    目录 前端框架 Vue 1.简介 1.1 优点 2 使用 2.1 基础 2.2 文本指令 2.3 事件指令 2.4 属性指令 JS面向对象补充 前端框架 angular ---更新程度太快,且不向下兼 ...

  2. 《少年先疯队》第九次团队作业:Beta冲刺第一天

    1.1 今日完成任务情况 姚玉婷:酒店会员中房间管理功能的完善 马丽莎:登录功能测试文档的编写 张   琼:不同用户登录功能的测试,如管理员和会员 孙苗坤:登录功能测试用例的设计 1.2 明天任务安排 ...

  3. dns-prefetch应用好,网上速度能提高一半!

    今天一个朋友给我说在网页上添加dns-prefetch,网页访问速度能提高,于是我百度查询关于dns-prefetch. DNS Prefetch,即DNS预获取,是前端优化的一部分.一般来说,在前端 ...

  4. postgresql —— 表的继承

    示例: CREATE TABLE cities ( --父表 name text, population float, altitude int ); CREATE TABLE capitals ( ...

  5. win 10 VMware与Hyper-v共存

    管理员身份运行命令提示符 cmd bcdedit /copy {current} /d "Windows10 no Hyper-V bcdedit /set {XXXXXXXX-XXXX-X ...

  6. 题解 UVa11388

    题目大意 \(T\) 组数据,每组数据给定两个整数 \(G,L\),输出数对 \(x,y\) 满足 \(GCD(x,y)=G,LCM(x,y)=L\) 且 \(x\) 最小.若无解则输出 \(-1\) ...

  7. 2019-2020-1 20199312《Linux内核原理与分析》第十一周作业

    实验简介 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况.这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段.这一漏洞的出现是由于数据缓冲器和返回地址的暂时关闭,溢出 ...

  8. centOS下实践查询版本/CPU/内存/硬盘容量等硬件信息

    更详细参考: https://blog.csdn.net/dream_broken/article/details/52883883 1.查看内存 DirectMap2M: 33544192 kB [ ...

  9. MongoDB 复制集监控

    1.复制集状态查询:rs.status() 2.查看当前副本集oplog状态:rs.printReplicationInfo() 3.查看复制延迟:rs.printSlaveReplicationIn ...

  10. c语言实现杨辉三角形

    #include <stdio.h> int main(void) { int a[9][9]={}; int i,j; for(i=0;i<9;i++){ for(j=0;j< ...