Total number of detected cars
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Image Analyst
il 12 Nov 2021
You need to index numCars so add a loop counter
loopCounter = 1;
while hasFrame(videoReader)
numCars(loopCounter) = size(bbox, 1);
result = insertText(result, [10 10], numCars(loopCounter), 'BoxOpacity', 1, 'FontSize', 14);
loopCounter = loopCounter + 1;
end
6 Commenti
Image Analyst
il 12 Nov 2021
I've not really had the need to do tracking myself (yet). If that works for you, you can run Python and OpenCV from within MATLAB, or just translate his Python code into MATLAB.
Più risposte (1)
yanqi liu
il 12 Nov 2021
sir,may be use a line to detect the car pass,and add to total,such as
3 Commenti
yanqi liu
il 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
il 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.
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!