Let's create a file called PySpinCapture.py. Not surprisingly, we will begin its implementation with the following import statements:
import PySpin
import cv2
As a practical introduction to PySpin, let's add the following function, which returns the number of PySpin-compatible cameras currently connected to the system:
def getNumCameras():
system = PySpin.System.GetInstance()
numCameras = len(system.GetCameras())
system.ReleaseInstance()
return numCameras
Here, we see that our standalone getNumCameras function (like any self-contained module of code that uses PySpin) is responsible for acquiring and releasing a reference to the PySpin system. We also see that the PySpin system is a gateway, providing access to any connected PySpin-compatible cameras.
Our primary goal in this file is to implement a class...