Clion配置dlib库 for Mac OS X

1. 下载dlib库:git clone https://github.com/davisking/dlib.git

2. CLion中新建项目Face,可以看到Face的目录中的文件如下:

  Clion配置dlib库 for Mac OS X_第1张图片

3.CMakeLists.txt中编译配置语句(下面博文中绿色语句是需要的部分也可以参考图片

 参考dlib/examples/CMakeLists.txt

Clion配置dlib库 for Mac OS X_第2张图片

cmake_minimum_required(VERSION 2.8.12)#version可以改

# Every project needs a name. We call this the "examples" project.

#这里我的项目名称为Face

project(examples)


# Tell cmake we will need dlib. This command will pull in dlib and compile it

# into your project. Note that you don't need to compile or install dlib. All

# cmake needs is the dlib source code folder and it will take care of everything.

#dlib_build是要cmake以后才会生成的一个文件夹事实上可以不需要在下载的dlibintallcmake之类的。

#add_subdirectory(../dlib dlib_build)

#直接用include语句将库包含进去

include(xxx/dlib/cmake)

#注意这个dlib是在dlib里的dlib文件夹


# The next thing we need to do is tell CMake about the code you want to

# compile. We do this with the add_executable() statement which takes the name

# of the output executable and then a list of .cpp files to compile. Here we

# are going to compile one of the dlib example programs which has only one .cpp

# file, assignment_learning_ex.cpp. If your program consisted of multiple .cpp

# files you would simply list them here in the add_executable() statement. 

#这里第一个为项目名,第二个为文件名,我的分别为Facemain.cpp

add_executable(assignment_learning_ex assignment_learning_ex.cpp)


# Finally, you need to tell CMake that this program, assignment_learning_ex,

# depends on dlib. You do that with this statement: 

target_link_libraries(assignment_learning_ex dlib::dlib)

#dlib::dlib为什么是这样的语句暂时不清楚> <


4. 到你的cmake-build-debug文件夹中配置需要的库。教程里面如下

#   mkdir build

#   cd build

#   cmake ..

#   cmake --build . --config Release

#但你已经不需要再新建一个build文件夹了。此buildcmake-build-debug替换。因此:

cd cmake-build-debug

cmake .. #因为CMakeLists.txt在上一级目录里

cmake --build . --config Release



5.不要忘记配置opencv

没有opencvdlib无法使用

6.有人说需要显示的链接stdc++,类似于make -stdlib=libstdc++语句的功能。不过实际上并不是这个问题,注释后仍然不报错。

7.网上的dlib example有错误,其实可以直接在tutorial里面找到dlib例子。比如这个。

// 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 perspective_window tool
    in the dlib C++ Library.  It is a simple tool for displaying 3D point
    clouds on the screen.

*/

#include 
#include 
#include 

using namespace dlib;
using namespace std;

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

int main()
{
    // Let's make a point cloud that looks like a 3D spiral.
    std::vector points;
    dlib::rand rnd;
    for (double i = 0; i < 20; i+=0.001)
    {
        // Get a point on a spiral
        dlib::vector val(sin(i),cos(i),i/4);

        // Now add some random noise to it
        dlib::vector temp(rnd.get_random_gaussian(),
                                  rnd.get_random_gaussian(),
                                  rnd.get_random_gaussian());
        val += temp/20;

        // Pick a color based on how far we are along the spiral
        rgb_pixel color = colormap_jet(i,0,20);

        // And add the point to the list of points we will display
        points.push_back(perspective_window::overlay_dot(val, color));
    }

    // Now finally display the point cloud.
    perspective_window win;
    win.set_title("perspective_window 3D point cloud");
    win.add_overlay(points);
    win.wait_until_closed();
}

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

BTW:下载前记得安装XQuartz







你可能感兴趣的:(DIP)