Skip to content

Commit dcfc1fe

Browse files
committed
Merge pull request opencv#9333 from dkurt:update_mobilenet_sample
2 parents 63cd581 + 1e3052d commit dcfc1fe

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

samples/dnn/mobilenet_ssd_python.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@
2323
if __name__ == "__main__":
2424
parser = argparse.ArgumentParser()
2525
parser.add_argument("--video", help="path to video file. If empty, camera's stream will be used")
26-
parser.add_argument("--prototxt", default="MobileNetSSD_300x300.prototxt",
26+
parser.add_argument("--prototxt", default="MobileNetSSD_deploy.prototxt",
2727
help="path to caffe prototxt")
28-
parser.add_argument("-c", "--caffemodel", help="path to caffemodel file, download it here: "
29-
"https://github.com/chuanqi305/MobileNet-SSD/blob/master/MobileNetSSD_train.caffemodel")
28+
parser.add_argument("-c", "--caffemodel", default="MobileNetSSD_deploy.caffemodel",
29+
help="path to caffemodel file, download it here: "
30+
"https://github.com/chuanqi305/MobileNet-SSD/")
3031
parser.add_argument("--thr", default=0.2, help="confidence threshold to filter out weak detections")
3132
args = parser.parse_args()
3233

33-
net = dnn.readNetFromCaffe(args.prototxt, args.caffemodel)
34+
net = cv.dnn.readNetFromCaffe(args.prototxt, args.caffemodel)
3435

3536
if len(args.video):
36-
cap = cv2.VideoCapture(args.video)
37+
cap = cv.VideoCapture(args.video)
3738
else:
38-
cap = cv2.VideoCapture(0)
39+
cap = cv.VideoCapture(0)
3940

4041
while True:
4142
# Capture frame-by-frame
4243
ret, frame = cap.read()
43-
blob = dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal)
44+
blob = cv.dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal)
4445
net.setInput(blob)
4546
detections = net.forward()
4647

@@ -71,17 +72,17 @@
7172
xRightTop = int(detections[0, 0, i, 5] * cols)
7273
yRightTop = int(detections[0, 0, i, 6] * rows)
7374

74-
cv2.rectangle(frame, (xLeftBottom, yLeftBottom), (xRightTop, yRightTop),
75+
cv.rectangle(frame, (xLeftBottom, yLeftBottom), (xRightTop, yRightTop),
7576
(0, 255, 0))
7677
label = classNames[class_id] + ": " + str(confidence)
77-
labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
78+
labelSize, baseLine = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1)
7879

79-
cv2.rectangle(frame, (xLeftBottom, yLeftBottom - labelSize[1]),
80+
cv.rectangle(frame, (xLeftBottom, yLeftBottom - labelSize[1]),
8081
(xLeftBottom + labelSize[0], yLeftBottom + baseLine),
81-
(255, 255, 255), cv2.FILLED)
82-
cv2.putText(frame, label, (xLeftBottom, yLeftBottom),
83-
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))
82+
(255, 255, 255), cv.FILLED)
83+
cv.putText(frame, label, (xLeftBottom, yLeftBottom),
84+
cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))
8485

85-
cv2.imshow("detections", frame)
86-
if cv2.waitKey(1) >= 0:
86+
cv.imshow("detections", frame)
87+
if cv.waitKey(1) >= 0:
8788
break

samples/dnn/ssd_mobilenet_object_detection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const char* about = "This sample uses Single-Shot Detector "
2727
"(https://arxiv.org/abs/1512.02325)"
2828
"to detect objects on image.\n"
2929
".caffemodel model's file is avaliable here: "
30-
"https://github.com/chuanqi305/MobileNet-SSD/blob/master/MobileNetSSD_train.caffemodel\n";
30+
"https://github.com/chuanqi305/MobileNet-SSD\n";
3131

3232
const char* params
3333
= "{ help | false | print usage }"
34-
"{ proto | MobileNetSSD_300x300.prototxt | model configuration }"
35-
"{ model | | model weights }"
34+
"{ proto | MobileNetSSD_deploy.prototxt | model configuration }"
35+
"{ model | MobileNetSSD_deploy.caffemodel | model weights }"
3636
"{ video | | video for detection }"
3737
"{ out | | path to output video file}"
3838
"{ min_confidence | 0.2 | min confidence }";

0 commit comments

Comments
 (0)