## How are images from sim.getVisionSensorImage() formatted?

Typically: "How do I... ", "How can I... " questions
tim_wiesner
Posts: 1
Joined: 01 Apr 2021, 13:55

### How are images from sim.getVisionSensorImage() formatted?

I'm using a vision sensor that I'm reading from python through the legacy API. The sensor has a resolution of 32x32 (RGB). Hence, I get 3072 individual numbers. In python, I want to reformat this one long array into something more useful, ideally a numpy array of size 32x32x3 and in a way that the first element of the outer array corresponds to the first row of pixels, and the first element from that array corresponds to RGB values of the left-most pixel. I'm currently using this code

Code: Select all

np.array(cam_image).reshape((res[0], res[1], 3))
in python, with cam_image being the 3072 elements-long array I get from Coppelia and res the x and y resolution (so both 32 in my case). However, I can't find anything that states if that's the correct way of reformatting it.

fferri
Posts: 722
Joined: 09 Sep 2013, 19:28

### Re: How are images from sim.getVisionSensorImage() formatted?

Yes reshape is used to change the shape of a matrix (without changing the order of elements).