applying an image (from Python API) to a Shape(Vrep)-applying texture from PY3 Api

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 4
Joined: 18 Nov 2018, 13:46

applying an image (from Python API) to a Shape(Vrep)-applying texture from PY3 Api

Post by Adel » 17 Apr 2019, 02:27

i am trying to put an image (so called texture) on a shape, not by Texture menu in Vrep but by feeding the image in Python remote API side.
I would be so thankful if someone could help me find a way.
my biggest problem is:
1) How and *through which type of array should i send the image from Python to Vrep? 1D-numpy-array?
  • with simxSetVisionSensorImage?
    or with vrep.simxPackFloats and simxSetStringSignal ?
2) How to receive the array in Vrep?
  • with sim.getVisionSensorCharImage?
    or with sim.unpackInt32Table and then simxReadStringStream?
3) How should i encode/convert the received array back to image (.png) in Vrep so that i can feed the image into sim.createTexture() and sim.setShapeTexture() in a child script?

So far this is what i could do:
1. defining a function in Python remote API that gets in an image (.png), converts it to 1D-numpy-array and then send this 1D-array to Vrep by using simxSetVisionSensorImage with following code in PY3 API side:

Code: Select all

        img ='/Users/Adel/Desktop/tenoraa.png)
        print('imgshape', img.shape)----> 64*64=4096
        pix=np.array(img, dtype=np.uint64).reshape((4096))
         _, self.visionHandel = vrep.simxGetObjectHandle(self.clientID, 'Vision_sensor1', vrep.simx_opmode_blocking)
        vrep.simxSetVisionSensorImage(self.clientID, self.visionHandel, pix, 1, vrep.simx_opmode_blocking)
and then the following code in a threaded child script attached to shape:

Code: Select all

local imgBuffer = sim.getVisionSensorCharImage(visionHandeBest0,0,0)
Thanks, Adel

Site Admin
Posts: 7157
Joined: 14 Dec 2012, 00:25

Re: applying an image (from Python API) to a Shape(Vrep)-applying texture from PY3 Api

Post by coppelia » 23 Apr 2019, 06:23


I would call simxCallScriptFunction. This allows you to send an RGB image to a script function. Then, in the script function, you can apply the image to a shape like:

Code: Select all

function applyTexture(inInts,inFloats,inStrings,inBuffer)
    local shapeHandle=inInts[1]
    local rgbImg=inBuffer
    local textureId=sim.getShapeTextureId(shapeHandle) -- there must already be a texture attached
	return {},{},{},''

Post Reply