Hiding Certain Objects from Vision Sensor

Typically: "How do I... ", "How can I... " questions
Post Reply
ashrafaiman6
Posts: 5
Joined: 30 May 2022, 09:21

Hiding Certain Objects from Vision Sensor

Post by ashrafaiman6 »

Hello;

I wanted to hide certain objects or robots from the vision sensor. I enabled the explicit handling for the vision sensor and also made a collection for the objects that are wanted to be visible. The Lua Code I used is as follows:

Code: Select all

function sysCall_init()
    -- do some initialization here

-- Collection defined as: <object1> + <object2> + <object3> + <object4>

local object1=sim.getObject('/Floor')
local object2=sim.getObject('/20cmHighWall100cm')
local object3=sim.getObject('/20cmHighWall100cm0')
local object4=sim.getObject('/20cmHighWall100cm1')
collectionHandle=sim.createCollection(0)
sim.addItemToCollection(collectionHandle,sim.handle_single,object1,0)
sim.addItemToCollection(collectionHandle,sim.handle_single,object2,0)
sim.addItemToCollection(collectionHandle,sim.handle_single,object3,0)
sim.addItemToCollection(collectionHandle,sim.handle_single,object4,0)

visionSensorHandle=sim.getObjectHandle(sim.handle_self)
end


function sysCall_sensing()
    -- put your sensing code here
    sim.checkVisionSensor(visionSensorHandle, collectionHandle)
end

Hope to get some answers soon. Thank you

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

Re: Hiding Certain Objects from Vision Sensor

Post by coppelia »

Hello,

you need to create your collection with options set to 1, and add a vision callback function, e.g. something like:

Code: Select all

function sysCall_init()
    h=sim.getObject('.')
    c=sim.createCollection(1)
    local o1=sim.getObject('/Cuboid')
    local o2=sim.getObject('/Sphere')
    sim.addItemToCollection(c,sim.handle_single,o1,0)
    sim.addItemToCollection(c,sim.handle_single,o2,0)
end

function sysCall_sensing()
    sim.checkVisionSensor(h,c)
end

function sysCall_vision(inData)
    simVision.sensorImgToWorkImg(inData.handle)
    simVision.workImgToSensorImg(inData.handle)
end
Cheers

ashrafaiman6
Posts: 5
Joined: 30 May 2022, 09:21

Re: Hiding Certain Objects from Vision Sensor

Post by ashrafaiman6 »

Hello;

Thanks for the reply, now only the desired objects are visible by the vision sensor as desired. However, they only show the handle of the object (highlight of the object?) and if I wanted to get a real view of the scene, I would have to use resolution?
But I keep getting errors saying:
[string "/Top_View_Camera@childScript"]:43: attempt to call a table value (field 'resolution')
stack traceback:
[string "/Top_View_Camera@childScript"]:43: in function 'sysCall_vision'
This I how I called for the resolution:

Code: Select all

function sysCall_vision(inData)
    simVision.sensorImgToWorkImg(inData.resolution(512))
    simVision.workImgToSensorImg(inData.resolution(512))
end
Also on another note, I connected CoppeliaSim to Matlab for a project and when explicit handling is enabled for the vision sensor, the view I get in Matlab is a black screen. How do I fix this so that only the desired objects are visible in Matlab as well?
Thanks for the help.

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

Re: Hiding Certain Objects from Vision Sensor

Post by coppelia »

I have no idea what you are trying to achieve with the resolution in the vision callback function. You have only one option, and that is to use the handle of the vision sensor, as shown in my code example.

If your vision callback function runs with the same code as in my example, then you should also be able to read a vision sensor image from an external application, even when the sensor is explicitly handled.

Cheers

ashrafaiman6
Posts: 5
Joined: 30 May 2022, 09:21

Re: Hiding Certain Objects from Vision Sensor

Post by ashrafaiman6 »

What I wanted to achieve with the resolution is that when for example, I wanted to view an indoorPlant placed on the scene in CoppeliaSim, the vision sensor only displays a cylinder in its place. That is why I tried for the other vision callback function such as resolution, clipplingPlanes and viewAngle but they all come up with an error. That is my enquiry, to get a live view o the objects instead of just the handles.

For the reading of vision sensor image from external application, I followed your example exactly but with the addition of extra local objects only. The sensor is explicitly handled as well. Hope that clarifies some things. Thanks

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

Re: Hiding Certain Objects from Vision Sensor

Post by coppelia »

...to get a live view o the objects instead of just the handles.
Do you mean object vs model? If you need all the objects that are part of a specific hierarchy tree, use sim.getObjectsInTree. Additionally, you'll have to remove invisible objects. You can check visibility with sim.getObjectInt32Param(objectHandle,sim.objintparam_visible)

Cheers

Post Reply