Dlib是一个机器学习的C++库,包含了许多机器学习常用的算法。而且文档和例子都非常详细,以后准备深入学习。
Dlib官网地址:http://www.dlib.net/ml.html
但准备使用的时候并没在网上找到很多关于安装的资料=.=对我们小白来说很不方便。所以决定在这里记录一下安装的过程。
我使用的是VS2013。
在官网下载 dlib-18.14 之后解压到 D 盘。
然后新建一个项目,右击解决方案管理器中的该项目打开属性。在项目目录中添加 dlib- 18.14的路径(注意:是 ..\dlib- 18.14而不是..\dlib- 18.14\dlib)
项目的源码我们使用Dlib中介绍GUI的例子。
项目结构如上,我们只需要把example中的源码拷贝到ConsoleApplication6.cpp 中,注意要不要漏了头文件”stdafx.h”
代码如下:
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the gui api from the dlib C++ Library.
This is a pretty simple example. It makes a window with a user
defined widget (a draggable colored box) and a button. You can drag the
box around or click the button which increments a counter.
*/
#include "stdafx.h"
#include <dlib/gui_widgets.h>
#include <sstream>
#include <string>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------
class color_box : public draggable
{
/*
Here I am defining a custom drawable widget that is a colored box that
you can drag around on the screen. draggable is a special kind of drawable
object that, as the name implies, is draggable by the user via the mouse.
To make my color_box draggable all I need to do is inherit from draggable.
*/
unsigned char red, green, blue;
public:
color_box(
drawable_window& w,
rectangle area,
unsigned char red_,
unsigned char green_,
unsigned char blue_
) :
draggable(w),
red(red_),
green(green_),
blue(blue_)
{
rect = area;
set_draggable_area(rectangle(10, 10, 400,