C++之Dlib库实现68个特征点人脸的提取(根据Dlib官网例程改写)
来源:互联网 发布:野兽派与roseonly 知乎 编辑:程序博客网 时间:2024/06/03 15:05
#include <fstream> #include <string> #include <iostream> #include <dlib/image_processing/frontal_face_detector.h>#include <dlib/image_processing/render_face_detections.h>#include <dlib/image_processing.h>#include <dlib/gui_widgets.h>#include <dlib/image_io.h>#include <opencv2/core/core.hpp> #include <dlib/timer.h>#include "highgui.h"using namespace dlib;using namespace std;// ----------------------------------------------------------------------------------------int main(){ try{// We need a face detector. We will use this to get bounding boxes for// each face in an image.frontal_face_detector detector = get_frontal_face_detector();// And we also need a shape_predictor. This is the tool that will predict face// landmark positions given an image and face bounding box. Here we are just// loading the model from the shape_predictor_68_face_landmarks.dat file you gave// as a command line argument.shape_predictor sp;//deserialize(argv[1]) >> sp;deserialize("D:\\CAFFE\\caffe-windows-master\\buildVS2013\\faceverification\\shape_predictor_68_face_landmarks.dat") >> sp;//deserialize("./shape_predictor_68_face_landmarks.dat") >> sp;image_window win, win_faces;ifstream in("path.txt");string filename;string picture;if (in){int picNo = 1;// Loop over all the images provided in the txt file.while (getline(in, picture)){cout << "processing image " << picture << endl;array2d<rgb_pixel> img;load_image(img, picture);// Make the image larger so we can detect small faces.pyramid_up(img);// Now tell the face detector to give us a list of bounding boxes// around all the faces in the image.long long detec_time = cv::getTickCount();std::vector<rectangle> dets = detector(img);detec_time = cv::getTickCount() - detec_time;cout << "detect time : " << 1000 * detec_time / cv::getTickFrequency() << " ms" << endl;cout << "Number of faces detected: " << dets.size() << endl;// Now we will go ask the shape_predictor to tell us the pose of// each face we detected.std::vector<full_object_detection> shapes;//int64 t;long long total = cv::getTickCount();for (unsigned long j = 0; j < dets.size(); ++j){//计时long long t = cv::getTickCount();full_object_detection shape = sp(img, dets[j]);cout << "number of parts: " << shape.num_parts() << endl;cout << "pixel position of first part: " << shape.part(0) << endl;cout << "pixel position of second part: " << shape.part(1) << endl;// You get the idea, you can get all the face part locations if// you want them. Here we just store them in shapes so we can// put them on the screen.shapes.push_back(shape);t = cv::getTickCount() - t;cout << "process time : " << 1000 * t / cv::getTickFrequency() << " ms" << endl;}total = cv::getTickCount() - total;cout << "process time : " << 1000 * total / cv::getTickFrequency() << " ms" << endl;// Now let's view our face poses on the screen.win.clear_overlay();win.set_image(img);win.add_overlay(render_face_detections(shapes));// We can also extract copies of each face that are cropped, rotated upright,// and scaled to a standard size as shown here:dlib::array<array2d<rgb_pixel> > face_chips;extract_image_chips(img, get_face_chip_details(shapes), face_chips);win_faces.set_image(tile_images(face_chips));if (dets.size()>0){char str[10];const string source = strcat(itoa(picNo, str, 10), ".jpg");save_jpeg(tile_images(face_chips), source, 75);picNo = picNo + 1;//cout << picNo << endl;}cout << "Hit enter to process the next image..." << endl;cin.get();}}else{cout << "no such file!" << endl;}}catch (exception& e){cout << "\nexception thrown!" << endl;cout << e.what() << endl;}return 0;}// ----------------------------------------------------------------------------------------
0 0
- C++之Dlib库实现68个特征点人脸的提取(根据Dlib官网例程改写)
- Dlib提取Hog特征
- 【Python】dlib实现视频中人脸68特征点提取
- Dlib + python + opencv 实时人脸68特征点提取
- Dlib提取人脸特征点(68点,opencv画图)
- Dlib提取人脸特征点(68点,opencv画图)
- VS2013+Dlib提取特征点使用总结
- 表情识别的简单实现(实时,C++,SVM+Dlib)
- 【Python】使用openCV与dlib实现人脸68特征点的检测与手动修改
- dlib库中svm 例程解析
- 使用Dlib库进行68个人脸特征点检测
- 人脸检测、提取特征点(dlib下的三个例子)
- 【dlib】人脸68特征点检测
- 人脸特征检测--基于DLIB库
- 人脸旋转归一化 (根据特征点定位,dlib+opencv)
- Dlib库的安装配置
- Dlib库介绍(一)
- 利用dlib库(Python)实现实时(摄像头)人脸检测以及特征点标定(landmark))
- 定位功能iOS SDK
- 备库启动报错ORA-48108 ORA-48410 ORA-48187
- [Android] 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?
- Windows下MySQL忘记了密码怎么修改
- android 动画代码实现
- C++之Dlib库实现68个特征点人脸的提取(根据Dlib官网例程改写)
- exec() 方法和match方法
- iOS之轻松上手block(上)
- VS2013 EF6连接MySql需要几步?
- CentOS 6.3下配置LVM(逻辑卷管理)
- alter table move和alter table shrink space的区别
- Zxing扫描二维码
- IOS 网络浅析-(三 NSURLConnection代理)
- java反射之通过反射了解集合泛型的本质