Total number of detected cars
Ältere Kommentare anzeigen
I am learning some new materials through this matlab example . In addition to the number of detected cars in each frame, I am intersted to add a counter that keep tracks of the total number cars that passed since frame1.
For example lets say:
in frame 1, 2 cars are detected, and the counters are, "current frame=2", "from begining=2"
in frame 2, 1 more car enters and one of the cars from frame 1 exits, and the counters are, "current frame=2", "from begining=4"
how would you modify the code? copied the loop from the example here.
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
videoPlayer.Position(3:4) = [650,400]; % window size: [width, height]
se = strel('square', 3); % morphological filter for noise removal
while hasFrame(videoReader)
frame = readFrame(videoReader); % read the next video frame
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, frame);
% Use morphological opening to remove noise in the foreground
filteredForeground = imopen(foreground, se);
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
bbox = step(blobAnalysis, filteredForeground);
% Draw bounding boxes around the detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
step(videoPlayer, result); % display the results
end
Akzeptierte Antwort
Weitere Antworten (1)
yanqi liu
am 12 Nov. 2021
0 Stimmen
sir,may be use a line to detect the car pass,and add to total,such as

3 Kommentare
Tala
am 12 Nov. 2021
yanqi liu
am 12 Nov. 2021
sir,i think when the car detect on the line,then add it to total number
of course,can use some target tracking method to compute
Image Analyst
am 12 Nov. 2021
It might lie across the line for several frames so you'd have to be aware of that and only add it when it first appeared, so you don't double count it. Then to handle any kind of video noise you might check to make sure that one it appeared it was there for at least 2 or 3 frames.
Kategorien
Mehr zu Computer Vision Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!