2

当前的 C++ 设置是:

  • 克莱恩 IDE
  • dlib

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

#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 文件?

4

3 回答 3

6

您需要通过以下方式构建 dlib:

  1. 光盘库
  2. mkdir 构建 --> cd 构建
  3. 制作..
  4. 制作
  5. 须藤使安装
  6. sudo ldconfig --> 将更新共享库缓存

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

于 2016-11-17T05:50:00.420 回答
2

我想你已经在你的电脑上编译了 dlib。然后,在您的 CMakeLists.txt 中添加以下两个语句,它将起作用。

find_package(dlib REQUIRED)
target_link_libraries(${PROJECT_NAME} ${dlib_LIBS})
于 2016-09-11T02:29:55.863 回答
0

如果您正在寻找 Windows 操作系统的答案。然后,您可以按照以下简单步骤进行操作。

  1. 安装 C++ 11 编译器(支持 C++ 11 或更高版本的编译器)。我会建议使用TDM-GCC-64 编译器

  2. 安装编译器后,将路径变量C:\TDM-GCC-64\bin设置为您的操作系统。

  3. 接下来下载 dlib 文件夹并将其解压缩到C:\dlib中。现在按照这些步骤。假设您在命令提示符的C:\位置。

  • 光盘库

  • mkdir 构建

  • 光盘构建

  • cmake .. -G "MinGW Makefiles"

  • mingw32-make

  • mingw32-make 安装

  1. 接下来将dlibConfig.cmakedlib.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:/程序文件 (x86)/Project/include/dlib/cmake_utils/use_cpp_11.cmake")

  3. 在CMakeList.txt文件中添加以下行。

  • 包含目录(${dlib_LIBRARIES})

  • 包含目录(${dlib_LIBS})

  • 包含目录(${dlib_INCLUDE_DIRS})

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

现在您可以在 CLion 中使用 dlib 库。

于 2020-06-24T16:21:08.890 回答