From 8c5018510e53c9f2586e063513e287ebcbb90412 Mon Sep 17 00:00:00 2001 From: "ac (tb)" <andrew.r.cohen@drexel.edu> Date: Wed, 9 Mar 2022 15:38:05 -0500 Subject: [PATCH] added leversc spinMovie.py --- src/Python/leversc/spinMovie.py | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Python/leversc/spinMovie.py diff --git a/src/Python/leversc/spinMovie.py b/src/Python/leversc/spinMovie.py new file mode 100644 index 0000000..32e49f5 --- /dev/null +++ b/src/Python/leversc/spinMovie.py @@ -0,0 +1,68 @@ +""" 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 -- GitLab