There are many questions that explain how to find the projection matrix but they don't apply to my situation. The Matlab function cameraMatrix(cameraParams,rotMatrix,tranVector) can easily find the projection matrix.
I obtained my cameraParams variable by using the camera calibrator app in Matlab by providing checkerboard images in the input. The problem is that in my cameraParams variable, there are 10 rotation matrices and 10 translation vectors for some reason. The app always returns 10 rotation and translation vectors no matter what. The function cameraMatrix() can only accept a single rotation matrix and translation vector as inputs.
Why are there multiple rotation matrices and translation vectors and how do I find the projection matrix?
Related
I need to calculate 3D cross-correlation in MATLAB. Anyone know which function I should use? For 2–D cross-correlation it has xcorr2, but I don't know about is 3D.
Correlation is similar to convolution except that one does not need to flip an input about the origin (but correlation needs taking the complex conjugate of one of the operands), so for 3D real matrices, you can use convn(x3d,y3d(end:-1:1,end:-1:1,end:-1:1)) to compute 3D cross correlation.
I'm using Matlab 2013a on Windows 7 Pro 64 bit.
In 2010 (using a different version of Matlab), I wrote the following code to calculate a 3x3 rotation matrix
C=rotate (omega, i, w);
R=C*Ro;
where omega, i, and w are rotation angles in radians. On my current system, giving the example input of omega = i = w = 0, C will be a 3x3 identity matrix.
If I copy the code into another directory that I wrote in the past few months, the same code will result in the following error.
Error using rotate
Too many output arguments.
So my question to SO is why the same lines of code on the same computer with the same version of Matlab will work in one directory but not in another directory?
If you had read the help for rotate, you would have seen that this one does not calculate the rotation matrix, but rotates a matlab graph. Some toolboxes eg Phased Array System Toolbox have some functions rotx, roty,... to calculate the rotational matrix.
However, functions for calculating the rotation matrix is not that hard to construct. Looking at http://en.wikipedia.org/wiki/Rotation_matrix the rotational matrices for every axis is given. The general rotation matrix is then a product of the individual rotation matrices. This should be piece of cake.
I want to create in Simulink, a homogenous matrix in order to simulate the rotation and translation of an object in space.
How can I create a 4x4 matrix which will take as input the angle given?
For example a translation across the X axes combined with a rotation in Z would be in MATLAB:
%Supposing the input is
in = [a, b]
%translational part:
transl = eye(4);
transl (1,4) = in(1);
%Rotational Part:
rotat = eye(4);
rotat(1:3,1:3) = rotx(in(2));
move = transl*rotat;
The main problem is that I would like the Simulink model to be the more code-free (without MATLAB interpreted functions etc), just blocks.
Thank you.
First off, sometimes code is the better way to accomplish something. Some things are needlessly complicated when done as signal processing.
A Vector Concatenate can be used to generate a vector, which in turn can be fed into a Matrix Concatenate to create a matrix. Both blocks are found under Math Operations. There you should also find all methods necessary to multiply it with the given values, etc.
Try the 'Rotation Angles to Direction Cosine Matrix' block. It converts rotation angles to direction cosine matrix. The output is a 3x3 matrix, Rxyz, that performs coordinate transformations based on rotation angles from body frame to earth frame.
I have a 3-by-N matrix X whose columns are vectors on the unit sphere (i.e., the Euclidean length of each vector is 1), and I have a 1-by-N vector Theta whose entries are all angles between 0 and pi. For each i, there is a circle on the sphere centered at X(:,i) defined as the set of all points that have the angle Theta(i) with X(:,i). I would like to get one uniform sample from the circle for each i, avoiding for loops because they can be slow in Matlab. I know that in vectorized Matlab code I can easily get one sample each from all circles with angles in Theta if I assume the center of all circles is [0,0,1], and then I know how to get a rotation matrix (using Rodrigues rotation formula) that rotates [0,0,1] to another desired vector x, so for each i, I can just apply this rotation matrix to the sample point I obtained assuming [0,0,1] was the center.
I would like to this for all i without for loops, i.e. using array/matrix/vector notation.
If you're using Rodrigues' rotation formula, you're trying to convert from axis-angle representation to rotation matrices. You're in luck. I happen to have written fast vectorized code to do exactly what I believe you're asking about. You can can find the code here: axang2rotmat.m. Use is pretty straightforward (read the help):
n = 1e3; % Number of axis-angles and rotation matrices
th = pi*rand(1,n); % Random rotation angles between 0 and pi
v = normc(rand(3,n)); % Random rotation vectors, normalized across columns
R = axang2rotmat(v,th); % Generate n rotation matrices, R is 3-by-3-n
Note, the above code is just to demonstrate the use of axang2rotmat and won't give you uniformly sampled rotation matrices (See Miles, Biometrika 1962 for details on why and workaround). I recommend that you calculate random rotation matrices directly, however. You can us another of my functions for that: randrotmat.m.
I also have code to convert back from rotation matrices to axis-angle and check if a particular matrix is a rotation matrix here.
I have the Rotation matrix and the translation vector between the 2 cameras .Is there a way to find out the 4 X 4 disparity-to-depth mapping matrix using Matlab ?
I used this link for finding the R and T parameter values between the two cameras.
You can always compile OpenCv and use it in matlab as external DLL.