Parallel Usage of Multiple Cameras

This topic explains how to use two cameras independently by running commands in separate execution nodes.

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, even 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

Multi Threaded

// Processing pipeline for a single camera, parametrized by camera serial number
auto processingPipeline = [](std::string const& cameraSerial) {
	// Call the Open command to open the camera
	NxLibCommand open(cmdOpen);
	open.parameters()[itmCameras] = cameraSerial;
	open.execute();

	for (int imageIndex = 0; imageIndex < 10; imageIndex++) {
		// Execute the Capture and ComputeDisparityMap command only on our own camera
		NxLibCommand capture(cmdCapture);
		capture.parameters()[itmCameras] = cameraSerial;
		capture.execute();
		NxLibCommand computeDisparityMap(cmdComputeDisparityMap);
		computeDisparityMap.parameters()[itmCameras] = cameraSerial;
		computeDisparityMap.execute();
	}
};

// Launch two threads, each executing the pipeline on a different camera
std::thread first(processingPipeline, "1234");  // replace "1234" with your camera's serial number
std::thread second(processingPipeline, "2345"); // replace "2345" with your camera's serial number

first.join();
second.join();