Remote API: Depth Sensor Reading

Typically: "How do I... ", "How can I... " questions
Post Reply
jalone

Remote API: Depth Sensor Reading

Post by jalone » 18 Jun 2013, 12:31

I have some troubles reading the data of an emulated kinect from an external c++ script.

I need to get the depth image acquired from the kinect in the VREP simulation (the one taken from base library in Components > Sensors > Library > Kinect) from an external script, at current moment i achieved to get the handles of both depth and vision sensors, but i don't know neither which function to call nor the data structure to store it.

Code: Select all

int clientID = simxStart("x.x.x.x", port, true, true, 2000, 5);

if(clientID != -1){
        //get depth sensor handler
        int depthHandle = 0;
        simxGetObjectHandle(clientID, "kinect_visionSensor", &depthHandle, simx_opmode_oneshot_wait);
}
i'd say it must be something corresponding to simReadVisionSensorDepthBuffer() but i dont really know which data structure to bind it to.

Do you have any example available?
Thank you.

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

Re: Remote API: Depth Sensor Reading

Post by coppelia » 18 Jun 2013, 12:46

Hello,

Try with this:

Code: Select all

int clientID = simxStart("x.x.x.x", port, true, true, 2000, 5);

if(clientID != -1){
	//get depth sensor handler
	int depthHandle = 0;
	simxGetObjectHandle(clientID, "kinect_visionSensor", &depthHandle, simx_opmode_oneshot_wait);
	int res[2];
	float* data;
	simxGetVisionSensorDepthBuffer(clientID,depthHandle,res,&data,simx_opmode_streaming); // enable streaming
	while (simxGetConnectionId(clientID)!=-1){
		if (simxGetVisionSensorDepthBuffer(clientID,depthHandle,res,&data,simx_opmode_buffer)==simx_error_noerror){
			// here you can read the data. The data buffer remains valid until you call another remote API function
			for (int i=0;i<res[1];i++){ // go through the rows (y)
				for (int j=0;j<res[0];j++){ // go through the columns (x)
					float depthValueOfPixel=data[i*res[0]+j]; // this is location j/i, i.e. x/y
				}			
			}			
		}
	}		
}
Cheers

jalone

Re: Remote API: Depth Sensor Reading

Post by jalone » 18 Jun 2013, 15:35

Thank you very much, i didn't expect the double call to simxGetVisionSensorDepthBuffer(...).

Looks like it is going to work, but res[2] has these weird values:

Res[0]: 32767
Res[1]: 1606423447

the second seems to be just a timestamp, not the resolution...
Very kind.

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

Re: Remote API: Depth Sensor Reading

Post by coppelia » 18 Jun 2013, 16:22

When you call a remote API function, always check for the error code.
In your case, the first time you call simxGetVisionSensorDepthBuffer, the returned resolution and buffer are not valid! The first call to simxGetVisionSensorDepthBuffer is only telling the server (V-REP) to start sending buffer data. It will take some time until the first buffer message has arrived. You can read valid data in the second call to simxGetVisionSensorData, when the return value is simx_error_noerror.

Make sure you understand how the remote API is working.

Cheers

jalone

Re: Remote API: Depth Sensor Reading

Post by jalone » 18 Jun 2013, 19:14

Thank you!

Post Reply