Add Vision Sensor Filter via Code

Typically: "How do I... ", "How can I... " questions
Post Reply
PvtSchneewitchen
Posts: 1
Joined: 12 Jul 2019, 09:37

Add Vision Sensor Filter via Code

Post by PvtSchneewitchen » 16 Jul 2019, 07:38

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.

coppelia
Site Admin
Posts: 7267
Joined: 14 Dec 2012, 00:25

Re: Add Vision Sensor Filter via Code

Post by coppelia » 18 Jul 2019, 15:20

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

Post Reply