如何使用DLIB libarary加载jpeg文件? [英] how to load jpeg file using DLIB libarary?

查看:401
本文介绍了如何使用DLIB libarary加载jpeg文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行从



问题的基础可能从这里开始,我不知道



6.使用正确的配置构建jpeg.sln(我用它构建了很多次不同的配置,最近我使用



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

  // #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>
//
使用命名空间dlib;
using namespace std;

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

int main(int argc,char ** argv)
{
try
{
//此示例接受形状模型文件然后列表图像到
//进程。我们将这些文件名作为命令行参数。
// Dlib附带examples / faces文件夹中的示例图像,所以给
//这些作为该程序的参数。
if(argc == 1)
{
cout<< 像这样调用这个程序:<< ENDL;
cout<< ./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces / * .jpg<< ENDL;
cout<< \ n你可以从:\ n获取shape_predictor_68_face_landmarks.dat文件;
cout<< http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2<< ENDL;
返回0;
}

//我们需要一个面部检测器。我们将使用它来获得
//图像中每个面的边界框。
frontal_face_detector detector = get_frontal_face_detector();
//我们还需要一个shape_predictor。这是一个工具,可以在给定图像和面部边界框的情况下预测面部
//地标位置。这里我们只是
//从shape_predictor_68_face_landmarks.dat文件加载模型,你给
//作为命令行参数。
shape_predictor sp;
反序列化(argv [1])>> sp;


image_window win,win_faces;
//遍历命令行上提供的所有图像。
for(int i = 2; i< argc; ++ i)
{
cout<< 处理图像<< argv [i]<< ENDL;
array2d< rgb_pixel> IMG;
load_image(img,argv [i]);
//使图像变大,以便检测小脸。
pyramid_up(img);

//现在告诉面部检测器给我们一个边界框列表
//围绕图像中的所有面。
std :: vector< rectangle> dets = detector(img);
cout<< 检测到的面部数量:<< dets.size()<< ENDL;

//现在我们将要求shape_predictor告诉我们
//我们检测到的每张脸的姿势。
std :: vector< full_object_detection>形状;
for(unsigned long j = 0; j< dets.size(); ++ j)
{
full_object_detection shape = sp(img,dets [j]);
cout<< 部件数量:<< shape.num_parts()<< ENDL;
cout<< 第一部分的像素位置:<< shape.part(0)<< ENDL;
cout<< 第二部分的像素位置:<< shape.part(1)<< ENDL;
//你明白了,如果
//你想要它们,你可以获得所有面部位置。在这里,我们只是将它们存储在形状中,这样我们就可以将它们放在屏幕上。
shapes.push_back(shape);
}

//现在让我们在屏幕上查看我们的脸部姿势。
win.clear_overlay();
win.set_image(img);
win.add_overlay(render_face_detections(shapes));

//我们还可以提取每个裁剪的面部副本,直接旋转,
//并缩放到标准尺寸,如下所示:
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<< 按Enter键处理下一张图像...<< ENDL;
cin.get();
}
}
catch(例外& e)
{
cout<< \ @ception抛出! << ENDL;
cout<< e.what()<< ENDL;
}
}

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



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



我还阅读了这些链接:





- 包含source.cpp





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





- 在预处理器中定义





- 您无需使用任何其他库。


After attempting to run a example program downloaded from Here, I understand for working with jpeg files , I must add #define DLIB_JPEG_SUPPORT directive to the project. but before that It's necessary to download jpeg library and add it to the project. I did These steps:

1.Download jpegsr9a.zip from here and unzipped it.

2.Download WIN32.mak and paste it into the jpeg root folder

3.Open Developer Command Prompt from visual studio 2013 tools

4.In command prompt type : nmake -f makefile.vc setup-v10

5.After these steps jpeg.sln created ,the note is when I open jpeg.sln in VS2013 the message come:

maybe base of the problem start from here , I don't know

6.Build the jpeg.sln with the proper configuration (I built it many times with different configurations, recently I built it using this .) at the end of building the error came :"unable to start jpeg.lib" but in release folder or debug folder (depend on configuration) jpeg.lib was created

  1. open main project which is using DLIB for detecting face,I added jpeg root folder to Additonal Include Directory and jepegroot/release to Additional Libarary Directories ,then change the UseLibrary dependencies to "yes" and I also added jpeg.lib to the dependecies.

during building the project errors come:

This is the source which I trying to build and run

//#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;
    }
}

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

I can choose other alternatives but I spend too much time to reach here , I want to know How I can solve this problem and load jpeg file when using DLIB

I also read these links:

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/

解决方案

I solved my problem by below instruction, please follow it.

- Add include directory in VC++

- Include source.cpp

- Add add files in dlib/external/libjpeg to project

- Define in Preprocessor

-- You don't need to use any additional library.

这篇关于如何使用DLIB libarary加载jpeg文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆