I'm using OpenCV calibrateCamera function to extract intrinsic end extrinsic parameters of my camera. I have a big problem with the extrinsic one (rotation and translation) because the rotation matrix, that should be a 3x3 matrix, it's only a 3x1. Does someone know why I have this output or how can I use it?
Thanks in advance!
You get a vector which is actually the axis-angle representation of your rotation. You can convert that in a 3x3 rotation matrix using the Rodrigues formula:
Rodrigues on Wikipedia
Rodrigues using OpenCV
Related
I want to implement the function for rotation matrix to rotation vector in pytorch. I have read the document in opencv tutorial Rodrigues and refer the code in c Rodrigues in c. The transformation for rotation vector to rotation matrix is straightforward according to the formulation, but the reverse is obscure and undirect.
Is there any implement for the code in pytorch or any guide for implement this by myself?
I want to know any basic mathematics based algorithm to rotate an image using the nearest neighbor and bilinear interpolation without using OpenCV library and imrotate.
The image won't be cropped after rotation and full image must be displayed.
A rotation corresponds to an affine transformation of the coordinates and is easily described using matrix/vectors. It is no great deal to find the formulas on the Web.
Now the important thing to know, is that rather than taking the pixels of the original image an mapping them to the transformed image, you must work backwards.
Scan every pixel of the transformed image and by applying the inverse transform, find the corresponding coordinates in the original image. You need to do this using real coordinates.
Then
for the nearest-neighbor method, round the coordinates and just copy the source pixel value to the destination;
for the bilinear method, consider the four pixels around the obtained coordinates (you will perform a truncation to integer). Finally, compute the destination pixel as a bilinear combination of the four source pixels, using the fractional part of the coordinates as the weights to perform the interpolation.
Check the figures here: http://wtlab.iis.u-tokyo.ac.jp/wataru/lecture/rsgis/rsnote/cp9/cp9-7.htm
I have a series of points in two 3D systems. With them, I use np.linalg.lstsq to calculate the affine transformation matrix (4x4) between both. However, due to my project, I have to "disable" the shear in the transform. Is there a way to decompose the matrix into the base transformations? I have found out how to do so for Translation and Scaling but I don't know how to separate Rotation and Shear.
If not, is there a way to calculate a transformation matrix from the points that doesn't include shear?
I can only use numpy or tensorflow to solve this problem btw.
I'm not sure I understand what you're asking.
Anyway If you have two sets of 3D points P and Q, you can use Kabsch algorithm to find out a rotation matrix R and a translation vector T such that the sum of square distances between (RP+T) and Q is minimized.
You can of course combine R and T into a 4x4 matrix (of rotation and translation only. without shear or scale).
I'm newbie in image processing, i have tried to implement filter2D to reduce noise image with RGB color recently, and it works well. But i don't understand how it works manually in image matrix. Anybody can help me to explain how it works manually?
This is the input matrix and output matrix i get.
Input Image Matrix
Output Image Matrix
Thanks for your help. :)
as a short answer, filtering an image means apply a filter (or kernel) to it, i.e; convolving the image by this kernel. For that, you take each pixel on your image and consider a neighbourhood around it. You apply the kernel to the neighbourhood by multiplying each pixel of the neighbourhood with the corresponding kernel coefficient and sum all these values.
For a pixel, this can be summarized by this figure (source) :
For example, by setting all the coefficients to 1/N (where N is the number of elements in your kernel), you compute the average intensity of your neighbourhood.
You can see https://en.wikipedia.org/wiki/Multidimensional_discrete_convolution for more information about image convolutions.
OpenCV's documentation gives some practical examples of image smoothing.
Hope it helps
I have a class that holds a 4x4 matrix for scaling and translations. How would I implement rotation methods to this class? And should I implement the rotation as a separate matrix?
You can multiply Your current matrix with a rotation matrix. Take a look at http://en.wikipedia.org/wiki/Rotation_matrix
There's a site which I use every time when I need to look up the details of a 3D transformation, called http://www.euclideanspace.com. The particular page on matrix rotations can be found here.
Edit: Rotation around a given axis, look at the axis & angle representation. This page also links to a description on how to translate one representation to another.
If you need to rotate around mutiple axes, simply multiply the corresponding matrices.
Answering the second half of the question, a single 4x4 matrix is perfectly capable of holding a scaling, a translation, and a rotation. So unless you've put special limitations on what sort of 4x4 matrices you can handle, a single 4x4 is a fine for what you want.
As for rotation about an arbitrary vector (as you are asking in comments), look at the "Rotation about an arbitrary vector" section in the Wikipedia article yabcok links to. You will want to extend that to a 4x4 matrix by padding it out with zeros except for the 4,4 (scaling) position, which should be one. Then use matrix multiplication with your scaling/translation 4x4 to generate a new 4x4 matrix.
You want to make sure you find a reference which talks about the right kind of matrix that's used for computer graphics (namely 3D homogeneous coordinates using a 4x4 transformation matrix for rotation/translation/skewing).
See a computer graphics "bible" such as Foley and Van Dam (pg. 213), or one of these:
The Mathematics of the 3D Rotation Matrix
Mathematics of 3D Graphics
MSDN 3D graphics tutorial
SIGGRAPH article about 3D rotation
other page from CProgramming.com
This page has quite a bit of useful information:
http://knol.google.com/k/matrices-for-3d-applications-translation-rotation