function [CamOPT PIopt output]=OptimizeResult1Mirror(CamEST,PIest,Points,CalibInfo)



options=optimset('Algorithm','levenberg-marquardt','Display','iter','MaxIter',200,...
                 'TolFun',1E-12,'TolX',1E-12,...
                 'ScaleProblem','none');


clear global IN indexPOINTS 
global IN indexPOINTS;
IN=CalibInfo;
indexPOINTS=cumsum([Points.sizePoints]);
Saux=[1 0 0 0;0 1 0 0;0 0 -1 0;0 0 0 1];

% make x0
d=PIest(4,:);
auxPI=PIest(1:3,:)*diag(d); 
vecPI=reshape(auxPI,numel(auxPI),1);
CamEST=CamEST*Saux;
vecCamEST=[rodrigues(CamEST(1:3,1:3)) ; CamEST(1:3,4) ];
x0=[vecCamEST;vecPI];
% make xdata (3D points) and ydata (2D points)
xdata=[Points.X];
ydata=[Points.x_px];

[output.x_opt,output.resnorm,output.residual,output.exitflag,output.info] ...
 = lsqcurvefit(@ObjectiveFunction1Mirror,x0,xdata,ydata,[],[],options);


CamOPT=Rt2T(rodrigues(output.x_opt(1:3)),output.x_opt(4:6));
CamOPT=CamOPT*Saux;
auxPIopt=output.x_opt(7:end);
auxPIopt=reshape(auxPIopt,3,numel(auxPIopt)/3);
dOPT=sqrt(sum(auxPIopt.^2));
PIopt=[ auxPIopt./[dOPT;dOPT;dOPT] ; dOPT];

