Package: simple-pyspin
simple_pyspinA Pythonic class-based wrapper for the FLIR PySpin Library.More documentation can be found onGithub Pages, and the source can be found onGithub.Why?Why does this even exist, as the PySpin module already exists?  Because it's a pain to use, and difficult to wrap your head around basic operations.  For example, on some camera manually setting frame rate requires accessing methods by finding nodes, which is quite complicated.  This library makes it incredibly simple, and can also auto-document all the features of yourspecificcameras for easy reference.InstallationIf you don't already have them, I would recommend installing Numpy and the Python Imaging Library.  The easiest way to do this is to install a scientific Python distribution likeAnaconda.Install Spinnaker and PySpin from FLIR.You will likely need to follow several manual steps after the Spinnaker installation to get PySpin (Mac Instructions)Install simple_pyspin module:Install from PyPi:pip install simple-pyspin.Download source from GitHub and usesetup.py.UsageSee the examples directory of the source for these examples and more.Basic Usage# dead_simple.pyfromsimple_pyspinimportCamerawithCamera()ascam:# Acquire and initialize Cameracam.start()# Start recordingimgs=[cam.get_array()forninrange(10)]# Get 10 framescam.stop()# Stop recordingprint(imgs[0].shape,imgs[0].dtype)# Each image is a numpy array!Note that as long as you open the camera using awithclause, you don't need to worry about initialization or cleanup of the camera -- the module handles this for you!Equivalently, you can do this manually; the following code is functionally identical to the above:fromsimple_pyspinimportCameracam=Camera()# Acquire Cameracam.init()# Initialize cameracam.start()# Start recordingimgs=[cam.get_array()forninrange(10)]# Get 10 framescam.stop()# Stop recordingcam.close()# You should explicitly clean upprint(imgs[0].shape,imgs[0].dtype)# Each image is a numpy array!Changing Camera SettingsHere is a more complicated example, which manual changes a number of settings, and saves a number of images using PIL.# manual_setup.pyfromsimple_pyspinimportCamerafromPILimportImageimportoswithCamera()ascam:# Initialize Camera# Set the area of interest (AOI) to the middle halfcam.Width=cam.SensorWidth//2cam.Height=cam.SensorHeight//2cam.OffsetX=cam.SensorWidth//4cam.OffsetY=cam.SensorHeight//4# If this is a color camera, get the image in RGB format.if'Bayer'incam.PixelFormat:cam.PixelFormat="RGB8"# To change the frame rate, we need to enable manual controlcam.AcquisitionFrameRateAuto='Off'cam.AcquisitionFrameRateEnabled=Truecam.AcquisitionFrameRate=20# To control the exposure settings, we need to turn off autocam.GainAuto='Off'# Set the gain to 20 dB or the maximum of the camera.gain=min(20,cam.get_info('Gain')['max'])print("Setting gain to%.1fdB"%gain)cam.Gain=gaincam.ExposureAuto='Off'cam.ExposureTime=10000# microseconds# If we want an easily viewable image, turn on gamma correction.# NOTE: for scientific image processing, you probably want to#    _disable_ gamma correction!try:cam.GammaEnabled=Truecam.Gamma=2.2except:print("Failed to change Gamma correction (not avaiable on some cameras).")cam.start()# Start recordingimgs=[cam.get_array()forninrange(10)]# Get 10 framescam.stop()# Stop recording# Make a directory to save some imagesoutput_dir='test_images'ifnotos.path.exists(output_dir):os.makedirs(output_dir)print("Saving images to:%s"%output_dir)# Save them# NOTE: images may be very dark or bright, depending on the camera lens and#   room conditions!forn,imginenumerate(imgs):Image.fromarray(img).save(os.path.join(output_dir,'%08d.png'%n))LicenseCopyright 2019 Dustin KlecknerLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.