Skip to content
Snippets Groups Projects
Commit 8c501851 authored by ac (tb)'s avatar ac (tb)
Browse files

added leversc spinMovie.py

parent bd0143b1
Branches
No related tags found
No related merge requests found
""" Python sample for using the leversc multichannel 3-d viewer to generate a video
mark winter and andrew r. cohen
this script generates an mp4. it was tested on windows, but may work on other platforms.
it relies on scikit-video (pip install scikit-video) and ffmpeg (you must download and install)
"""
import numpy as np, matplotlib.pyplot as plt
from leversc import leversc
import time
import skvideo
# note - you must download ffmpeg and enter the path to the bin folder here!
skvideo.setFFmpegPath('C:\\Users\\ANDYR\\git\\ffmpeg-master-latest-win64-gpl\\bin')
import skvideo.io
def setMovieUI(lsc):
""" setMovieUI(lsc) - sets the ui elements for screen capture
lsc - leversc class instance
"""
# wait for leversc to finish any image render before we set ui
# so all pending ui updates are completed before our changes
while (not lsc1.drawComplete()):
time.sleep(0.1)
# pull ui dictionary, modify and then write it back
# this allows us to properly use the property setter, and also allows
# bulk property changes
ui=lsc.uiParams
ui['webToolbar']='none'
ui['clockButton']='none'
ui['sidebar']='none'
lsc.uiParams=ui
# show the .LEVER sample image
strDB='../../sampleImages/lscSampleImage.LEVER'
(im,CONSTANTS)=leversc.readImage(strDB)
lsc1 = leversc(im=im,imD=CONSTANTS)
# hint - i like to set a breakpoint here in the debugger and adjust the leversc viewer window
# so the aspect ratio and view settings looks right for my movie
pass
# set UI to look better for movie capture
setMovieUI(lsc1)
# hint - you may want to check that your UI windows looks good after turning off the elements
# via setMovieUI
pass
outputFile='sampleVolume.mp4'
# set pix_fmt to yuv420p because windows media player has trouble with default mp4 setting
# note - VLC plays the default so if you have trouble, try that
writer = skvideo.io.FFmpegWriter(outputFile, outputdict={"-pix_fmt": "yuv420p"})
# spin the volume, capturing and writing frames
angles = np.linspace(0,np.pi,50);
for theta in angles:
# set the rotation matrix
lsc1.viewParams['worldRot']=[np.cos(theta), 0, np.sin(theta),0,
0,1,0,0,
-np.sin(theta),0,np.cos(theta),0,
0,0,0,1]
# alternative rotations / zoom adjustments / etc. as needed
# ...
# now grab image
im=lsc1.captureImage()
writer.writeFrame(im)
writer.close()
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment