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.
Working with ScriptLab is straightforward. Just follow these steps:
%CVB%Applications
(Windows) or /opt/cvb/bin
(Linux). 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:
During startup the CvbVisionScript
class will be created.
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.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.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.
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.
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
.
ScriptLab will always use the loaded workspace as working directory and therefore the CVMockTL.json will be used when loading a simulated camera.
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.