Hello everyone, OpenCV, the image processing library that I mostly use in the projects I write in Python language, and modules such as dlib and imutils for these libraries are available. We will make great use of the dlib library to effectively track multiple objects in real-time videos and images that I’ll describe today 🤗
In this step, we will examine two types of Python code together.
⏩ multi_object_tracking_slow.py : Simple “naive” method of dlib multi-object tracking
⏩ multi_object_tracking_fast.py : Quick method*
👍 First, let’s import the required packages and modules. We will also use some features from FPS for convenience functions such as frames per second in the imutils package.
🔮 In the image you see above, we have introduced the necessary libraries for us. If you do not have imutils or dlib packages installed in your IDE, you can install them from the terminal with pip package manager. I’d also like to give you a little reminder. Your current pip version may remain low for these packages, you may be faced with a warning such as the following.
To resolve this issue, you must provide the necessary updates by upgrading the pip version as follows.
👍 The command line arguments for the required trust value, output, and model uses came to be written in this script.. We need to place the argument command lines below the libraries. If you are not familiar with these arguments, please see the link I left above.
(command line arguments)
🔎 Let’s take a close look at these parameters together, shall we?
— prototxt: The “distribute” path to Caffe’s prototxt file.
— model: Path to the model file that came with Prototxt.
— video: The path to the input video file.
— output: An optional path to an output video file ( .avi , .mp4)
— confidence: This value represents the minimum probability to filter out weak determinations from object detection.
We face the defined model of multiple objects that will be detected in the array specified as Classes. The trained models include objects such as bicycles, dogs, trains, and cows. These objects operate completely depending on the model and can be changed upon request.
📸 In order to make real-time detection on the Video, the camera must first be turned on Via OpenCV via VideoCapture. In this detection application, parameter 0 is selected because the work will be performed on the computer’s own camera. If an external camera is to be used -usb webcam-1 will be selected as the parameter.
It is possible to select the width and height values on the image according to the dimensions of the received image. In this step we selected (320,180) random values 👩🏽🏫
In the Image Processing area, it is usually converted to grayscale if a change or determination is made on an image. The camera image stored in this system can be used or the camera is operated in real time. If the detection process is to be performed on a recorded video, it is sufficient to call the name of the video in VideoCapture.
🧷 A final footnote is another concept that is frequently used in the image processing field, the concept of fourcc (four character code). Defines the video decoder of the media file as 4 bytes. Fourcc format must be used for recorded video recordings. The video recording required for the system was provided with the following lines of code.
As a result of the model executed during object detection, we are faced with the following result. The Terminal line contains the time and frame Thu second values. FPS is the number of frames per second ⏱
Inferences were determined in real-time on-camera percentile slices. It will now be quite easy to detect people with USB cameras.
It is used to filter weak calculations with the Confidence value. Unwanted values were filtered out in this way. In other words, if the object shown is less than 0.5, it does not label that name to that object.
We’ve detected multiple objects on camera. Wishing to learn more beautiful information in another article 🙋