Commit b28e874d authored by Thomas Dowrick's avatar Thomas Dowrick
Browse files

More refactoring

parent 2a46b1d1
Pipeline #1915 failed with stages
in 70 minutes and 4 seconds
......@@ -88,91 +88,33 @@ class BlankFeed:
""" Don't want to call the base class version, so override."""
pass
def add_vtk_models(self, models):
pass
def add_vtk_overlay(self):
""" Don't want to call the base class version, so override."""
pass
class MonoViewer(QtWidgets.QWidget):
"""
Generates a VTK interactor UI with a video stream as background
:param video_source: OpenCV compatible video source (int or filename)
"""
def __init__(self, video_source):
super().__init__()
LOGGER.info("Creating Mono Viewer")
self.left_view = OverlayOnVideoFeedCropRecord(video_source)
self.right_view = None
self.UI = UI(self.left_view)
def get_foreground_camera(self):
pass
self.auto_cropper = AutoCropBlackBorder(threshold = 50)
self.autocrop_timer = QTimer()
self.autocrop_timer.timeout.connect(self.update_autocrop)
def set_foreground_camera(self, camera):
""" Blank method. """
pass
self.setup_UI_callbacks()
def set_screen(self):
""" Blank method. """
pass
def setup_UI_callbacks(self):
self.UI.screenshot_button.clicked.connect(self.on_screenshot_clicked)
self.UI.record_button.clicked.connect(self.on_record_start_clicked)
self.UI.crop_button.clicked.connect(self.on_crop_clicked)
self.UI.autocrop_button.clicked.connect(self.on_autocrop_started)
def add_vtk_models(self, models):
"""
Add vtk model overlays to the window
:param models: list of vtk models to add
:type models: list of VTKSurfaceModels
"""
self.UI.add_vtk_models(models)
def set_geometry(self):
""" Blank. """
pass
def start(self):
""" Start the viewer. """
self.left_view.start()
def on_screenshot_clicked(self):
""" Save a screenshot to disk, using date and time as filename """
fname = datetime.datetime.now().strftime("%Y-%m-%d.%H-%M-%S") + '.png'
self.left_view.vtk_overlay_window.save_scene_to_file(fname)
def on_record_start_clicked(self):
""" Start recording a video using current time as filename """
self.UI.record_button.setText("Stop recording")
self.UI.record_button.clicked.disconnect()
self.UI.record_button.clicked.connect(self.on_record_stop_clicked)
self.left_view.on_record_start()
def on_record_stop_clicked(self):
""" Stop recording data to file and restore button settings. """
self.left_view.on_record_stop()
self.UI.record_button.setText("Record video")
self.UI.record_button.clicked.disconnect()
self.UI.record_button.clicked.connect(self.on_record_start_clicked)
def on_crop_clicked(self):
""" Crop the incoming video stream using ImageCropper. """
self.left_view.set_roi()
def on_autocrop_started(self):
""" Start auto cropping. """
self.UI.autocrop_button.setText("Disable Auto Crop")
self.UI.autocrop_button.clicked.disconnect()
self.UI.autocrop_button.clicked.connect(self.on_autocrop_stopped)
self.autocrop_timer.start(500)
def on_autocrop_stopped(self):
""" Stop auto cropping. """
self.UI.autocrop_button.setText("Enable Auto Crop")
self.UI.autocrop_button.clicked.disconnect()
self.UI.autocrop_button.clicked.connect(self.on_autocrop_started)
self.autocrop_timer.stop()
self.left_view.roi = None
def update_autocrop(self):
""" Automatically crop the incoming video stream using AutoCropper.
"""
roi = self.auto_cropper.get_roi(self.left_view.img)
self.left_view.roi = roi
pass
def stop(self):
pass
class StereoViewerBase(QtWidgets.QWidget):
......@@ -185,21 +127,21 @@ class StereoViewerBase(QtWidgets.QWidget):
# These are overridden in subclasses.
# Included here for clarity.
super().__init__()
self.UI = None
self.left_view = None
self.right_view = None
self.UI = BlankFeed()
self.left_view = BlankFeed()
self.right_view = BlankFeed()
self.ui_view = BlankFeed()
self.left_overlay = BlankFeed()
self.right_overlay = BlankFeed()
self.ui_overlay = BlankFeed()
def setup_widgets(self):
""" Sync the cameras between the widgets,
and setup Qt output signal. """
self.UI = UI(self.ui_view)
self.UI.screenshot_button.clicked.connect(self.on_screenshot_clicked)
self.UI.record_button.clicked.connect(self.on_record_start_clicked)
self.UI.crop_button.clicked.connect(self.on_crop)
self.left_overlay = self.left_view.vtk_overlay_window
self.right_overlay = self.right_view.vtk_overlay_window
self.ui_overlay = self.ui_view.vtk_overlay_window
self.UI.crop_button.clicked.connect(self.on_crop_clicked)
self.sync_camera_view_between_windows()
......@@ -349,10 +291,64 @@ class StereoViewerBase(QtWidgets.QWidget):
self.UI.record_button.clicked.disconnect()
self.UI.record_button.clicked.connect(self.on_record_start_clicked)
def on_crop(self):
def on_crop_clicked(self):
self.left_view.set_roi()
self.right_view.roi = self.left_view.roi
class MonoViewer(StereoViewerBase):
"""
Generates a VTK interactor UI with a video stream as background
:param video_source: OpenCV compatible video source (int or filename)
"""
def __init__(self, video_source):
super().__init__()
LOGGER.info("Creating Mono Viewer")
self.left_view = OverlayOnVideoFeedCropRecord(video_source)
self.left_overlay = self.left_view.vtk_overlay_window
#TODO: Change this bit, don't really want ui_view diff from UI
self.UI = UI(self.left_view)
self.auto_cropper = AutoCropBlackBorder(threshold = 50)
self.autocrop_timer = QTimer()
self.autocrop_timer.timeout.connect(self.update_autocrop)
# TODO: Move this to super class, then call super at end of this init
self.setup_widgets()
def setup_UI_callbacks(self):
self.UI.autocrop_button.clicked.connect(self.on_autocrop_started)
def on_autocrop_started(self):
""" Start auto cropping. """
self.UI.autocrop_button.setText("Disable Auto Crop")
self.UI.autocrop_button.clicked.disconnect()
self.UI.autocrop_button.clicked.connect(self.on_autocrop_stopped)
self.autocrop_timer.start(500)
def on_autocrop_stopped(self):
""" Stop auto cropping. """
self.UI.autocrop_button.setText("Enable Auto Crop")
self.UI.autocrop_button.clicked.disconnect()
self.UI.autocrop_button.clicked.connect(self.on_autocrop_started)
self.autocrop_timer.stop()
self.set_all_roi(None)
def update_autocrop(self):
""" Automatically crop the incoming video stream using AutoCropper.
"""
roi = self.auto_cropper.get_roi(self.left_view.img)
self.set_all_roi(roi)
def set_all_roi(self, roi):
""" Set the roi for left/right views. """
self.left_view.roi = roi
self.right_view.roi = roi
class MockStereoViewer(StereoViewerBase):
"""
Mock stereo viewer, duplicating a single webcam input
......@@ -366,6 +362,7 @@ class MockStereoViewer(StereoViewerBase):
LOGGER.info("Creating Mock Stereo Viewwer")
#TODO: Move to superclass
self.left_view = OverlayOnVideoFeedCropRecord(video_source)
self.right_view = DuplicateOverlayWindow()
......@@ -374,6 +371,12 @@ class MockStereoViewer(StereoViewerBase):
self.ui_view = DuplicateOverlayWindow()
self.ui_view.set_source_window(self.left_view)
self.left_overlay = self.left_view.vtk_overlay_window
self.right_overlay = self.right_view.vtk_overlay_window
self.ui_overlay = self.ui_view.vtk_overlay_window
self.UI = UI(self.ui_view)
self.setup_widgets()
class StereoViewer(StereoViewerBase):
......@@ -396,23 +399,11 @@ class StereoViewer(StereoViewerBase):
self.ui_view = DuplicateOverlayWindow()
self.ui_view.set_source_window(self.left_view)
self.setup_widgets()
def on_record_start_clicked(self):
""" Start recording a video using current time as filename """
super().on_record_start_clicked()
self.left_overlay = self.left_view.vtk_overlay_window
self.right_overlay = self.right_view.vtk_overlay_window
self.ui_overlay = self.ui_view.vtk_overlay_window
fname_right = self.video_fname_base + '-RIGHT.avi'
self.right_view.output_filename = fname_right
self.right_view.on_record_start()
self.UI = UI(self.ui_view)
def on_record_stop_clicked(self):
""" Stop recording data to file and restore button settings. """
self.right_view.on_record_stop()
super().on_record_stop_clicked()
self.setup_widgets()
def on_crop(self):
""" Crop video feed on left view, and propagate results to right view.
"""
self.left_view.set_roi()
self.right_view.roi = self.left_view.roi
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment