hasFrame and readFrame are not working in synchrony.

조회 수: 4 (최근 30일)
Neon Argentus
Neon Argentus 2020년 4월 25일
답변: Walter Roberson 2020년 4월 26일
It is interesting that hasFrame and readFrame doesn't work in synchrony. Here is the example:
atFrame = 0;
while hasFrame(videoObject)
atFrame = atFrame +1;
if atFrame < myConstant % Say myConstant be 500
continue
end
thatFrame = readFrame(videoObject);
imshow(thatFrame)
pause
end
Then what you will see is the first frame of the video object but not 500th frame. hasFrame looked for 500 times consequently into the video object to verify there still contained at least one image in the video object but readFrame didn't synchronize with hasFrame.
Is there any way to start video scan with hasFrame and make the video object being read at that point?

답변 (2개)

darova
darova 2020년 4월 25일
Just get numer of frames
xyloObj = VideoReader('xylophone.mp4');
n = xyloObj.NumberOfFrames;
for i = 1:n
fr = read(xyloObj,i);
imshow(fr)
pause(.5)
end
  댓글 수: 4
Neon Argentus
Neon Argentus 2020년 4월 25일
편집: Neon Argentus 2020년 4월 25일
VideoReader, read function and Duration*FrameRate formula may compute different number of frames. To be sure how many frames exist, the best way, to my opinion, is scan the video and verify each frame exists then do processing on them. I have some videos that VideoReader.NumFrames and result of the hasFrame-readFrame scan differs by six.
darova
darova 2020년 4월 26일
Aha. Thank you

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 4월 26일
hasFrame() does not trigger reading a frame. You can test hasFrame() any number of times you want without it changing the frame number.
atFrame = 0;
while hasFrame(videoObject)
atFrame = atFrame +1;
thatFrame = readFrame(videoObject);
if atFrame < myConstant % Say myConstant be 500
continue
end
imshow(thatFrame)
pause
end
You would use this method when you were sure that you wanted to proceed by way of frame number, regardless of what time that frame occurred at. If you wanted to proceed to a particular time, then you should instead set the object CurrentTime property.
Note: for backwards compatibility, it is still possible to use read(videoObject, frame_number) . This is not recommended because read() can end up triggering it to read the entire video just to get an accurate frame count (the old read() interface was defined to set the number of frames field to be exactly accurate; the readFrame() interface is only defined to set the number of frames field to highest frame number you have read so far.)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by