function F=ObjectiveFunction(x0,xdata)

% load intrinsic parameters
global IN indexPOINTS Ti;

N=size(indexPOINTS,2);

% des-vetorize
PlaneEST=Rt2T(rodrigues(x0(1:3)),x0(4:6));
% normalize PI
auxPI=reshape(x0(7:end),3,N);
d=sqrt(sum(auxPI.^2));
PIest=[ auxPI./[d;d;d] ; d];

reproject(N)=struct();
auxIND=1;
for i=1:N,
 T=Ti(:,:,i)*ReflectTransf(PIest(1:3,i),-PIest(4,i))*inv(Ti(:,:,i))*PlaneEST;
 reproject(i).x=ProjectPoints(xdata(:,auxIND:indexPOINTS(i)),T,IN.fc,IN.cc,IN.kc,IN.alpha);
 auxIND=indexPOINTS(i)+1;
end

F=[reproject.x];
