Use quaternions for 2d rotations - ios

Is there a way to use quaternions for only 2d rotations?
I have an iPhone app which should get every rotation avoiding Gimbal Lock, and I understood that the solution could be using quaternions or rotation matrix.
However, I find difficult to understand how can I use quaternions for 2d rotation instead of using 3d rotation.
Can you give me a suggestion?
Thank you in advantage!

From algorithmic point of view you can start from understanding quaternions. However, you can see how to convert 3D rotation to 2D rotation. Finally, you can see how to include quaternions in ios graphics using GLKQuaternion Reference.

Related

Using OpenCV rotation and translation in iOS Metal to draw AR cube

I am new to playing the AR, computer vision and graphics. I am trying to use make a AR experience using OpenCV and Metal in iOS. Rotation and Translation was retrieved by SolvePnP and passed to Metal to draw the cube pose.
However, there are a few problems:
The cube jump out of the view as soon as the R and T are passed.
Even can see the cube sometimes, the rotation seems not match with phone movement.
Translation values seems not doing to move the cube with respect to phone movement. Therefore, failed to anchor to any surface or a point at space.
I can provide more information to analysis my problem if needed. Thank you.

Finding transformation between cameras looking at the same scene from different angles

I have a camera setup with two or more cameras looking at he same object from opposite directions:
I want to find a transformations between these cameras using asymmetric circles pattern and cv::stereoCalibrate. Is it going to work in this setup?
First problem that I've noticed is that OpenCV can't find inverted pattern, so second camera does not recognize pattern. To solve for that I flip image about x for second camera and then flip found points.

Rotation Estimation between two images

I want to get the rotation between two images taken from the same camera (known intrinsic). I have a nearly perfect pure rotation!
I use findhomography but if there is a little translation movement I get four results. Is there a way to force the homography that it assumes it is a pure rotation?
EDIT: Picture sample: the camera is rotating
You can decrease the dimension of the problem a bit by using cv::estimateRigidTransform and passing false for fullAffine argument. This will make it translation, rotation, and uniform scaling but there is is not pure rotation method in OpenCV.

opengl ios pitch yaw roll prevent gimbal lock

I found this on stackoverflow.
"You will probably need to use quaternions for composing rotations, if you are not doing so already. This avoids the problem of gimbal lock which you can get when orienting a camera by rotation around the 3 axes."
But how do I use the quaternion from the motionmanager in opengl. the code was first based on pitch and yaw only. Now I want to use the roll also, so you can use the gyroscope to look around. Could anybody help me this one?
Thank you.
My advice, don't use Eulers. Just track orientation with vectors(Forward, up, and right) for the object or camera.
To rotate, just do relative rotations of the current forward, up and right. Like rotate right 5 degress.
Quanternions have excessvie operations and physics don't work via yaw, pitch and roll, they are merely measurements to capture orientation, not how things get orientated.

How to create 3D perspective views of an image using OpenCV?

I have an image on the wall. I'd like to create its 3D perspective views by myself. Suppose the points on the images, camera location, orientation of the camera are given, how can I do to obtain the 3d perspective matrix to play with the original image?
I understand I can use the orientation of the camera to calculate the 3d rotation matrix, but I've no idea how to calculate the subsequent projection matrix...
I've come across this link (see Section Perspective Projection), but I don't understand what's going on after projection.. And what is the difference between the camera position and the viewer's position?
Thanks a lot.
use openGl and its open example to solve your problem.
in bellow link there are good samples to undestand 3d reconstruction:
http://www.songho.ca/opengl/gl_transform.html
wish helpful

Resources