Skip to content

Commit

Permalink
Merge pull request #556 from mprib/554-post-processing-widget-interfa…
Browse files Browse the repository at this point in the history
…ces-with-controller

554 post processing widget interfaces with controller
  • Loading branch information
mprib authored Dec 3, 2023
2 parents 49a33d0 + 55d0ccb commit d42c0fc
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 429 deletions.
19 changes: 19 additions & 0 deletions dev/demo/demo_gui_capture_volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from PySide6.QtWidgets import QApplication
import sys
from pathlib import Path
from pyxy3d.controller import Controller
from pyxy3d.gui.post_processing_widget import PostProcessingWidget
from pyxy3d.gui.vizualize.calibration.capture_volume_widget import CaptureVolumeWidget

app = QApplication(sys.argv)
workspace_dir = Path(r"C:\Users\Mac Prible\OneDrive\pyxy3d\4_cam_prerecorded_practice_working")
controller = Controller(workspace_dir)
# controller.load_camera_array()
controller.load_estimated_capture_volume()
window = CaptureVolumeWidget(controller)


window.show()

app.exec()

17 changes: 17 additions & 0 deletions dev/demo/demo_gui_post_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from PySide6.QtWidgets import QApplication
import sys
from pathlib import Path
from pyxy3d.controller import Controller
from pyxy3d.gui.post_processing_widget import PostProcessingWidget

app = QApplication(sys.argv)
workspace_dir = Path(r"C:\Users\Mac Prible\OneDrive\pyxy3d\4_cam_prerecorded_practice_working")
controller = Controller(workspace_dir)
controller.load_camera_array()
window = PostProcessingWidget(controller)


window.show()

app.exec()

16 changes: 8 additions & 8 deletions pyxy3d/cameras/synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DROPPED_FRAME_TRACK_WINDOW = 100 # trailing frames tracked for reporting purposes

class Synchronizer:
def __init__(self, streams: dict, fps_target=6):
def __init__(self, streams: dict):
self.streams = streams
self.current_synched_frames = None

Expand All @@ -38,8 +38,8 @@ def __init__(self, streams: dict, fps_target=6):
self.subscribe_to_streams()

# note that self.fps target is set in set_stream_fps
self.set_stream_fps(fps_target)
self.fps_mean = fps_target
# self.set_stream_fps(fps_target)
# self.fps_mean = fps_target

# place to store a recent history of dropped frames
self.dropped_frame_history = {port:[] for port in sorted(self.ports)}
Expand All @@ -66,11 +66,11 @@ def dropped_fps(self):
return {port:np.mean(drop_history) for port,drop_history in self.dropped_frame_history.items()}


def set_stream_fps(self, fps_target):
self.fps_target = fps_target
logger.info(f"Attempting to change target fps in streams to {fps_target}")
for port, stream in self.streams.items():
stream.set_fps_target(fps_target)
# def set_stream_fps(self, fps_target):
# self.fps_target = fps_target
# logger.info(f"Attempting to change target fps in streams to {fps_target}")
# for port, stream in self.streams.items():
# stream.set_fps_target(fps_target)

def subscribe_to_streams(self):
for port, stream in self.streams.items():
Expand Down
49 changes: 23 additions & 26 deletions pyxy3d/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from pathlib import Path
from PySide6.QtGui import QPixmap
from time import sleep
from pyxy3d.interface import Tracker
from pyxy3d.trackers.tracker_enum import TrackerEnum
from pyxy3d.post_processing.post_processor import PostProcessor
from pyxy3d.calibration.charuco import Charuco
from pyxy3d.intrinsic_stream_manager import IntrinsicStreamManager
from pyxy3d.configurator import Configurator
Expand All @@ -17,7 +20,7 @@
from pyxy3d.calibration.capture_volume.helper_functions.get_point_estimates import (
get_point_estimates,
)
from pyxy3d.synchronized_stream_manager import SynchronizedStreamManager
from pyxy3d.synchronized_stream_manager import SynchronizedStreamManager, read_video_properties
from collections import OrderedDict

import pyxy3d.logger
Expand Down Expand Up @@ -48,7 +51,8 @@ class Controller(QObject):
ExtrinsicCalibrationComplete = Signal()
extrinsic_2D_complete = Signal()
intrinsicStreamsLoaded = Signal()

post_processing_complete = Signal()

def __init__(self, workspace_dir: Path):
super().__init__()
self.workspace = workspace_dir
Expand All @@ -67,7 +71,7 @@ def __init__(self, workspace_dir: Path):
self.extrinsic_dir = Path(self.workspace, "calibration", "extrinsic")
# make sure the containing directory exists
self.extrinsic_dir.mkdir(exist_ok=True, parents=True)

self.recording_dir = Path(self.workspace, "recordings")
self.capture_volume = None

def set_camera_count(self, count:int):
Expand Down Expand Up @@ -341,26 +345,19 @@ def worker():
)
self.extrinsicCalibrationThread.start()

def read_video_properties(source_path: Path) -> dict:
# Dictionary to hold video properties
properties = {}

# Open the video file
video = cv2.VideoCapture(str(source_path))
logger.info(f"Attempting to open video file: {source_path}")

# Check if video opened successfully
if not video.isOpened():
raise ValueError(f"Could not open the video file: {source_path}")

# Extract video properties
properties["frame_count"] = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
properties["fps"] = video.get(cv2.CAP_PROP_FPS)
properties["width"] = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
properties["height"] = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
properties["size"] = (properties["width"], properties["height"])

# Release the video capture object
video.release()

return properties
def process_recordings(self, recording_path:Path, tracker_enum:TrackerEnum):
"""
Initiates worker thread to begin post processing.
TrackerEnum passed in so that access is given to both the tracker and the name because the name is needed for file/folder naming
"""
def worker():
logger.info(f"Beginning to process video files at {recording_path}")
logger.info(f"Creating post processor for {recording_path}")
self.post_processor = PostProcessor(self.camera_array, recording_path, tracker_enum)
self.post_processor.create_xy()
self.post_processor.create_xyz()

self.process_recordings_thread = QThread()
self.process_recordings_thread.run = worker
self.process_recordings_thread.finished.connect(self.post_processing_complete)
self.process_recordings_thread.start()
Loading

0 comments on commit d42c0fc

Please sign in to comment.