Skip to content

add qt video example #341

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

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions examples/qt/video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Use a simple Plot to display a video frame that can be updated using a QSlider
"""
from PyQt6 import QtWidgets, QtCore
import fastplotlib as fpl
import imageio.v3 as iio

# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objects
app = QtWidgets.QApplication([])

video = iio.imread("imageio:cockatoo.mp4")

# force qt canvas, wgpu will sometimes pick glfw by default even if Qt is present
plot = fpl.Plot(canvas="qt")

plot.add_image(video[0], name="video")
plot.camera.local.scale *= -1


def update_frame(ix):
plot["video"].data = video[ix]
# you can also do plot.graphics[0].data = video[ix]


# create a QMainWindow, set the plot canvas as the main widget
# The canvas does not have to be in a QMainWindow and it does
# not have to be the central widget, it will work like any QWidget
main_window = QtWidgets.QMainWindow()
main_window.setCentralWidget(plot.canvas)

# Create a QSlider for updating frames
slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
slider.setMaximum(video.shape[0] - 1)
slider.setMinimum(0)
slider.valueChanged.connect(update_frame)

# put slider in a dock
dock = QtWidgets.QDockWidget()
dock.setWidget(slider)

# put the dock in the main window
main_window.addDockWidget(
QtCore.Qt.DockWidgetArea.BottomDockWidgetArea,
dock
)

# calling plot.show() is required to start the rendering loop
plot.show()

# set window size from width and height of video
main_window.resize(video.shape[2], video.shape[1])

# show the main window
main_window.show()

# execute Qt app
app.exec()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy