Skip to content
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

Render a video on a Cube #322 #862

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
deb99c6
video on a cube
robinroy03 Feb 20, 2024
41848f7
import vtk through fury lib.py, added some comments on possible impro…
robinroy03 Feb 20, 2024
2773729
fixing pep8 one line at a time
robinroy03 Feb 20, 2024
6feeeb0
fixing pep8 one line at a time (part 2)
robinroy03 Feb 20, 2024
d4b3344
Merge branch 'fury-gl:master' into cube_viz
robinroy03 Mar 2, 2024
f58f41d
modified cube viz with different textures on all 6 sides
robinroy03 Mar 3, 2024
ed688ca
pep8 fix
robinroy03 Mar 3, 2024
1887ccb
pep8
robinroy03 Mar 3, 2024
5a7c6fc
textured cube final version without tests
robinroy03 Mar 10, 2024
6fc3dcd
tutorial for viz_play_cube
robinroy03 Mar 10, 2024
a351499
pep8 fix
robinroy03 Mar 10, 2024
78f8135
pep8
robinroy03 Mar 10, 2024
724ee56
modified to elininate circular import error, removed get_scene() beca…
robinroy03 Mar 11, 2024
6a84176
added tests and fixed some docstrings, also added to lib.py
robinroy03 Mar 12, 2024
f735ad9
using isintance for the type comparison
robinroy03 Mar 13, 2024
c141f31
Added center coordinate parameter, used util.py helper function to si…
robinroy03 Mar 15, 2024
1953851
Removed classes, made it functional. Changed the tests accordingly. M…
robinroy03 Mar 19, 2024
0367526
Merge branch 'fury-gl:master' into cube_viz
robinroy03 Mar 20, 2024
dc74532
fixed a coordinate bug, now it is perfectly aligned to the center
robinroy03 Mar 21, 2024
264721b
fixed docs, made it cleaner. Fixed uneven variable names for texture_…
robinroy03 Mar 21, 2024
20d668d
small typo fix
robinroy03 Mar 21, 2024
62ac13c
fixed the normal directions (it now points outwards, earlier it point…
robinroy03 Mar 21, 2024
faf40bf
Merge branch 'fury-gl:master' into cube_viz
robinroy03 May 1, 2024
b26842a
https version of videos, removed implementation note from docstring, …
robinroy03 May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions docs/examples/viz_play_cube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
=======================================================
Play a video in the 3D world
=======================================================

The goal of this demo is to show how to visualize a video
on a cube by updating a texture.
"""

import cv2
import vtk # only for vtkCubeSource which needs to be added to lib.py

import numpy as np

from fury import actor, window
from fury.lib import (
numpy_support,
ImageData,
Texture,
# lib.py needs to have CubeSource,
PolyDataMapper,
Actor
)


def texture_on_cube(image):
"""
Map an RGB texture on a cube.

Parameters:
-----------
image : ndarray
Input 2D RGB array. Dtype should be uint8.

Returns:
--------
actor : Actor
"""

grid = ImageData()
grid.SetDimensions(image.shape[1], image.shape[0], 1)

# we need a numpy array -> vtkTexture function in numpy_support
arr = np.flip(image.swapaxes(0, 1), axis=1).reshape((-1, 3), order='F')
vtkarr = numpy_support.numpy_to_vtk(arr)
vtkarr.SetName('Image')

grid.GetPointData().AddArray(vtkarr)
grid.GetPointData().SetActiveScalars('Image')

vtex = Texture()
vtex.SetInputDataObject(grid)
vtex.Update()

cubeSource = vtk.vtkCubeSource()

mapper = PolyDataMapper()
mapper.SetInputConnection(cubeSource.GetOutputPort())

actor = Actor()
actor.SetMapper(mapper)
actor.SetTexture(vtex)

return actor


# timer_callback is called by window.showManager
def timer_callback(caller, timer_event):
_, image = cam.read()

if image is None:
showmanager.exit()
else:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
actor.texture_update(cube, image)
showmanager.render()


# openCV video capture and conversion to RGB
cam = cv2.VideoCapture('http://commondatastorage.googleapis.com/'
+ 'gtv-videos-bucket/sample/BigBuckBunny.mp4')
fps = int(cam.get(cv2.CAP_PROP_FPS))

_, image = cam.read()
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Scene creation
scene = window.Scene()

# actor for fury
cube = texture_on_cube(image)

# working with window.ShowManager to setup timer_callbacks
scene.add(cube)
showmanager = window.ShowManager(scene, size=(600, 600), reset_camera=False)
showmanager.add_timer_callback(True, int(1000/fps), timer_callback)
showmanager.start()