Commit 2501e17a authored by Thomas Dowrick's avatar Thomas Dowrick

Merge branch 'add-text-overlay-demo' into 'master'

Add text overlay demo

See merge request WEISS/SoftwareRepositories/SNAPPY/scikit-surgeryutils!6
parents cb04dd4a 0bc91148
Pipeline #1761 failed with stages
in 13 minutes and 34 seconds
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from sksurgeryutils.ui.sksurgerytextoverlay_command_line import main
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
# coding=utf-8
""" Command line processing for charucotest app. """
import argparse
from sksurgeryutils import __version__
from sksurgeryutils.ui.sksurgerytextoverlay_demo import run_demo
def main(args=None):
"""Entry point for sksurgerytextoverlay application"""
parser = argparse.ArgumentParser(description='sksurgerytextoverlay')
version_string = __version__
friendly_version_string = version_string if version_string else 'unknown'
parser.add_argument(
"-v", "--version",
action='version',
version='sksurgerytextoverlay version ' + friendly_version_string)
args = parser.parse_args(args)
run_demo()
# coding=utf-8
""" Demo app, to show text overlay"""
import logging
import sys
from PySide2.QtWidgets import QApplication, QInputDialog
from sksurgeryvtk.text import text_overlay
from sksurgeryutils import common_overlay_apps
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)
#pylint:disable=line-too-long, invalid-name, unused-argument
class TextOverlayDemo(common_overlay_apps.OverlayOnVideoFeed):
""" Demo app, to show text overlay"""
def __init__(self, video_source):
super().__init__(video_source)
self.vtk_overlay_window.GetRenderWindow().SetWindowName("Click on image to add text")
self.overlay_layer = 2
# ADD ANNOTATIONS TO EACH CORNER
corner_annotation = text_overlay.VTKCornerAnnotation()
corner_annotation.set_text(["1", "2", "3", "4"])
self.vtk_overlay_window.add_vtk_actor(corner_annotation.text_actor, 2)
# ADD LARGE TEXT IN CENTRE OF SCREEN
# Need to stretch them vertically more.
large_text = text_overlay.VTKLargeTextCentreOfScreen("Click to add text")
large_text.set_parent_window(self.vtk_overlay_window)
self.vtk_overlay_window.add_vtk_actor(large_text.text_actor, 2)
# ADD TEXT IN RESPONSE TO LEFT MOUSE CLICK
self.vtk_overlay_window.AddObserver('LeftButtonPressEvent', self.mouse_click_callback)
def mouse_click_callback(self, obj, ev):
""" Callback to create text at left mouse click position. """
# Open a dialog box to get the input text
text, _ = QInputDialog.getText(None, "Create text overlay", "Text:")
# Get the mouse click position
x, y = obj.GetEventPosition()
# Create a text actor and add it to the VTK scene
vtk_text = text_overlay.VTKText(text, x, y)
vtk_text.set_parent_window(self.vtk_overlay_window)
self.vtk_overlay_window.add_vtk_actor(vtk_text.text_actor, 2)
def run_demo():
""" Run demo """
app = QApplication([])
video_source = 0
demo = TextOverlayDemo(video_source)
demo.start()
return sys.exit(app.exec_())
# coding=utf-8
"""sksurgerytextoverlay tests"""
from sksurgeryutils.ui.sksurgerytextoverlay_demo import TextOverlayDemo
import pytest
import sys
def test_sksurgerytextoverlay():
""" Basic test to run the widget and make sure everything loads OK."""
if sys.platform == "darwin":
pytest.skip("Test not working on Mac runner")
# Use input video rather than camera to test
input_file = 'tests/data/test_video.avi'
gui = TextOverlayDemo(input_file)
gui.start()
......@@ -4,6 +4,7 @@
from sksurgeryutils.ui.sksurgeryvideolag_demo import DemoGui
import pytest
import sys
def test_sksurgeryvideolag(qtbot):
""" Basic test to run the widget and make sure everything loads OK."""
......
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