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
1e3052d3
Commit
1e3052d3
authored
Aug 08, 2017
by
Dmitry Kurtaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update MobileNet object detection sample
parent
b67c64e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
18 deletions
+19
-18
mobilenet_ssd_python.py
samples/dnn/mobilenet_ssd_python.py
+16
-15
ssd_mobilenet_object_detection.cpp
samples/dnn/ssd_mobilenet_object_detection.cpp
+3
-3
No files found.
samples/dnn/mobilenet_ssd_python.py
View file @
1e3052d3
...
@@ -23,24 +23,25 @@ classNames = ('background',
...
@@ -23,24 +23,25 @@ classNames = ('background',
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--video"
,
help
=
"path to video file. If empty, camera's stream will be used"
)
parser
.
add_argument
(
"--video"
,
help
=
"path to video file. If empty, camera's stream will be used"
)
parser
.
add_argument
(
"--prototxt"
,
default
=
"MobileNetSSD_
300x300
.prototxt"
,
parser
.
add_argument
(
"--prototxt"
,
default
=
"MobileNetSSD_
deploy
.prototxt"
,
help
=
"path to caffe prototxt"
)
help
=
"path to caffe prototxt"
)
parser
.
add_argument
(
"-c"
,
"--caffemodel"
,
help
=
"path to caffemodel file, download it here: "
parser
.
add_argument
(
"-c"
,
"--caffemodel"
,
default
=
"MobileNetSSD_deploy.caffemodel"
,
"https://github.com/chuanqi305/MobileNet-SSD/blob/master/MobileNetSSD_train.caffemodel"
)
help
=
"path to caffemodel file, download it here: "
"https://github.com/chuanqi305/MobileNet-SSD/"
)
parser
.
add_argument
(
"--thr"
,
default
=
0.2
,
help
=
"confidence threshold to filter out weak detections"
)
parser
.
add_argument
(
"--thr"
,
default
=
0.2
,
help
=
"confidence threshold to filter out weak detections"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
net
=
dnn
.
readNetFromCaffe
(
args
.
prototxt
,
args
.
caffemodel
)
net
=
cv
.
dnn
.
readNetFromCaffe
(
args
.
prototxt
,
args
.
caffemodel
)
if
len
(
args
.
video
):
if
len
(
args
.
video
):
cap
=
cv
2
.
VideoCapture
(
args
.
video
)
cap
=
cv
.
VideoCapture
(
args
.
video
)
else
:
else
:
cap
=
cv
2
.
VideoCapture
(
0
)
cap
=
cv
.
VideoCapture
(
0
)
while
True
:
while
True
:
# Capture frame-by-frame
# Capture frame-by-frame
ret
,
frame
=
cap
.
read
()
ret
,
frame
=
cap
.
read
()
blob
=
dnn
.
blobFromImage
(
frame
,
inScaleFactor
,
(
inWidth
,
inHeight
),
meanVal
)
blob
=
cv
.
dnn
.
blobFromImage
(
frame
,
inScaleFactor
,
(
inWidth
,
inHeight
),
meanVal
)
net
.
setInput
(
blob
)
net
.
setInput
(
blob
)
detections
=
net
.
forward
()
detections
=
net
.
forward
()
...
@@ -71,17 +72,17 @@ if __name__ == "__main__":
...
@@ -71,17 +72,17 @@ if __name__ == "__main__":
xRightTop
=
int
(
detections
[
0
,
0
,
i
,
5
]
*
cols
)
xRightTop
=
int
(
detections
[
0
,
0
,
i
,
5
]
*
cols
)
yRightTop
=
int
(
detections
[
0
,
0
,
i
,
6
]
*
rows
)
yRightTop
=
int
(
detections
[
0
,
0
,
i
,
6
]
*
rows
)
cv
2
.
rectangle
(
frame
,
(
xLeftBottom
,
yLeftBottom
),
(
xRightTop
,
yRightTop
),
cv
.
rectangle
(
frame
,
(
xLeftBottom
,
yLeftBottom
),
(
xRightTop
,
yRightTop
),
(
0
,
255
,
0
))
(
0
,
255
,
0
))
label
=
classNames
[
class_id
]
+
": "
+
str
(
confidence
)
label
=
classNames
[
class_id
]
+
": "
+
str
(
confidence
)
labelSize
,
baseLine
=
cv
2
.
getTextSize
(
label
,
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
1
)
labelSize
,
baseLine
=
cv
.
getTextSize
(
label
,
cv
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
1
)
cv
2
.
rectangle
(
frame
,
(
xLeftBottom
,
yLeftBottom
-
labelSize
[
1
]),
cv
.
rectangle
(
frame
,
(
xLeftBottom
,
yLeftBottom
-
labelSize
[
1
]),
(
xLeftBottom
+
labelSize
[
0
],
yLeftBottom
+
baseLine
),
(
xLeftBottom
+
labelSize
[
0
],
yLeftBottom
+
baseLine
),
(
255
,
255
,
255
),
cv
2
.
FILLED
)
(
255
,
255
,
255
),
cv
.
FILLED
)
cv
2
.
putText
(
frame
,
label
,
(
xLeftBottom
,
yLeftBottom
),
cv
.
putText
(
frame
,
label
,
(
xLeftBottom
,
yLeftBottom
),
cv
2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
0
))
cv
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
0
))
cv
2
.
imshow
(
"detections"
,
frame
)
cv
.
imshow
(
"detections"
,
frame
)
if
cv
2
.
waitKey
(
1
)
>=
0
:
if
cv
.
waitKey
(
1
)
>=
0
:
break
break
samples/dnn/ssd_mobilenet_object_detection.cpp
View file @
1e3052d3
...
@@ -27,12 +27,12 @@ const char* about = "This sample uses Single-Shot Detector "
...
@@ -27,12 +27,12 @@ const char* about = "This sample uses Single-Shot Detector "
"(https://arxiv.org/abs/1512.02325)"
"(https://arxiv.org/abs/1512.02325)"
"to detect objects on image.
\n
"
"to detect objects on image.
\n
"
".caffemodel model's file is avaliable here: "
".caffemodel model's file is avaliable here: "
"https://github.com/chuanqi305/MobileNet-SSD
/blob/master/MobileNetSSD_train.caffemodel
\n
"
;
"https://github.com/chuanqi305/MobileNet-SSD
\n
"
;
const
char
*
params
const
char
*
params
=
"{ help | false | print usage }"
=
"{ help | false | print usage }"
"{ proto | MobileNetSSD_
300x300
.prototxt | model configuration }"
"{ proto | MobileNetSSD_
deploy
.prototxt | model configuration }"
"{ model |
| model weights
}"
"{ model |
MobileNetSSD_deploy.caffemodel | model weights
}"
"{ video | | video for detection }"
"{ video | | video for detection }"
"{ out | | path to output video file}"
"{ out | | path to output video file}"
"{ min_confidence | 0.2 | min confidence }"
;
"{ min_confidence | 0.2 | min confidence }"
;
...
...
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