Skip to content

Commit

Permalink
Add Text overaly tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
tdowrick committed Nov 18, 2020
1 parent dfb11d6 commit 4c3193e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
Binary file added docs/tutorials/text_overlay.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions docs/tutorials/text_overlay.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Add Text to VTKOverlayWindow
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Classes are provided that can add persistent text to a VTKOverlayWindow as:

* Corner annotations
* Large centered text
* Generic text anywhere in the window

.. image:: text_overlay.png

First, we need to import relevant modules, setup a Qt Application, and create a VTKOverlayWindow.

.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py
:language: python
:start-after: #Tutorial-start
:end-before: #Tutorial-section1

We can now create a corner annotations:

.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py
:language: python
:start-after: #Tutorial-section1
:end-before: #Tutorial-section2

centred text:

.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py
:language: python
:start-after: #Tutorial-section2
:end-before: #Tutorial-section3

and place some text at given co-ordinates in the window:

.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py
:language: python
:start-after: #Tutorial-section3
:end-before: #Tutorial-end

`layer=2` is typically used for text overlay (layer 0 is the background image and layer 1 is used for VTK models).
Finally, we execute the Qt app to show the window:

.. code-block:: python
overlay_window.show()
sys.exit(app.exec_())
46 changes: 24 additions & 22 deletions tests/tutorials/test_text_overlay_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
#Tutorial-start
import sys
import cv2
from PySide2 import QtWidgets
from sksurgeryvtk.widgets import vtk_overlay_window
from sksurgeryvtk.text import text_overlay

def test_text():
app = QtWidgets.QApplication([])

background = cv2.imread('tests/data/rendering/background-960-x-540.png')
overlay_window = vtk_overlay_window.VTKOverlayWindow()
overlay_window.set_video_image(background)

corner_annotation = text_overlay.VTKCornerAnnotation()
corner_annotation.set_text(["1", "2", "3", "4"])
overlay_window.add_vtk_actor(corner_annotation.text_actor, layer=2)

large_text = text_overlay.VTKLargeTextCentreOfScreen("Central Text")
large_text.set_colour(1.0, 0.0, 0.0)
large_text.set_parent_window(overlay_window)
overlay_window.add_vtk_actor(large_text.text_actor, layer=2)

more_text = text_overlay.VTKText("More text", x=50, y=100)
more_text.set_colour(0.0, 1.0, 0.0)
overlay_window.add_vtk_actor(more_text.text_actor, layer=2)

overlay_window.show()
#sys.exit(app.exec_())
app = QtWidgets.QApplication([])

background = cv2.imread('tests/data/rendering/background-960-x-540.png')
overlay_window = vtk_overlay_window.VTKOverlayWindow()
overlay_window.set_video_image(background)
#Tutorial-section1
corner_annotation = text_overlay.VTKCornerAnnotation()
corner_annotation.set_text(["1", "2", "3", "4"])
overlay_window.add_vtk_actor(corner_annotation.text_actor, layer=2)
#Tutorial-section2
arge_text = text_overlay.VTKLargeTextCentreOfScreen("Central Text")
large_text.set_colour(1.0, 0.0, 0.0)
large_text.set_parent_window(overlay_window)
overlay_window.add_vtk_actor(large_text.text_actor, layer=2)
#Tutorial-section3
more_text = text_overlay.VTKText("More text", x=50, y=100)
more_text.set_colour(0.0, 1.0, 0.0)
overlay_window.add_vtk_actor(more_text.text_actor, layer=2)
#Tutorial-end

overlay_window.show()

#sys.exit(app.exec_())


0 comments on commit 4c3193e

Please sign in to comment.