0

I am trying to apply a rotation to fix the camera pose in my setup, since one of the axes seems to be off. I suspect this axis to be Z of "world" frame. In other words, I need to rotate "stereo_camera" frame around the Z axis of the "world frame" by 90 degrees. Then all should be OK.

enter image description here

I've tried using several Python libraries and Octave to achieve this but I failed. Somehow either the multiplication or the way I express the quarternion doesn't seem to comply.

# Here is the current quarternion of "stereo_camera"
q = np.array([0.0, 0.70710678, 0.0, 0.70710678])

# Rotation matrix, 90 degrees around Z would be:
I = np.array([[0, -1, 0],[1,0,0],[0,0,1]])

# apply the transformation
q.dot(I)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: shapes (4,) and (3,3) not aligned: 4 (dim 0) != 3 (dim 0)

Is there anyone who could suggest me a nice Python package which can handle such situations, with a minimal example? It shouldn't be hard to apply 1 single rotation to a quarternion.

Schütze
  • 1,044
  • 5
  • 28
  • 48
  • quaternions I don't know. But I do know how to rotate a vector around the z-axis.. – WiseDev Jul 03 '19 at 11:03
  • Keep in mind that I am asking for the rotation around Z of the "world", not Z of "stereo_camera". Given this, how do you rotate a vector? – Schütze Jul 03 '19 at 11:07
  • rotation around Z of the "world" is equal to rotation of "stereo_camera" plus a translation.. – WiseDev Jul 03 '19 at 11:08
  • Translation? That shouldn't be necessary? I thought it's all about in which order you do the multiplication. Anyway, perhaps we are talking about different things. – Schütze Jul 03 '19 at 11:13
  • Regardless of what `q.dot(I)` [actually does](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.dot.html?highlight=ndarray%20dot#numpy.ndarray.dot), what did you *expect* it to do? You are mixing a quaternion-like object with a matrix-like one. If you insist on using quaternions, you might want to read the [Wikipedia article](https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation). – Leporello Jul 03 '19 at 12:10

1 Answers1

-1

So, what had to be done was to use the rotation matrix, not the quarternion. I used this to convert from quarternion to rotation matrix.

Rotation matrix is a matrix which looks like this:

[  0.0000000, -1.0000000,  0.0000000;
   0.0000000,  0.0000000,  1.0000000;
  -1.0000000,  0.0000000,  0.0000000 ]

Once this matrix is acquired, it can be multiplied.

Schütze
  • 1,044
  • 5
  • 28
  • 48