Total number of detected cars

2 Ansichten (letzte 30 Tage)
Tala
Tala am 12 Nov. 2021
Kommentiert: Image Analyst am 12 Nov. 2021
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

Image Analyst
Image Analyst am 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 Kommentare
Tala
Tala am 12 Nov. 2021
thanks @Image Analyst. Doing some reserach, this gentelman demosntrates how to do such a thing in open cv. apparently there are functions to use in open cv. if you have time, please take a look at the 7 seconds from 28:21 through 28:28. The counter probably picks up some background noise and adds on, but the idea is works. It keep adding up the number of detected objects instead of starting from zero in each frame. Are you familiar with such an example in matlab or its time for me to start using open cv! haha
Image Analyst
Image Analyst am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

yanqi liu
yanqi liu am 12 Nov. 2021
sir,may be use a line to detect the car pass,and add to total,such as
  3 Kommentare
yanqi liu
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
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by