0001 function scores=getinitestscore(delta,phi,Nci,BoardCorners,angleVector,rangeMatrix,debug)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 noscans=size(rangeMatrix,1);
0045
0046
0047
0048 [z,x]=pol2cart(repmat(angleVector,[noscans,1]),rangeMatrix);
0049
0050
0051 cameraPlanes = Nci;
0052
0053 scores=zeros(size(rangeMatrix));
0054
0055
0056 if ~exist('debug','var') || isempty(debug)
0057 debug=0;
0058 end
0059
0060
0061
0062 org=[0;0;0];
0063 xax=[1;0;0];
0064 yax=[0;1;0];
0065 zax=[0;0;1];
0066 org=phi*(org-delta);
0067 xax=phi*(xax-delta);
0068 yax=phi*(yax-delta);
0069 zax=phi*(zax-delta);
0070
0071 if debug
0072 figure;
0073 end
0074
0075 for cntr=1:noscans
0076
0077
0078 if cntr<=size(BoardCorners,2) && ~isnan(BoardCorners(cntr).corners(1))
0079
0080 lBoardCorners=BoardCorners(cntr).corners;
0081 lBoardCorners=lBoardCorners-repmat(delta,1,size(lBoardCorners,2));
0082 lBoardCorners=phi*lBoardCorners;
0083
0084
0085 meanpt=mean(lBoardCorners,2);
0086
0087 lpts=[x(cntr,:);zeros(size(angleVector));z(cntr,:)];
0088 lvecs=lpts-repmat(meanpt,[1,length(lpts)]);
0089
0090
0091 N=cameraPlanes(:,cntr);
0092
0093 N=phi*N;
0094
0095
0096 N=N/norm(N);
0097
0098
0099 if debug
0100 clf;
0101
0102 lBoardCornersx=zeros(BoardCorners(cntr).n_sq_x+1,BoardCorners(cntr).n_sq_y+1);
0103 lBoardCornersy=zeros(BoardCorners(cntr).n_sq_x+1,BoardCorners(cntr).n_sq_y+1);
0104 lBoardCornersz=zeros(BoardCorners(cntr).n_sq_x+1,BoardCorners(cntr).n_sq_y+1);
0105
0106 lBoardCornersx(:)=lBoardCorners(1,:);
0107 lBoardCornersy(:)=lBoardCorners(2,:);
0108 lBoardCornersz(:)=lBoardCorners(3,:);
0109 hold on;
0110 h= mesh(lBoardCornersx,lBoardCornersy,lBoardCornersz);
0111 set(h,'edgecolor','red');
0112 plot3(x(cntr,:),zeros(size(x(cntr,:))),z(cntr,:),'.');
0113 xlabel('x');
0114 ylabel('y');
0115 zlabel('z');
0116 axis equal;
0117 title(num2str(cntr));
0118
0119
0120 plot3([org(1),xax(1)],[org(2),xax(2)],[org(3),xax(3)]);text(xax(1),xax(2),xax(3),'x');
0121 plot3([org(1),yax(1)],[org(2),yax(2)],[org(3),yax(3)]);text(yax(1),yax(2),yax(3),'y');
0122 plot3([org(1),zax(1)],[org(2),zax(2)],[org(3),zax(3)]);text(zax(1),zax(2),zax(3),'z');
0123 plot3([0,N(1)],[0,N(2)],[0,N(3)]);text(N(1),N(2),N(3),'N');
0124 axis tight;
0125 cameratoolbar(gcf);
0126 cameratoolbar(gcf,'SetCoordSys','y');
0127 while 1
0128 b=waitforbuttonpress;
0129 if b~=0
0130 btnprsd=get(gcf,'CurrentCharacter');
0131 if btnprsd=='e'
0132 debug=0;
0133 end
0134 break;
0135 end
0136 end
0137 end
0138
0139 N=repmat(N,[1,length(angleVector)]);
0140 dists=cross(lvecs,N);
0141 dists=sqrt(sum(dists.^2));
0142 dists=dists+abs(dot(lvecs,N));
0143
0144 dists=dists./max(dists);
0145 scores(cntr,:)=1-dists;
0146 else
0147 scores(cntr,:)=0;
0148 end
0149 end