Skip to content

Commit

Permalink
Merge pull request #42 from UCL/41-imagecropper-removed
Browse files Browse the repository at this point in the history
41 imagecropper removed
  • Loading branch information
thompson318 committed Jan 24, 2022
2 parents b259336 + 5ccce9c commit 2f2b282
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -9,17 +9,17 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-ver: [3.6, 3.7]
python-ver: [3.7, 3.8]
experimental: [false]
include:
- python-ver: 3.8
- python-ver: 3.9
os: ubuntu-latest
experimental: true

- python-ver: 3.8
- python-ver: 3.9
os: windows-latest
experimental: true
- python-ver: 3.8
- python-ver: 3.9
os: macos-latest
experimental: true

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -4,7 +4,7 @@
# doc/requirements.rst
six>=1.10
numpy>=1.11
opencv-contrib-python>=4.1.1.26
opencv-contrib-python-headless>=4.1.1.26
PySide2<5.15.0
scikit-surgerycore>=0.1.7
scikit-surgeryimage>=0.2.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -53,7 +53,7 @@
install_requires=[
'six>=1.10',
'numpy>=1.11',
'opencv-contrib-python>=4.1.1.26',
'opencv-contrib-python-headless>=4.1.1.26',
'PySide2<5.15.0',
'scikit-surgerycore>=0.1.7',
'scikit-surgeryimage>=0.2.0',
Expand Down
28 changes: 10 additions & 18 deletions sksurgeryutils/common_overlay_apps.py
Expand Up @@ -9,7 +9,6 @@
from PySide2.QtCore import QTimer
from sksurgeryimage.acquire.video_source import TimestampedVideoSource
from sksurgeryimage.acquire.video_writer import TimestampedVideoWriter
from sksurgeryimage.ui.ImageCropper import ImageCropper

from sksurgeryvtk.widgets.vtk_overlay_window import VTKOverlayWindow
from sksurgeryvtk.models.vtk_surface_model_directory_loader \
Expand Down Expand Up @@ -89,21 +88,13 @@ def __init__(self, video_source, output_filename=None, dims=None):
super().__init__(video_source, dims)
self.output_filename = output_filename
self.video_writer = None
self.roi = None

def update(self):
""" Get the next frame of input, crop and/or
write to file (if either enabled). """
_, self.img = self.video_source.read()
if self.roi:
start_x, start_y = self.roi[0]
end_x, end_y = self.roi[1]
self.vtk_overlay_window.set_video_image(self.img[start_y:end_y,
start_x:end_x,
:])

else:
self.vtk_overlay_window.set_video_image(self.img)
self.vtk_overlay_window.set_video_image(self.img)

self.vtk_overlay_window._RenderWindow.Render()

Expand All @@ -112,11 +103,15 @@ def update(self):
self.video_writer.write_frame(output_frame,
self.video_source.timestamp)

def set_roi(self):
"""Crop the incoming video stream using ImageCropper."""
#pylint:disable=attribute-defined-outside-init
self.roi = ImageCropper().crop(self.img)
logging.debug("Setting ROI: %i", self.roi)
def set_roi(self): #pylint: disable=no-self-use
"""
Crop the incoming video stream using ImageCropper.
Function is depreciated due to moving to opencv-headless
in sksurgeryvtk. I've left it in for the minute in case
any one is using it without my knowlegde
"""
raise RuntimeError ("Set Roi function is depreciated and",
" is not longer implemented in sksurgeryutils")

def get_output_frame(self):
""" Get the output frame to write in numpy format."""
Expand Down Expand Up @@ -192,6 +187,3 @@ def on_record_start(self):

def on_record_stop(self):
""" Don't want to call the base class version, so override."""

def set_roi(self):
""" Don't want to call the base class version, so override."""
12 changes: 3 additions & 9 deletions tests/test_common_overlay_apps.py
Expand Up @@ -91,19 +91,13 @@ def something(self):
overlay_app = ErrorApp(input_file)
overlay_app.update()

roi = [(25, 25), (50, 50)]
@mock.patch('sksurgeryutils.common_overlay_apps.ImageCropper.crop')
def test_OverlayOnVideoFeedCropRecord_set_roi(mock_crop, setup_qt):
mock_crop.return_value = roi
def test_OverlayOnVideoFeedCropRecord_set_roi(setup_qt):

input_file = 'tests/data/100x50_100_frames.avi'
overlay_app = coa.OverlayOnVideoFeedCropRecord(input_file)
overlay_app.update() # Get a frame so that we can crop it
overlay_app.set_roi()
overlay_app.update() # This should apply the roi to the next frame

expected_shape = (roi[1][0] - roi[0][0], roi[1][1] - roi[0][1])
assert overlay_app.vtk_overlay_window.input.shape[:2] == expected_shape
with pytest.raises(RuntimeError):
overlay_app.set_roi()

def test_DuplicateOverlayWindow(setup_qt):

Expand Down

0 comments on commit 2f2b282

Please sign in to comment.