bensondaled / pseyepy

PSEye-py: a python interface to the PS3Eye camera
Apache License 2.0
78 stars 26 forks source link
api camera driver movies playstation python python-3 python3 video

pseyepy: a python API for acquisition, display, and saving of video from the PS3Eye camera


About this package

pseyepy is a lightweight, cross-platform, and open-source Python interface to the Playstation PS3Eye USB camera. Its core is a wrapper of a C API that derives from the excellent PS3EYEDriver project.

At this point, the dependencies for the project are:

The important features are:

Contributions are greatly appreciated!


Installation

Installation has not yet been thoroughly tested on all platforms. Eventually I will get around to enabling a pip install. For now:

  1. (If you are on Windows: download & install libusb; Mac and Linux are handled without this step)
  2. Download the source code, unzip, and navigate to the root directory
  3. sudo python setup.py install

If that does not work, it's likely a libusb issue. Try adjusting paths such that libusb paths are included by default.

  1. (If you want to use ffmpeg for saving, download and install ffmpeg)

Examples

Basic usage:

from pseyepy import Camera

# initialize all connected cameras
c = Camera()

# read from the camera/s
frame, timestamp = c.read()

# when finished, close the camera
c.end()

You may specify specific camera/s:

c = Camera(0) # camera at index 0
c = Camera([0,1]) # cameras at indices 0 and 1

Set initialization parameters for your camera/s:

c = Camera([0,1], fps=60, resolution=Camera.RES_LARGE, colour=False)

Note that frame rate, resolution, and colour are the 3 parameters that cannot be changed after initializing.

Set initialization parameters for each camera independently:

c = Camera([0,1], fps=[30, 60], resolution=[Camera.RES_LARGE, Camera.RES_SMALL], colour=[True, False])

Set mutable image acquisition parameters upon initialization:

c = Camera(fps=30, colour=[False,True], gain=50, vflip=[True, False])

The mutable parameters include gain, exposure, whitebalance, vflip, hflip. See docstring for full details.

Set parameters after initialization:

c.exposure = 23

For each camera independently:

c.exposure[0] = 23
c.exposure[1] = 45

Read from all cameras:

frames, timestamps = c.read()

Read from a specific camera:

frame1, timestamp1 = c.read(1) # read from camera at index 1

Live display of camera feed with parameter controls:

from pseyepy import Camera, Display

c = Camera() # initialize a camera
d = Display(c) # begin the display

Stream camera data to a file using ffmpeg:

from pseyepy import Camera, Stream

c = Camera() # initialize a camera
s = Stream(c, file_name='example_movie.avi', codec='png') # begin saving data to files

# when finished, close the stream
s.end()

Stream to file while also displaying (beta):

s = Stream(c, file_name='example_movie.avi', display=True)

# when finished, close the stream
s.end()

Troubleshooting and known pitfalls


Todo