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();
Open frame grabbers with the parallel_execution flag. All NxLib commands (as well as grab_data operations) will then automatically be executed in a different command slot than the commands for other handles.
Procedure 1 (opens and uses camera “1234”)
open_framegrabber ('Ensenso-NxLib', 0, 0, 0, 0, 0, 0, 'default', 0, 'Raw', 'parallel_execution=1', 'false', 'Stereo', '1234', 0, 0, CameraHandle1)
set_framegrabber_param (CameraHandle1, 'grab_data_items', 'Images/PointMap')
grab_data (Image, Region, Contours, CameraHandle1, Data)
Procedure 2 (opens and uses camera “2345”)
open_framegrabber ('Ensenso-NxLib', 0, 0, 0, 0, 0, 0, 'default', 0, 'Raw', 'parallel_execution=1', 'false', 'Stereo', '2345', 0, 0, CameraHandle2)
set_framegrabber_param (CameraHandle2, 'grab_data_items', 'Images/PointMap')
grab_data (Image, Region, Contours, CameraHandle2, Data)