Page 1 of 1

Add Vision Sensor Filter via Code

Posted: 16 Jul 2019, 07:38
by PvtSchneewitchen
As you can see in the Topic Discription, I would like to know if it's possible to add Filters (e.g. Extract coordinates from work image) to Vision Sensors via script. I neither found any functions for that in the API-Descriptions nor any topic about that in the Forum. I hope someone knows if that is possible or even how it's done.

Re: Add Vision Sensor Filter via Code

Posted: 18 Jul 2019, 15:20
by coppelia
You can use sim.setVisionSensorFilter for that. I wouldn't make too complex things with it, maybe simply enabling/disabling a filter component.
If you need more complex operations on vision sensor images, then use the image (or OpenCV) plugin, e.g.:

Code: Select all

function sysCall_init()
    visionSensor=sim.getObjectAssociatedWithScript(sim.handle_self)
end

function sysCall_sensing()
    local imgHandle=simIM.readFromVisionSensor(visionSensor,-1)
    simIM.rgb2gray(imgHandle,true)
    simIM.gray2rgb(imgHandle,true)
    simIM.writeToVisionSensor(imgHandle,visionSensor)
    simIM.destroy(imgHandle)
--[[ or by doing simple image buffer manipulations:
    local img=sim.getVisionSensorCharImage(visionSensor)
    img=sim.transformBuffer(img,sim.buffer_uint8rgb,1,0,sim.buffer_uint8)
    img=sim.transformBuffer(img,sim.buffer_uint8,1,0,sim.buffer_uint8rgb)
    sim.setVisionSensorImage(visionSensor,img)
--]]
end
Cheers