Skip to content

Commit

Permalink
Merge pull request #485 from mprib/484-video-playback-widget
Browse files Browse the repository at this point in the history
484 video playback widget
  • Loading branch information
mprib authored Nov 4, 2023
2 parents f0c6982 + 6d6cf70 commit 616a25a
Show file tree
Hide file tree
Showing 43 changed files with 620 additions and 982 deletions.
4 changes: 2 additions & 2 deletions dev/demo/demo_capture_volume_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import sys
from pyxy3d.calibration.capture_volume.capture_volume import CaptureVolume
import pickle
from pyxy3d.session.session import Session
from pyxy3d.session.session import LiveSession
from pyxy3d.configurator import Configurator
from pyxy3d.gui.vizualize.calibration.capture_volume_widget import CaptureVolumeWidget

session_path = Path(__root__, "tests" , "sessions_copy_delete", "2_cam_set_origin_test")
config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)

session.load_estimated_capture_volume()

Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_gui_calibrate_capture_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyxy3d import __root__
from pathlib import Path
from pyxy3d.configurator import Configurator
from pyxy3d.session.session import Session, SessionMode
from pyxy3d.session.session import LiveSession, SessionMode
import toml
from pyxy3d import __app_dir__

Expand All @@ -16,7 +16,7 @@
session_path = Path(recent_projects[recent_project_count-1])

config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)
session.set_mode(SessionMode.ExtrinsicCalibration)
app = QApplication(sys.argv)
window = CalibrateCaptureVolumeWidget(session)
Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_gui_capture_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyxy3d import __root__
from pathlib import Path
from pyxy3d.configurator import Configurator
from pyxy3d.session.session import Session, SessionMode
from pyxy3d.session.session import LiveSession, SessionMode
import toml
from pyxy3d import __app_dir__

Expand All @@ -17,7 +17,7 @@
session_path = Path(recent_projects[recent_project_count-1])

config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)
session.load_estimated_capture_volume()
# session.set_mode(SessionMode.ExtrinsicCalibration)
app = QApplication(sys.argv)
Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_gui_extrinsic_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyxy3d.gui.main_widget import MainWindow
from pyxy3d.configurator import Configurator
from pyxy3d.gui.extrinsic_calibration_widget import ExtrinsicCalibrationWidget
from pyxy3d.session.session import Session, SessionMode
from pyxy3d.session.session import LiveSession, SessionMode


app_settings = toml.load(Path(__app_dir__, "settings.toml"))
Expand All @@ -21,7 +21,7 @@
recent_project_count = len(recent_projects)
session_path = Path(recent_projects[recent_project_count - 1])
config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)
session.set_mode(SessionMode.ExtrinsicCalibration)

# while not hasattr(session.synchronizer, "current_sync_packet"):
Expand Down
6 changes: 3 additions & 3 deletions dev/demo/demo_gui_intrinsic_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pyxy3d import __app_dir__
from pyxy3d.gui.main_widget import MainWindow
from pyxy3d.configurator import Configurator
from pyxy3d.gui.camera_config.intrinsic_calibration_widget import IntrinsicCalibrationWidget
from pyxy3d.session.session import Session, SessionMode
from pyxy3d.gui.live_camera_config.intrinsic_calibration_widget import IntrinsicCalibrationWidget
from pyxy3d.session.session import LiveSession, SessionMode


app_settings = toml.load(Path(__app_dir__, "settings.toml"))
Expand All @@ -17,7 +17,7 @@
recent_project_count = len(recent_projects)
session_path = Path(recent_projects[recent_project_count - 1])
config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)
session.set_mode(SessionMode.IntrinsicCalibration)

app = QApplication(sys.argv)
Expand Down
2 changes: 1 addition & 1 deletion dev/demo/demo_gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
import toml
from pyxy3d import __app_dir__
from pyxy3d.gui.single_main_widget import MainWindow
from pyxy3d.gui.main_widget import MainWindow

app_settings = toml.load(Path(__app_dir__, "settings.toml"))
recent_projects: list = app_settings["recent_projects"]
Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_gui_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from time import sleep
from pyxy3d import __root__
from pyxy3d.configurator import Configurator
from pyxy3d.session.session import Session
from pyxy3d.session.session import LiveSession
from pathlib import Path
from pyxy3d import __app_dir__

Expand All @@ -24,7 +24,7 @@
logger.info(f"Launching post processing widget for {session_path}")

config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)

app = QApplication(sys.argv)

Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_gui_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import toml

from pyxy3d.gui.recording_widget import RecordingWidget
from pyxy3d.session.session import Session, SessionMode
from pyxy3d.session.session import LiveSession, SessionMode
from pyxy3d.cameras.synchronizer import Synchronizer
from pyxy3d import __root__
from pyxy3d.helper import copy_contents
Expand All @@ -31,7 +31,7 @@
session_path = Path(recent_projects[recent_project_count-1])
# copy_contents(session_origin_path,session_path)
config = Configurator(session_path)
session = Session(config)
session = LiveSession(config)
session.set_mode(SessionMode.Recording)

App = QApplication(sys.argv)
Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_playback_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyxy3d.recording.recorded_stream import RecordedStreamPool
from pyxy3d.cameras.synchronizer import Synchronizer
from pyxy3d.triangulate.sync_packet_triangulator import SyncPacketTriangulator
from pyxy3d.session.session import Session
from pyxy3d.session.session import LiveSession
from pyxy3d.gui.vizualize.playback_triangulation_widget import (
PlaybackTriangulationWidget,
)
Expand All @@ -37,7 +37,7 @@


logger.info(f"Loading session {session_path}")
session = Session(config)
session = LiveSession(config)

app = QApplication(sys.argv)
recording_path = Path(session_path, "recording_1")
Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_process_prerecorded.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyxy3d.recording.recorded_stream import RecordedStreamPool
from pyxy3d.cameras.synchronizer import Synchronizer
from pyxy3d.triangulate.sync_packet_triangulator import SyncPacketTriangulator
from pyxy3d.session.session import Session
from pyxy3d.session.session import LiveSession
from pyxy3d.gui.vizualize.playback_triangulation_widget import (
PlaybackTriangulationWidget,
)
Expand Down Expand Up @@ -53,7 +53,7 @@


logger.info(f"Loading session {session_path}")
session = Session(config)
session = LiveSession(config)

app = QApplication(sys.argv)

Expand Down
4 changes: 2 additions & 2 deletions dev/demo/demo_real_time_triangulator_mediapipe_hands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pyxy3d.gui.vizualize.realtime_triangulation_widget import \
RealTimeTriangulationWidget
from pyxy3d.interface import FramePacket, PointPacket, SyncPacket
from pyxy3d.session.session import Session
from pyxy3d.session.session import LiveSession
from pyxy3d.trackers.charuco_tracker import Charuco, CharucoTracker
from pyxy3d.trackers.hand_tracker import HandTracker
from pyxy3d.triangulate.sync_packet_triangulator import SyncPacketTriangulator
Expand All @@ -32,7 +32,7 @@
app = QApplication(sys.argv)
session_path = Path(__root__,"dev", "sample_sessions", "low_res")

session = Session(session_path)
session = LiveSession(session_path)
tracker = TrackerEnum.HAND

session.load_stream_tools(tracker=tracker)
Expand Down
90 changes: 90 additions & 0 deletions dev/dev_playback_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import sys
import cv2
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QSlider, QLabel)
from PySide6.QtCore import (Qt, QTimer)
from PySide6.QtGui import (QPixmap, QImage)

class VideoPlayer(QWidget):
def __init__(self, video_path, parent=None):
super().__init__(parent)
self.video_path = video_path
self.cap = cv2.VideoCapture(self.video_path)
self.frame_rate = int(self.cap.get(cv2.CAP_PROP_FPS))
self.total_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
self.timer = QTimer()

self.place_widgets()
self.connect_widgets()

def place_widgets(self):
self.layout = QVBoxLayout()

self.image_label = QLabel(self)
self.layout.addWidget(self.image_label)

self.play_button = QPushButton("Play", self)
self.layout.addWidget(self.play_button)

self.slider = QSlider(Qt.Horizontal, self)
self.slider.setMaximum(self.total_frames)
self.layout.addWidget(self.slider)

self.setLayout(self.layout)

def connect_widgets(self):
self.play_button.clicked.connect(self.play_video)
self.slider.sliderMoved.connect(self.slider_moved)
self.timer.timeout.connect(self.next_frame)

def play_video(self):
if self.timer.isActive():
self.timer.stop()
self.play_button.setText("Play")
else:
self.timer.start(1000 // self.frame_rate)
self.play_button.setText("Pause")

def next_frame(self):
ret, frame = self.cap.read()
if ret:
self.display_image(frame)
self.slider.setValue(self.slider.value() + 1)
else:
self.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
self.slider.setValue(0)

def slider_moved(self, position):
self.cap.set(cv2.CAP_PROP_POS_FRAMES, position)
ret, frame = self.cap.read()
if ret:
self.display_image(frame)

def display_image(self, frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
height, width, channel = frame.shape
bytes_per_line = 3 * width
q_img = QImage(frame.data, width, height, bytes_per_line, QImage.Format_RGB888)
pixmap = QPixmap.fromImage(q_img)
self.image_label.setPixmap(pixmap.scaled(self.image_label.width(), self.image_label.height(), Qt.KeepAspectRatio))

def closeEvent(self, event):
self.cap.release()
super().closeEvent(event)

class VideoWindow(QMainWindow):
def __init__(self, video_path, parent=None):
super().__init__(parent)
self.setWindowTitle("Video Player")
self.player = VideoPlayer(video_path, self)
self.setCentralWidget(self.player)

if __name__ == "__main__":
app = QApplication(sys.argv)
# Define the input file path here.
input_file = r"C:\Users\Mac Prible\repos\pyxy3d\tests\sessions\4_cam_recording\calibration\extrinsic\port_0.mp4"


window = VideoWindow(input_file)
window.resize(800, 600)
window.show()
sys.exit(app.exec())
Loading

0 comments on commit 616a25a

Please sign in to comment.