dlib学习

编译

dlib

使用 cmake 生成 vs2019 项目

注意一下配置项符合自己的需求就可以了。

打开项目后,可以顺利的生成 debug 和 release 版本。

使用

使用时需要修改一个 dlib/config.h 文件,否则会提示 USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2?

在 cmake 生成的 build 目录下面,也会有个 config.h 文件,参考里面的内容,根据自己的需要修改一下 dlib/config.h 文件

// If you are compiling dlib as a shared library and installing it somewhere on your system
// then it is important that any programs that use dlib agree on the state of the
// DLIB_ASSERT statements (i.e. they are either always on or always off). Therefore,
// uncomment one of the following lines to force all DLIB_ASSERTs to either always on or
// always off. If you don't define one of these two macros then DLIB_ASSERT will toggle
// automatically depending on the state of certain other macros, which is not what you want
// when creating a shared library.
//#define ENABLE_ASSERTS // asserts always enabled
#define DLIB_DISABLE_ASSERTS // asserts always disabled

//#define DLIB_ISO_CPP_ONLY
#define DLIB_NO_GUI_SUPPORT
//#define DLIB_ENABLE_STACK_TRACE

// You should also consider telling dlib to link against libjpeg, libpng, libgif, fftw, CUDA,
// and a BLAS and LAPACK library. To do this you need to uncomment the following #defines.
// #define DLIB_JPEG_SUPPORT
// #define DLIB_PNG_SUPPORT
// #define DLIB_GIF_SUPPORT
// #define DLIB_USE_FFTW
// #define DLIB_USE_BLAS
// #define DLIB_USE_LAPACK
// #define DLIB_USE_CUDA


// Define this so the code in dlib/test_for_odr_violations.h can detect ODR violations
// related to users doing bad things with config.h
//#define DLIB_NOT_CONFIGURED
#define DLIB_CHECK_FOR_VERSION_MISMATCH DLIB_VERSION_MISMATCH_CHECK__EXPECTED_VERSION_19_19_0

使用 最小二乘法 做曲线拟合

#include <dlib/optimization.h>

#ifdef _DEBUG
#ifdef _WIN64
#pragma comment(lib,"dlib19.19.0_debug_64bit_msvc1925.lib")
#else
#pragma comment(lib,"xx.lib")
#endif
#else
#ifdef _WIN64
#pragma comment(lib,"dlib19.19.0_minsizerel_64bit_msvc1925.lib")
#else
#pragma comment(lib,"xx.lib")
#endif
#endif