I am using a blob detection for detecting objects and I would like to mark the centre of the object with a cross by drawing 2 short lines in the image of the vision sensor. The follwing code runs, but the cross is not drawn. Any help?
function sysCall_init()
sensor=sim.getObjectAssociatedWithScript(sim.handle_self)
imgHandle=simIM.readFromVisionSensor(sensor)
center={64,64}
end
function sysCall_actuation()
res, pack1, pack2 = sim.readVisionSensor(sensor)
center={64,64}
simIM.line(imgHandle, {center[1]-40, center[2]}, {center[1]+40, center[2]}, {100,100,100})
simIM.line(imgHandle, {center[1], center[2]-40}, {center[1], center[2]+40}, {100,100,100})
simIM.writeToVisionSensor(imgHandle,sensor)
.....
Drawing a line into a vision sensor image
Re: Drawing a line into a vision sensor image
Following code works. The vision sensor is in "explicit handling" mode.
Code: Select all
function sysCall_init()
sensor=sim.getObjectAssociatedWithScript(sim.handle_self)
center={x=64,y=64}; color={100,100,100}
end
function sysCall_actuation()
sim.handleVisionSensor(sensor)
imgHandle=simIM.readFromVisionSensor(sensor)
simIM.line(imgHandle, {center.x-40, center.y}, {center.x+40, center.y}, color)
simIM.line(imgHandle, {center.x, center.y-40}, {center.x, center.y+40}, color)
simIM.writeToVisionSensor(imgHandle, sensor)
simIM.destroy(imgHandle)
end
Re: Drawing a line into a vision sensor image
Or the same via the vision callback function (the below script should be attached to the vision sensor):
Cheers
Code: Select all
function sysCall_init()
color={100,100,100}
end
function sysCall_vision(inData)
if simIM then
local imgHandle=simIM.readFromVisionSensor(inData.handle)
local center={x=inData.resolution[1]/2,y=inData.resolution[2]/2}
simIM.line(imgHandle, {center.x-40, center.y}, {center.x+40, center.y}, color)
simIM.line(imgHandle, {center.x, center.y-40}, {center.x, center.y+40}, color)
simIM.writeToVisionSensor(imgHandle, inData.handle)
simIM.destroy(imgHandle)
end
outData={}
outData.trigger=false -- whether the sensor should trigger
outData.packedPackets={}
return outData
end