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

Python - Download File Created From ASPX Form Submission
Find number of weeks in a month
breaking up a list entry in several lists at every /n Python 3
How can I get the default colors in GTK?
Ndb entry .put() not executed?
Tensorflow: NaNs propagating throughout network, even though using sparse_softmax etc
How to do a Python argparse mutually required argument group
scaling websocket game application server
Is there a way to find a character's Unicode code point in Python 2.7?
figtext datetime function matplotlib
environment variable in ubuntu
Cross-platform Python Executables
Extract subarray from collection of 2D coordinates?
tkinter populate treeview using threading pool
How to make a function determining the winner of Tic-Tac-Toe more concise
Django update model entry using form fails

Categories

HOME
ajax
payment-gateway
tinyos
project-management
translation
computer-vision
recyclerview
defragmentation
ipfs
google-shopping
image-recognition
cratedb
datagrip
sql-tuning
reduction
quartus
saiku
google-people
eclipselink
excel-2010
tcpclient
tampermonkey
printdocument
non-deterministic
skmaps
branch
reactiveui
pitest
referenceerror
pari
postgresql-9.2
exponential
receipt
geo
transient
shibboleth
nlb
socketpair
socketscan
viewgroup
crop
python-idle
rdw
azure-availability-set
chown
bnd
rollback
cgcontext
mbaas
selenium-firefoxdriver
teiid
gulp-typescript
chessboard.js
mix
bacnet
nofollow
git-rebase
loose-typing
enyo
site-prism
ibm-data-studio
rspec3
callstack
client-side-validation
java-melody
cg
httpcontext
openkinect
sanitization
threadx
adomd.net
sharpmap
reporting-tools
cgpath
osi
autostart
subtract
expression-evaluation
z-machine
maven-ant-tasks
v4l
objectbrowser
electronic-signature
phpcrawl
nagle
requestfactory
gwt-2.2-celltable
scala-2.8
mvvm-foundation
winsnmp
method-signature
data-entry

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