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
2113818f
Commit
2113818f
authored
Sep 17, 2018
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12364 from dkurt:dnn_change_blob_from_image
parents
29bee6f0
58ac3e09
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
40 deletions
+21
-40
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+6
-6
test_caffe_importer.cpp
modules/dnn/test/test_caffe_importer.cpp
+2
-2
test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+1
-2
test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+2
-2
MainActivity.java
...src/org/opencv/samples/opencv_mobilenet/MainActivity.java
+10
-28
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
2113818f
...
...
@@ -46,9 +46,9 @@
#include <opencv2/core.hpp>
#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS
#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v
8
{
#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_34_v
9
{
#define CV__DNN_EXPERIMENTAL_NS_END }
namespace
cv
{
namespace
dnn
{
namespace
experimental_dnn_34_v
8
{
}
using
namespace
experimental_dnn_34_v8
;
}}
namespace
cv
{
namespace
dnn
{
namespace
experimental_dnn_34_v
9
{
}
using
namespace
experimental_dnn_34_v9
;
}}
#else
#define CV__DNN_EXPERIMENTAL_NS_BEGIN
#define CV__DNN_EXPERIMENTAL_NS_END
...
...
@@ -843,7 +843,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @returns 4-dimensional Mat with NCHW dimensions order.
*/
CV_EXPORTS_W
Mat
blobFromImage
(
InputArray
image
,
double
scalefactor
=
1.0
,
const
Size
&
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
tru
e
,
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
false
,
bool
crop
=
fals
e
,
int
ddepth
=
CV_32F
);
/** @brief Creates 4-dimensional blob from image.
...
...
@@ -852,7 +852,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
*/
CV_EXPORTS
void
blobFromImage
(
InputArray
image
,
OutputArray
blob
,
double
scalefactor
=
1.0
,
const
Size
&
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
tru
e
,
int
ddepth
=
CV_32F
);
bool
swapRB
=
false
,
bool
crop
=
fals
e
,
int
ddepth
=
CV_32F
);
/** @brief Creates 4-dimensional blob from series of images. Optionally resizes and
...
...
@@ -873,7 +873,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @returns 4-dimensional Mat with NCHW dimensions order.
*/
CV_EXPORTS_W
Mat
blobFromImages
(
InputArrayOfArrays
images
,
double
scalefactor
=
1.0
,
Size
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
tru
e
,
Size
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
false
,
bool
crop
=
fals
e
,
int
ddepth
=
CV_32F
);
/** @brief Creates 4-dimensional blob from series of images.
...
...
@@ -882,7 +882,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
*/
CV_EXPORTS
void
blobFromImages
(
InputArrayOfArrays
images
,
OutputArray
blob
,
double
scalefactor
=
1.0
,
Size
size
=
Size
(),
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
true
,
bool
crop
=
tru
e
,
const
Scalar
&
mean
=
Scalar
(),
bool
swapRB
=
false
,
bool
crop
=
fals
e
,
int
ddepth
=
CV_32F
);
/** @brief Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure
...
...
modules/dnn/test/test_caffe_importer.cpp
View file @
2113818f
...
...
@@ -307,7 +307,7 @@ TEST_P(Reproducibility_SqueezeNet_v1_1, Accuracy)
net
.
setPreferableBackend
(
DNN_BACKEND_OPENCV
);
net
.
setPreferableTarget
(
targetId
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
,
true
);
ASSERT_TRUE
(
!
input
.
empty
());
Mat
out
;
...
...
@@ -403,7 +403,7 @@ TEST_P(Test_Caffe_nets, DenseNet_121)
const
string
model
=
findDataFile
(
"dnn/DenseNet_121.caffemodel"
,
false
);
Mat
inp
=
imread
(
_tf
(
"dog416.png"
));
inp
=
blobFromImage
(
inp
,
1.0
/
255
,
Size
(
224
,
224
));
inp
=
blobFromImage
(
inp
,
1.0
/
255
,
Size
(
224
,
224
)
,
Scalar
(),
true
,
true
);
Mat
ref
=
blobFromNPY
(
_tf
(
"densenet_121_output.npy"
));
Net
net
=
readNetFromCaffe
(
proto
,
model
);
...
...
modules/dnn/test/test_tf_importer.cpp
View file @
2113818f
...
...
@@ -62,8 +62,7 @@ TEST(Test_TensorFlow, inception_accuracy)
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
ASSERT_TRUE
(
!
sample
.
empty
());
resize
(
sample
,
sample
,
Size
(
224
,
224
));
Mat
inputBlob
=
blobFromImage
(
sample
);
Mat
inputBlob
=
blobFromImage
(
sample
,
1.0
,
Size
(
224
,
224
),
Scalar
(),
/*swapRB*/
true
);
net
.
setInput
(
inputBlob
,
"input"
);
Mat
out
=
net
.
forward
(
"softmax2"
);
...
...
modules/dnn/test/test_torch_importer.cpp
View file @
2113818f
...
...
@@ -278,7 +278,7 @@ TEST_P(Test_Torch_nets, OpenFace_accuracy)
sampleF32
/=
255
;
resize
(
sampleF32
,
sampleF32
,
Size
(
96
,
96
),
0
,
0
,
INTER_NEAREST
);
Mat
inputBlob
=
blobFromImage
(
sampleF32
);
Mat
inputBlob
=
blobFromImage
(
sampleF32
,
1.0
,
Size
(),
Scalar
(),
/*swapRB*/
true
);
net
.
setInput
(
inputBlob
);
Mat
out
=
net
.
forward
();
...
...
@@ -305,7 +305,7 @@ TEST_P(Test_Torch_nets, ENet_accuracy)
net
.
setPreferableTarget
(
target
);
Mat
sample
=
imread
(
_tf
(
"street.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
);
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
,
Size
(),
Scalar
(),
/*swapRB*/
true
);
net
.
setInput
(
inputBlob
,
""
);
Mat
out
=
net
.
forward
();
...
...
samples/android/mobilenet-objdetect/src/org/opencv/samples/opencv_mobilenet/MainActivity.java
View file @
2113818f
...
...
@@ -86,29 +86,13 @@ public class MainActivity extends AppCompatActivity implements CvCameraViewListe
// Forward image through network.
Mat
blob
=
Dnn
.
blobFromImage
(
frame
,
IN_SCALE_FACTOR
,
new
Size
(
IN_WIDTH
,
IN_HEIGHT
),
new
Scalar
(
MEAN_VAL
,
MEAN_VAL
,
MEAN_VAL
),
false
);
new
Scalar
(
MEAN_VAL
,
MEAN_VAL
,
MEAN_VAL
),
/*swapRB*/
false
,
/*crop*/
false
);
net
.
setInput
(
blob
);
Mat
detections
=
net
.
forward
();
int
cols
=
frame
.
cols
();
int
rows
=
frame
.
rows
();
Size
cropSize
;
if
((
float
)
cols
/
rows
>
WH_RATIO
)
{
cropSize
=
new
Size
(
rows
*
WH_RATIO
,
rows
);
}
else
{
cropSize
=
new
Size
(
cols
,
cols
/
WH_RATIO
);
}
int
y1
=
(
int
)(
rows
-
cropSize
.
height
)
/
2
;
int
y2
=
(
int
)(
y1
+
cropSize
.
height
);
int
x1
=
(
int
)(
cols
-
cropSize
.
width
)
/
2
;
int
x2
=
(
int
)(
x1
+
cropSize
.
width
);
Mat
subFrame
=
frame
.
submat
(
y1
,
y2
,
x1
,
x2
);
cols
=
subFrame
.
cols
();
rows
=
subFrame
.
rows
();
detections
=
detections
.
reshape
(
1
,
(
int
)
detections
.
total
()
/
7
);
for
(
int
i
=
0
;
i
<
detections
.
rows
();
++
i
)
{
...
...
@@ -116,26 +100,24 @@ public class MainActivity extends AppCompatActivity implements CvCameraViewListe
if
(
confidence
>
THRESHOLD
)
{
int
classId
=
(
int
)
detections
.
get
(
i
,
1
)[
0
];
int
xLeftBottom
=
(
int
)(
detections
.
get
(
i
,
3
)[
0
]
*
cols
);
int
yLeftBottom
=
(
int
)(
detections
.
get
(
i
,
4
)[
0
]
*
rows
);
int
xRightTop
=
(
int
)(
detections
.
get
(
i
,
5
)[
0
]
*
cols
);
int
yRightTop
=
(
int
)(
detections
.
get
(
i
,
6
)[
0
]
*
rows
);
int
left
=
(
int
)(
detections
.
get
(
i
,
3
)[
0
]
*
cols
);
int
top
=
(
int
)(
detections
.
get
(
i
,
4
)[
0
]
*
rows
);
int
right
=
(
int
)(
detections
.
get
(
i
,
5
)[
0
]
*
cols
);
int
bottom
=
(
int
)(
detections
.
get
(
i
,
6
)[
0
]
*
rows
);
// Draw rectangle around detected object.
Imgproc
.
rectangle
(
subFrame
,
new
Point
(
xLeftBottom
,
yLeftBottom
),
new
Point
(
xRightTop
,
yRightTop
),
Imgproc
.
rectangle
(
frame
,
new
Point
(
left
,
top
),
new
Point
(
right
,
bottom
),
new
Scalar
(
0
,
255
,
0
));
String
label
=
classNames
[
classId
]
+
": "
+
confidence
;
int
[]
baseLine
=
new
int
[
1
];
Size
labelSize
=
Imgproc
.
getTextSize
(
label
,
Core
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
1
,
baseLine
);
// Draw background for label.
Imgproc
.
rectangle
(
subFrame
,
new
Point
(
xLeftBottom
,
yLeftBottom
-
labelSize
.
height
),
new
Point
(
xLeftBottom
+
labelSize
.
width
,
yLeftBottom
+
baseLine
[
0
]),
new
Scalar
(
255
,
255
,
255
),
Core
.
FILLED
);
Imgproc
.
rectangle
(
frame
,
new
Point
(
left
,
top
-
labelSize
.
height
),
new
Point
(
left
+
labelSize
.
width
,
top
+
baseLine
[
0
]),
new
Scalar
(
255
,
255
,
255
),
Imgproc
.
FILLED
);
// Write class name and confidence.
Imgproc
.
putText
(
subFrame
,
label
,
new
Point
(
xLeftBottom
,
yLeftBottom
),
Imgproc
.
putText
(
frame
,
label
,
new
Point
(
left
,
top
),
Core
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
new
Scalar
(
0
,
0
,
0
));
}
}
...
...
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