can someone tell me why cant i use any other video as an example in this code : https://in​.mathworks​.com/help/​vision/exa​mples/dete​cting-cars​-using-gau​ssian-mixt​ure-models​.html

10 次查看(过去 30 天)
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames',80 );
videoReader = vision.VideoFileReader('visiontraffic.avi');
for i = 1:150
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame);
end
figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
se = strel('square', 3);
filteredForeground = imopen(foreground, se);
figure; imshow(filteredForeground); title('Clean Foreground');
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 150);
bbox = step(blobAnalysis, filteredForeground);
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
figure; imshow(result); title('Detected Cars');
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 ~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, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
step(videoPlayer, result); % display the results
end
release(videoReader); % close the video file

回答(1 个)

Steven Lord
Steven Lord 2018-11-26
You didn't say what happens when you try using a different video in the example.
  • Do you have Computer Vision System Toolbox installed? That example uses many functions from that toolbox, so if you don't have it installed you won't be able to run the example. Check the ver function output to determine if you have it installed.
  • Which release of MATLAB are you using? The online documentation is for the most recent release (currently release R2018b.) I'm not sure how much (if any) that example has changed in recent releases, but if you're using a sufficiently old release you may need to use the version of that example included in the documentation for the release you're using. If you're using a really old version (one that predates the introduction of some of the functions/objects used in the example) that example may not exist or may be significantly different.
  • Do you receive an error? If so, what is the full text of the error message (everything displayed in red text) that you receive when you try running the code?
  • Do you receive a different result than you expected? If so, what result do you receive and what result did you expect to receive? Be specific about the differences between the actual results and your expected results.
  • Did something else happen? if so, describe in detail what happened.
  3 个评论
Steven Lord
Steven Lord 2018-11-26
What exactly happens when you change this line of the example to use a different video file?
videoReader = vision.VideoFileReader('visiontraffic.avi');
Y.Rahul Kumar
Y.Rahul Kumar 2018-11-26
i don't know exactly whether im doing it in a correct way or not but instead of using this visiontraffic.avi i tryed randomvideo.avi (randomvideo=some video that i had downloaded)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Computer Vision Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by