Как мне включить dlib как часть моего проекта в CLion?

Текущая настройка С++:

  • Клион IDE
  • dlib

Я запускаю один из примеров C++, предоставленных 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

> 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?


person Community    schedule 20.07.2015    source источник
comment
Что произошло, когда вы использовали файл cmake, прилагаемый к примеру?   -  person Davis King    schedule 20.07.2015
comment
Когда я использую пример файла CMake, я получаю сообщение об ошибке, в котором говорится, что include не может найти файл загрузки.   -  person    schedule 21.07.2015
comment
Вы вводили команды cmake точно так, как показано здесь? dlib.net/compile.html   -  person Davis King    schedule 21.07.2015
comment
Я использую clion IDE, поэтому он делает это за меня.   -  person    schedule 22.07.2015


Ответы (3)


Вам нужно собрать dlib следующим образом:

  1. компакт-диск dlib
  2. сборка mkdir --> сборка компакт-диска
  3. сделай ..
  4. делать
  5. судо сделать установить
  6. sudo ldconfig --> обновит кеш общей библиотеки

это создаст файлы .so и dlibConfig.cmake, которые будут распознаны CLion IDE.

person shruti    schedule 17.11.2016
comment
изначально, где я должен разместить папку dlib? Например, если dlib находится внутри диска C как C:\dlib, то могу ли я использовать предложенную вами последовательность команд. - person Mayank Tiwari; 23.06.2020
comment
вы используете Windows, приведенные выше команды будут работать в Linux. Я думаю, что после того, как вы установите dlib через pip или создадите исходный код, путь в конечном итоге будет настроен используемой вами версией Python. вы можете использовать cmake cmake.org/download - person shruti; 23.06.2020
comment
спасибо за эту помощь. Я нашел решение для Windows и опубликовал его. - person Mayank Tiwari; 24.06.2020

Я полагаю, вы скомпилировали dlib на своем компьютере. Затем добавьте два утверждения ниже в свой CMakeLists.txt, и это сработает.

find_package(dlib REQUIRED)
target_link_libraries(${PROJECT_NAME} ${dlib_LIBS})
person voidwalker    schedule 11.09.2016

В случае, если вы ищете ответ для операционной системы Windows. Затем вы можете выполнить следующие простые шаги.

  1. Установите компилятор C++ 11 (компилятор, поддерживающий C++ 11 или более поздние версии). Я предлагаю использовать компилятор TDM-GCC-64

  2. После установки компилятора задайте для переменной пути C:\TDM-GCC-64\bin значение вашей операционной системы.

  3. Затем скачайте папку dlib и распакуйте ее в C:\dlib. Теперь выполните следующие действия. Предположим, что вы находитесь в папке C:\ в командной строке.

  • компакт-диск dlib

  • сборка mkdir

  • сборка компакт-диска

  • cmake .. -G Makefiles MinGW

  • mingw32-сделать

  • mingw32-сделать установить

  1. Затем скопируйте файлы dlibConfig.cmake и dlib.cmake в папку cmake-build-debug. Эта папка будет внутри вашего проекта CLion C++.

  2. Теперь проверьте файл dlibConfig.cmake и, если вы найдете строку типа include(C:/Program Files (x86)/Project/include/dlib/cmake_utils/use_cpp_11.cmake) затем преобразуйте его в include(C:/Program Files (x86)/Project/include/dlib/cmake_utils/use_cpp_11.cmake).

  3. Добавьте следующие строки в файл CMakeList.txt.

  • include_directories(${dlib_LIBRARIES})

  • include_directories(${dlib_LIBS})

  • include_directories(${dlib_INCLUDE_DIRS})

  • target_link_libraries(${PROJECT_NAME} ${dlib_LIBS})

Теперь вы можете использовать библиотеку dlib в своем CLion.

person Mayank Tiwari    schedule 24.06.2020