近期由于要做一个关于人脸计数的项目,因此对dlib库进行了编译和使用,其中遇到了不少问题,下面请听我一一道来
第一步:从dlib官网下载dlib源码,链接地址:
https://github.com/davisking/dlib
第二步,采用cmake配置环境,并生成工程,配置环境如下:dlib源码全部放在了source下,build为要生成的工程地址路径(选择Advanced),点击config弹出vs配置界面,选择vs2015,X64
CUDA的配置(默认):
libjpeg和libpng的相关配置
生成工程以后,点击Open Project。
第三步:配置release库的生成环境:Release X64
右键dlib->属性->常规->文件名扩展:改成dlib即可(如下图):
等待片刻以后,在路径…/dlib-19.20/build/dlib/Release下便生成dlib.lib文件,此文件就是我们所要用的。
第四步:我们进行实例验证(问题出现的地方):
创建工程vs2015->新建->项目->win32控制台应用程序
实例采用的是D:\compile_mxnet\dlib-19.20\source\examples\video_tracking_ex.cpp
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This example shows how to use the correlation_tracker from the dlib C++ library. This
object lets you track the position of an object as it moves from frame to frame in a
video sequence. To use it, you give the correlation_tracker the bounding box of the
object you want to track in the current video frame. Then it will identify the
location of the object in subsequent frames.
In this particular example, we are going to run on the video sequence that comes with
dlib, which can be found in the examples/video_frames folder. This video shows a juice
box sitting on a table and someone is waving the camera around. The task is to track the
position of the juice box as the camera moves around.
*/
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
using namespace dlib;
using namespace std;
int main(int argc, char** argv) try
{
if (argc != 2)
{
cout << "Call this program like this: " << endl;
cout << "./video_tracking_ex ../video_frames" << endl;
return 1;
}
// Get the list of video frames.
std::vector<file> files = get_files_in_directory_tree(argv[1], match_ending(".jpg"));
std::sort(files.begin(), files.end());
if (files.size() == 0)
{
cout << "No images found in " << argv[1] << endl;
return 1;
}
// Load the first frame.
array2d<unsigned char> img;
load_image(img, files[0]);
// Now create a tracker and start a track on the juice box. If you look at the first
// frame you will see that the juice box is centered at pixel point(92,110) and 38
// pixels wide and 86 pixels tall.
correlation_tracker tracker;
tracker.start_track(img, centered_rect(point(93, 110), 38, 86));
// Now run the tracker. All we have to do is call tracker.update() and it will keep
// track of the juice box!
image_window win;
for (unsigned long i = 1; i < files.size(); ++i)
{
load_image(img, files[i]);
tracker.update(img);
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
cout << "hit enter to process next frame" << endl;
cin.get();
}
}
catch (std::exception& e)
{
cout << e.what() << endl;
}
1)将代码放入test.cpp文件夹下;
2)右键test->添加->现有项(到…\dlib-19.20\source\dlib\all\下 添加文件进来source.cpp)
3)添加新建筛选器:libjpeg, libpng, libz(很关键,因为我在编译dlib.lib库的时候把anaconda下libjpeg_support等都取消了,因为anconda下安装的jpeglib.h的头文件里JPEG_LIB_VERSION 90,而dlib库里面的是80,版本要更高,不能兼容,错误如下:)
anaconda下:
dlib下的:
将三个文件夹下的内容分别添加进libjpeg,libpng, libz中,此时要把如下三个文件从libjpeg文件中剔除,否则会包各种error LINK2005 LINK2001的错误
4)环境配置:
可以参考链接即可
https://www.cnblogs.com/www-caiyin-com/p/7484390.html
5)效果展示: