Capturing Images with Hardware Trigger

When working with hardware trigger you need to make sure that the camera is continuously armed and waiting for a new trigger signal in order to not miss any trigger edges. The pseudo code opens a camera, enables hardware trigger and captures and processes a fixed number of images.

Code Examples

Using the Trigger and Retrieve commands and a polling wait loop

NxLibItem root; // References the tree's root item at path "/"

// replace "1234" with your camera's serial number:
NxLibItem camera =
    root[itmCameras][itmBySerialNo]["1234"]; // References the camera's item at path "/Cameras/BySerialNo/1234"

// Call the Open command to open the camera
NxLibCommand open(cmdOpen); // Note: the variable name 'open' does not matter; the constant 'cmdOpen'
// specifies the name of the command to be executed when '.execute()' is called
// on the object.
// Set parameters for the command
open.parameters()[itmCameras] =
    "1234"; // Insert the serial number of the camera to be opened into the Cameras parameter of Open
open.execute();

// Set the camera to trigger on a falling edge on the GPIO port
camera[itmParameters][itmCapture][itmTriggerMode] = valFallingEdge; // the default for TriggerMode is "Software"

for (int imageIndex = 0; imageIndex < 10; imageIndex++) {
    // :ref:`Trigger <cmdtrigger>` cameras that are not yet armed and waiting for a hardware trigger (e.g. when
    // taking the first image)
    NxLibCommand(cmdTrigger).execute(); // with default settings this will trigger untriggered cameras only

    // Call Retrieve in a loop to poll for newly arrived images; you could also use the
    // Timeout parameter here if you don't want to poll
    NxLibCommand retrieve(cmdRetrieve);
    while (true) {
        retrieve.parameters()[itmTimeout] = 0;
        retrieve.execute();
        if (retrieve.result()["1234"][itmRetrieved].asBool()) {
            // a new image has been received and copied into the raw image node
            break;
        }
    }

    // Trigger the camera again, so that it is immediately armed for the next trigger again
    NxLibCommand(cmdTrigger).execute();

    // Compute the disparity map, point map, and process the data according to your needs
}

Using the Capture command and a fixed wait timeout

When using the Capture command the entire trigger, wait and re-arm sequence can be accomplished with a single command:

for (int imageIndex = 0; imageIndex < 10; imageIndex++) {
	NxLibCommand capture(cmdCapture);
	capture.parameters()[itmInitialTrigger] =
	    valUntriggered; // Trigger any camera that is not armed yet at the beginning of the command execution
	capture.parameters()[itmWaitFor] = valTriggered; // Wait for all triggered cameras
	capture.parameters()[itmTimeout] = 10000;        // wait up to 10 seconds
	capture.parameters()[itmFinalTrigger] =
	    valAll; // After the wait period trigger all cameras again to arm them for the next hardware trigger signal
	capture.execute(); // Execute the command with the previously specified parameters

	// Compute the disparity map, point map, and process the data according to your needs.
	// ...
}

Note

See Grabbing 3D Data for an example on how to process data according to your needs.

Using the Capture command with a polling loop

You can also use the Capture command to trigger the camera and retrieve images by polling:

int imageIndex = 0;
while (imageIndex < 10) {
	NxLibCommand capture(cmdCapture);
	capture.parameters()[itmInitialTrigger] =
	    valNone; // Skip trigger phase 1 at the beginning of the command (see :ref:`Capture <cmdcapture>` for a
	             // description of the execution phases)
	capture.parameters()[itmWaitFor] =
	    valNone; // Don't wait for any cameras; the command will still retrieve images in phase 2 if they are ready
	capture.parameters()[itmFinalTrigger] =
	    valUntriggered; // Re-arm all idle cameras again for the next hardware trigger signal
	capture.execute();  // Execute the command with the previously specified parameters

	// Check if an image has been retrieved; you need to know the camera serial number ("1234") to query the flags for
	// the camera of interest.
	if (capture.result()["1234"][itmRetrieved].asBool()) {
		// Compute the disparity map, point map, and process the data according to your needs
		// ...
		imageIndex++;
	}
}

Note

  • See Capture for a description of the execution phases.

  • See Grabbing 3D Data for an example on how to process data according to your needs.