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
Adel
Posts: 1
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

Hi,
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 = Image.open('/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

visionHandel=sim.getObjectHandle('Vision_sensor1')
sim.handleVisionSensor(visionHandel)
local imgBuffer = sim.getVisionSensorCharImage(visionHandeBest0,0,0)
Thanks, Adel

Post Reply