1

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

1.从这里下载 jpegsr9a .zip并解压。

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

3.从visual studio 2013工具打开开发者命令提示符

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

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

在此处输入图像描述

也许问题的根源从这里开始,我不知道

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

  1. 打开使用 DLIB 检测人脸的主项目,我将 jpeg 根文件夹添加到 Additonal Include Directory 和 jepegroot/release 到 Additional Libarary Directory ,然后将 UseLibrary 依赖项更改为“yes”,我还将 jpeg.lib 添加到依赖项中。

在构建项目期间,错误来了: 在此处输入图像描述

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

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

我还阅读了这些链接:

编译 libjpeg

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

dlib 加载 jpeg 文件

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

4

1 回答 1

3

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

- 在 VC++ 中添加包含目录 在此处输入图像描述

- 包括 source.cpp

在此处输入图像描述

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

在此处输入图像描述

- 在预处理器中定义

在此处输入图像描述

-- 你不需要使用任何额外的库。

于 2016-01-04T07:29:33.400 回答