如何使用DLIB libarary加载jpeg文件?

时间:2015-09-23 09:44:28

标签: c++ image libjpeg dlib

尝试运行从Here下载的示例程序后,我理解使用jpeg文件,我必须将 #define DLIB_JPEG_SUPPORT 指令添加到项目中。但在此之前,下载jpeg库并将其添加到项目中是必要的。我做了这些步骤:

1.从here下载 jpegsr9a .zip并解压缩。

2.下载 WIN32.mak 并将其粘贴到jpeg根文件夹

3.从Visual Studio 2013工具中打开开发人员命令提示符

4.在命令提示符下键入: nmake -f makefile.vc setup-v10

5.创建jpeg.sln这些步骤后,注意事项是当我在VS2013中打开jpeg.sln消息时:

enter image description here

问题的根源可能从这里开始,我不知道

6.使用正确的配置构建jpeg.sln(我使用不同的配置多次构建它,最近我使用this构建它。) 在构建错误结束时:"无法启动jpeg.lib" 但是在发布文件夹或调试文件夹(取决于配置)中创建了jpeg.lib

  1. 打开使用DLIB检测面部的主项目,我将jpeg根文件夹添加到Additonal Include Directory并将jepegroot / release添加到其他Libarary目录,然后将UseLibrary依赖项更改为" yes"我还将jpeg.lib添加到了dependecies。
  2. 在构建项目期间出现错误: enter image description here

    这是我尝试构建和运行的源代码

    //#define HAVE_BOOLEAN
    #define DLIB_JPEG_SUPPORT
    #include <dlib/image_processing/frontal_face_detector.h>
    #include <dlib/image_processing/render_face_detections.h>
    #include <dlib/image_processing.h>
    #include<dlib/image_transforms.h>
    #include <dlib/gui_widgets.h>
    #include <dlib/image_io.h>
    #include <iostream>
    //
    using namespace dlib;
    using namespace std;
    
    // ----------------------------------------------------------------------------------------
    
    int main(int argc, char** argv)
    {
        try
        {
            // This example takes in a shape model file and then a list of images to
            // process.  We will take these filenames in as command line arguments.
            // Dlib comes with example images in the examples/faces folder so give
            // those as arguments to this program.
            if (argc == 1)
            {
                cout << "Call this program like this:" << endl;
                cout << "./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces/*.jpg" << endl;
                cout << "\nYou can get the shape_predictor_68_face_landmarks.dat file from:\n";
                cout << "http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
                return 0;
            }
    
            // We need a face detector.  We will use this to get bounding boxes for
            // each face in an image.
            frontal_face_detector detector = get_frontal_face_detector();
            // And we also need a shape_predictor.  This is the tool that will predict face
            // landmark positions given an image and face bounding box.  Here we are just
            // loading the model from the shape_predictor_68_face_landmarks.dat file you gave
            // as a command line argument.
            shape_predictor sp;
             deserialize(argv[1])>>sp;
    
    
            image_window win, win_faces;
            // Loop over all the images provided on the command line.
            for (int i = 2; i < argc; ++i)
            {
                cout << "processing image " << argv[i] << endl;
                array2d<rgb_pixel> img;
                load_image(img, argv[i]);
                // Make the image larger so we can detect small faces.
                pyramid_up(img);
    
                // Now tell the face detector to give us a list of bounding boxes
                // around all the faces in the image.
                std::vector<rectangle> dets = detector(img);
                cout << "Number of faces detected: " << dets.size() << endl;
    
                // Now we will go ask the shape_predictor to tell us the pose of
                // each face we detected.
                std::vector<full_object_detection> shapes;
                for (unsigned long j = 0; j < dets.size(); ++j)
                {
                    full_object_detection shape = sp(img, dets[j]);
                    cout << "number of parts: " << shape.num_parts() << endl;
                    cout << "pixel position of first part:  " << shape.part(0) << endl;
                    cout << "pixel position of second part: " << shape.part(1) << endl;
                    // You get the idea, you can get all the face part locations if
                    // you want them.  Here we just store them in shapes so we can
                    // put them on the screen.
                    shapes.push_back(shape);
                }
    
                // Now let's view our face poses on the screen.
                win.clear_overlay();
                win.set_image(img);
                win.add_overlay(render_face_detections(shapes));
    
                // We can also extract copies of each face that are cropped, rotated upright,
                // and scaled to a standard size as shown here:
                dlib::array<array2d<rgb_pixel> > face_chips;
                extract_image_chips(img, get_face_chip_details(shapes), face_chips);
                win_faces.set_image(tile_images(face_chips));
    
                cout << "Hit enter to process the next image..." << endl;
                cin.get();
            }
        }
        catch (exception& e)
        {
            cout << "\nexception thrown!" << endl;
            cout << e.what() << endl;
        }
    }
    

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

    我可以选择其他选择,但我花了太多时间到达这里,我想知道如何解决这个问题并在使用DLIB时加载jpeg文件

    我也阅读了这些链接:

    Compiling libjpeg

    http://www.dahlsys.com/misc/compiling_ijg_libjpeg/index.html

    dlib load jpeg files

    http://sourceforge.net/p/dclib/discussion/442518/thread/8a0d42dc/

1 个答案:

答案 0 :(得分:2)

我通过以下说明解决了我的问题,请关注它。

- 在VC ++中添加include目录 enter image description here

- 包括source.cpp

enter image description here

- 将dlib / external / libjpeg中的文件添加到项目中

enter image description here

- 在预处理器中定义

enter image description here

- 您不需要使用任何其他库。