function [PPMdlt m M]=PPMcalib()
rgb_img= imread('chesscalib.bmp');
 rawimg = .2989*rgb_img(:,:,1)+.5870*rgb_img(:,:,2)+.1140*rgb_img(:,:,3);
 tic;
 [accum, circen, cirrad] = CircularHough_Grd(rawimg, [1 30]); %cerca i cerchi di raggio 1 fino a 30
 toc;
 %%%%%con6punti
 rgb_imgcroc=croce(rgb_img,10,round(circen(1,1)),round(circen(1,2)),255,0,0);
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(2,1)),round(circen(2,2)),255,0,0);
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(3,1)),round(circen(3,2)),255,0,0);
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(4,1)),round(circen(4,2)),255,0,0);
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(5,1)),round(circen(5,2)),255,0,0);
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(6,1)),round(circen(6,2)),255,0,0);
  %%%%%con10punti
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(7,1)),round(circen(7,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(8,1)),round(circen(8,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(9,1)),round(circen(9,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(10,1)),round(circen(10,2)),255,0,0);
%%%%%%%con14punti
  rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(11,1)),round(circen(11,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(12,1)),round(circen(12,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(13,1)),round(circen(13,2)),255,0,0);
rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(14,1)),round(circen(14,2)),255,0,0);
%rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(15,1)),round(circen(15,2)),255,0,0);
%rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(16,1)),round(circen(16,2)),255,0,0);
%rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(17,1)),round(circen(17,2)),255,0,0);
%rgb_imgcroc=croce(rgb_imgcroc,10,round(circen(18,1)),round(circen(18,2)),255,0,0);
imshow(rgb_imgcroc)



figure(1)
pause(5)
[u,v] = ginput(14)


u_1=u(1)
v_1=v(1)
u_2=u(2)
v_2=v(2)
u_3=u(3)
v_3=v(3)
u_4=u(4)
v_4=v(4)
u_5=u(5)
v_5=v(5)
u_6=u(6)
v_6=v(6)  %6 punti
u_7=u(7)
v_7=v(7)
u_8=u(8)
v_8=v(8)
u_9=u(9)
v_9=v(9)
u_10=u(10)
v_10=v(10) %10 punti
u_11=u(11)
v_11=v(11)
u_12=u(12)
v_12=v(12)
u_13=u(13)
v_13=v(13)
u_14=u(14)
v_14=v(14)%14 punti
% i punti vengono dunque accoppiati in questo modo


X_1=1
Y_1=0
Z_1=0
X_2=3
Y_2=0
Z_2=0
X_3=1
Y_3=0
Z_3=1
X_4=3
Y_4=0
Z_4=1
X_5=1
Y_5=1
Z_5=0
X_6=3
Y_6=1
Z_6=0
%%%%%fino qui per 6 punti
X_7=1
Y_7=0
Z_7=2
X_8=3
Y_8=0
Z_8=2
X_9=1
Y_9=2
Z_9=0
X_10=3
Y_10=2
Z_10=0
%%%%%%%fino qui per 10 punti
X_11=1
Y_11=0
Z_11=3
X_12=3
Y_12=0
Z_12=3
X_13=1
Y_13=3
Z_13=0
X_14=3
Y_14=3
Z_14=0



%%%%%%con 6 punti
m=[u_1 u_2 u_3 u_4 u_5 u_6;v_1 v_2 v_3 v_4 v_5 v_6]
M=[X_1 X_2 X_3 X_4 X_5 X_6;Y_1 Y_2 Y_3 Y_4 Y_5 Y_6;Z_1 Z_2 Z_3 Z_4 Z_5 Z_6]
%%%%con 10 punti
m=[u_1 u_2 u_3 u_4 u_5 u_6 u_7 u_8 u_9 u_10;v_1 v_2 v_3 v_4 v_5 v_6 v_7 v_8 v_9 v_10]
M=[X_1 X_2 X_3 X_4 X_5 X_6 X_7 X_8 X_9 X_10;Y_1 Y_2 Y_3 Y_4 Y_5 Y_6 Y_7 Y_8 Y_9 Y_10;Z_1 Z_2 Z_3 Z_4 Z_5 Z_6 Z_7 Z_8 Z_9 Z_10]
%%%%%%%%%%%%%%% con 14 punti
m=[u_1 u_2 u_3 u_4 u_5 u_6 u_7 u_8 u_9 u_10 u_11 u_12 u_13 u_14;v_1 v_2 v_3 v_4 v_5 v_6 v_7 v_8 v_9 v_10 v_11 v_12 v_13 v_14]
M=[X_1 X_2 X_3 X_4 X_5 X_6 X_7 X_8 X_9 X_10 X_11 X_12 X_13 X_14;Y_1 Y_2 Y_3 Y_4 Y_5 Y_6 Y_7 Y_8 Y_9 Y_10 Y_11 Y_12 Y_13 Y_14;Z_1 Z_2 Z_3 Z_4 Z_5 Z_6 Z_7 Z_8 Z_9 Z_10 Z_11 Z_12 Z_13 Z_14]
PPMdlt=resect(m,M)

%%%ppmdlt
[K R t]=art(PPMdlt)
yteta=asind(-R(3,1))
xbo=asind(R(3,2)/cosd(yteta))
zfi=asind(R(2,1)/cosd(yteta))
[a,b]=ieul(R)
angolideg = convang(a,'rad','deg')
psi=angolideg(1)
theta=angolideg(2)
phi=angolideg(3)

strcat('H',num2str(a(1)),'P',num2str(a(2)),'B',num2str(a(3)),'X',num2str(t(1)),'Y',num2str(t(2)),'Z',num2str(t(3)),'E')
G1=[R t;0 0 0 1]



%NEL PROGRAMMA GLI PER FAR GIRARE IL RIFERIMENTO MODO CORRETTAMENTE METTI
%LA PUNTA DELL'ASSE SUGLI OCCHI E POI  L'ANGOLO POSITIVO è IN VERSO ORARIO