フィルターのクリア

How can I save the video file from matlab videoPlayer

37 ビュー (過去 30 日間)
GeonWoo Jeon
GeonWoo Jeon 2018 年 1 月 12 日
回答済み: Vemana 2023 年 9 月 6 日
How can I save the video file from matlab videoPlayer? I want to export the processed video https://kr.mathworks.com/help/vision/examples/detecting-cars-using-gaussian-mixture-models.html Or how can I change the videoPlayer to videoWriter command?
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
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 件のコメント
KD IS
KD IS 2019 年 10 月 28 日
videoReader = vision.VideoFileReader('visiontraffic.avi');
videoFWriter=vision.VideoFileWriter('result.avi',...
'FrameRate',videoReader.info.VideoFrameRate);
...
...
step(videoPlayer, result); % display the results
step(videoFWriter,result); % saves video
...
...
release(videoReader); % close the videoReader
release(videoFWriter); % close the videoWriter

サインインしてコメントする。

回答 (2 件)

Harish Ramachandran
Harish Ramachandran 2018 年 1 月 17 日
編集済み: Harish Ramachandran 2018 年 1 月 17 日
In the piece of code you attached above, you are using a VideoReader in order to get the individual frames and implement the car detection algorithm.
In a similar manner, you need to create a VideoWriter object in order to write the frames and process/save them into a video.
(Think of it as 'fread' and 'fwrite' but for video files)
Start a 'for' loop and use the 'open' command. Inside the loop, you will need to use the method 'writeVideo'. Then close the file after the loop.
video_object = VideoWriter('getframes');
open(video_object);
for i = 1:number of input frames
writeVideo(video_object, format, other options);
end
close(video_object );
Reference:
  1 件のコメント
Thomas Dixon
Thomas Dixon 2021 年 1 月 27 日
The second link seems to have expired

サインインしてコメントする。


Vemana
Vemana 2023 年 9 月 6 日
Create a video reader named turtleVideo for the video file turtles.avi.

カテゴリ

Help Center および File ExchangeFeature Detection and Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!