clc
clear all
close all


vis = false    
% visualizacao gráficos on/off
nimg = 10;              
% número imagens padrão
grao = 'P600'
% padrão a gravar
pds = [' a';' b';' c';' d';' e';' f';' g';' h';' i';' j';' l';' m';' n';' o';' p'];
% padrões alternativos ou amostras
spc = [' aa';' bb';' cc';' dd';' ee';' ff';' gg';' hh';' ii';' jj';' ll';' mm';' nn';' oo';' pp'];
%spc = ['ar';'br';'cr';'dr';'er';'fr';'gr';'hr';'jr';'lr';'mr';'nr';'or';'pr'];
%fgs = ['FG1';'FG2';'FG3';'FG4';'FG5';'FG6';'FG7';'FG8';'FG9'];

caminho = 'E:\Programas\MATLAB71\work\Ensaios Mestrado - 05.05.08\Imagens 2ºparte Trabalho\10.03.09 - Darkfield\';
dttlx = '\100309 L AGUA RL ';
   
focado = false;

t=1;
while t < 11
    
    iadq =aquisicaoim;    
    vecam =leituraAmostra2(iadq, vis);
    vecfoca =  verificafoca(iadq, vis);
    
    if t==1
        Pvecam = vecam;
    end
    soma =0;
    
    for i = 1:10
        soma = soma + (Pvecam(i) - vecam(i))^2;
        mtrcs = sqrt(soma);
    end
    
    
    figure(1)
    imshow(iadq)
    text(150,72,'5 segundos','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    pause(1);
    figure(1)
    imshow(iadq)
    text(150,72,'4 segundos','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    pause(1);
    figure(1)
    imshow(iadq)
    text(150,72,'3 segundos','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    pause(1);
    figure(1)
    imshow(iadq)
    text(150,72,'2 segundos','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    pause(1);
    figure(1)
    imshow(iadq)
    text(150,72,'1 segundo','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    pause(1);
    figure(1)
    imshow(iadq)
    text(150,72,'A ADQUIRIR','Color','y',...
    'FontWeight', 'bold');
    text(150,100,int2str(mtrcs),'Color','y',...
    'FontWeight', 'bold');
    
    fn = strcat(caminho, grao);
    fn = [fn dttlx grao pds(t,:) '.jpg']
    
    if mtrcs ~= NaN
        if mtrcs < 2
            imwrite(iadq,fn);
            t = t +1
        end
    end
    
    
end
        
        
        
