【问题标题】:How to get the width and height of a photo in dlib and C++?如何在 dlib 和 C++ 中获取照片的宽度和高度?
【发布时间】:2019-07-28 03:13:35
【问题描述】:

我正在编写一个应用程序来检测人脸并对其进行构图。为了更好地识别,我将照片放大了 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


    【解决方案1】:

    pyramid_up() 有一个相反的功能,pyramid_down()

    【讨论】:

    • 没有这个功能。
    • @Герман 哦? dlib.net/imaging.html#pyramid_down 说:“pyramid_down - 这是一个帮助创建图像金字塔的简单函数对象。它以 N 到 N-1 的比率对图像进行下采样,其中 N 由用户作为模板参数提供。”
    • 好的,但它仍然不是一个函数,我不知道如何在我的代码中使用它。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      • 2017-03-19
      • 2018-07-28
      • 2011-07-12
      • 2014-05-01
      • 2021-02-07
      • 2013-06-01
      相关资源
      最近更新 更多