load_image_dataset_abstract.h 6.58 KB
Newer Older
1
2
3
4
5
// Copyright (C) 2012  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__
#ifdef DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__

Davis King's avatar
Davis King committed
6
7
#include "image_dataset_metadata.h"
#include "../array/array_kernel_abstract.h"
8
#include <string>
Davis King's avatar
Davis King committed
9
#include <vector>
10
#include "../image_processing/full_object_detection_abstract.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25


namespace dlib
{

// ----------------------------------------------------------------------------------------

    template <
        typename image_type, 
        typename MM
        >
    void load_image_dataset (
        array<image_type,MM>& images,
        std::vector<std::vector<rectangle> >& object_locations,
        const std::string& filename,
26
27
        const std::string& label,
        bool skip_empty_images = false
28
29
    );
    /*!
Davis King's avatar
Davis King committed
30
31
32
        requires
            - image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits<typename image_type::type> is defined  
33
        ensures
34
35
36
37
38
            - This routine loads the images and their associated object boxes from the
              image metadata file indicated by filename.  This metadata file should be in
              the XML format used by the save_image_dataset_metadata() routine.
            - #images.size() == The number of images loaded from the metadata file.  This
              is all the images listed in the file unless skip_empty_images is set to true.
Davis King's avatar
Davis King committed
39
            - #images.size() == #object_locations.size()
40
41
            - This routine is capable of loading any image format which can be read by the
              load_image() routine.
42
            - for all valid i:  
43
                - #images[i] == a copy of the i-th image from the dataset
44
                - #object_locations[i] == a vector of all the rectangles associated with
45
46
47
48
                  #images[i].  
                - if (skip_empty_images == true) then
                    - #object_locations[i].size() != 0
                      (i.e. only images with detection boxes in them will be loaded.)
49
50
51
                - if (labels != "") then
                    - only boxes with the given label will be loaded into object_locations.
                - else
Davis King's avatar
Davis King committed
52
                    - all boxes in the dataset will be loaded into object_locations.
53
54
55
56
    !*/

// ----------------------------------------------------------------------------------------

Davis King's avatar
Davis King committed
57
58
59
60
    template <
        typename image_type, 
        typename MM
        >
61
62
63
64
65
66
    void load_image_dataset (
        array<image_type,MM>& images,
        std::vector<std::vector<rectangle> >& object_locations,
        const std::string& filename
    );
    /*!
Davis King's avatar
Davis King committed
67
68
69
        requires
            - image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits<typename image_type::type> is defined  
70
71
72
73
74
        ensures
            - performs: load_image_dataset(images, object_locations, filename, "");
              (i.e. it ignores box labels and therefore loads all the boxes in the dataset)
    !*/

75
76
77
78
79
80
81
82
83
84
// ----------------------------------------------------------------------------------------

    template <
        typename image_type, 
        typename MM
        >
    std::vector<std::string> load_image_dataset (
        array<image_type,MM>& images,
        std::vector<std::vector<full_object_detection> >& object_locations,
        const std::string& filename,
85
86
        const std::string& label,
        bool skip_empty_images = false
87
88
89
90
91
92
93
94
95
96
97
98
    );
    /*!
        requires
            - image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits<typename image_type::type> is defined  
        ensures
            - This routine loads the images and their associated object locations from the
              image metadata file indicated by filename.  This metadata file should be in
              the XML format used by the save_image_dataset_metadata() routine.
            - The difference between this function and the version of load_image_dataset()
              defined above is that this version will also load object part information and
              thus fully populates the full_object_detection objects.
99
100
            - #images.size() == The number of images loaded from the metadata file.  This
              is all the images listed in the file unless skip_empty_images is set to true.
101
102
103
104
105
106
107
108
109
            - #images.size() == #object_locations.size()
            - This routine is capable of loading any image format which can be read
              by the load_image() routine.
            - returns a vector, call it RETURNED_PARTS, that contains the list of object
              parts found in the input file and loaded into object_locations.  
            - for all valid i:  
                - #images[i] == a copy of the ith image from the dataset.
                - #object_locations[i] == a vector of all the object detections associated
                  with #images[i]. 
110
111
112
                - if (skip_empty_images == true) then
                    - #object_locations[i].size() != 0
                      (i.e. only images with detection boxes in them will be loaded.)
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
                - for all valid j:
                    - #object_locations[i][j].num_parts() == RETURNED_PARTS.size()
                    - for all valid k:
                        - #object_locations[i][j].part(k) == the location of the part
                          with name RETURNED_PARTS[k] or OBJECT_PART_NOT_PRESENT if the
                          part was not indicated for object #object_locations[i][j].
                - if (labels != "") then
                    - only boxes with the given label will be loaded into object_locations.
                - else
                    - all boxes in the dataset will be loaded into object_locations.
    !*/

// ----------------------------------------------------------------------------------------

    template <
        typename image_type, 
        typename MM
        >
    std::vector<std::string> load_image_dataset (
        array<image_type,MM>& images,
        std::vector<std::vector<full_object_detection> >& object_locations,
        const std::string& filename
    );
    /*!
        requires
            - image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits<typename image_type::type> is defined  
        ensures
            - performs: return load_image_dataset(images, object_locations, filename, "");
              (i.e. it ignores box labels and therefore loads all the boxes in the dataset)
    !*/

145
146
147
148
149
150
151
// ----------------------------------------------------------------------------------------

}

#endif // DLIB_LOAD_IMAGE_DaTASET_ABSTRACT_H__