LOGIN
Engineer (Project Leader)
 · AbbottabadPakistan
Share
Report
Get Link
STATUS

Lot of you are asking about code, Here is it.

foregroundDetector = vision.ForegroundDetector(‘NumGaussians’, 3, …
‘NumTrainingFrames’, 50);

videoReader = vision.VideoFileReader(‘visiontraffic.avi’);
for i = 1:150
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame);
end

se = strel(‘square’, 3);
filteredForeground = imopen(foreground, se);

blobAnalysis = vision.BlobAnalysis(‘BoundingBoxOutputPort’, true, …
‘AreaOutputPort’, false, ‘CentroidOutputPort’, false, …
‘MinimumBlobArea’, 150);
bbox = step(blobAnalysis, filteredForeground);
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
countint=0;
while ~isDone(videoReader)

frame = step(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, [320 320], numCars, 'BoxOpacity', 1, ...
    'FontSize', 32);


step(videoPlayer, result);  % display the results

end

release(videoReader); % close the video file

0 like 
Like
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
Chat with us!
Help
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard