How do i solve the error of VideoWriter/writeVideo

25 ビュー (過去 30 日間)
chaima
chaima 2023 年 10 月 11 日
編集済み: Bhanu Prakash 2023 年 10 月 11 日

Hello , i wrote this code to detect a face during a video :
%Reading the video
VideoFileReader=VideoReader('vidto.avi');
myvideo = VideoWriter('myfile.avi');
depVideoPlayer=vision.DeployableVideoPlayer;
faceDetector = vision.CascadeObjectDetector ;

%Read frame by Frame
while hasFrame(VideoFileReader)
videoFrame = readFrame(VideoFileReader);
bbox = faceDetector(videoFrame);
videoFrame = insertShape(videoFrame,'rectangle',bbox);

% display video
depVideoPlayer(videoFrame);

writeVideo(myvideo, videoFrame);
pause(1/VideoFileReader.FrameRate);
end

but each time i try the same error shows : 'Error using VideoWriter/writeVideo
OBJ must be open before writing video. Call open(obj) before calling writeVideo.'
why does this keep happening ? and how can i solve this

回答 (1 件)

Bhanu Prakash
Bhanu Prakash 2023 年 10 月 11 日
編集済み: Bhanu Prakash 2023 年 10 月 11 日
Hi Chaima,
I understand that you are facing an error while writing frames into a video file using the ‘VideoWriter’ function.
To write the modified frames into a video file, the ‘VideoWriter’ object ‘myvideo’ should be opened. To do this, you can use the ‘open’ function in MATLAB.
Please find the edited part of the code below:
faceDetector = vision.CascadeObjectDetector;
% Open the VideoWriter object
open(myvideo);
% Read frame by frame
For more information on the ‘open’ function, refer to the following documentation:

カテゴリ

Help Center および File ExchangeTracking and Motion Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by