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
dcfc1fe1
Commit
dcfc1fe1
authored
Aug 24, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9333 from dkurt:update_mobilenet_sample
parents
63cd581d
1e3052d3
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 @
dcfc1fe1
...
...
@@ -23,24 +23,25 @@ classNames = ('background',
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
()
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"
)
parser
.
add_argument
(
"-c"
,
"--caffemodel"
,
help
=
"path to caffemodel file, download it here: "
"https://github.com/chuanqi305/MobileNet-SSD/blob/master/MobileNetSSD_train.caffemodel"
)
parser
.
add_argument
(
"-c"
,
"--caffemodel"
,
default
=
"MobileNetSSD_deploy.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"
)
args
=
parser
.
parse_args
()
net
=
dnn
.
readNetFromCaffe
(
args
.
prototxt
,
args
.
caffemodel
)
net
=
cv
.
dnn
.
readNetFromCaffe
(
args
.
prototxt
,
args
.
caffemodel
)
if
len
(
args
.
video
):
cap
=
cv
2
.
VideoCapture
(
args
.
video
)
cap
=
cv
.
VideoCapture
(
args
.
video
)
else
:
cap
=
cv
2
.
VideoCapture
(
0
)
cap
=
cv
.
VideoCapture
(
0
)
while
True
:
# Capture frame-by-frame
ret
,
frame
=
cap
.
read
()
blob
=
dnn
.
blobFromImage
(
frame
,
inScaleFactor
,
(
inWidth
,
inHeight
),
meanVal
)
blob
=
cv
.
dnn
.
blobFromImage
(
frame
,
inScaleFactor
,
(
inWidth
,
inHeight
),
meanVal
)
net
.
setInput
(
blob
)
detections
=
net
.
forward
()
...
...
@@ -71,17 +72,17 @@ if __name__ == "__main__":
xRightTop
=
int
(
detections
[
0
,
0
,
i
,
5
]
*
cols
)
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
))
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
),
(
255
,
255
,
255
),
cv
2
.
FILLED
)
cv
2
.
putText
(
frame
,
label
,
(
xLeftBottom
,
yLeftBottom
),
cv
2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
0
))
(
255
,
255
,
255
),
cv
.
FILLED
)
cv
.
putText
(
frame
,
label
,
(
xLeftBottom
,
yLeftBottom
),
cv
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
0
,
0
))
cv
2
.
imshow
(
"detections"
,
frame
)
if
cv
2
.
waitKey
(
1
)
>=
0
:
cv
.
imshow
(
"detections"
,
frame
)
if
cv
.
waitKey
(
1
)
>=
0
:
break
samples/dnn/ssd_mobilenet_object_detection.cpp
View file @
dcfc1fe1
...
...
@@ -27,12 +27,12 @@ const char* about = "This sample uses Single-Shot Detector "
"(https://arxiv.org/abs/1512.02325)"
"to detect objects on image.
\n
"
".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
=
"{ help | false | print usage }"
"{ proto | MobileNetSSD_
300x300
.prototxt | model configuration }"
"{ model |
| model weights
}"
"{ proto | MobileNetSSD_
deploy
.prototxt | model configuration }"
"{ model |
MobileNetSSD_deploy.caffemodel | model weights
}"
"{ video | | video for detection }"
"{ out | | path to output video file}"
"{ 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