视觉SFM一个实例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

视觉(15)SFM的一个例子
这里采用的是Yi Ma , Stefano Soatto. An Invitation to 3-D Vision , From Images to Geometric Models 的算法(window.cproArray = window.cproArray || []).push({ id: "u2280119" });
%// Algorithm 8.1. also 11.7
%// Rank based factorization algorithm for multiview reconstruction %// using point features %// as described in Chapter 8, "An introduction to 3-D Vision" %// by Y. Ma, S. Soatto, J. Koseck a, S. Sastry (MASKS) %// Code distributed free for non-commercial use %// Copyright (c) MASK S, 2003
%// Generates multiple synthetic views of a house and computes the %// motion and structure, cal ibrated case, point features only %// Jana Kosecka, George Mason University, 2002
%// =================================================================== ===
close all; clear; FRAMES = 3;
PLOTS = 3;
%// transformation is expressed wrt to the camera frame
Zinit = 5;
%// cube in the object frame
XW = [0 1 1 0 0 1 1 0 0.2 0.8 0.2 0.8 0 0 1 1 0 0 1 1 1.5 1.5 1.5 1.5; 1 1 1 1 0 0 0 0 0.8 0 .8 0.2 0.2 1 1 1 1 1 1 1 1 1 1 1 1];
NPOINTS = 12;
XC = zeros(4,NPOINTS,FRAMES);
%// initial displacement摄像机的初始位置 Rinit = rot_matrix([1 1 1],0);
Tinit = [ Rinit(1,:) -0.5 Rinit(2,:) -0.5 Rinit(3,:) Zinit; 0 0 0 1];
%// first camera coodinates XC(:,:,1) = Tinit*XW;
%//画出三维的结构 original motion and 3D structure figure; hold on;
plot3_struct(XC(1,:,1),XC(2,:,1),XC(3,:,1)); plot3(XC(1,:,1),XC(2,:,1),XC(3,:,1),'*');
draw_frame_scaled([diag([1,1,1]), zeros(3,1)],0.5); title('original motion and 3D structure'); view( 220,20); grid on; axis equal; %// axis off; pause;
%// image coordinates 计算第一帧时的图像坐标 xim(:,:,1) = project(XC(:,:,1));
Zmax = max(XC(3,:,1)); Zmin = min(XC(3,:,1)); rinc = pi/30;
rot_axis = [1 0 0; 0 -1 0]'; trans_axis = [1 0 0; 0 1 0]';
ratio = 1;
rinc = 10; %// rotation increment 20 degrees Zmid = (Zmax+Zmin)/2;
tinc = 0.5*ratio*Zmid*rinc*pi/180;
ploting = 1;
for i=2:FRAMES %//计算第i帧的图像坐标xim theta = (i-1)*rinc*pi/180;
r_axis = rot_axis(:,i-1)/norm(rot_axis(:,i-1)); t_axis = trans_axis(:,i-1)/norm(trans_axis(:,i-1)) ; trans = (i-1)*tinc*t_axis; R = rot_matrix(r_axis,theta);
%// translation represents origin of the camera frame %// in the world frame T(:,:,i) = ([ R
trans; 0 0 0 1]);
%// all transformation with respect to the object frame XC(:,:,i) = T(:,:,i)*XC(:,:,1); %// XW; draw_frame_scaled(T(1:3,:,i),0.5);
xim(:,:,i) = [XC(1,:,i)./XC(3,:,i); XC(2,:,i)./XC(3,:,i);
ones(1,NPOINTS)]; end;
for j = 2:FRAMES T_ini(:,j) = T(1:3,4,j); end;。

相关文档
最新文档