function XYsIn3D = CalcXYsIn3D( frameNum, SeqTemplate, numDigs, iFirsts, iLasts, DataBlock ) %% %% LARGLY from inside MotBoostEvalOneFrame MOSTLY %% numLasts = size(iLasts(:),1); iLast = iLasts( numLasts ); if( frameNum > iLast ) fprintf( 1, 'Error: Wanted Eval frame %d but batches only reach %d\n', frameNum, iLast ); elseif( frameNum > iLast -25 ) iBatch = numLasts; else iBatch = find( iLasts - 25 > frameNum, 1 ); % The (...,1) says: give me at most 1 index. end; if( numDigs == 4 ) % These two have been precomputed already! %banFileName = sprintf( '%s%.4d_%.4d.ban', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %txt2DfileName = sprintf( '%s%.4d_%.4d_2D.txt', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); matFileName = sprintf( '%s%.4d_%.4d.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %matTriFileName = sprintf( '%s%.4d_%.4d_TriVIds.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); elseif( numDigs == 5 ) % These two have been precomputed already! %banFileName = sprintf( '%s%.5d_%.5d.ban', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %txt2DfileName = sprintf( '%s%.5d_%.5d_2D.txt', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); matFileName = sprintf( '%s%.5d_%.5d.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %matTriFileName = sprintf( '%s%.5d_%.5d_TriVIds.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); elseif( numDigs == 6 ) % These two have been precomputed already! %banFileName = sprintf( '%s%.5d_%.5d.ban', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %txt2DfileName = sprintf( '%s%.5d_%.5d_2D.txt', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); matFileName = sprintf( '%s%.6d_%.6d.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); %matTriFileName = sprintf( '%s%.6d_%.6d_TriVIds.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); end; %Using pad-by-6 for all TriFiles!! %matTriFileName = sprintf( '%s%.6d_%.6d_TriVIds.mat', SeqTemplate, iFirsts(iBatch), iLasts(iBatch) ); % Now load up the 2D traj file and 3D camera calibs load( matFileName ); %load( matTriFileName ); if( DataBlock == 1 ) % Restore! After ICCV deadline. %debugImgName = sprintf( 'G:\\MotBoostData01\\StillsRaw_full\\Test\\Seq05VD_f%.5d.png', frameNum ); debugImgName = sprintf( 'G:\\MotBoostData01\\701_StillsRaw_full\\Seq05VD_f%.5d.png', frameNum ); elseif( DataBlock == 2 ) debugImgName = sprintf( 'G:\\MotBoostData01\\701_StillsRaw_full\\0016E5_%.5d.png', frameNum ); elseif( DataBlock ==3 ) debugImgName = sprintf( 'G:\\MotBoostData01\\701_StillsRaw_full\\0006R0_f%.5d.png', frameNum ); elseif( DataBlock ==4 ) debugImgName = sprintf( 'G:\\MotBoostData01\\701_StillsRaw_full\\0001TP_%.6d.png', frameNum ); end; % debugImgName = % 'G:\\MotBoostData01\\StillsRaw_full\\blankWhite320x240.png'; % debugImgName = % 'G:\\MotBoostData01\\StillsRaw_full\\blankWhite960x720.png'; % find( TrajTable(:, 1) == 7074 ); % Find indexes to all frames with this Traj# % find( TrajTable(:, 2) == 1502 ); % Find indexes to all Traj's with this Frame# isOfTrajsExistingNow = find( TrajTable(:, 2) == frameNum ); % Look through column 2 of TrajTable, return indexes. XYs = TrajTable( isOfTrajsExistingNow, 3:4 ); %% %% Accum 3D camera center for the frames in this batch: %% numXYs = size(XYs,1); offsetForFrameNums = iFirsts(iBatch) -1; Cs = zeros( iLasts(iBatch) - iFirsts(iBatch) + 1, 3); j=1; for( iFrameC = iFirsts(iBatch):iLasts(iBatch) ) iInBig = iFrameC - offsetForFrameNums; % Long way, if we only have P... %P = Kbig(:,:, iInBig ) * Rbig(:,:, iInBig ) * [eye(3) -Tbig(:,:, iInBig )]; %p1 = P(:,1); p2 = P(:,2); P(:,3); p3 = P(:,3); p4 = P(:,4); %C = [det([p2 p3 p4]) -det([p1 p3 p4]) det([p1 p2 p4]) -det([p1 p2 p3]) ]; %Rbig(:,:, iInBig ) * [eye(3) -Tbig(:,:, iInBig )] %C = C(1:3) / C(4); %Cs(j, 1:3) = C; Cs(j, 1:3) = [Tbig(:,:, iInBig )]'; % ...vs short way if we have T j = j+1; end; % curC = Cs( frameNum-offsetForFrameNums, 1:3); % Unused? XYsIn3D = zeros( numXYs, 3 ); for( iTraj = 1:numXYs ) %fprintf(1, 'iTraj #%d\n', iTraj); trajNum = TrajTable(isOfTrajsExistingNow(iTraj), 1); rowsTrajWasTracked = find( TrajTable(:, 1) == trajNum ); %rowsTrajWasTracked = find( (TrajTable(:, 1) <= trajNum+0.001) && (TrajTable(:, 1) >= trajNum-0.001) ); %% Weird hacks, attempting to circumvent Matlab bug that would crash %% here... Still breaks! %% %TrajByFrame = sortrows( TrajTable(rowsTrajWasTracked, 2:4), 1); rowsTrajWasTracked2 = find( TrajTable(:, 1) == trajNum ); while( (size(rowsTrajWasTracked,1) ~= size(rowsTrajWasTracked2,1)) || sum(rowsTrajWasTracked == rowsTrajWasTracked2) ~= size(rowsTrajWasTracked,1) ) fprintf(1, ','); rowsTrajWasTracked = find( TrajTable(:, 1) == trajNum ); rowsTrajWasTracked2 = find( TrajTable(:, 1) == trajNum ); end; TrajByFrame = TrajTable(round(rowsTrajWasTracked), 2:4); if( size( TrajByFrame, 1 ) < 3 ) continue; % No point in processing too short a track. end; %[VarianceIn3D Res] = VarOfBackProjectTraj( TrajByFrame, offsetForFrameNums, Kbig, Rbig, Tbig ); XYsIn3D(iTraj, 1:3) = BackProject2DTrajTo3D( TrajByFrame, offsetForFrameNums, Kbig, Rbig, Tbig ); fprintf(1, '.'); end; fprintf(1, '\n');