Common Vision Blox 15.0
Loading...
Searching...
No Matches
ScriptLab

Introduction

The ScriptLab application is a small GUI that provides a ready to use interface to Python scripting. It mainly offers a display alongside some convenience functions to quickly test, prototype and visualize Python script results. Be aware that the python code may also be loaded through the API and used in custom applications. To use ScriptLab the same prerequisites apply as for Python Scripting.

Workflow

Start by creating a script in a folder that will become your working directory or workspace. This will create some files, the main Python interface file and some qml files for GUI adjustment in the chosen folder. In addition the ScriptLab will load the default version listed below.

import cvb
from typing import Tuple
from typing import List
from typing import Optional
class CvbVisionScript:
def __init__(self):
pass
def open_device(self) -> cvb.GenICamDevice:
discovery = cvb.DeviceFactory.discover_from_root(cvb.DiscoverFlags.IgnoreVins | cvb.DiscoverFlags.IncludeMockTL)
return cvb.DeviceFactory.open(discovery[0].access_token, cvb.AcquisitionStack.GenTL)
def open_stream(self, device : cvb.GenICamDevice) -> cvb.ImageStream:
stream = device.stream(cvb.ImageStream)
stream.register_managed_flow_set_pool(6)
return stream
def process(self, image : cvb.Image) -> Tuple[cvb.Image, List[Tuple[cvb.Point2D, str, Optional[cvb.RectLT]]]]:
return (image, [])
Union[cvb.GenICamDevice, cvb.VinDevice, cvb.EmuDevice, cvb.VideoDevice, cvb.NonStreamingDevice] open(str provider, int acquisition_stack=cvb.AcquisitionStack.PreferVin)
List[cvb.DiscoveryInformation] discover_from_root(int flags=cvb.DiscoverFlags.FindAll, int time_span=300)

During startup the CvbVisionScript class will be created, then open_device is called and is supposed to return a cvb.GenICamDevice. By default it will discover the CVMockTL and return the first device found on it. Then open_stream is called and the previously returned device is provided as argument. It is supposed to return a cvb.ImageStream. Use this method to configure your acquisition. The default implementation just returns the first stream after increasing the flow set pool to 6.

Once a script is loaded you can either acquire a single image or start a continuous stream. Either way process is called with the acquired cvb.Image. Here you can implement any image processing based on any library you can access from Python. The default implementation just returns the input image to be displayed. In addition you may return a tuple list. Each tuple contains a cvb.Point2D, a label string and an optional bounding cvb.RectLT. The returned tuples will be shown as overlays in the display.

Once you have modified the script you can trigger an application reload, to see the results. All errors including Python script errors are displayed in the console window opened alongside ScriptLab on Windows. Please run from the terminal on Linux, to see the output!

Advanced Usage

Load on Startup

By default ScriptLab starts without any script or workspace loaded. However, if a script is provided as command line argument it will be loaded on startup and the script folder will be used as workspace.

Adjust Appearance

In addition to change the functionality with a Python script also the appearance of the result overlays can be modified using the exported QML files.

Test Images from Disk

ScriptLab will always use the loaded workspace as working directory and therefore the CVMockTL.json will be used when loading a simulated camera.

Debug a Script

Debugging a script in ScriptLab works the same way as with Python Scripting. Be aware that continuous acquisition runs in a dedicated thread and therefore requires a manual debugger attachment.