How to Build Real-Time Object Detection with OpenCV and Deep Learning in Python
This tutorial explains how to extend a deep‑learning object detection project with OpenCV and Python to process live video streams, covering setup, command‑line arguments, model loading, frame‑by‑frame detection, drawing bounding boxes, FPS measurement, and performance tips for achieving real‑time results.
Using OpenCV and Python, real‑time video stream deep‑learning object detection can be built by combining a few code snippets, connecting a video source, and adding the existing detection logic.
Using Deep Learning and OpenCV for Video Object Detection
To build a real‑time detector based on OpenCV deep learning, we must efficiently connect a camera or video stream and apply detection to each frame.
First, create a file real_time_object_detection.py and import the required packages (imutils, OpenCV 3.3+, OpenCV‑contrib). Ensure OpenCV 3.3 or newer with the DNN module is installed.
Command‑line arguments include:
--prototxt : path to Caffe prototxt file.
--model : path to the pretrained model.
--confidence : minimum probability threshold (default 0.20).
Initialize class labels and random colors, then load the serialized model using the provided prototxt and model files.
Start a VideoStream (or video file), wait for the camera to warm up, and begin FPS measurement using the FPS class from imutils.
For each frame, resize it, construct a DNN blob, set the blob as network input, and obtain detections. Loop over detections, filter by confidence, extract class index, compute bounding‑box coordinates, and draw colored rectangles with labels on the frame.
Display each processed frame, check for the “q” key to quit, and update the FPS counter. When the loop ends, stop the FPS timer, print the elapsed FPS, close windows, and stop the video stream.
The resulting detector runs at about 6–8 FPS on a typical system; speed can be improved by skipping frames, using faster MobileNet variants, or employing a quantized SqueezeNet model.
Author: 机器之心 Source: https://www.jiqizhixin.com/articles/2017-09-21-3
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
