【问题标题】:how to load jpeg file using DLIB libarary?如何使用 DLIB 库加载 jpeg 文件?
【发布时间】:2015-12-20 13:39:28
【问题描述】:

在尝试运行从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时消息来了:

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

6.使用正确的配置构建 jpeg.sln(我用不同的配置构建了很多次,最近我使用 this 构建了它。) 在构建结束时出现错误:“无法启动 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 文件

我还阅读了这些链接:

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/

【问题讨论】:

  • 我认为问题出在 jpeg.lib
  • 您是否在旧版本的 Visual Studio 中制作过项目?

标签: c++ image libjpeg dlib


【解决方案1】:

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

- 在 VC++ 中添加包含目录

- 包括 source.cpp

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

- 在预处理器中定义

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

【讨论】:

  • 您为什么不按照dlib.net/compile.html 的建议使用cmake 创建您的Visual Studio 项目?
  • 其实我也试过了,但是失败了,只能按照上面的方法手动配置。
  • 您是否在此页面顶部键入了确切的命令? dlib.net/compile.html。我刚刚做了,他们在 Visual Studio 2013 中编译没有错误
  • 对不起,因为我的问题是指 3 个月前,我用另一个工具完成了我的项目,检查你的答案然后标记它需要时间。谢谢
猜你喜欢
  • 2015-03-04
  • 2015-12-20
  • 2011-01-30
  • 2015-11-08
  • 1970-01-01
  • 2019-03-07
  • 1970-01-01
  • 2016-09-26
相关资源
最近更新 更多