0

I'm writing an app that detects a face and frames it. For better recognition, I increase the photo 2 times and when I display it, it turns out 2 times more than initially, how to reduce it 2 times? The window has the resize () method, but to use it you need to know the initial size of the photo, but I do not know how.

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

How do I know the size of a photo or reduce it 2 times before displaying?

German
  • 321
  • 1
  • 7

2 Answers2

1

pyramid_up() has an opposite function, pyramid_down().

webwurst
  • 4,830
  • 3
  • 23
  • 32
L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28
  • There is no such function. – German Mar 06 '19 at 16:40
  • @Герман Oh? http://dlib.net/imaging.html#pyramid_down says: "pyramid_down -- This is a simple function object to help create image pyramids. It downsamples an image by a ratio of N to N-1 where N is supplied by the user as a template argument. " – L. Scott Johnson Mar 06 '19 at 16:44
  • Okay, but it's still not a function, and I have no idea how to use it in my code. – German Mar 06 '19 at 16:52
1

The array2d class has member functions nc()and nr() to get the number of columns and rows, which should somehow (potentially divided by the color depth, i.e. number of bytes per pixel) correspond to the size of the image in pixels.

dasmy
  • 569
  • 4
  • 10