Page 1 of 1

Getting Image via Python Remote API

Posted: 14 Feb 2018, 09:21
by mash2612
I am trying to learn V-rep and its integration with Python remote API. I created a dummy model and added a vision sensor to it. I am running V-rep on continuous remote server mode by editing 'remoteconnections.txt' file.
I have not selected 'explicit Handling' in Vision Sensor Object Scene Properties(as per my understanding from documentation)
I wrote the following code to get the image file and I get following error.Is there any way to work around this? Any help would be much appreciated.

Code: Select all

from PIL import Image
import array
import vrep
vrep.simxFinish(-1) # just in case, close all opened connections

clientID=vrep.simxStart('',19999,True,True,5000,5) # Connect to V-REP
if clientID!=-1:
    x = vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot)
    res, v0 = vrep.simxGetObjectHandle(clientID, 'Vision_sensor', vrep.simx_opmode_oneshot_wait)

    res, resolution, image = vrep.simxGetVisionSensorImage(clientID, v0, 0, vrep.simx_opmode_streaming)
    image_byte_array = array.array('b', image)
    im = Image.frombuffer("RGB", (256, 144), image_byte_array, "raw", "RGB", 0, 1)
I get the following error:' TypeError: argument 1 must be read-only bytes-like object, not array.array'

Re: Getting Image via Python Remote API

Posted: 15 Feb 2018, 09:10
by coppelia

have a look here.


Re: Getting Image via Python Remote API

Posted: 15 Feb 2018, 10:11
by mash2612
Thanks Coppelia,
I will try this out!