-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source code from http://www.cs.unc.edu/~rraguram/usac/.
- Loading branch information
0 parents
commit 0a766c1
Showing
28 changed files
with
4,972 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (c) 2012 University of North Carolina at Chapel Hill | ||
// All Rights Reserved | ||
// | ||
// Permission to use, copy, modify and distribute this software and its | ||
// documentation for educational, research and non-profit purposes, without | ||
// fee, and without a written agreement is hereby granted, provided that the | ||
// above copyright notice and the following paragraph appear in all copies. | ||
// | ||
// The University of North Carolina at Chapel Hill make no representations | ||
// about the suitability of this software for any purpose. It is provided | ||
// 'as is' without express or implied warranty. | ||
// | ||
// Please send BUG REPORTS to rraguram@cs.unc.edu | ||
// | ||
//////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
%% reads in inliers and f matrix, shows epipolar lines | ||
%function show_epipolar_lines | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% paths and constants | ||
clear; | ||
clc; | ||
close all; | ||
working_dir = 'E:\rraguram\projects\USAC\data\fundmatrix\test1'; | ||
im1_fname = 'im1.jpg'; | ||
im2_fname = 'im2.jpg'; | ||
orig_pts_file = 'orig_pts.txt'; | ||
inliers_file = 'inliers.txt'; | ||
fund_file = 'F.txt'; | ||
|
||
skip = 5; % show subset of epipolar lines based on skip size | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in images | ||
im1 = imread(fullfile(working_dir, im1_fname)); | ||
im2 = imread(fullfile(working_dir, im2_fname)); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in original data points | ||
fid_o = fopen(fullfile(working_dir, orig_pts_file), 'r'); | ||
num_pts = str2num(fgetl(fid_o)); | ||
m1 = zeros(2, num_pts); | ||
m2 = zeros(2, num_pts); | ||
for i = 1:num_pts | ||
temp = textscan(fgetl(fid_o), '%s'); | ||
m1(1, i) = str2num(temp{1,1}{1}); | ||
m1(2, i) = str2num(temp{1,1}{2}); | ||
m2(1, i) = str2num(temp{1,1}{3}); | ||
m2(2, i) = str2num(temp{1,1}{4}); | ||
end | ||
fclose(fid_o); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in inlier data | ||
inliers = textread(fullfile(working_dir, inliers_file)); | ||
inliers_ind = find(inliers > 0); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in fundamental matrix | ||
F = textread(fullfile(working_dir, fund_file)); | ||
F = reshape(F(1:9), 3, 3)'; | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% show inlier matches and epipolar lines for all images | ||
|
||
% form vectors of inlying data points | ||
x1 = m1(:,inliers_ind); x1 = [x1; ones(1, length(x1))]; | ||
x2 = m2(:,inliers_ind); x2 = [x2; ones(1, length(x2))]; | ||
|
||
% display images side by side | ||
I = []; | ||
[M1,N1,K1]=size(im1); | ||
[M2,N2,K2]=size(im2); | ||
N3=N1+N2; | ||
M3=max(M1,M2); | ||
oj=N1; | ||
oi=0; | ||
I(1:M1,1:N1,:) = im1; | ||
I(oi+(1:M2),oj+(1:N2),:) = im2; | ||
|
||
% step through each matched pair of points and display the | ||
% corresponding epipolar lines on the two images | ||
l2 = F*x1; % epipolar lines in image2 | ||
l1 = F'*x2; % epipolar lines in image1 | ||
|
||
% solve for epipoles | ||
[U,D,V] = svd(F); | ||
e1 = hnormalise(V(:,3)); | ||
e2 = hnormalise(U(:,3)); | ||
|
||
figure(1); imshow(uint8(im1)); hold on; axis image; axis off; | ||
for n = 1:skip+1:length(inliers_ind) | ||
hline(l1(:,n), 'g'); plot(e1(1), e1(2), 'g*'); | ||
end | ||
figure(2); imshow(uint8(im2)); hold on; axis image; axis off; | ||
for n = 1:skip+1:length(inliers_ind) | ||
hline(l2(:,n), 'g'); plot(e2(1), e2(2), 'g*'); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
%% warp and display images using the estimated homography | ||
%function show_h_transformed | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% paths and constants | ||
working_dir = 'E:\rraguram\projects\USAC\data\homog\test1'; | ||
im1_fname = 'im1.jpg'; | ||
im2_fname = 'im2.jpg'; | ||
h_file = 'H.txt'; | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in images | ||
im1 = imread(fullfile(working_dir, im1_fname)); | ||
im2 = imread(fullfile(working_dir, im2_fname)); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in homography | ||
H = textread(fullfile(working_dir, h_file)); | ||
H = reshape(H(1:9), 3, 3)'; | ||
H = inv(H); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% transform image and display | ||
|
||
mytform = maketform('projective', H'); | ||
[im2t xd yd] = imtransform(im2, mytform, 'FillValues', 255); | ||
figure; imshow(im2t, 'XData', xd, 'YData', yd); hold on; | ||
h = imshow(im1, gray(256)); | ||
set(h, 'AlphaData', 0.6) | ||
|
||
mytform = maketform('projective', inv(H)'); | ||
[im1t xd yd] = imtransform(im1, mytform, 'FillValues', 255); | ||
figure; imshow(im1t, 'XData', xd, 'YData', yd); hold on; | ||
h = imshow(im2, gray(256)); | ||
set(h, 'AlphaData', 0.6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
%% display inliers for an image pair | ||
%function show_inliers | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% paths and constants | ||
% clear; | ||
clc; | ||
working_dir = 'E:\rraguram\projects\USAC\data\homog\test2'; | ||
im1_fname = 'im1.jpg'; | ||
im2_fname = 'im2.jpg'; | ||
orig_pts_file = 'orig_pts.txt'; | ||
inliers_file = 'inliers.txt'; | ||
|
||
skip = 5; % show subset of inliers based on skip size | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in images | ||
im1 = imread(fullfile(working_dir, im1_fname)); | ||
im2 = imread(fullfile(working_dir, im2_fname)); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in original data points | ||
fid_o = fopen(fullfile(working_dir, orig_pts_file), 'r'); | ||
num_pts = str2num(fgetl(fid_o)); | ||
m1 = zeros(2, num_pts); | ||
m2 = zeros(2, num_pts); | ||
for i = 1:num_pts | ||
temp = textscan(fgetl(fid_o), '%s'); | ||
m1(1, i) = str2num(temp{1,1}{1}); | ||
m1(2, i) = str2num(temp{1,1}{2}); | ||
m2(1, i) = str2num(temp{1,1}{3}); | ||
m2(2, i) = str2num(temp{1,1}{4}); | ||
end | ||
fclose(fid_o); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% read in inlier data | ||
inliers = textread(fullfile(working_dir, inliers_file)); | ||
inliers_ind = find(inliers > 0); | ||
n = randperm(length(inliers_ind)); | ||
inliers_ind = inliers_ind(n); | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% display images side by side and plot inliers | ||
I = []; | ||
padding = 15; | ||
[M1,N1,K1]=size(im1); | ||
[M2,N2,K2]=size(im2); | ||
N3=N1+N2+padding; | ||
M3=max(M1,M2); | ||
oj=N1+padding; | ||
oi=0; | ||
I(1:M3, 1:N3, 1) = 255; I(1:M3, 1:N3, 2) = 255; I(1:M3, 1:N3, 3) = 255; | ||
I(1:M1,1:N1,:) = im1; | ||
I(oi+(1:M2),oj+(1:N2),:) = im2; | ||
|
||
figure(1); | ||
title_str = sprintf('%s and %s: %d inliers',im1_fname, im2_fname, length(inliers_ind)); | ||
imshow(uint8(I)); set(1,'name', title_str); hold on; axis image; axis off; | ||
for m = 1:skip+1:length(inliers_ind) | ||
plot([m1(1,inliers_ind(m)) m2(1,inliers_ind(m))+oj], [m1(2,inliers_ind(m)) m2(2,inliers_ind(m))+oi],'go-','LineWidth',2,'MarkerSize',2,'MarkerFaceColor','g'); | ||
end | ||
|
Oops, something went wrong.