% Algorithms 11.6. , 11.7, 11.8
% Step-by-step euclidean reconstruction algorithm from multiple views
% as described in Chapter 11, "An introduction to 3-D Vision"
% by Y. Ma, S. Soatto, J. Kosecka, S. Sastry (MASKS)
% Code distributed free for non-commercial use
% Copyright (c) MASKS, 2003
%
% Last modified 5/5/2005
% Following shell loads tracked point features
% and corresponding frames and computes the motion and
% 3D structure of tracked features and focal lenght of the camera
% the skew and center of projection of the calibration matrix
% is assumed to be known
% 1. Given n features in m view
% 2. Compute fundamental matrix and projective reconstuction from 2 views
% 3. Use rank based factorization for multiview projective reconstruction
% 4. Solve for uknown focal lenght using absolute quadric constraints
% 5. Upgrade projective structure to euclidean one
% 6. Compute rectifying transformations
% 7. Warp the first and last view of the sequence
% ==================================================================
close all; clear;
% with the affine tracker and undone radial distortion
seq_name = 'oldhouse2/A2000';
image_type = 'bmp';
load oldhouse2/A2000_result_ST; % tracks from 110 to 200
% specify index of starting frame fs, end frame fe
% and the subsampling factor ft
fs = 0; fe = 88; ft = 12;
findex = [fs:ft:fe]; offset = 1;
indf = 1:size(findex,2);
% find features tracked in all the frames
ind = find(goodfeat ~= 0);
j = 0;
for i = (1+offset-1):ft:(fe-fs+1)
j = j+1;
xim(1,:,j) = xttfirst(2,ind) + SaveSTB(2,ind,i);
xim(2,:,j) = xttfirst(1,ind) + SaveSTB(1,ind,i);
xim(3,:,j) = 1;
end;
% consider only indf frames
xim = xim(:,:,indf);
[s, n, m] = size(xim);
opt = '%03d';
imfile = sprintf('%s%s.%s',seq_name,sprintf(opt,findex(1)),image_type)
seq(1).im = (imread(imfile));
% read images
for i = 2:m
if findex(1) < 10 opt = '%03d';
elseif findex(1) < 100 opt = '%02d';
else opt = '%01d';
end;
imfile = sprintf('%s%s.%s',seq_name,sprintf(opt,findex(i)),image_type)
seq(i).im = imread(imfile);
end;
[ydim,xdim,cdim] = size(seq(1).im);
for i = 1:m
imagesc(seq(i).im); colormap gray; hold on;
axis equal; axis image; axis off;
plot(xim(1,:,i), xim(2,:,i),'y.');
for k = 1:n
t = text(xim(1,k,i)+3, xim(2,k,i)+3,num2str(k));
set(t, 'Color', 'yellow');
end
end
disp('tracked features - press ENTER to continue');
pause
%-------------------------------------------------------------
% Structure and motion and focal length recovery given xim
% guess intrinsic parameter matrix
[s, n, m] = size(xim);
fguess = 700; % max(xdim,ydim);
Aguess = [fguess 0 xdim/2; 0 fguess ydim/2; 0 0 1];
%----------------------------
% Normalize the measurements
for i = 1:m
xn(:,:,i) = inv(Aguess)*xim(:,:,i); % partially calibrated views
end
%--------------------------------------------
% uncalibrated case - two view initialization
% compute F and decompose it
Rhat(:,:,1) = diag([1 1 1]);
That(:,1) = zeros(3,1);
F = dfundamental(xn(:,:,1), xn(:,:,m))
[uf, sf, vf] = svd(F'); ep = vf(:,3);
M = skew(ep)'*F; % + rand(3,1)*ep';
Rhat(:,:,m) = M;
That(:,m) = ep;
%----------------------------
% compute projective stucture
[X,lambda] = compute3DStructure(xn(:,:,1),xn(:,:,m),Rhat(:,:,m),That(:,m));
alpha = 1./lambda;
alpha = alpha/alpha(1);
%--------------------------------
% plot projective reconstruction
figure; hold on;
plot3(X(1,:,1),X(2,:,1),X(3,:,1),'k.');
xlabel('x'); ylabel('y'); zlabel('z');
draw_scale = X(3,1,1)/10;
Ts = That(:,1)*draw_scale;
plot3(Ts(1),Ts(2),Ts(3),'r.','MarkerSize',14);
Ts = That(:,m)*draw_scale;
plot3(Ts(1),Ts(2),Ts(3),'r.','MarkerSize',14);
title('Projective reconstruction from two views');
view(220,20); box on; grid off; axis equal;
negative_depth = (~isempty(find(lambda < 0)))
disp('end two view initialization - press ENTER');
pause;
%------------------------------------------------
% Compute initial motion estimates for all frames
init_error = 10; fs = [100]; ns = [];
errabs = init_error; err_prev = 500; iter = 1; errrel = init_error;
while (errabs > 1e-4) & (iter < 30) & (errrel > 1e-5) % (errlambda > 1e-4)
for k = 2:m
j = indf(k);
Q = []; % setup matrix P
for i = 1:n
Q = [Q; kron(skew(xn(:,i,j)),xn(:,i,1)') alpha(i)*skew(xn(:,i,j))];
end;
[um, sm, vm] = svd(Q);
That(:,j) = vm(10:12,12);
Rhat(:,:,j) = reshape(vm(1:9,12),3,3)';
end;
%--------------------------------------
% recompute alpha's based on all views
lambda_prev = lambda;
% recompute alpha's
for i = 1:n
M = []; % setup matrix M
for k = 2:m % set up Hl matrix for all m views
j = indf(k);
a = [ skew(xn(:,i,j))*That(:,j) skew(xn(:,i,j))*Rhat(:,:,j)*xn(:,i,1)];
M = [M; a];
end;
alpha(i) = -M(:,1)'*M(:,2)/norm(M(:,1))^2;
end;
scale = alpha(1);
alpha = alpha/scale; % set the global scale
lambda = 1./alpha;
X = [lambda.*xn(1,:,1); lambda.*xn(2,:,1); lambda.*xn(3,:,1); ones(1,n)];
res = [];
i = 1;
for l = 1:m
j = indf(l);
P(i*3-2:i*3,:) = [Rhat(:,:,j) scale*That(:,j)];
tt = P(i*3-2:i*3,:)*X;
if sum(sign(tt(3,:))) < -n/2
P(i*3-2:i*3,:) = -[Rhat(:,:,j) scale*That(:,j)];
Rhat(:,:,j) = -Rhat(:,:,j);
That(:,j) = -That(:,j);
tt = P(i*3-2:i*3,:)*X;
end;
xr(:,:,i) = Aguess*project(tt);
xd = xim(1:2,:,j) - xr(1:2,:,i);
errnorm = sqrt(xd(1,:).^2 + xd(2,:).^2);
res = [res, errnorm];
i = i+1;
end
f = sum(res)/(n*m);
iter = iter + 1;
fs = [fs f];
if iter > 1
errrel = norm(fs(iter-1) - f);
if fs(iter - 1) < f
errrel = 1e-10;
end;
end;
errabs = norm(f);
errlambda = norm(lambda_prev-lambda);
lambda_prev = lambda;
end % end while iter
disp('end rank based factorization - press ENTER');
pause;
clear xres;
res = [];
%-------------------
% final reprojection
for i = 1:m
j = indf(i);
XP(:,:,i) = P(i*3-2:i*3,:)*X;
xres(:,:,i) = Aguess*project(XP(:,:,i));
PC(:,:,i) = [Rhat(:,:,i) That(:,i)];
xd = xim(1:2,:,j) - xres(1:2,:,i);
errnorm = sqrt(xd(1,:).^2 + xd(2,:).^2);
res(i) = sum(errnorm)/(m*n);
end
figure; hold on;
plot3(2*X(1,:),2*X(2,:),2*X(3,:),'k.'); box on; view(220,20);
title('Projective reconstruction from multiple views');
xlabel('x'); ylabel('y'); zlabel('z');
for i = 1:m
Ts = That(:,i)*2*i*scale;
plot3(Ts(1),Ts(2),Ts(3),'r.','MarkerSize',14);
end
disp('projective reconstruction from multiple views - press ENTER');
pause;
%------------------------------------------------------------
% self-calibration - linear algorithm for unknown focal length
% set up the constraints on absolute quadric
Omega = quadric_linear_f(PC);
if Omega(1,1) < 0;
Omega = - Omega
end
for k = 1:m
t = PC(:,:,k)*Omega*PC(:,:,k)';
fest(k) = sqrt(t(1,1)/t(3,3));
fest2(k) = sqrt(t(2,2)/t(3,3));
Atmp(:,:,k) = Aguess*[fest(k) 0 0; 0 fest(k) 0; 0 0 1];
end
%-------------------------------------------------------
% Estimate the projective to euclidean upgrade transf Hp
v = -[Omega(1,4)/(fest(1)^2); Omega(2,4)/(fest2(1)^2); Omega(3,4)];
K1 = [fest(1) 0 0; 0 fest2(1) 0 ; 0 0 1];
v4 = 1;
Hp = [K1 zeros(3,1); -v'*K1 v4];
%------------------------------------
% update the structure to Euclidean
Xe = inv(Hp)*X;
Xe = [Xe(1,:,1)./Xe(4,:,1);Xe(2,:,1)./Xe(4,:,1);Xe(3,:,1)./Xe(4,:,1);ones(1,size(X,2))];
if (sum(sign(Xe(3,:,1))) < 0) & (sum(sign(Xe(3,:,1))) == -size(Xe,2))
Hp = [K1 zeros(3,1); -v'*K1 -v4];
Xe = inv(Hp)*X;
warning('Flipping the sign of Hp');
elseif (sum(sign(Xe(3,:,1))) < 0) & (sum(sign(Xe(3,:,1))) ~= -size(Xe,2))
error('Projective upgrade: so
没有合适的资源?快使用搜索试试~ 我知道了~
Matlabtuxiangpipei.rar_matlab 图像重构
共72个文件
m:47个
pnm:14个
jpg:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 133 浏览量
2022-07-15
09:57:38
上传
评论
收藏 1.87MB RAR 举报
温馨提示
matlab图像匹配,三位图像重构,都可以用这个程序
资源推荐
资源详情
资源评论
收起资源包目录
Matlabtuxiangpipei.rar (72个子文件)
Matlab图像匹配的都可以用的到,做三维重建
matlabcode
examples-code
test_11_9.m 1017B
yos.1.pnm 78KB
makeRows.m 162B
edgeDetection.m 1KB
yos.10.pnm 78KB
yos.11.pnm 78KB
LocalMaximum.m 1016B
project.m 146B
Hwarp.m 1KB
dfundamental.m 1KB
plot3Lines.m 192B
test_4.m 155B
yos.16.pnm 78KB
plotLines.m 149B
al.tif 64KB
sfm_projective.m 9KB
yos.13.pnm 78KB
skew.m 241B
vanishing_point.m 727B
sampleFlow.m 3KB
ch4appendix.m 797B
examples-code.zip 851KB
sfm_points.m 5KB
plot_struct.m 1KB
angle_vec.m 303B
essentialDiscrete.m 4KB
compute3DStructure.m 1KB
test_5_1.m 3KB
quadric_linear_f.m 2KB
alExample.m 760B
yos.14.pnm 78KB
11.jpg 10KB
harrisCorner.m 2KB
yos.15.pnm 78KB
warpNonlin.m 794B
test_test.m 475B
sfm_mixed.m 5KB
step_by_step.m 10KB
plotLineNormal.m 758B
triple_product.m 249B
yos.7.pnm 78KB
exp_matrix.m 331B
isoscale.m 472B
test_6_2.m 4KB
draw_frame_scaled.m 1KB
homography2Motion.m 2KB
yos.2.pnm 78KB
lady.gif 67KB
shelves.jpg 196KB
addons
test_11_9.m 1017B
shelves.jpg 196KB
rectifData.mat 2KB
yos.4.pnm 78KB
rot_matrix.m 535B
rectifData.mat 2KB
row_quadric_f.m 389B
corridor.jpg 21KB
test_6_1.m 3KB
houselines_mixed.m 1KB
yos.5.pnm 78KB
plot3_cube.m 704B
yos.6.pnm 78KB
rq.m 926B
test_5_2.m 2KB
addons.zip 196KB
yos.3.pnm 78KB
yos.12.pnm 78KB
gaussian_filt.m 2KB
projRectify.m 2KB
plot3_struct.m 1KB
warpLinear.m 682B
www.pudn.com.txt 218B
共 72 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 77
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
- Java项目:在线蛋糕商城系统(java+jsp+mysql)源码+数据库+期末大作业.zip
- ZapyaClient10_7-1.apk
- 织梦cms站长导航网站源码.zip
- 基于SSM+MySQL的网络投票调查问卷系统源码+数据库(java期末大作业).zip
- 基于jsp+servlet的宠物商城网站系统源码+数据库(java期末大作业).zip
- 基于Python+Tensorflow实现声纹识别+源代码+文档说明.zip
- java-leetcode题解之第112题路径总和.zip
- java-leetcode题解之第111题二叉树的最小深度.zip
- java-leetcode题解之第110题平衡二叉树.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功