In the previous article, I set up a stereo vision rig. Now, its time to take pictures with it. The most important thing to do is to set things up so that the synchronized capture works correctly.
The cameras I used are Blackfly S cameras which use the Spinnaker API. I’ve opted to use the python version of the API because python is great for tinkering. The first thing to do is to go onto Flir‘s website, search for Spinnaker, and then download and install the SDK and Spinnaker for python. I’ve opted to use Ubuntu 16.04 with Spinnaker version 184.108.40.206.
After you install the SDK and python extension, take a look at the documentation for synchronized capture. If you scroll down to configuring Blackfly S cameras, you must:
- For the primary camera: 1) enable the 3.3V output for line 2
- For the secondary camera: 1) set the trigger source to line 3, 2) set the trigger overlap to “read out”, and 3) then set trigger mode to “on”.
Lets go ahead and start coding this up. The first step is to find the cameras and initialize them:
import PySpin # Get system system = PySpin.System.GetInstance() # Get camera list cam_list = system.GetCameras() # Figure out which is primary and secondary if cam_list.GetByIndex(0).TLDevice.DeviceSerialNumber() == '16276941': cam_primary = cam_list.GetByIndex(0) cam_secondary = cam_list.GetByIndex(1) else: cam_primary = cam_list.GetByIndex(1) cam_secondary = cam_list.GetByIndex(0) # Initialize cameras cam_primary.Init() cam_secondary.Init()
In my case, the primary camera has a serial of “16276941”. Next, we follow the documentation and set up the hardware trigger:
# Set up primary camera trigger cam_primary.LineSelector.SetValue(PySpin.LineSelector_Line2) cam_primary.V3_3Enable.SetValue(True) # Set up secondary camera trigger cam_secondary.TriggerMode.SetValue(PySpin.TriggerMode_Off) cam_secondary.TriggerSource.SetValue(PySpin.TriggerSource_Line3) cam_secondary.TriggerOverlap.SetValue(PySpin.TriggerOverlap_ReadOut) cam_secondary.TriggerMode.SetValue(PySpin.TriggerMode_On)
The final step is to acquire the stereo images:
# Set acquisition mode cam_primary.AcquisitionMode.SetValue(PySpin.AcquisitionMode_SingleFrame) cam_secondary.AcquisitionMode.SetValue(PySpin.AcquisitionMode_SingleFrame) # Start acquisition; note that secondary camera has to be started first so # acquisition of primary camera triggers secondary camera. cam_secondary.BeginAcquisition() cam_primary.BeginAcquisition() # Acquire images image_primary = cam_primary.GetNextImage() image_secondary = cam_secondary.GetNextImage() # Save images image_primary.Save('primary.png') image_secondary.Save('secondary.png')
If the hardware trigger is set up properly, there should be two images in the current working directory:
secondary.png. A link to the full script (with added cleanup at the end) is here.
I’ve taken the liberty of writing a simple library/gui for acquiring stereo images with the python Spinnaker API (PySpin) and matplotlib:
If you’re interested in using it, please follow the installation instructions on the github page.
The gui allows for gain and exposure to be adjusted and image pairs to be acquired easily:
An example image pair:
We now have our stereo camera rig and an app for acquiring synchronized capture of images. The next step is to perform camera calibration, which is discussed in the next article.