win10下VS2017+dlib19.17配置

本文详细介绍了如何在VC++环境下配置并使用预编译的dlib库进行人脸检测。通过修改包含目录、库目录及链接器设置,完成dlib库的配置。示例代码展示了如何使用dlib库进行人脸检测、面部关键点定位,并提供了图像窗口展示结果的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

https://download.youkuaiyun.com/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;
}

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

结果如下,成功运行 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值