Total number of detected cars
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2021-11-12
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 个评论
Image Analyst
2021-11-12
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.
更多回答(1 个)
yanqi liu
2021-11-12
sir,may be use a line to detect the car pass,and add to total,such as

3 个评论
yanqi liu
2021-11-12
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
2021-11-12
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!