Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
91ae3de1
Commit
91ae3de1
authored
May 25, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made extract_image_4points() use std::array instead of std::vector and also
made it more robust to funky inputs.
parent
e3a9ddb2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
44 deletions
+15
-44
interpolation.h
dlib/image_transforms/interpolation.h
+5
-34
interpolation_abstract.h
dlib/image_transforms/interpolation_abstract.h
+10
-10
No files found.
dlib/image_transforms/interpolation.h
View file @
91ae3de1
...
...
@@ -14,6 +14,7 @@
#include "../simd.h"
#include "../image_processing/full_object_detection.h"
#include <limits>
#include <array>
#include "../rand.h"
namespace
dlib
...
...
@@ -2146,6 +2147,7 @@ namespace dlib
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
...
...
@@ -2153,11 +2155,9 @@ namespace dlib
void
extract_image_4points
(
const
image_type
&
img_
,
image_type
&
out_
,
const
std
::
vector
<
dpoint
>&
pts
const
std
::
array
<
dpoint
,
4
>&
pts
)
{
DLIB_CASSERT
(
pts
.
size
()
==
4
);
const_image_view
<
image_type
>
img
(
img_
);
image_view
<
image_type
>
out
(
out_
);
if
(
out
.
size
()
==
0
)
...
...
@@ -2202,39 +2202,10 @@ namespace dlib
void
extract_image_4points
(
const
image_type
&
img
,
image_type
&
out
,
const
std
::
vector
<
line
>&
lines
const
std
::
array
<
line
,
4
>&
lines
)
{
DLIB_CASSERT
(
lines
.
size
()
==
4
);
// first find the pair of lines that are most parallel to each other
size_t
best_i
=
0
,
best_j
=
1
;
double
best_angle
=
1000
;
for
(
size_t
i
=
0
;
i
<
lines
.
size
();
++
i
)
{
for
(
size_t
j
=
i
+
1
;
j
<
lines
.
size
();
++
j
)
{
double
angle
=
angle_between_lines
(
lines
[
i
],
lines
[
j
]);
if
(
angle
<
best_angle
)
{
best_angle
=
angle
;
best_i
=
i
;
best_j
=
j
;
}
}
}
std
::
vector
<
dpoint
>
pts
;
// now find the corners of the best quadrilateral we can make from these lines.
for
(
size_t
k
=
0
;
k
<
lines
.
size
();
++
k
)
{
if
(
k
==
best_i
||
k
==
best_j
)
continue
;
pts
.
emplace_back
(
intersect
(
lines
[
k
],
lines
[
best_i
]));
pts
.
emplace_back
(
intersect
(
lines
[
k
],
lines
[
best_j
]));
}
extract_image_4points
(
img
,
out
,
pts
);
extract_image_4points
(
img
,
out
,
find_convex_quadrilateral
(
lines
));
}
// ----------------------------------------------------------------------------------------
...
...
dlib/image_transforms/interpolation_abstract.h
View file @
91ae3de1
...
...
@@ -6,6 +6,7 @@
#include "../pixel.h"
#include "../image_processing/full_object_detection_abstract.h"
#include "../image_processing/generic_image.h"
#include <array>
namespace
dlib
{
...
...
@@ -1456,14 +1457,13 @@ namespace dlib
void
extract_image_4points
(
const
image_type
&
img
,
image_type
&
out
,
const
std
::
vector
<
dpoint
>&
pts
const
std
::
array
<
dpoint
,
4
>&
pts
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- pixel_traits<typename image_traits<image_type>::pixel_type>::has_alpha == false
- pts.size() == 4
ensures
- The 4 points in pts define a convex quadrilateral and this function extracts
that part of the input image img and stores it into #out. Therefore, each
...
...
@@ -1484,21 +1484,21 @@ namespace dlib
void
extract_image_4points
(
const
image_type
&
img
,
image_type
&
out
,
const
std
::
vector
<
line
>&
lines
const
std
::
array
<
line
,
4
>&
lines
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- pixel_traits<typename image_traits<image_type>::pixel_type>::has_alpha == false
- lines.size() == 4
ensures
- This routine simply finds the 4 intersecting points of the given lines and
uses them in a call to the version of extract_image_4points() defined above.
i.e. extract_image_4points(img, out, intersections_between_lines)
- Since 4 lines might intersect at more than 4 locations, we select the
intersections that give a quadrilateral with opposing sides that are as
parallel as possible.
- This routine finds the 4 intersecting points of the given lines which form a
convex quadrilateral and uses them in a call to the version of
extract_image_4points() defined above. i.e. extract_image_4points(img, out,
intersections_between_lines)
throws
- no_convex_quadrilateral: this is thrown if you can't make a convex
quadrilateral out of the given lines.
!*/
// ----------------------------------------------------------------------------------------
...
...
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