// 鼻尖 30 // 鼻根 27 // 下巴 8 // 左眼外角 36 // 左眼内角 39 // 右眼外角 45 // 右眼内角 42 // 嘴中心 66 // 嘴左角 48 // 嘴右角 54 // 左脸最外 0 // 右脸最外 16
https://blog.csdn.net/zj360202/article/details/78674700python
--------------------------------------------------------------------------web
对于一些经常使用的人脸库经常会提供对应的人脸框的位置以及人脸的特征点的坐标。虽然每每会有68个特征点的坐标,可是若是是用于人脸对齐,并不须要用到全部的点坐标。因此知道特征点的检测顺序可以帮助咱们很快的找到咱们所须要的特定点坐标。算法
如图1所示,图中将68个特征点的检测顺序一次标注了出来。(图片摘自http://blog.csdn.net/zmdsjtu/article/details/53454071) 数据库
固然不是全部的数据库都提供68个特征点,也有78个点,例如图2所示。(图片摘自http://blog.163.com/huai_jing@126/blog/static/1718619832013111525150259/)
编程
对于更加少的特征点的出现顺序与前面相似,能够推理出来。例如5个特征点的坐标信息能够判别出来每一个坐标对应的是那个部位(左右眼,鼻子,左右嘴角)。windows
固然不是全部的特征点都会按照这个顺序进行变化,可是能够经过简单的算法将每一个点一次显示出来,从而能够找到咱们所须要的点。(python)数组
def point_xy(s): first = s.find(':') x = s[0:first] y = s[first+1:] return x,y for eachpoint in img_point: [x,y] = point_xy(eachpoint) [x,y] = [float(x),float(y)] cv2.circle(im,(int(x),int(y)),2,(0,0,255),-1) cv2.imshow('img',img) cv2.waitKey(0)
其中 img_point是保存了全部特征点的一个数组。这样就可以一步一步的看出每一个特征点的顺序。ide
https://blog.csdn.net/u011732139/article/details/56286838?locationNum=4&fps=1函数
--------------------------------------------------------------测试
本文主要演示Dlib在windows环境下利用VS配置环境运行成功调用摄像头的实时人脸特征点提取以及轮廓的描绘。
///////////////////////////////软件资源////////////////////////////////
Dlib下载连接:http://download.csdn.net/detail/zmdsjtu/9614780
//官网连接 http://dlib.net
//但最新版的dlib用VS2015会报一个很奇葩的错误,故而推荐上面的下载连接
人脸库下载连接:http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
//////////////////////////////正文/////////////////////////////////////
下载完Dlib以后解压。
接着新建一个空项目,把下载的人脸库(.dat文件解压压缩包后)添加到以下的目录下。
继而在项目里添加Dlib人脸库里的dlib\\all\\source.cpp进入项目
//若是不添加会报错,添加了source.cpp至关于把须要用的东西全引入进来了
接着再添加examples\\webcam_face_pose_ex.cpp进入项目
//这个是咱们此次主要测试的提取人脸特征点的重要CPP
接着咱们开始配置环境~
首先要配置opencv环境以及加上webcam须要调用的文件的目录
参考以下连接:http://blog.csdn.net/zmdsjtu/article/details/52235056
添加包含目录:
C:\opencv_310\build\include 这个是opencv的包含目录
C:\Users\handsome\Desktop\dlib-master 这个是dlib的主目录
添加库目录:
C:\opencv_310\build\x86\vc14\lib 这个是opencv的lib存储位置
附加依赖项的输入加上:
opencv_world310.lib opencv_ts310.lib 若是是debug或者其余版本的opencv换掉便可
须要注意的几点:
1.配置环境时选择的是X86仍是X64以及是Release仍是Debug,以后调试的时候也要选择好
2.人脸库(也就是那个一百兆的.dat文件)须要放对位置,否则程序没结果!若是直接打开EXE测试的话直接放到和EXE一个目录便可。
3.电脑必定要有摄像头!这里利用的是opencv调用摄像头
4.程序卡顿是由于detector函数耗时过长,能够考虑压缩画质或者换好一点的处理器
5.笔记本亲测效果远不如外置摄像头
6.这个库能够商用
接着就能够正常运行程序啦~~~
结果如图:
最后祝你们编程愉快:)
https://blog.csdn.net/zmdsjtu/article/details/52422847
-----------------------------------------------------------------------------------------------
主要在官网给的Demo基础之上用Opencv把特征点描绘出来了。
很早以前写过一篇配置Dlib环境的博客,如今来稍微梳理下提取特征点的使用方法。
上一篇配置环境博客地址:http://blog.csdn.net/zmdsjtu/article/details/52422847
惯例先放效果图吧:
动图以下:
接着就是简单粗暴的代码:
//@zmdsjtu@163.com //2016-12-4 //http://blog.csdn.net/zmdsjtu/article/details/53454071 #include <dlib/opencv.h> #include <opencv2/opencv.hpp> #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> using namespace dlib; using namespace std; int main() { try { cv::VideoCapture cap(0); if (!cap.isOpened()) { cerr << "Unable to connect to camera" << endl; return 1; } //image_window win; // Load face detection and pose estimation models. frontal_face_detector detector = get_frontal_face_detector(); shape_predictor pose_model; deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model; // Grab and process frames until the main window is closed by the user. while (cv::waitKey(30) != 27) { // Grab a frame cv::Mat temp; cap >> temp; cv_image<bgr_pixel> cimg(temp); // Detect faces std::vector<rectangle> faces = detector(cimg); // Find the pose of each face. std::vector<full_object_detection> shapes; for (unsigned long i = 0; i < faces.size(); ++i) shapes.push_back(pose_model(cimg, faces[i])); if (!shapes.empty()) { for (int i = 0; i < 68; i++) { circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1); // shapes[0].part(i).x();//68个 } } //Display it all on the screen imshow("Dlib特征点", temp); } } catch (serialization_error& e) { cout << "You need dlib's default face landmarking model file to run this example." << endl; cout << "You can get it from the following URL: " << endl; cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl; cout << endl << e.what() << endl; } catch (exception& e) { cout << e.what() << endl; } }
来看下上面那段代码,全部的须要的特征点都存储在Shapes里。仔细看看下面这行代码:
circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
能够看到shpes[0]表明的是第一我的(能够同时检测到不少我的),part(i)表明的是第i个特征点,x()和y()是访问特征点坐标的途径。
每一个特征点的编号以下:
在上述画图的基础上加了以下一行代码:
putText(temp, to_string(i), cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar(255, 0, 0),1,4);
效果图:
对照着上图,好比说想获取鼻尖的坐标,那么横坐标就是shapes[0].part[30].x(),其他的相似。
在这个的基础上就能够作不少有意思的事情啦,2333
最后祝你们开发愉快:)
原贴地址:https://blog.csdn.net/zmdsjtu/article/details/53454071