Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
47e1133e
Commit
47e1133e
authored
Oct 11, 2017
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnn: add crop flag to blobFromImage
parent
1ea1ff19
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
+23
-14
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+8
-4
dnn.cpp
modules/dnn/src/dnn.cpp
+15
-10
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
47e1133e
...
@@ -695,12 +695,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
...
@@ -695,12 +695,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param scalefactor multiplier for @p image values.
* @param scalefactor multiplier for @p image values.
* @param swapRB flag which indicates that swap first and last channels
* @param swapRB flag which indicates that swap first and last channels
* in 3-channel image is necessary.
* in 3-channel image is necessary.
* @details input image is resized so one side after resize is equal to corresponing
* @param crop flag which indicates whether image will be cropped after resize or not
* @details if @p crop is true, input image is resized so one side after resize is equal to corresponing
* dimension in @p size and another one is equal or larger. Then, crop from the center is performed.
* dimension in @p size and another one is equal or larger. Then, crop from the center is performed.
* If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
* @returns 4-dimansional Mat with NCHW dimensions order.
* @returns 4-dimansional Mat with NCHW dimensions order.
*/
*/
CV_EXPORTS_W
Mat
blobFromImage
(
const
Mat
&
image
,
double
scalefactor
=
1.0
,
const
Size
&
size
=
Size
(),
CV_EXPORTS_W
Mat
blobFromImage
(
const
Mat
&
image
,
double
scalefactor
=
1.0
,
const
Size
&
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
);
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
true
);
/** @brief Creates 4-dimensional blob from series of images. Optionally resizes and
/** @brief Creates 4-dimensional blob from series of images. Optionally resizes and
* crops @p images from center, subtract @p mean values, scales values by @p scalefactor,
* crops @p images from center, subtract @p mean values, scales values by @p scalefactor,
* swap Blue and Red channels.
* swap Blue and Red channels.
...
@@ -711,12 +713,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
...
@@ -711,12 +713,14 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param scalefactor multiplier for @p images values.
* @param scalefactor multiplier for @p images values.
* @param swapRB flag which indicates that swap first and last channels
* @param swapRB flag which indicates that swap first and last channels
* in 3-channel image is necessary.
* in 3-channel image is necessary.
* @details input image is resized so one side after resize is equal to corresponing
* @param crop flag which indicates whether image will be cropped after resize or not
* @details if @p crop is true, input image is resized so one side after resize is equal to corresponing
* dimension in @p size and another one is equal or larger. Then, crop from the center is performed.
* dimension in @p size and another one is equal or larger. Then, crop from the center is performed.
* If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
* @returns 4-dimansional Mat with NCHW dimensions order.
* @returns 4-dimansional Mat with NCHW dimensions order.
*/
*/
CV_EXPORTS_W
Mat
blobFromImages
(
const
std
::
vector
<
Mat
>&
images
,
double
scalefactor
=
1.0
,
CV_EXPORTS_W
Mat
blobFromImages
(
const
std
::
vector
<
Mat
>&
images
,
double
scalefactor
=
1.0
,
Size
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
);
Size
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
true
);
/** @brief Convert all weights of Caffe network to half precision floating point.
/** @brief Convert all weights of Caffe network to half precision floating point.
* @param src Path to origin model from Caffe framework contains single
* @param src Path to origin model from Caffe framework contains single
...
...
modules/dnn/src/dnn.cpp
View file @
47e1133e
...
@@ -85,15 +85,15 @@ static String toString(const T &v)
...
@@ -85,15 +85,15 @@ static String toString(const T &v)
}
}
Mat
blobFromImage
(
const
Mat
&
image
,
double
scalefactor
,
const
Size
&
size
,
Mat
blobFromImage
(
const
Mat
&
image
,
double
scalefactor
,
const
Size
&
size
,
const
Scalar
&
mean
,
bool
swapRB
)
const
Scalar
&
mean
,
bool
swapRB
,
bool
crop
)
{
{
CV_TRACE_FUNCTION
();
CV_TRACE_FUNCTION
();
std
::
vector
<
Mat
>
images
(
1
,
image
);
std
::
vector
<
Mat
>
images
(
1
,
image
);
return
blobFromImages
(
images
,
scalefactor
,
size
,
mean
,
swapRB
);
return
blobFromImages
(
images
,
scalefactor
,
size
,
mean
,
swapRB
,
crop
);
}
}
Mat
blobFromImages
(
const
std
::
vector
<
Mat
>&
images_
,
double
scalefactor
,
Size
size
,
Mat
blobFromImages
(
const
std
::
vector
<
Mat
>&
images_
,
double
scalefactor
,
Size
size
,
const
Scalar
&
mean_
,
bool
swapRB
)
const
Scalar
&
mean_
,
bool
swapRB
,
bool
crop
)
{
{
CV_TRACE_FUNCTION
();
CV_TRACE_FUNCTION
();
std
::
vector
<
Mat
>
images
=
images_
;
std
::
vector
<
Mat
>
images
=
images_
;
...
@@ -104,13 +104,18 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
...
@@ -104,13 +104,18 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
size
=
imgSize
;
size
=
imgSize
;
if
(
size
!=
imgSize
)
if
(
size
!=
imgSize
)
{
{
float
resizeFactor
=
std
::
max
(
size
.
width
/
(
float
)
imgSize
.
width
,
if
(
crop
)
size
.
height
/
(
float
)
imgSize
.
height
);
{
resize
(
images
[
i
],
images
[
i
],
Size
(),
resizeFactor
,
resizeFactor
);
float
resizeFactor
=
std
::
max
(
size
.
width
/
(
float
)
imgSize
.
width
,
Rect
crop
(
Point
(
0.5
*
(
images
[
i
].
cols
-
size
.
width
),
size
.
height
/
(
float
)
imgSize
.
height
);
0.5
*
(
images
[
i
].
rows
-
size
.
height
)),
resize
(
images
[
i
],
images
[
i
],
Size
(),
resizeFactor
,
resizeFactor
);
size
);
Rect
crop
(
Point
(
0.5
*
(
images
[
i
].
cols
-
size
.
width
),
images
[
i
]
=
images
[
i
](
crop
);
0.5
*
(
images
[
i
].
rows
-
size
.
height
)),
size
);
images
[
i
]
=
images
[
i
](
crop
);
}
else
resize
(
images
[
i
],
images
[
i
],
size
);
}
}
if
(
images
[
i
].
depth
()
==
CV_8U
)
if
(
images
[
i
].
depth
()
==
CV_8U
)
images
[
i
].
convertTo
(
images
[
i
],
CV_32F
);
images
[
i
].
convertTo
(
images
[
i
],
CV_32F
);
...
...
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