如何在dlib和C ++中获取照片的宽度和高度?

时间:2019-03-06 12:41:14

标签: c++ face-detection dlib

我正在编写一个检测人脸并将其框起来的应用。为了获得更好的识别效果,我将照片增加了2倍,而在显示时,结果却比最初增加了2倍,如何将其缩小2倍?该窗口具有resize()方法,但是要使用它,您需要知道照片的初始大小,但是我不知道如何。

#include <iostream>
#include <clocale>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>

using namespace dlib;
using namespace std;

int main(int argc, char* argv[])
{
    try
    {
        setlocale(LC_ALL, "Rus");
        if (argc < 2)
        {
            cout << "face_detector photo.jpg";
            cin.get();
            return 0;
        }
        array2d<unsigned char> img;
        frontal_face_detector detector = get_frontal_face_detector();
        image_window win;
        load_image(img, argv[1]);
        pyramid_up(img); //upsize photo x2
        std::vector<rectangle> dets = detector(img);
        cout << "Faces count: " << dets.size() << endl;
        win.clear_overlay();
        //win.set_size();
        win.set_image(img);
        win.add_overlay(dets, rgb_pixel(255, 0, 0));
        cin.get();
    }
    catch (exception& ex)
    {
        cout << "Exception: " << ex.what() << endl;
        cin.get();
    }
    return 0;
}

在显示前如何知道照片的大小或将其缩小2倍?

2 个答案:

答案 0 :(得分:1)

array2d类具有成员函数nc()nr(),以获取列数和行数,这应该以某种方式(可能除以颜色深度,即每像素的字节数) )对应的图像尺寸(以像素为单位)。

答案 1 :(得分:0)

pyramid_up()具有相反的功能pyramid_down()