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

insert for $out failed
django rest framework - tricky is_valid()
binary search tree impelemntation in python
In SQLAlchemy is it possible to dump and load from a Table (not from a mapped class)?
Python: Parsing logical string into list of lists
Optical flow with OpenCV and Python using initial flow estimate
What is the difference between numpy.polyfit and scipy.polyfit? [duplicate]
How to get the value of submitted option of django_filters in view?
Cannot upload text files to django project
How to create a unit test to check the response of an API made in Flask?
cannot access excel file using Pandas Python
Python OpenCV: Conversion from float to int for using cv2.line()
Make a Scatter Plot in matplotlib with dates on x axis and values on y
Decoding NumPy int64 binary representation
Groupby DataFram by its rank/percentile
AttributeError: 'str' object has no attribute 'loads', json.loads()

Categories

HOME
makefile
vue.js
cntk
tinyos
textwatcher
raspbian
backup
decorator
d
formal-verification
actionscript
ruby-on-rails-3
csvhelper
couchdb-2.0
javamail
rebol
quill
iis-7.5
sequelize.js
google-spreadsheet-api
contact-form-7
desktop
iso
onsen-ui2
intellij-plugin
cloudflare
ssms-2016
jquery-terminal
saiku
jni
backpropagation
rails-activerecord
richfaces
go-cd
logarithm
fabric
onesignal
spring-data-neo4j
android-vpn-service
google-drive-realtime-api
geopy
gettext
powershell-remoting
honeysql
bing-maps-api
office365connectors
freetts
agent
equivalence
linq-to-entities
lexical-analysis
onbackpressed
android-maps-v2
taglib
php-ews
prototypejs
3scale
ajp
jtds
ideone
gd
spell-checking
volume
cdk
verbose
inject
android-navigationview
gradle-script-kotlin
icefaces
c#-interactive
mongoose-populate
uiprogressview
gherkin
fps
selecteditem
elastix
search-regex
asynccallback
axes
difference
getrusage
insert-into
app.xaml
unity5.3
textkit
windowlistener
webhdfs
mogrify
pylearn
epl
musl
obfuscar
tilestache
cpu-speed
dmp
sthttprequest
valence
funkload
dbsetup
installshield-2009
vmware-server
argb
hashalgorithm
fileutils
selectmanycheckbox
ruby-debug
zend-form-element
grooveshark
graph-layout
rd





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss