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

问题描述 投票:0回答:2

我正在编写一个可以检测到脸部并对其构图的应用程序。为了更好地识别,我将照片增加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次?

c++ face-detection dlib
2个回答
1
投票

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


1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.