%Program for acquiring panoramic images from SVAVISCA camera
%Author: Branislav Micusik
%Date: 8 September 2001 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
platform ='sva9x';    %%%%%%svaNT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

show_images = 1;        %put acquired image to the screen
write_to_file = 0;        %write captured images to file
start_idx = 1;				%start of index which will be added to file name

fname = ['sv_video_02_'];  %name of file
dname = ['g:\giotto\motion\data\'];
fovea = 43;               %size of fovea
num_images = 300;         %number of acquired images

global stop;
stop = 1;

str_init=[platform '(''init'',1);'];
str_acq=['im=' platform '(''acq'',1);'];
str_end=[platform '(''end'',1);'];

eval(str_init);              %init SVAVISCA camera
eval(str_acq);                %start of acquiring

if(show_images == 1)
   fig=figure(1); 
	imshow(im,[]); 
	s = uimenu('Label','STOP','Callback','stop=0;');

	%set parameter for faster drawing to the screen
	set(fig,'BackingStore','off');
	set(fig,'DoubleBuffer','on')
	set(fig,'Position',[100 100 size(im,2)*2 size(im,1)*2]);
end;

idx=start_idx;
while(stop & (idx~=(num_images+1) | ~write_to_file))    %repeat after stop will be pushed
   eval(str_acq);             %acquire image
   if(show_images == 1)
     set(get(gca,'children'),'cdata',im);
     drawnow; 
   end;
   if(write_to_file == 1)
     fname1=[dname fname fix_format_int_str(idx,4) '.bmp'];
     imwrite(im(fovea:end,:),gray(256),fname1,'bmp');
   end;
   idx=idx+1;
end;
eval(str_end);