Parallel Capturing and Processing

This topic explains how to run image acquisition and 3d data computation independently when using a single camera.

Please read the topics Opening a Camera and Grabbing 3D Data first.

Note

Rendering commands like RenderPointMap and RenderView use a single OpenGL context and therefore will be internally serialized and run sequentially, also when executed from separate Execute nodes. As these commands also have a single, global output node it is recommended to run at most one instance of each at a time.

Code Examples

Single Threaded

// Call the Open command to open the camera
NxLibCommand open(cmdOpen);
open.parameters()[itmCameras] = "1234";
open.execute();

// Create persistent command objects, each with its own separate execution slot under /Execute. Each of these nodes
// has its own Command, Parameters and Result subnodes and can be used to execute any command independently from
// commands in any other execution slot.
NxLibCommand capture(cmdCapture);
NxLibCommand computeDisparityMap(cmdComputeDisparityMap);

// Note: parameters will usually be cleared after command execution. Using this function, the parameters can be
// reused for the next execution in this slot
capture.rememberParameters();

// Set a capture timeout of 200ms
capture.parameters()[itmTimeout] = 200;

int numImagesCaptured = 0;
int numDisparityMapsComputed = 0;

// start the first capture command before entering the loop
capture.executeAsync();
// run loop until 50 images have been captured
while (numImagesCaptured < 50) {
	// wait for the capture command
	capture.wait();
	numImagesCaptured++;

	// start the disparity map computation
	computeDisparityMap.executeAsync();

	// start the next capture operation
	capture.executeAsync();

	// wait for the disparity map computation
	computeDisparityMap.wait();
	numDisparityMapsComputed++;
}
printf("Captured %d images and computed %d disparity maps.\n", numImagesCaptured, numDisparityMapsComputed);

Multi Threaded

Note

The two command objects capture and computeDisparityMap in Thread 1 and Thread 2 create two separate execution nodes. Each of these nodes has its own Command, Parameters and Result subnodes and can be used to execute any command independently from commands in any other execution node.

Preparation (e.g. in main thread):

// Call the Open command to open the camera
NxLibCommand open(cmdOpen);
open.parameters()[itmCameras] = "1234";
open.execute();

// capture one image synchronously so that the computation thread has an initial image to process
NxLibCommand(cmdCapture).execute();

// ... start thread 1 and thread 2 now

Thread 1 (capturing):

// Create command object working in a separate execution slot "capture" under /Execute
NxLibCommand capture(cmdCapture);

// Note: parameters will usually be cleared after command execution. Using this function, the parameters can be
// reused for the next execution in this slot
capture.rememberParameters();

// Set a capture timeout of 200ms
capture.parameters()[itmTimeout] = 200;

int numImagesCaptured = 0;

while (numImagesCaptured < 50) { // run loop until 50 images have been captured
	capture.execute();
	numImagesCaptured++;
}

Thread 2 (disparity map computation):

// Create command object working in a separate execution slot "compute" under /Execute
NxLibCommand compute(cmdComputeDisparityMap);

int numDisparityMapsComputed = 0;

while (numDisparityMapsComputed < 50) { // run loop until 50 images have been processed
	compute.execute();
	numDisparityMapsComputed++;
}