Visualizzazione post con etichetta matlab. Mostra tutti i post
Visualizzazione post con etichetta matlab. Mostra tutti i post

venerdì 10 luglio 2009

Nice blog on stereo-vision

I've found a nice blog on stereo-vision:

http://siddhantahuja.wordpress.com/category/stereo-vision/

Pretty cool examples!

domenica 10 maggio 2009

lunedì 4 maggio 2009

Numpy for Matlab users: getting in touch with Numpy!!!!

http://www.scipy.org/NumPy_for_Matlab_Users
On the link above the official documentation about compairisons between Matlab and Numpy: bloody interesting and usefull!

From MATLAB to PYTHON!!!!

http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/
On the link above, I've found an interesting article about migrating from closed source Matlab to very very open source Python...thanks God, Guido has done that snake!

lunedì 27 aprile 2009

Computation of a 3D structure: some sample code

http://cs.gmu.edu/~kosecka/examples-code/compute3DStructure.m
Some sample code for traingulating points in matlab on the link above.

% [X,lambda] = compute3DStructure(p, q, R, T)
% p - first image coordinates
% q - second image coordinates
% R, T - displacement between the views
% X - 3D coordinates of the points with respect to 1st and 2nd view
% lambda - scales with respect to the first view (lambda x = X)

% The basic linear triangulation algorithm
% for recovering the depth of a point given the projection onto
% two images and the relative pose of the cameras,
% as described in Chapter 5, "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/2003


function [XP, lambda] = compute3DStructure(p, q, R, T);
nc = size(q, 2);

% linear triangulation method
M = [];
for i=1:nc
A = [ 0 -1 p(2,i) 0;
-1 0 p(1,i) 0;
(-R(2,:) + q(2,i)*R(3,:)) -T(2) + q(2,i)*T(3);
(-R(1,:) + q(1,i)*R(3,:)) -T(1) + q(1,i)*T(3)];
[ua,sa,va] = svd(A);
X(:,i) = va(:,4);
end
XP(:,:,1) = [X(1,:)./X(4,:);X(2,:)./X(4,:);X(3,:)./X(4,:); X(4,:)./X(4,:)];
lambda = XP(3,:,1);

XP(:,:,2) = [R, T; 0 0 0 1]*XP(:,:,1);









Two view Demo: an example

http://vision.ucla.edu//MASKS/twoview_reconstruction/TwoViewDemo.m
Inserisci linkOn the link above some sample code in matlab for fulfilling some triangulation operations.
% two view example of calibrated structure from motion
% recovery
close all; clear;

im0 = rgb2gray(imread('boxes1.bmp','bmp'));
im1 = rgb2gray(imread('boxes8.bmp', 'bmp'));
[ydim, xdim] = size(im0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% intrinsic parameter matrix
Khat = [653.91 0 320.52; 0 649.72 220.40; 0 0 1];

%%%%%%%%%%%%%%%%%%%
% undo distortion
im0 = distortion(im0,0.03);
im1 = distortion(im1,0.03);

%%%%%%%%%%%%%%%%%%%%%
load boxpoints % 13 points seen in two frames frames
NPOINTS = size(xim(:,:,1),2);

figure(1); imagesc(im0); colormap gray; hold on; axis equal; axis off;
plot(xim(1,:,1), xim(2,:,1),'w.');
figure(2); imagesc(im1); colormap gray; hold on; axis equal; axis off;
plot(xim(1,:,2), xim(2,:,2),'w.');


FRAMES = 2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute retinal coordinates
for i = 1:FRAMES
xn(:,:,i) = inv(Khat)*xim(:,:,i);
end

%%%%%%%%%%%%%%%%%%%%
% initialize motion
[T0, R0] = dessential(xn(:,:,1), xn(:,:,2));

lambda = zeros(1,NPOINTS);
XE = zeros(3,NPOINTS,FRAMES);
[X,lambda]=compute3DStructure(xn(:,:,1),xn(:,:,2), R0, T0);
figure(FRAMES + 1);
XE(:,:,1) = X(:,:,1);
XE(:,:,2) = X(:,:,2);
plot3(XE(1,:,1),XE(2,:,1),XE(3,:,1),'r.'); hold on;

% pause
[l3d, inc] = boxseqlines(XE(1:3,:,1));
lnum = size(l3d,2);
for i=1:lnum
line([l3d(1,i) l3d(4,i)], [l3d(2,i) l3d(5,i)], [l3d(3,i) l3d(6,i)]);
end;
xlabel('x'); ylabel('y'); zlabel('z'); % axis equal;
title('Euclidean reconstruction'); view(220,20); axis equal; box on;
hold on;
pause;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute residuals and reproject them
xres0=Khat*[X(1,:,1)./X(3,:,1); X(2,:,1)./X(3,:,1); ones(1,NPOINTS)];
xres1=Khat*[X(1,:,2)./X(3,:,2); X(2,:,2)./X(3,:,2); ones(1,NPOINTS)];
figure(1); hold on; plot(xres0(1,:), xres0(2,:),'y.');
figure(FRAMES); hold on; plot(xres1(1,:), xres1(2,:),'y.');
pause;

xd0 = xim(1:2,:,1) - xres0(1:2,:);
xd1 = xim(1:2,:,2) - xres1(1:2,:);
res = [xd0'; xd1'];
f = [norm(res'*res)/2];
% pause
% two view example of calibrated structure from motion
% recovery
close all; clear;

im0 = rgb2gray(imread('boxes1.bmp','bmp'));
im1 = rgb2gray(imread('boxes8.bmp', 'bmp'));
[ydim, xdim] = size(im0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% intrinsic parameter matrix
Khat = [653.91 0 320.52; 0 649.72 220.40; 0 0 1];

%%%%%%%%%%%%%%%%%%%
% undo distortion
im0 = distortion(im0,0.03);
im1 = distortion(im1,0.03);

%%%%%%%%%%%%%%%%%%%%%
load boxpoints % 13 points seen in two frames frames
NPOINTS = size(xim(:,:,1),2);

figure(1); imagesc(im0); colormap gray; hold on; axis equal; axis off;
plot(xim(1,:,1), xim(2,:,1),'w.');
figure(2); imagesc(im1); colormap gray; hold on; axis equal; axis off;
plot(xim(1,:,2), xim(2,:,2),'w.');


FRAMES = 2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute retinal coordinates
for i = 1:FRAMES
xn(:,:,i) = inv(Khat)*xim(:,:,i);
end

%%%%%%%%%%%%%%%%%%%%
% initialize motion
[T0, R0] = dessential(xn(:,:,1), xn(:,:,2));

lambda = zeros(1,NPOINTS);
XE = zeros(3,NPOINTS,FRAMES);
[X,lambda]=compute3DStructure(xn(:,:,1),xn(:,:,2), R0, T0);
figure(FRAMES + 1);
XE(:,:,1) = X(:,:,1);
XE(:,:,2) = X(:,:,2);
plot3(XE(1,:,1),XE(2,:,1),XE(3,:,1),'r.'); hold on;

% pause
[l3d, inc] = boxseqlines(XE(1:3,:,1));
lnum = size(l3d,2);
for i=1:lnum
line([l3d(1,i) l3d(4,i)], [l3d(2,i) l3d(5,i)], [l3d(3,i) l3d(6,i)]);
end;
xlabel('x'); ylabel('y'); zlabel('z'); % axis equal;
title('Euclidean reconstruction'); view(220,20); axis equal; box on;
hold on;
pause;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% compute residuals and reproject them
xres0=Khat*[X(1,:,1)./X(3,:,1); X(2,:,1)./X(3,:,1); ones(1,NPOINTS)];
xres1=Khat*[X(1,:,2)./X(3,:,2); X(2,:,2)./X(3,:,2); ones(1,NPOINTS)];
figure(1); hold on; plot(xres0(1,:), xres0(2,:),'y.');
figure(FRAMES); hold on; plot(xres1(1,:), xres1(2,:),'y.');
pause;

xd0 = xim(1:2,:,1) - xres0(1:2,:);
xd1 = xim(1:2,:,2) - xres1(1:2,:);
res = [xd0'; xd1'];
f = [norm(res'*res)/2];
% pause





mercoledì 22 aprile 2009

VLFeat is a MATLAB-compatible implementation common computer vision algorithms

http://www.vlfeat.org/

VLFeat is a MATLAB-compatible implementation common computer vision algorithms such as SIFT, MSER, k-means, hierarchical k-means, and agglomerative information bottleneck.

MSER for Matlab

http://www.vlfeat.org/~vedaldi/code/mser.html

MSER algorithm to find correspondences between images' features. It's gor Matlab but quite handy to rewrite into other languages.