saving captured images to a folder (error in imwrite function)
Show older comments
Dear friends,
When I run the following code to save the captured image files to a folder it works. But If I set the n value (FramesPerTrigger) to more than 1 then I get an error message.
vid = videoinput('winvideo', 1, 'RGB24_1920x1080');
src = getselectedsource(vid);
vid.LoggingMode = 'memory';
m=5;
vid.TriggerRepeat = 5;
triggerconfig(vid, 'manual');
vid.TimerFcn = 'trigger(vid)';
vid.TimerPeriod = 1;
n=1;
vid.FramesPerTrigger = n;
start(vid)
mkdir('C:\Documents and Settings\suleyman\My Documents\MATLAB\trial\deneme')
for i=1:m*n
imagename = ['C:\Documents and Settings\bae50742\My Documents\MATLAB\kinking\deneme\deneme5_Sample1_image' num2str(i) '.jpg'];
imwrite(getdata(vid), imagename);
end
stop(vid)
Here is the error message;
Error using writejpg (line 38)
4-D data not supported for JPEG files
Error in imwrite (line 477)
feval(fmt_s.write, data, map, filename, paramPairs{:});
How can I fix this problem? thank you in advance for your help.
Answers (2)
Youssef Khmou
on 27 Mar 2013
Edited: Youssef Khmou
on 27 Mar 2013
hi,
The data you are trying to save are 4D , its a sequence of images as :
Width x height x channels x Frames
I suggest this way : After the acquisition process :
data=getdata(vid);
% Try to look at the size of the data : >>size(data)
N=size(data,4); % N is the number of frames
for x=1:N
filename=strcat('Image',int2str(x),'.jpg'); % OR JPEG AS YOU LIKE
imwrite(data(:,:,:,x),filename);
end
1 Comment
Suleyman Deveci
on 27 Mar 2013
kash
on 27 Mar 2013
Try this code
close all
imaqhwinfo
dev_info=imaqhwinfo('winvideo',1)
%info=imaqhwinfo('winvideo')
celldisp(dev_info.SupportedFormats)
vid=videoinput('winvideo',1,'RGB24_1920x1080');
%Open Figure
hFigure=figure(1);
%set parameters for video
%Acquire only one frame each time
triggerconfig(vid,'Manual');
set(vid,'framespertrigger',1);
%Go on forever untill stopped
set(vid,'triggerrepeat',Inf);
%Get a grayscale image
set(vid,'ReturnedColorSpace','RGB');
start(vid);
preview(vid);
data = getsnapshot(vid);
[Save,savename] = uiputfile('*.jpg','save this file')
fname=fullfile(savename,Save);
imwrite(data,fname); % where F is your image
stop(vid),delete(vid),clear('vid')
Categories
Find more on Image Preview and Device Configuration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!