

clear all
clc


i1=vfm('grab',1);

I2=rgb2gray(i1);

I2=imadjust(I2,[0 0.4]);
I3=im2bw(I2);

B=~[0 0 0;0 1 0;0 0 0];

I2=filter2(B,I3);
I21=filter2(B,I2);

I4=bwmorph(I2,'clean');
I41=bwmorph(I4,'dilate');
I4=I41;

figure(1)
imshow(I4)

I3=I4;
Icentro_1 = bwmorph(I3,'shrink',inf);
figure(2)
imshow(Icentro_1)


Icentro_2 = bwmorph(I3,'erode',4);
I2=filter2(~B,Icentro_2);

figure(3)
imshow(Icentro_2)
% pause
Icentro_21 = bwmorph(I2,'shrink',inf);
figure(4)
imshow(Icentro_21)

% pause
I_final=double(Icentro_21)+double(Icentro_1);
figure(5)
imshow(I_final)

[ponto1_y,ponto1_x] = find(Icentro_21)
[ponto2_y,ponto2_x] = find(Icentro_1)
%direcao = 180/pi*atan2(ponto1_y-ponto2_y,ponto2_x-ponto1_x)

