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, 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¶
Multi Threaded¶
Note
The code of the two threads only differs in the first two lines which specify a different execution node “thread1” or “thread2” and different camera serial number “1234” or “2345” to operate on.
Thread 1 (opens and uses camera “1234”):
std::string executionSlot =
"thread1"; // Use a separate execution slot name for all commands carried out by this thread
std::string cameraSerial = "1234"; // replace "1234" with your camera's serial number
// Call the Open command to open the cameras
NxLibCommand open(cmdOpen, executionSlot); // Make sure to execute all commands in the execution slot for this
// thread, so they don't collide with thread 2
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, executionSlot);
capture.parameters()[itmCameras] = cameraSerial;
capture.execute();
NxLibCommand computeDisparityMap(cmdComputeDisparityMap, executionSlot);
computeDisparityMap.parameters()[itmCameras] = cameraSerial;
computeDisparityMap.execute();
}
Thread 2 (opens and uses camera “2345”):
std::string executionSlot =
"thread2"; // Use a separate execution slot name for all commands carried out by this thread
std::string cameraSerial = "2345"; // replace "2345" with your camera's serial number
// Call the Open command to open the cameras
NxLibCommand open(cmdOpen, executionSlot); // Make sure to execute all commands in the execution slot for this
// thread, so they don't collide with thread 1
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, executionSlot);
capture.parameters()[itmCameras] = cameraSerial;
capture.execute();
NxLibCommand computeDisparityMap(cmdComputeDisparityMap, executionSlot);
computeDisparityMap.parameters()[itmCameras] = cameraSerial;
computeDisparityMap.execute();
}
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)