Commit cab12bb1 authored by Davis King's avatar Davis King

Added add_image_left_right_flips()

parent dc907c33
......@@ -578,6 +578,60 @@ namespace dlib
assign_image(out_img, flipud(mat(in_img)));
}
// ----------------------------------------------------------------------------------------
namespace impl
{
inline rectangle flip_rect_left_right (
const rectangle& rect,
const rectangle& window
)
{
rectangle temp;
temp.top() = rect.top();
temp.bottom() = rect.bottom();
const long left_dist = rect.left()-window.left();
temp.right() = window.right()-left_dist;
temp.left() = temp.right()-rect.width()+1;
return temp;
}
}
template <
typename image_type
>
void add_image_left_right_flips (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
)
{
// make sure requires clause is not broken
DLIB_ASSERT( images.size() == objects.size(),
"\t void add_image_left_right_flips()"
<< "\n\t Invalid inputs were given to this function."
<< "\n\t images.size(): " << images.size()
<< "\n\t objects.size(): " << objects.size()
);
image_type temp;
std::vector<rectangle> rects;
const unsigned long num = images.size();
for (unsigned long j = 0; j < num; ++j)
{
flip_image_left_right(images[j], temp);
rects.clear();
for (unsigned long i = 0; i < objects[j].size(); ++i)
rects.push_back(impl::flip_rect_left_right(objects[j][i], get_rect(images[j])));
images.push_back(temp);
objects.push_back(rects);
}
}
// ----------------------------------------------------------------------------------------
namespace impl
......
......@@ -421,6 +421,31 @@ namespace dlib
(i.e. it is flipped as if viewed though a mirror)
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void add_image_left_right_flips (
dlib::array<image_type>& images,
std::vector<std::vector<rectangle> >& objects
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
- images.size() == objects.size()
ensures
- This function computes all the left/right flips of the contents of images and
then appends them onto the end of the images array. It also finds the
left/right flips of the rectangles in objects and similarly appends them into
objects. That is, we assume objects[i] is the set of bounding boxes in
images[i] and we flip the bounding boxes so that they still bound the same
objects in the new flipped images.
- #images.size() == images.size()*2
- #objects.size() == objects.size()*2
!*/
// ----------------------------------------------------------------------------------------
template <
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment