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, sim.setVisionSensorImage, and sim.setVisionSensorCharImage.

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:

function sysCall_vision(inData)
    -- We have:
    -- inData.handle : the handle of the vision sensor.
    -- inData.resolution : the x/y resolution of the vision sensor
    -- inData.clippingPlanes : the near and far clipping planes of the vision sensor
    -- inData.viewAngle : the view angle of the vision sensor (if in persp. proj. mode)
    -- inData.orthoSize : the ortho size of the vision sensor (if in orth. proj. mode)
    -- inData.perspectiveOperation : true if the sensor is in persp. proj. mode

    local outData={}
    outData.trigger=false -- true if the sensor should trigger
    outData.packedPackets={} -- a table of packed packets. Can be accessed via e.g. sim.readVisionSensor
    return outData

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):

function sysCall_vision(inData)

    local outData={}
    local packetData={1.0,42.123,129.3}
    return outData

Following represents a vision callback function, that draws a circle onto the acquired image (based on the image plugin functions):

function sysCall_vision(inData)
    local imgHandle=simIM.readFromVisionSensor(inData.handle)
    local center={inData.resolution[1]/2,inData.resolution[2]/2}
    local radius=(inData.resolution[1]+inData.resolution[2])/8,center,radius,{255,0,255},4)