{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 2: Interacting with images in phenopype\n", "\n", "In this tutorial we learn how to open and close images in phenopype, and how to use the interactive featues of the program. Phenopype uses OpenCV's HighGUI module to display images and to allow users to interact with images. HighGUI has a few pros and cons: \n", "\n", "```\n", "+ native OpenCV GUI (no extra GUI libraries required)\n", "+ the module is extremely fast in displaying images \n", "+ it can display very large image-arrays (> 10000x10000 pixels)\n", "+ it can display multiple images side by side\n", "+ interactions (drawing and measuring) are possible \n", "\n", "- sometimes unstable (e.g. windows are not closed but freeze)\n", "- issues with cross plattform stability (e.g. on macOS)\n", "- displaying instructions is hacky (text is \"painted\" onto a displayed image) \n", "- user input (key strokes and mouse clicks) sometimes isn't captured properly\n", "```\n", "\n", "Currently Phenopype uses the standard HighGUI libraries that ship with the most recent precompiled `opencv-contrib-python` package, which is `Qt` for Linux and macOS, and `Win32 UI` on Windows. The `Qt` GUI is a bit more userfriendly with builtin buttons, scrollbars, RGB info and zoom, but you don't actually need those things for basic Phenopype GUI interactions." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
See also:
\n", "\n", "\n", "* [CV resources in the phenopype docs](https://www.phenopype.org/docs/resources/cv/)\n", "* [OpenCV HighGUI docs](https://docs.opencv.org/master/dc/d46/group__highgui__qt.html)\n", " \n", "
\n", "IMPORTANT - read before continuing:
\n", " \n", "\n", "\n", "**Open**\n", "\n", "In a very simple case, where you want to just inspect an image file from within phenopype, you use the `load_image` function to load an image file into Python as an array, and then display it with `show_image`. A HighGUI window will pop up and display the array. While the window is open, the Python kernel is \"busy\", and you cannot interact with the console, i.e. run any code - you first have to close the image again.\n", "\n", "**Close**\n", " \n", "Although the HighGUI window has the \"red crossed\" close button in the upper right corner, DO NOT USE IT! For practical reasons, phenopype relies on key strokes to control the windows. Make sure that the window is selected / highlighted, and use the following key combinations to close it: \n", " \n", "- `Enter` - close window or finish an interactive function in `pype`-mode \n", "- `Ctrl+Enter` - close and finish a window in `pype`-mode \n", "- `Esc` - close a window and quit the Phenoype process that invoked it. This may also work when the process is frozen. \n", "\n", "**Issues**\n", "\n", "Unfortunately the HighGUI isn't exactly stable, and may sometimes behave unexpectedly. Here are solutions to the most comment issues:\n", "\n", "- If a keystroke doen't do anything the first time, try a few times more (Phenopype \"listens\" to your keystroke while refreshing the presented image, and sometimes a refreshing operation overlaps with user input and it is not recognized).\n", "- If your keystore still isn't recognized, make sure the window is highlighted (i.e. click on it) and try again.\n", "- If you killed a process but the window still open (i.e. the kernel is not busy anymore), type \n", "`import cv2` and `cv2.destroyAllWindows()` into the console to close the window.\n", "- If a window and the Python kernel is frozen permanently, you need to restart it - sorry!\n", " \n", "
\n", "