NP-CP-1
NP-CP-1
Overview
Provided code implements a real-time object detection and tracking system. Core principles
behind the code are based on image processing techniques such as edge detection,
background subtraction, and centroid tracking. Goal is to analyze motion in video frames,
identify moving objects, track their paths, and compute their speed.
OpenCV is used to capture each frame, which forms the input for the system.
Code converts each frame to grayscale and reduces noise using Gaussian blur.
This preprocessing step helps to minimize the complexity of the image, ensuring
that subsequent detection algorithms perform more efficiently.
Sobel edge detection is applied to each frame. Sobel operator calculates the
gradient of the image intensity at each pixel, allowing the system to highlight
areas where significant changes in pixel intensity occur. These areas generally
correspond to edges in the objects within the scene.
The Sobel filter is used to detect edges in both the horizontal and vertical
directions. This is a good approach to detecting boundaries of moving objects, as
it enhances regions where significant motion is likely to be present.
To highlight the moving parts of the frame, the code applies a binary thresholding
technique. This converts the image into a binary format, where the white areas
represent detected motion, and the black areas represent static or background
regions.
Contour Detection
Contours are detected from the thresholded binary image, refer to the boundaries
of the moving objects, which are typically formed from the regions marked in
white.
Each contour is a potential object in the scene. The code computes the centroid
(geometric center) of each contour, which represents the approximate center of
the object.
4. Speed Calculation
The moving average technique is a good way to handle real-time data processing
where speed variations may occur due to frame-to-frame inconsistencies or
transient object behavior.
1. Displaying Results
The code overlays the calculated speeds on the video feed using OpenCV. text is
drawn near each moving object, showing the speed in real-time. total number of
moving objects detected is also displayed, allowing users to track the number of
objects being monitored. also includes a bounding box around each detected
object to clearly indicate the area of interest.
Since the camera is positioned directly above the players, their contours are
clearly visible, which allows the Sobel edge detection to identify sharp
boundaries.
Also, background subtraction works well because the motion of the players is
distinct and separated from the relatively static background.
In a horizontal side view, the player's contours are less distinct compared to a
top-down view, making it harder for the tracking algorithm to differentiate the
player from the background.
background subtraction fail to distinguish the player from the background, the
tracking is less effective because the lack of multiple objects to differentiate may
cause the centroid tracking to either lose the player or mistakenly track the
background.
Since there are fewer objects in the scene, the tracking algorithm struggles to
maintain focus on the player, often leading to incorrect tracking or loss of the
player.
Conclusion
This approach successfully detects and tracks multiple moving objects in videos with
clear contrasts between the objects and the background. However, it faces challenges in
scenarios with complex backgrounds or a single object, where edge detection and
tracking should be reviewed and handled different way.