## carrega imagem permitindo operações com valores negativos nos pixels.
function processaVideo(limiar,flag, alfa)
  BG=int16(imread('out0045.jpeg'));
   BG=(BG(:,:,1)+BG(:,:,2)+BG(:,:,3))/3;
   temp1=BG;
   BG1=BG;
   for i=45:1:1000;
     X=sprintf("%04d",i);
     temp=int16(imread(['out',X,'.jpeg']));
     temp=(temp(:,:,1)+temp(:,:,2)+temp(:,:,3))/3;
     if(flag<2)
       diff = abs(temp-BG);
     else if(flag==2)
            diff= abs(temp-temp1);
          endif
     endif
     BG = alfa * temp + (1-alfa)*BG1;
     BG1=BG;
     temp1=temp;
     output=uint8(255*(diff>limiar));
     imwrite(output,['temp',X,'.jpg']);
  endfor
endfunction 
