You are here: Start » PyAVL » Python Examples

Python Examples

The Python examples show how to use PyAVL for typical tasks: loading and processing images, working with regions, reading barcodes and data codes, measuring shapes, handling errors and acquiring images from a GigE Vision camera. Every example is a single script that can be started with the Python interpreter.

ScriptTopic
load_image.pyLoading an image and reading its properties
basic_image_operations.pyBasic image operations
basic_region_operations.pyBasic region operations
region.pyRegions
rotate_image.pyRotating an image
shape_fitting.pyShape fitting
mounts_blob_analysis.pyBlob analysis
blister_inspection.pyBlister inspection
barcodes.py, barcodes_IK.pyReading barcodes
datamatrix.pyReading Data Matrix codes
error_handling.pyHandling errors
gigevision_simple_streaming.pyAcquiring images from a GigE Vision camera

The scripts load their images from the _media folder using relative paths (for example ../_media/face.png). Start every script from the folder that contains it, and keep the _media folder next to that folder.

Examples on Windows

The installer copies the examples to the following folder:

C:\Users\Public\Documents\Aurora Vision Library 5.7\Examples\08 Python

The images used by the examples are installed in the Examples\_media folder next to it. To run an example, open a command prompt in the folder of the examples and start the script:

cd "C:\Users\Public\Documents\Aurora Vision Library 5.7\Examples\08 Python"
python load_image.py

PyAVL has to be installed before (see Installation). No other packages are needed. The examples show images and shapes with AVL.DebugPreview, which is available on Windows only.

Examples on Linux

On Linux the examples are part of the library archive (.tar.xz). The unpacked directory contains the following folders:

  • examples/05 Python —the scripts
  • examples/_media —the images

The install script does not copy the examples to the installation directory (/opt/AuroraVision/AVL-5.7.<Build>). Run them from the unpacked directory, or copy the 05 Python and _media folders together to another location and keep them side by side.

The Linux scripts need the following in addition to PyAVL:

  • Tkinter, provided by the system package python3-tk (for example sudo apt install python3-tk). It is not installed with pip.
  • Pillow and NumPy: pip install Pillow numpy

AVL.DebugPreview is not available on Linux. The Linux scripts use the helper module avl_display_tk.py, which is located in the same folder and is imported by the scripts. It displays images and regions in Tkinter windows:

  • show(title, image) displays one image or region and waits until the window is closed.
  • show_multi(images, titles) displays several images in one window.
  • LiveWindow is a window that is updated repeatedly with set_image, as in a processing loop.
  • LiveWindowThreaded does the same for calls that can block for a long time, such as receiving an image from a camera.

The module can be reused in other programs. It also contains conversion functions from AVL.Image to NumPy arrays and to Pillow images, see Interoperability with Other Libraries.

To run an example, start it from the folder of the scripts:

cd "05 Python"
python3 load_image.py

Deep Learning Examples

The examples of PyAVL-DL show how to deploy a trained model and run it on test images. Each example is a folder that contains the script main.py, the trained model in the model folder and the test images in the images folder. The folder also contains the C++ version of the same example. The paths in the scripts are relative, so a script has to be started from the folder of its example.

Example folderFunction
Classify_Object_Nut_ClassificationDL_ClassifyObject
Detect_Anomalies_Egg_Inspection, Detect_Anomalies_Injection_Moulding_Inspection, Detect_Anomalies_PCB_Inspection, Detect_Anomalies_Rope_InspectionDL_DetectAnomalies2
Detect_Features_Tea_Inspection, Detect_Features_Thread_InspectionDL_DetectFeatures
Locate_Objects_Candy_Detection, Locate_Objects_Fish_DetectionDL_LocateObjects
Locate_Points_Bee_DetectionDL_LocatePoints
Locate_Text_Locating_Text_of_Varing_SizesDL_LocateText
Read_Characters_Cosmetic_Composition_Reading, Read_Characters_Serial_Number_Recognition, Read_Characters_Various_Fonts_ReadingDL_ReadCharacters

Every example follows the workflow described in Deep Learning (PyAVL-DL): it deploys the model, processes the images in a loop and unloads the model.

Deep Learning Examples on Windows

The examples are installed with a separate installer, avdeeplearning_examples_<version>.exe. The scripts show the results with AVL.DebugPreview, which is available on Windows only. Start a script from the folder of its example:

cd <examples folder>\Classify_Object_Nut_Classification
python main.py

Deep Learning Examples on Linux

The Linux archive of Aurora Deep Learning contains the examples in its examples folder, one folder for every example. As in the case of the PyAVL examples, the install script does not copy them to the installation directory (/opt/AuroraVision/AVLDL-5.7.<Build>), so they are run from the unpacked directory.

The scripts display the results with the helper module avl_display_tk.py, which is copied to every example folder, and need the same additional packages as the Linux examples of PyAVL: Tkinter (python3-tk), Pillow and NumPy.

cd examples/Classify_Object_Nut_Classification
python3 main.py

PyAVL-DL requires PyAVL, so both packages have to be installed (see Installation).

See Also

Previous: Relation between PyAVL and AVL/C++ Next: Deep Learning (PyAVL-DL)