如何将dlib作为我在CLion中的项目的一部分? [英] How do I include dlib as part of my project in CLion?

查看:242
本文介绍了如何将dlib作为我在CLion中的项目的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前的C ++设置为:

The current C++ setup is:


  • Clion IDE

  • dlib

我正在运行dlib给出的C ++示例之一

I'm running one of the C++ examples given by dlib

#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>


using namespace std;
using namespace dlib;

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

int main(int argc, char** argv)
{
    try
    {
        // make sure the user entered an argument to this program
        if (argc != 2)
        {
            cout << "error, you have to enter a BMP file as an argument to this program" << endl;
            return 1;
        }

        // Here we declare an image object that can store rgb_pixels.  Note that in 
        // dlib there is no explicit image object, just a 2D array and
        // various pixel types.  
        array2d<rgb_pixel> img;

        // Now load the image file into our image.  If something is wrong then
        // load_image() will throw an exception.  Also, if you linked with libpng
        // and libjpeg then load_image() can load PNG and JPEG files in addition
        // to BMP files.
        load_image(img, argv[1]);


        // Now let's use some image functions.  First let's blur the image a little.
        array2d<unsigned char> blurred_img;
        gaussian_blur(img, blurred_img); 

        // Now find the horizontal and vertical gradient images.
        array2d<short> horz_gradient, vert_gradient;
        array2d<unsigned char> edge_image;
        sobel_edge_detector(blurred_img, horz_gradient, vert_gradient);

        // now we do the non-maximum edge suppression step so that our edges are nice and thin
        suppress_non_maximum_edges(horz_gradient, vert_gradient, edge_image); 

        // Now we would like to see what our images look like.  So let's use a 
        // window to display them on the screen.  (Note that you can zoom into 
        // the window by holding CTRL and scrolling the mouse wheel)
        image_window my_window(edge_image, "Normal Edge Image");

        // We can also easily display the edge_image as a heatmap or using the jet color
        // scheme like so.
        image_window win_hot(heatmap(edge_image));
        image_window win_jet(jet(edge_image));

        // also make a window to display the original image
        image_window my_window2(img, "Original Image");

        // Sometimes you want to get input from the user about which pixels are important
        // for some task.  You can do this easily by trapping user clicks as shown below.
        // This loop executes every time the user double clicks on some image pixel and it
        // will terminate once the user closes the window.
        point p;
        while (my_window.get_next_double_click(p))
        {
            cout << "User double clicked on pixel:         " << p << endl;
            cout << "edge pixel value at this location is: " << (int)edge_image[p.y()][p.x()] << endl;
        }

        // wait until the user closes the windows before we let the program 
        // terminate.
        win_hot.wait_until_closed();
        my_window2.wait_until_closed();


        // Finally, note that you can access the elements of an image using the normal [row][column]
        // operator like so:
        cout << horz_gradient[0][3] << endl;
        cout << "number of rows in image:    " << horz_gradient.nr() << endl;
        cout << "number of columns in image: " << horz_gradient.nc() << endl;
    }
    catch (exception& e)
    {
        cout << "exception thrown: " << e.what() << endl;
    }
}

这就是我当前的CMakeList.txt文件的外观现在

This is how my current CMakeList.txt file looks right now

> cmake_minimum_required(VERSION 3.2)
project(Project-Hurst)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES src/main.cpp)
add_executable(Project-Hurst ${SOURCE_FILES})

我尝试使用示例CMakeList.txt文件,但无法正常工作。那么如何将dlib添加到我的项目路径中,并正确设置CMakeList文件?

I tried using the example CMakeList.txt file but it was not working properly. So how do I add dlib into my project path, and properly set up the CMakeList file?

推荐答案

您需要在dlib中构建

You need to build dlib in the following way:


  1. cd dlib

  2. mkdir build-> cd build

  3. cmake ..

  4. make

  5. sudo make install

  6. sudo ldconfig- ->将更新共享库缓存

  1. cd dlib
  2. mkdir build --> cd build
  3. cmake ..
  4. make
  5. sudo make install
  6. sudo ldconfig --> will update shared library cache

这将创建.so和dlibConfig.cmake文件,这些文件将被CLion IDE识别。

this will create .so and dlibConfig.cmake files that will be recognized by CLion IDE.

这篇关于如何将dlib作为我在CLion中的项目的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆