|
23 | 23 | if __name__ == "__main__":
|
24 | 24 | parser = argparse.ArgumentParser()
|
25 | 25 | 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", |
27 | 27 | 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/") |
30 | 31 | parser.add_argument("--thr", default=0.2, help="confidence threshold to filter out weak detections")
|
31 | 32 | args = parser.parse_args()
|
32 | 33 |
|
33 |
| - net = dnn.readNetFromCaffe(args.prototxt, args.caffemodel) |
| 34 | + net = cv.dnn.readNetFromCaffe(args.prototxt, args.caffemodel) |
34 | 35 |
|
35 | 36 | if len(args.video):
|
36 |
| - cap = cv2.VideoCapture(args.video) |
| 37 | + cap = cv.VideoCapture(args.video) |
37 | 38 | else:
|
38 |
| - cap = cv2.VideoCapture(0) |
| 39 | + cap = cv.VideoCapture(0) |
39 | 40 |
|
40 | 41 | while True:
|
41 | 42 | # Capture frame-by-frame
|
42 | 43 | ret, frame = cap.read()
|
43 |
| - blob = dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal) |
| 44 | + blob = cv.dnn.blobFromImage(frame, inScaleFactor, (inWidth, inHeight), meanVal) |
44 | 45 | net.setInput(blob)
|
45 | 46 | detections = net.forward()
|
46 | 47 |
|
|
71 | 72 | xRightTop = int(detections[0, 0, i, 5] * cols)
|
72 | 73 | yRightTop = int(detections[0, 0, i, 6] * rows)
|
73 | 74 |
|
74 |
| - cv2.rectangle(frame, (xLeftBottom, yLeftBottom), (xRightTop, yRightTop), |
| 75 | + cv.rectangle(frame, (xLeftBottom, yLeftBottom), (xRightTop, yRightTop), |
75 | 76 | (0, 255, 0))
|
76 | 77 | 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) |
78 | 79 |
|
79 |
| - cv2.rectangle(frame, (xLeftBottom, yLeftBottom - labelSize[1]), |
| 80 | + cv.rectangle(frame, (xLeftBottom, yLeftBottom - labelSize[1]), |
80 | 81 | (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)) |
84 | 85 |
|
85 |
| - cv2.imshow("detections", frame) |
86 |
| - if cv2.waitKey(1) >= 0: |
| 86 | + cv.imshow("detections", frame) |
| 87 | + if cv.waitKey(1) >= 0: |
87 | 88 | break
|
0 commit comments