pd_inria.cpp 2.11 KB
Newer Older
1
#include "opencv2/datasets/pd_inria.hpp"
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
2 3
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
4 5 6 7 8 9 10 11 12 13 14
#include <iostream>

using namespace std;
using namespace cv;
using namespace cv::datasets;

int main(int argc, char *argv[])
{
    const char *keys =
            "{ help h usage ? |    | show this message }"
            "{ path p         |true| path to dataset }";
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
15

16 17 18 19 20 21 22 23 24 25 26
    CommandLineParser parser(argc, argv, keys);
    string path(parser.get<string>("path"));
    if (parser.has("help") || path=="true")
    {
        parser.printMessage();
        return -1;
    }

    Ptr<PD_inria> dataset = PD_inria::create();
    dataset->load(path);

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
27 28 29 30
    size_t train_size = dataset->getTrain().size();
    size_t test_size = dataset->getTest().size();
    cout << "train size: " << train_size << endl;
    cout << "test size: " << test_size << endl;
31

Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
32
    for( size_t i = 0; i < train_size; i++ )
33
    {
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
        PD_inriaObj *example = static_cast<PD_inriaObj *>(dataset->getTrain()[i].get());
        cout << "\ntrain object index: " << i << endl;
        cout << "file name: " << example->filename << endl;

        // image size
        cout << "image size: " << endl;
        cout << "  - width: " << example->width << endl;
        cout << "  - height: " << example->height << endl;
        cout << "  - depth: " << example->depth << endl;

        Mat img = imread( example->filename );

        // bounding boxes
        for ( size_t j = 0; j < example->bndboxes.size(); j++ )
        {
            cout << "object " << j << endl;
            int x = example->bndboxes[j].x;
            int y = example->bndboxes[j].y;
            cout << "  - xmin = " << x << endl;
            cout << "  - ymin = " << y << endl;
            cout << "  - xmax = " << example->bndboxes[j].width + x << endl;
            cout << "  - ymax = " << example->bndboxes[j].height + y << endl;
            rectangle( img, example->bndboxes[j], Scalar( 0, 0, 255 ), 2 );
        }

        imshow("INRIAPerson Dataset Train Images", img);

        cout << "\nPress a key to continue or ESC to exit." << endl;
        int key = waitKey();
        if( key == 27 ) break;
64 65 66 67
    }

    return 0;
}