python


Camera rotation matrix


I am trying to raytrace a video. For that matter, I need the camera roation matrix for every frame, in world coordinates. The camera is at the origin. There are no translation.
I have the trajectory of the camera as changes in rotation for every frame.
So for every frame, I have three values (roll, yaw, pitch) that describe how much the camera should rotate from this frame to the next. These rotations are to be understand in the camera coordinate system.
How do I compute the world coordinate rotation matrices for the frames?
What I tried:
def rot_x(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
def rot_y(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
def rot_z(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
matrices = [initial_rot]
for pitch, yaw, roll in frames_data:
rx = rot_x(pitch)
ry = rot_y(yaw)
rz = rot_z(roll)
last_matrix = matrices[-1]
matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
(Since last_matrix should be orthonormal, so the inverse of it should be the transpose).
However, something is horribly wrong, the rendered video just flickers in the y dimension. I am sure there is something wrong with the math here..
The order of the matrix multiplications matters. Applying another rotation should be done by left-multiplying (assuming a standard convention).
Since this is simply composition multiple rotations, there should not be any need to inverse the last rotation.
The complete rotation that should be computed for frame N is:
R_n = R(yaw_n, pitch_n, roll_n) R_{n - 1} R_{n - 2} ... R_1 R_0
with:
R_0: the initial rotation (i.e. initial_rot)
R_n: the complete rotation for the frame N
R(yaw_n, pitch_n, roll_n): the rotation derived from the yaw / pitch / roll values applied between frame N - 1 and N (i.e. rx.dot(ry).dot(rz))
Hence the last line in the code excerpt should instead be:
rotation = rx.dot(ry).dot(rz)
matrices.append(rotation.dot(last_matrix))

Related Links

How to transform nested strings in array to separated words?
Data to be read by humans in Python (large data sets)
How can I rename strings of indices?
what is wrong with this DP solution?
Recursion error in Python function
CLion external tools macro
tkinter error when copying contents from clipboard in Python
Create new list (or numpy.array) with a named list (or numpy.array) [duplicate]
Filter by Day of Week in Flask-Admin
How to close GLUT Window when input_raw() is active? Python
Why does CVXOPT give a rank error for this nonlinear network flow optimisation?
Trying to solve randomly generated non-linear simultaneous equations using python
How to update equation links using openpyxl?
Send shellcode to interactive C program in Windows
assign new dimension of length one
How to print a 3D array in Python?

Categories

HOME
jdbc
xamarin.android
facebook-graph-api
ubuntu-16.04
tizen-wearable-sdk
data-science-experience
codeblocks
google-plus
eclipse-cdt
powershell-v3.0
pdo
uicollectionview
bootstrap-popover
pyyaml
saiku
linq-to-sql
mousewheel
plupload
aws-cognito
tweets
embedly
multiplayer
nmf
skmaps
metis
excel-2013
pentaho-report-designer
system.data.sqlite
clockwork
receipt
threshold
honeysql
pace
broadleaf-commerce
redhat-datavirt
inkscape
haskell-pipes
floating-accuracy
intersystems-ensemble
archer
forerunnerdb
tofixed
unity3d-editor
iron.io
cleditor
c64
push-diffusion
tomee
packagemaker
git-annex
mongoskin
galaxy
insertion-sort
getrusage
paypal-nvp
swift2.1
google-hadoop
jazz
robocode
jai
cpan
pisa
pgagent
jquery-autocomplete
errorprovider
formvalidation-plugin
cppdepend
jstack
internal
facebook-chat
logentries
entity-framework-4.1
zend-lucene
abnf
tridion2009
cbcentralmanager
socketstream
qsqltablemodel
jpf
v4l
nssavepanel
ajax.beginform
nemerle
serp
testunit
pivotal-crm
asp.net-routing
jquery-ui-button
grooveshark
graph-layout
weborb

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App