Skip to main content

An easy-to-use Pythonic wrapper for the FLIR PySpin Library. Developed by the Kleckner Lab at UC Merced.

Project description

simple_pyspin

A Pythonic class-based wrapper for the FLIR PySpin Library.

More documentation can be found on Github Pages, and the source can be found on Github.

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 your specific cameras for easy reference.

Installation

  1. If 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 like Anaconda.
  2. Install Spinnaker and PySpin from FLIR.
    • You will likely need to follow several manual steps after the Spinnaker installation to get PySpin (Mac Instructions)
  3. Install simple_pyspin module:
    • Install from PyPi: pip install simple-pyspin.
    • Download source from GitHub and use setup.py.

Usage

See the examples directory of the source for these examples and more.

Basic Usage

# dead_simple.py

from simple_pyspin import Camera

with Camera() as cam: # Acquire and initialize Camera
    cam.start() # Start recording
    imgs = [cam.get_array() for n in range(10)] # Get 10 frames
    cam.stop() # Stop recording

print(imgs[0].shape, imgs[0].dtype) # Each image is a numpy array!

Note that as long as you open the camera using a with clause, 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:

from simple_pyspin import Camera

cam = Camera() # Acquire Camera
cam.init() # Initialize camera

cam.start() # Start recording
imgs = [cam.get_array() for n in range(10)] # Get 10 frames
cam.stop() # Stop recording

cam.close() # You should explicitly clean up

print(imgs[0].shape, imgs[0].dtype) # Each image is a numpy array!

Changing Camera Settings

Here is a more complicated example, which manual changes a number of settings, and saves a number of images using PIL.

# manual_setup.py

from simple_pyspin import Camera
from PIL import Image
import os

with Camera() as cam: # Initialize Camera
    # Set the area of interest (AOI) to the middle half
    cam.Width = cam.SensorWidth // 2
    cam.Height = cam.SensorHeight // 2
    cam.OffsetX = cam.SensorWidth // 4
    cam.OffsetY = cam.SensorHeight // 4

    # If this is a color camera, get the image in RGB format.
    if 'Bayer' in cam.PixelFormat:
        cam.PixelFormat = "RGB8"

    # To change the frame rate, we need to enable manual control
    cam.AcquisitionFrameRateAuto = 'Off'
    cam.AcquisitionFrameRateEnabled = True
    cam.AcquisitionFrameRate = 20

    # To control the exposure settings, we need to turn off auto
    cam.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 %.1f dB" % gain)
    cam.Gain = gain
    cam.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 = True
        cam.Gamma = 2.2
    except:
        print("Failed to change Gamma correction (not avaiable on some cameras).")

    cam.start() # Start recording
    imgs = [cam.get_array() for n in range(10)] # Get 10 frames
    cam.stop() # Stop recording

# Make a directory to save some images
output_dir = 'test_images'
if not os.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!
for n, img in enumerate(imgs):
    Image.fromarray(img).save(os.path.join(output_dir, '%08d.png' % n))

License

Copyright 2019 Dustin Kleckner

Licensed 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.0

Unless 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_pyspin-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

simple_pyspin-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file simple_pyspin-0.1.1.tar.gz.

File metadata

  • Download URL: simple_pyspin-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for simple_pyspin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 31e27d8bede23a07d0c38ffe107827c9cacdf78af24e05295d057d47dc23617f
MD5 edbad07c79c8dceede6acd92caad58f3
BLAKE2b-256 d9b4487a3c037e4b11550e39a2bcb90ec4dbc7e849e0d632753627308503b4e3

See more details on using hashes here.

File details

Details for the file simple_pyspin-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: simple_pyspin-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for simple_pyspin-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53c365eb2f1fc97514d162720e3b9eb4ce2fc6eba648345ba8e3768b993af25c
MD5 5a8dcee375ffa5b5cea909da36a16bce
BLAKE2b-256 829b1693519389c89178842717987c76a3aa6d7738dc0da488bac4f0a8483c2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page