Getting Image via Python Remote API

Typically: "How do I... ", "How can I... " questions
Post Reply
mash2612
Posts: 6
Joined: 28 Jan 2018, 10:21

Getting Image via Python Remote API

Post by mash2612 » 14 Feb 2018, 09:21

Hello,
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('127.0.0.1',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)
    print(type(image))
    image_byte_array = array.array('b', image)
    im = Image.frombuffer("RGB", (256, 144), image_byte_array, "raw", "RGB", 0, 1)
    im.show()
else:
    print('Error')
I get the following error:' TypeError: argument 1 must be read-only bytes-like object, not array.array'

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

Re: Getting Image via Python Remote API

Post by coppelia » 15 Feb 2018, 09:10

Hello,

have a look here.

Cheers

mash2612
Posts: 6
Joined: 28 Jan 2018, 10:21

Re: Getting Image via Python Remote API

Post by mash2612 » 15 Feb 2018, 10:11

Thanks Coppelia,
I will try this out!

Post Reply