Commit 4c82b8a5 authored by Thomas Dowrick's avatar Thomas Dowrick
Browse files

Issue #12: Add cropping for StereoViewers

parent 7e5ad0da
Pipeline #1876 failed with stages
in 75 minutes and 32 seconds
......@@ -3,9 +3,8 @@ import logging
import datetime
from PySide2 import QtWidgets
from sksurgeryvtk.widgets.vtk_overlay_window import VTKOverlayWindow
from sksurgeryutils.common_overlay_apps import OverlayOnVideoFeed
from sksurgeryutils.common_overlay_apps import OverlayOnVideoFeedCropRecord
from sksurgeryutils.utils.screen_utils import ScreenController
from sksurgeryimage.processing.crop import ImageCropper
from sksurgerydavinci.ui.gui import UI
LOGGER = logging.getLogger(__name__)
......@@ -13,14 +12,14 @@ LOGGER = logging.getLogger(__name__)
#pylint: disable= no-member, attribute-defined-outside-init
#pylint: disable=protected-access, no-self-use
class DuplicateOverlayWindow(OverlayOnVideoFeed):
class DuplicateOverlayWindow(OverlayOnVideoFeedCropRecord):
"""
Set the background of vtk_overlay_window to duplicate
that of another vtk_overlay_window.
Example usage:
video_source = 0
source_window = OverlayOnVideoFeed(video_source)
source_window = OverlayOnVideoFeedCropRecord(video_source)
duplicate_window = DuplicateOverlayWindow()
duplicate_window.set_source_window(source_window)
......@@ -41,7 +40,16 @@ class DuplicateOverlayWindow(OverlayOnVideoFeed):
def update(self):
""" Update the frame with a new background image."""
self.vtk_overlay_window.set_video_image(self.source_window.img)
if self.source_window.roi:
start_x, start_y = self.source_window.roi[0]
end_x, end_y = self.source_window.roi[1]
self.vtk_overlay_window.set_video_image(self.source_window.img[start_y:end_y,
start_x:end_x,
:])
else:
self.vtk_overlay_window.set_video_image(self.source_window.img)
self.vtk_overlay_window._RenderWindow.Render()
......@@ -54,7 +62,7 @@ class MonoViewer(QtWidgets.QWidget):
super().__init__()
LOGGER.info("Creating Mono Viewer")
self.overlay_window = OverlayOnVideoFeed(video_source)
self.overlay_window = OverlayOnVideoFeedCropRecord(video_source)
self.UI = UI(self.overlay_window)
self.UI.screenshot_button.clicked.connect(self.on_screenshot_clicked)
......@@ -94,13 +102,7 @@ class MonoViewer(QtWidgets.QWidget):
def on_crop_clicked(self):
""" Crop the incoming video stream using ImageCropper. """
#TODO: Exit button disappearing before able to click?!?
roi = ImageCropper().crop(self.overlay_window.img)
self.overlay_window.set_roi(roi)
self.overlay_window.set_roi()
class StereoViewerBase(QtWidgets.QWidget):
......@@ -123,7 +125,8 @@ class StereoViewerBase(QtWidgets.QWidget):
self.UI = UI(self.ui_window)
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_window.vtk_overlay_window
......@@ -270,6 +273,9 @@ 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):
self.left_view.set_roi()
class MockStereoViewer(StereoViewerBase):
"""
Mock stereo viewer, duplicating a single webcam input
......@@ -283,7 +289,7 @@ class MockStereoViewer(StereoViewerBase):
LOGGER.info("Creating Mock Stereo Viewwer")
self.left_view = OverlayOnVideoFeed(video_source)
self.left_view = OverlayOnVideoFeedCropRecord(video_source)
self.right_view = DuplicateOverlayWindow()
self.right_view.set_source_window(self.left_view)
......@@ -309,8 +315,8 @@ class StereoViewer(StereoViewerBase):
LOGGER.info("Creating Stereo Viewer")
self.left_view = OverlayOnVideoFeed(left_source)
self.right_view = OverlayOnVideoFeed(right_source)
self.left_view = OverlayOnVideoFeedCropRecord(left_source)
self.right_view = OverlayOnVideoFeedCropRecord(right_source)
self.ui_window = DuplicateOverlayWindow()
self.ui_window.set_source_window(self.left_view)
......@@ -329,3 +335,9 @@ class StereoViewer(StereoViewerBase):
""" Stop recording data to file and restore button settings. """
self.right_view.on_record_stop()
super().on_record_stop_clicked()
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