필터 지우기
필터 지우기

How can I save the video file from matlab videoPlayer

조회 수: 24 (최근 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:

Vemana
Vemana 2023년 9월 6일
Create a video reader named turtleVideo for the video file turtles.avi.

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!