Contents

clear all;
data.xRect = [ 290 290 230 230]; data.yRect = [ 170 200 200 170];

vyvoj poctu bodu

if  (exist('homography.mat','file'))
    load ('homography.mat');
    if (isnumeric(xHistory.ID))
	IDs = unique(xHistory.ID); nums = zeros(size(xHistory.ID));
       for a = IDs';  nums(a) = sum(xHistory.ID == a); end;
       nums = nums(nums~=0); counts = zeros(max(nums),1);
       for a = 1:max(nums);  counts(a) = sum(nums>=a); end;
       figure; plot(counts,'LineWidth',2); xlabel('Frame number'); ylabel('Number of tracking points'); ylim([0, round(length(IDs)*50)/50 ]); grid on;
       img = im2double(rgb2gray(imread('billa_jpg_283.jpeg')));
       figure; imagesc(img); colormap gray; axis image; hold on;
       plot(xHistory.x(end-counts(end)+1:end),xHistory.y(end-counts(end)+1:end),'Color',hsv2rgb(0,0.9,1),'Marker','x','LineStyle','none');
       title('Remaining points in the last frame');
    else
	fprintf('Bad xHistory format\n\n');
    end
else
    fprintf('Result file homography.mat not found\n\n');
end

homografie dle odevzdaneho .mat souboru

if  (exist('homography.mat','file'))
    load ('homography_ref.mat'); hHistoryRef = hHistory; xHistoryRef = xHistory; load ('homography.mat');
    H = eye(3);
    for a = 1:length(hHistory); H = (hHistory{a}./hHistory{a}(3,3)) * H; end
    Href = eye(3);
    for a = 1:length(hHistoryRef); Href = (hHistoryRef{a}./hHistoryRef{a}(3,3)) * Href; end
    fprintf('Your homography result:\n'); disp(H/H(3,3));
    fprintf('Our homography result:\n');  disp(Href/Href(3,3));
    tmp = H * [data.xRect; data.yRect; ones(size(data.xRect))];
    dataOut.xRect = tmp(1,:)./tmp(3,:); dataOut.yRect = tmp(2,:)./tmp(3,:);
    fprintf('Your transformed rectangle:\n'); disp([dataOut.xRect; dataOut.yRect]);
    tmp = Href * [data.xRect; data.yRect; ones(size(data.xRect))];
    dataRef.xRect = tmp(1,:)./tmp(3,:); dataRef.yRect = tmp(2,:)./tmp(3,:);
    fprintf('Our transformed rectangle:\n'); disp([dataRef.xRect; dataRef.yRect]);
    fprintf('Transforming difference:\n'); disp([dataRef.xRect - dataOut.xRect; dataRef.yRect - dataOut.yRect]);
else
    fprintf('Result file homography.mat not found\n\n');
end
Your homography result:
    0.9036   -0.5188  216.2183
    0.3478    0.4029   15.6236
    0.0001   -0.0003    1.0000

Our homography result:
    0.6486   -0.5466  242.7290
    0.2219    0.3673   22.9926
   -0.0002   -0.0006    1.0000

Your transformed rectangle:
  400.1807  387.9550  333.7946  346.6188
  189.7684  204.1364  183.6203  169.3655

Our transformed rectangle:
  406.8251  396.3648  343.2060  354.7411
  180.3197  198.2280  179.1135  161.9064

Transforming difference:
    6.6444    8.4098    9.4114    8.1223
   -9.4487   -5.9084   -4.5069   -7.4592

vypocet homografie z bodu, kontrola processMpvFrame

load ('homographyPoints.mat');
options.rnsc_threshold = 5; options.rnsc_confidence = 0.99;
figure; imagesc(imgPrev); colormap gray; axis image;
line([data.xRect data.xRect(1)],[data.yRect data.yRect(1)], 'color', 'y');
title('imgPrev with the original rectangle');
figure;
tic; [dataOut xNewOut] = processMpvFrame(data,imgPrev,imgNew,xPrev,xNew,options); t=toc;
fprintf('Found %d inliers %.2f percent of tentative correspondences in %.3f sec.\n\n', length(xNewOut.ID), 100*length(xNewOut.ID)/length(xNew.ID), t);
fprintf('Homography matrix:\n'); disp(dataOut.H);
fprintf('Transformed rectangle:\n'); disp([dataOut.xRect; dataOut.yRect]);
tic; [dataOut xNewOut] = processMpvFrame(data,imgPrev,imgNew,xPrev,xNew,options); t=toc;
fprintf('Found %d inliers %.2f percent of tentative correspondences in %.3f sec.\n\n', length(xNewOut.ID), 100*length(xNewOut.ID)/length(xNew.ID), t);
fprintf('Homography matrix:\n'); disp(dataOut.H);
fprintf('Transformed rectangle:\n'); disp([dataOut.xRect; dataOut.yRect]);
tic; [dataOut xNewOut] = processMpvFrame(data,imgPrev,imgNew,xPrev,xNew,options); t=toc;
fprintf('Found %d inliers %.2f percent of tentative correspondences in %.3f sec.\n\n', length(xNewOut.ID), 100*length(xNewOut.ID)/length(xNew.ID), t);
fprintf('Homography matrix:\n'); disp(dataOut.H);
fprintf('Transformed rectangle:\n'); disp([dataOut.xRect; dataOut.yRect]);
title('imgNew with the transformed rectangle');
Found 100 inliers 100.00 percent of tentative correspondences in 0.155 sec.

Homography matrix:
   -0.0147    0.0017   -0.9576
   -0.0017   -0.0144    0.2869
   -0.0000    0.0000   -0.0150

Transformed rectangle:
  326.8801  323.5107  265.1654  268.5445
  176.9658  205.7722  199.0474  170.2281

Found 100 inliers 100.00 percent of tentative correspondences in 0.091 sec.

Homography matrix:
   -0.0141    0.0019   -0.9467
   -0.0019   -0.0135    0.3212
   -0.0000    0.0000   -0.0143

Transformed rectangle:
  326.6500  323.4612  265.6960  269.0391
  176.0453  204.6714  197.3288  168.6121

Found 100 inliers 100.00 percent of tentative correspondences in 0.086 sec.

Homography matrix:
    0.0149   -0.0015    0.9320
    0.0018    0.0149   -0.3614
    0.0000    0.0000    0.0151

Transformed rectangle:
  326.9826  323.6669  265.5574  268.8273
  176.3527  205.4347  198.6454  169.5145

harris detektor, kontrola track_init (byl-li implentovan)

if  (exist('track_init','file'))
    imgPrev = im2double(imread('cameraman.tif')); [h w]=size(imgPrev);
    options.sigma_d = 1; options.sigma_i = 1.5; options.thresh = 0.080^4; options.ps = 11;
    options.ROI = [1 1 h w];
    xPrev = track_init(imgPrev, options);
    fprintf('Found %d harris points.\n\n',length(xPrev.x));
    figure; imagesc(imgPrev); colormap gray; axis image; showPoints(xPrev);title('Harris detektor, sigma_d 1, sigma_i 1.5');
else
    fprintf('track_init.m not implemented\n\n');
end
Found 51 harris points.

kontrola sledovani

cv08 % spusti vase vlastni nastaveni parametru, ale s upravenou, testovaci processMpvVideo
Found 61 points of interest.

Found 56 inliers 100.00 percent of tentative correspondences.

Original transformation matrix:
    1.0000    0.0500   -5.0000
   -0.0500    1.0000   -2.0000
         0         0    1.0000

Your homography matrix:
    1.0225    0.0630   -7.9041
   -0.0610    1.0302   -2.3942
   -0.0000    0.0001    1.0000

Referece rectangle:
   93.1671   90.6733  140.5486  143.0424
   36.6584   86.5337   89.0274   39.1521

Your transformed rectangle:
   93.7834   91.2933  140.4731  142.6686
   37.1066   86.1418   89.0463   39.9989

Transformation error:
   -0.6163   -0.6200    0.0755    0.3738
   -0.4483    0.3919   -0.0188   -0.8467