Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
0da136b0
Commit
0da136b0
authored
Dec 10, 2012
by
Davis King
Browse files
Added an overload of draw_image() that's useful for drawing images
and doing interpolation at the same time.
parent
6643cbb8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
dlib/gui_widgets/canvas_drawing.h
dlib/gui_widgets/canvas_drawing.h
+31
-0
dlib/gui_widgets/canvas_drawing_abstract.h
dlib/gui_widgets/canvas_drawing_abstract.h
+27
-0
No files found.
dlib/gui_widgets/canvas_drawing.h
View file @
0da136b0
...
...
@@ -695,6 +695,37 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
void
draw_image
(
const
canvas
&
c
,
const
rectangle
&
rect
,
const
image_type
&
img
,
const
rectangle
&
area_
=
rectangle
(
std
::
numeric_limits
<
long
>::
min
(),
std
::
numeric_limits
<
long
>::
min
(),
std
::
numeric_limits
<
long
>::
max
(),
std
::
numeric_limits
<
long
>::
max
())
)
{
const
rectangle
area
=
c
.
intersect
(
rect
).
intersect
(
area_
);
if
(
area
.
is_empty
()
||
img
.
size
()
==
0
)
return
;
const
matrix
<
long
,
1
>
x
=
matrix_cast
<
long
>
(
round
(
linspace
(
0
,
img
.
nc
()
-
1
,
rect
.
width
())));
const
matrix
<
long
,
1
>
y
=
matrix_cast
<
long
>
(
round
(
linspace
(
0
,
img
.
nr
()
-
1
,
rect
.
height
())));
for
(
long
row
=
area
.
top
();
row
<=
area
.
bottom
();
++
row
)
{
const
long
r
=
y
(
row
-
rect
.
top
());
long
cc
=
area
.
left
()
-
rect
.
left
();
for
(
long
col
=
area
.
left
();
col
<=
area
.
right
();
++
col
)
{
assign_pixel
(
c
[
row
-
c
.
top
()][
col
-
c
.
left
()],
img
[
r
][
x
(
cc
++
)]);
}
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
pixel_type
>
...
...
dlib/gui_widgets/canvas_drawing_abstract.h
View file @
0da136b0
...
...
@@ -240,6 +240,33 @@ namespace dlib
- only draws the part of the image that overlaps with the area rectangle
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
void
draw_image
(
const
canvas
&
c
,
const
rectangle
&
rect
,
const
image_type
&
img
,
const
rectangle
&
area
=
rectangle
(
-
infinity
,
-
infinity
,
infinity
,
infinity
)
);
/*!
requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- draws the given image object onto the canvas such that the upper left corner
of the image will appear at the point rect.tl_corner() in the canvas's window
and the lower right corner of the image will appear at rect.br_corner() in
the canvas's window. (note that the upper left corner of the image is
assumed to be the pixel image[0][0] and the lower right corner of the image
is assumed to be image[image.nr()-1][image.nc()-1])
- only draws the part of the image that overlaps with the area rectangle
- Uses nearest neighbor interpolation when the given rect isn't the same size
as the input image.
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment