-
Notifications
You must be signed in to change notification settings - Fork 251
Render a video on a Cube #322 #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robinroy03
wants to merge
24
commits into
fury-gl:master
Choose a base branch
from
robinroy03:cube_viz
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
deb99c6
video on a cube
robinroy03 41848f7
import vtk through fury lib.py, added some comments on possible impro…
robinroy03 2773729
fixing pep8 one line at a time
robinroy03 6feeeb0
fixing pep8 one line at a time (part 2)
robinroy03 d4b3344
Merge branch 'fury-gl:master' into cube_viz
robinroy03 f58f41d
modified cube viz with different textures on all 6 sides
robinroy03 ed688ca
pep8 fix
robinroy03 1887ccb
pep8
robinroy03 5a7c6fc
textured cube final version without tests
robinroy03 6fc3dcd
tutorial for viz_play_cube
robinroy03 a351499
pep8 fix
robinroy03 78f8135
pep8
robinroy03 724ee56
modified to elininate circular import error, removed get_scene() beca…
robinroy03 6a84176
added tests and fixed some docstrings, also added to lib.py
robinroy03 f735ad9
using isintance for the type comparison
robinroy03 c141f31
Added center coordinate parameter, used util.py helper function to si…
robinroy03 1953851
Removed classes, made it functional. Changed the tests accordingly. M…
robinroy03 0367526
Merge branch 'fury-gl:master' into cube_viz
robinroy03 dc74532
fixed a coordinate bug, now it is perfectly aligned to the center
robinroy03 264721b
fixed docs, made it cleaner. Fixed uneven variable names for texture_…
robinroy03 20d668d
small typo fix
robinroy03 62ac13c
fixed the normal directions (it now points outwards, earlier it point…
robinroy03 faf40bf
Merge branch 'fury-gl:master' into cube_viz
robinroy03 b26842a
https version of videos, removed implementation note from docstring, …
robinroy03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """ | ||
| ======================================================= | ||
| Play video on a Cube | ||
| ======================================================= | ||
|
|
||
| The goal of this demo is to show how to visualize a video | ||
| on a cube by updating its textures. | ||
| """ | ||
|
|
||
| from fury import actor, window | ||
| import numpy as np | ||
| import cv2 | ||
|
|
||
| ######################################################################### | ||
| # The 6 sources for the video, can be URL or directory paths on your machine. | ||
| # There'll be a significant delay if your internet connectivity is poor, | ||
| # use local directory paths for fast rendering. | ||
| sources = [ | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4', | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4', | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4', | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4', | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4', | ||
| 'http://commondatastorage.googleapis.com/gtv-videos-bucket/' | ||
| + 'sample/BigBuckBunny.mp4' | ||
|
robinroy03 marked this conversation as resolved.
Outdated
|
||
| ] | ||
|
|
||
| ######################################################################### | ||
| # We are creating ``OpenCV videoCapture`` objects to capture frames from | ||
| # sources. | ||
| video_captures = [cv2.VideoCapture(source) for source in sources] | ||
|
|
||
| # rgb_images will store the RGB values of the frames. | ||
| rgb_images = [] | ||
| for video_capture in video_captures: | ||
| _, bgr_image = video_capture.read() | ||
|
|
||
| # OpenCV reads in BGR, we are converting it to RGB. | ||
| rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB) | ||
| rgb_images.append(rgb_image) | ||
|
|
||
|
|
||
| ######################################################################## | ||
| # ``timer_callback`` gets called repeatedly to change texture. | ||
|
|
||
| def timer_callback(_caller, _timer_event): | ||
| rgb_images = [] | ||
| for video_capture in video_captures: | ||
| # Taking the new frames | ||
| _, bgr_image = video_capture.read() | ||
|
|
||
| # Condition used to stop rendering when the smallest video is over. | ||
| if isinstance(bgr_image, np.ndarray): | ||
| rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB) | ||
| rgb_images.append(rgb_image) | ||
| else: | ||
| show_manager.exit() | ||
| return | ||
|
|
||
| for actor_, image in zip(cube, rgb_images): | ||
| # texture_update is a function to update the texture of an actor | ||
| actor.texture_update(actor_, image) | ||
|
|
||
| # you've to re-render the pipeline again to display the results | ||
| show_manager.render() | ||
|
|
||
| ####################################################################### | ||
| # ``texture_on_cube`` is the function we use, the images are assigned in | ||
| # cubemap order. | ||
|
|
||
|
|
||
| """ | ||
| |----| | ||
| | +Y | | ||
| |----|----|----|----| | ||
| | -X | +Z | +X | -Z | | ||
| |----|----|----|----| | ||
| | -Y | | ||
| |----| | ||
| """ | ||
| ###################################################################### | ||
|
|
||
|
|
||
| cube = actor.texture_on_cube(*rgb_images, centers=(0, 0, 0)) | ||
|
|
||
| # adding the returned Actors to scene | ||
| scene = window.Scene() | ||
| scene.add(*cube) | ||
|
|
||
| ###################################################################### | ||
| # ``ShowManager`` controls the frequency of changing textures. | ||
| # The video is rendered by changing textures very frequently. | ||
| show_manager = window.ShowManager(scene, size=(1280, 720), reset_camera=False) | ||
| show_manager.add_timer_callback(True, int(1/60), timer_callback) | ||
|
|
||
|
|
||
| ###################################################################### | ||
| # Flip it to ``True`` for video. | ||
| interactive = False | ||
| if interactive: | ||
| show_manager.start() | ||
|
|
||
| window.record(scene, size=(1280, 720), out_path='viz_play_cube.png') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.