[37] | 1 | % By Philip Torr 2002
|
---|
| 2 | % copyright Microsoft Corp.
|
---|
| 3 | %torr_matcher_script
|
---|
| 4 | %% to test the Harris corner detector and matcher
|
---|
| 5 |
|
---|
| 6 | clear all
|
---|
| 7 | n_corners = 500;
|
---|
| 8 |
|
---|
| 9 | i1 = imread('j1.bmp','bmp');
|
---|
| 10 | i2 = imread('j2.bmp','bmp');
|
---|
| 11 |
|
---|
| 12 | g1 = rgb2gray(i1);
|
---|
| 13 | g2 = rgb2gray(i2);
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | d1 = double(g1);
|
---|
| 18 | d2 = double(g2);
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | disp('detecting corners');
|
---|
| 22 | [ccr1] = torr_charris(d1,n_corners);
|
---|
| 23 | [ccr2] = torr_charris(d2,n_corners);
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | %imshow(c1);
|
---|
| 28 | %figure;
|
---|
| 29 | %imshow(g1);
|
---|
| 30 | %display corners
|
---|
| 31 | %hold on
|
---|
| 32 | % plot(c_col, c_row, '+');
|
---|
| 33 | % plot(ccr1(:,1), ccr1(:,2), 'g+');
|
---|
| 34 | % plot(ccr2(:,1), ccr2(:,2), 'r+');
|
---|
| 35 | %hold off
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | %imshow(c1);
|
---|
| 39 | f1 = figure;
|
---|
| 40 | imshow(g2);
|
---|
| 41 | title('Second Image')
|
---|
| 42 | %display corners
|
---|
| 43 | hold on
|
---|
| 44 | % plot(c_col, c_row, '+');
|
---|
| 45 | plot(ccr1(:,1), ccr1(:,2), 'g+');
|
---|
| 46 | plot(ccr2(:,1), ccr2(:,2), 'r+');
|
---|
| 47 | hold off
|
---|
| 48 | %[matches12,A12] = corn_matcher(c_patches1, c_patches2, ccr1, ccr2);
|
---|
| 49 | max_disparity = 20;
|
---|
| 50 | half_size = 2;
|
---|
| 51 |
|
---|
| 52 | disp('detecting matches')
|
---|
| 53 | [matches12,minc12,mat12] = torr_corn_matcher(d1, d2, ccr1, ccr2,max_disparity,half_size);
|
---|
| 54 |
|
---|
| 55 | max_corn_d = 0; %maximum corner motion
|
---|
| 56 | n_matches = length(matches12);
|
---|
| 57 |
|
---|
| 58 | med_minc = median(minc12);
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | disp('the maximum corner disparity is used for edge matching')
|
---|
| 62 | max_corn_d
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | display_numbers = 0;
|
---|
| 66 | torr_display_matches(matches12,display_numbers,f1);
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | %
|
---|
| 73 | %
|
---|
| 74 | %
|
---|
| 75 | %
|
---|
| 76 | %
|
---|
| 77 | % %displaying stuff
|
---|
| 78 | %
|
---|
| 79 | %
|
---|
| 80 | % figure
|
---|
| 81 | % %take minimum of matches; minc provides match scores
|
---|
| 82 | % imshow(g1);
|
---|
| 83 | % title('First Image: plus matches')
|
---|
| 84 | % hold on
|
---|
| 85 | % plot(ccr1(:,1), ccr1(:,2), 'bs')
|
---|
| 86 | % plot(ccr2(:,1), ccr2(:,2), 'rs')
|
---|
| 87 | %
|
---|
| 88 | % for i = 1:length(mat12)
|
---|
| 89 | % if mat12(i) ~= 0
|
---|
| 90 | % a = [ccr1(i,1),ccr2(mat12(i),1)]; %x1 x2
|
---|
| 91 | % b = [ccr1(i,2),ccr2(mat12(i),2)]; %y1 y2
|
---|
| 92 | % %x1 y1
|
---|
| 93 | % %x2 y2
|
---|
| 94 | % line(a,b);
|
---|
| 95 | % end
|
---|
| 96 | % end
|
---|
| 97 | % hold off
|
---|
| 98 | %
|
---|
| 99 | % %matches = mat12;
|
---|
| 100 | %
|
---|
| 101 | %
|
---|
| 102 | % hold off
|
---|
| 103 | % save corners |
---|