win10下VS2017+dlib19.17配置

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/BigDream123/article/details/99305230

可以在这直接下载已经编译好的dlib库文件

https://download.csdn.net/download/bigdream123/11527647

配置方法如下:

VC++目录下修改包含目录和库目录

 修改链接器-》输入-》附加依赖项,将其修改为解压文件下lib文件夹下的dlib.lib

 

如此就配置完成了,可以使用例子试一下

#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 <iostream>

using namespace dlib;
using namespace std;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)
{
	try
	{
		// 定义人脸检测器,使用它来获取一张图片中,每个人脸的边界位置
		frontal_face_detector detector = get_frontal_face_detector();

		//定义形状预测器,用来预测给定图片和脸边界框时候的标记点的位置。
		//这里我们从shape_predictor_68_face_landmarks.dat文件加载模型
		shape_predictor sp;
		deserialize("shape_predictor_68_face_landmarks.dat") >> sp;

		image_window win, win_faces;

		// 循环所有图片,为演示效果,只用了一张图片
		for (int i = 0; i < 1; ++i)
		{
			cout << "processing image " << "2.jpg" << endl;
			array2d<rgb_pixel> img;
			load_image(img, "2.jpg");

			// 放大图片以便检测到比较小的人脸.
			pyramid_up(img);

			//检测人脸,获得边界框
			std::vector<rectangle> dets = detector(img);
			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.
			//****调用shape_predictor类函数,返回每张人脸的姿势
			std::vector<full_object_detection> shapes;//注意形状变量的类型,full_object_detection
			for (unsigned long j = 0; j < dets.size(); ++j)
			{
				//预测姿势,注意输入是两个,一个是图片,另一个是从该图片检测到的边界框
				full_object_detection shape = sp(img, dets[j]);
				cout << "number of parts: " << shape.num_parts() << endl;

				/*打印出全部68个点*/
				/*for (int i = 0; i < 68; i++)
				{
				cout << "第 " << i+1 << " 个点的坐标: " << shape.part(i) << endl;
				}*/

				shapes.push_back(shape);
			}

			//显示结果
			win.clear_overlay();
			win.set_image(img);
			win.add_overlay(dets, rgb_pixel(255, 0, 0));
			win.add_overlay(render_face_detections(shapes));

			//我们也能提取每张对齐剪裁后的人脸的副本,旋转和缩放到一个标准尺寸
			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));

			cout << "Hit enter to process the next image..." << endl;
			cin.get();
		}
	}
	catch (exception& e)
	{
		cout << "\nexception thrown!" << endl;
		cout << e.what() << endl;
	}

	return 0;
}

// ----------------------------------------------------------------------------------------

结果如下,成功运行 

 

猜你喜欢

转载自blog.csdn.net/BigDream123/article/details/99305230