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

The ScriptLab application is a lightweight graphical user interface (GUI) that provides a ready-to-use environment for Python scripting. ScriptLab already takes care of much of the basic workflow, such as basic device discovery and image acquisition, and displaying results.

Acquire Images Process Images Display Images and Results
   
   
   
Add Your Python Code...
   

Get started by just adding your Python code for image processing and returning either a modified image and/or additional results (e.g., positions of detected patterns). ScriptLab then automatically displays both the updated image and any results you provide.

Quick Start Guide

Working with ScriptLab is straightforward. Just follow these steps:

  1. Make sure the same prerequisites are fulfilled as for Python Scripting.
  2. Start ScriptLab from %CVB%Applications (Windows) or /opt/cvb/bin (Linux).
  3. Open an existing script or create a new default script.
    • When creating a default script, ScriptLab automatically sets up a working directory containing:
      • the main Python interface script
      • QML files for GUI customization
    • The default script already includes functionality for device discovery and image acquisition, so you can start right away.
  4. Modify the script as explained in the section Writing Your First Script.
  5. Connect your camera and start image acquisition.
    ⇒ Results are displayed immediately.

Writing Your First Script

After you have loaded your script or created a default script, you can start adding your own Python code. The default script initially looks as follows:

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]]]]:
# your code...
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!

Be aware that the Python code may also be loaded through the API and used in custom applications.

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. When adjusting the QML files you can receive status and error messages in the terminal when setting the environment variable QML_IMPORT_TRACE=1.

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.