Commit d23084ef authored by Davis King's avatar Davis King

Added sub_image() and sub_image_proxy.

parent aa936bc6
......@@ -14,6 +14,80 @@
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <typename T>
struct sub_image_proxy
{
sub_image_proxy (
T& img_,
const rectangle& rect_
) : img(img_), rect(rect_.intersect(get_rect(img_)))
{}
T& img;
const rectangle rect;
};
template <typename T>
struct image_traits<sub_image_proxy<T> >
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
struct image_traits<const sub_image_proxy<T> >
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
inline long num_rows( const sub_image_proxy<T>& img) { return img.rect.height(); }
template <typename T>
inline long num_columns( const sub_image_proxy<T>& img) { return img.rect.width(); }
template <typename T>
inline void* image_data( sub_image_proxy<T>& img)
{
typedef typename image_traits<T>::pixel_type pixel_type;
return static_cast<pixel_type*>(image_data(img.img)) + img.rect.left() + img.rect.top()*num_columns(img.img);
}
template <typename T>
inline const void* image_data( const sub_image_proxy<T>& img)
{
typedef typename image_traits<T>::pixel_type pixel_type;
return static_cast<const pixel_type*>(image_data(img.img)) + img.rect.left() + img.rect.top()*num_columns(img.img);
}
template <typename T>
inline long width_step(
const sub_image_proxy<T>& img
)
{
return width_step(img.img);
}
template <
typename image_type
>
sub_image_proxy<image_type> sub_image (
image_type& img,
const rectangle& rect
)
{
return sub_image_proxy<image_type>(img,rect);
}
template <
typename image_type
>
const sub_image_proxy<const image_type> sub_image (
const image_type& img,
const rectangle& rect
)
{
return sub_image_proxy<const image_type>(img,rect);
}
// ----------------------------------------------------------------------------------------
class interpolate_nearest_neighbor
......
......@@ -1125,6 +1125,71 @@ namespace dlib
and stores the single output chip into #chip.
!*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
struct sub_image_proxy
{
/*!
REQUIREMENTS ON image_type
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
WHAT THIS OBJECT REPRESENTS
This is a lightweight image object for referencing a subwindow of an image.
It implements the generic image interface and can therefore be used with
any function that expects a generic image, excepting that you cannot change
the size of a sub_image_proxy.
Note that it only stores a pointer to the image given to its constructor
and therefore does not perform a copy. Moreover, this means that an
instance of this object becomes invalid after the image it references is
destroyed.
!*/
sub_image_proxy (
T& img,
const rectangle& rect
);
/*!
ensures
- This object is an image that represents the part of img contained within
rect. If rect is larger than img then rect is cropped so that it does
not go outside img.
!*/
};
template <
typename image_type
>
sub_image_proxy<image_type> sub_image (
image_type& img,
const rectangle& rect
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
ensures
- returns sub_image_proxy<image_type>(img,rect)
!*/
template <
typename image_type
>
const sub_image_proxy<const image_type> sub_image (
const image_type& img,
const rectangle& rect
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
ensures
- returns sub_image_proxy<const image_type>(img,rect)
!*/
// ----------------------------------------------------------------------------------------
chip_details get_face_chip_details (
......
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