Extraction of images from video: why images are missed?

4 次查看(过去 30 天)
INTRODUCTION:
I have a avi-video recorded at 2 frames per second and I used the following commands to extract the images of the video:
obj = VideoReader('C:\Desktop\test.avi');
vid = read(obj,[1 5000]);
for k = 1:1:5000
newname = strcat('C:\Desktop\TEST\',num2str(k),'.png');
imwrite(vid(:,:,:,k), newname);
end;
PROBLEM:
I controlled the extracted images and realized that one image is missed at every sixth image or 20 images per minutes. Instead of counting 120 images per minute I counted only 100.
I wonder if someone knows what is going wrong with the commands and what I can do to solve this problem.
Thank you in advance Emerson

采纳的回答

Image Analyst
Image Analyst 2013-3-13
Add k to your loop to display it:
for k = 1:5000
k % No semicolon.
newname = strcat('C:\Desktop\TEST\',num2str(k),'.png');
imwrite(vid(:,:,:,k), newname);
end
Now, do you see any missing k in the list printed to the command line?
  10 个评论
Emerson De Souza
Emerson De Souza 2013-4-5
I did further similars experiments as commented above and it turned out that the problem occurs always when the amount of images are larger than 10000, INDEPENDENT on the the size of the video. ONLY THE AMOUNT OF IMAGES MATTERS. You can try any small video build with small frames, say 20x30 pixels, but the amount of frames > 10000 frames, then again the problem will occur. Anyways, since I have many videos with more than 60000 frames,I will keep using VirtualDub to extract the images. If you still wish to have a look, I can upload it for you via Dropbox. Thanks again for participating in this discussion.
Emerson
AJ
AJ 2013-6-13
Hi Image Analyst, I have a problem , when I am using your code to extract individual frames from a video, I am only able to extract 80 frames from the total number of frames. Kindly help me.

请先登录,再进行评论。

更多回答(2 个)

Shaun VanWeelden
Shaun VanWeelden 2013-3-13
Also, I would do obj.FrameRate to see if it really is 2, this seems much more likely than a number not showing up in a vector.
  1 个评论
Emerson De Souza
Emerson De Souza 2013-3-13
Thank you Shaun,
I double checked the frame rate and it is correct 2. I recorded videos with different frame rate and the problem as described above persists. It seems that there is no relationship between frame rate and not writing the image in correct sequence during extraction. Thanks anyways.
Emerson

请先登录,再进行评论。


Akhilkumar1307
Akhilkumar1307 2017-3-8
Hi
I am facing similar problem too
My video frame rate is 30 fps, so it should show me a frame every 33(1000/30) millisecond but its not Its showing around a frame every 400 millisecond
please help

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by