Vision callback functions
Child scripts, or customization scripts can include a vision callback function (which is one of many system callback functions), when associated with a vision sensor. When present for a given vision sensor, then the system will call the callback function everytime a new image was acquired or applied, allowing the user to perform image processing. This is the case with following API functions: sim.handleVisionSensor, sim.checkVisionSensor, sim.checkVisionSensorEx, and sim.setVisionSensorImg.
Some conditions apply as to the location of the vision callback function: if a vision callback function is present in a child script as well as in a customization script, both attached to the vision sensor, then the child script will be called first, and the customization script second.
Following represents an empty vision callback function:
Image processing can be performed by using various API functions. The vision plugin exports a few very simple image processing functions. Many more image processing functions are supported via the image plugin (OpenCV wrapper).
Following represents a simple edge detection vision callback function, that triggers and returns a packet of data (based on the vision plugin functions):
Following represents a vision callback function, that draws a circle onto the acquired image (based on the image plugin functions):
In Python, a vision callback function can only be implemented via a non-threaded script, and it should be explicitly activated with a luaExec command: