windows 下编译dlib-18.17及测试

Dlib是一个机器学习的C++库,里面包含了许多常用的机器学习算法,如人脸检测识别,而且文档和例子都非常详细,学习了OenCV后准备也学习下。
Dlib官网地址:http://www.dlib.net/ml.html
目前官方最新的版本是:19.8。这个版本的dlib只支持VS2015及以后的版本,前面的版本需要自己去捣鼓,而本人用的是VS2013,于是下载了dlib-18.17。下载地址:https://pan.baidu.com/s/1gey9Wd1
1、安装cmake,这个很简单,一直next就可以了。
2、打开cmake,设置source code路径为解压目录,新建生成目录,起名为build,设为二进制生成输出目录。
3、点击Configure生成如下界面:
这里写图片描述
4、确保DLIB_LINK_WITH_LIBJPEG选项和DLIB_LINK_WITH_LIBPNG选项被勾选,再次点击Configure,Configuring done后,然后点击Generate,生成完毕后,在build目录下打开:dlib.vcxproj,然后选择dlib项目,点击生成,记得分别选择Debug 64 和Release 64模式生成对应的静态库文件:dlib.lib。
5、编译完成后,就可以使用了,
在C/C++ —>常规—>附加包含目录中加入 :F:\OpenCV\dlib-18.17,如果出现jpeg和png的错误,记得添加包含F:\OpenCV\dlib-18.17\dlib\external\libjpeg和F:\OpenCV\dlib-18.17\dlib\external\libpng,然后在链接器—>常规—>附加库目录中添加:F:\OpenCV\dlib-18.17\build\Release(如果是Debug模式,则为:F:\OpenCV\dlib-18.17\build\Debug),然后在链接器—>输入,中加入dlib.lib。
为了保证顺利载入jpeg和png图像,还需要在c++的预处理器中加入
DLIB_PNG_SUPPORT
DLIB_JPEG_SUPPORT
6、测试

// OpenCVDLIB.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <dlib/opencv.h>   
#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<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>



using namespace cv;
using namespace std;
using namespace dlib;

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        cv::VideoCapture cap(0);
        if (!cap.isOpened())
        {
            cerr << "Unable to connect to camera" << endl;
            return 1;
        }

        frontal_face_detector detector = get_frontal_face_detector();
        shape_predictor pose_model;
        deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;

        cv::namedWindow("show", 0);
        while (cv::waitKey(30) != 27)
        {
            // Grab a frame    
            cv::Mat temp;
            cap >> temp;

            cv_image<bgr_pixel> cimg(temp);
            std::vector<dlib::rectangle> faces = detector(cimg);
            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);
                }
            }
            imshow("show", 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;
    }
}

编译成功,运行就能打开电脑usb摄像头,检测人脸了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值