Skip to main content

Python wrapper for USB, blackfly, Raspi, Jetson Nano camerasWorks on Windows, Raspian, JetsonNano, MacOS

Project description

A collection of python threaded camera support routines for

  • USB and laptop internal webcams

  • RTSP streams

  • MIPI CSI cameras (Raspberry Pi, Jetson Nano)

  • FLIR blackfly USB camera

Save data as, HDF5, TIFF, AVI, MKV

Works on most platforms: Windows, MacOS, Unix

For detailed documentation please Readme.md.

Example program using camera

import cv2
import logging
import time
from queue import Queue

configs = {
 'camera_res'      : (1920, 1080),   # CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT
 'exposure'        : -6,             # depends on camera: e.g. -5 =(2^-5)=1/32,
                                     # 0=auto, 1...max=frame interval in microseconds
 'autoexposure'    : 3.0,            # depends on camera: 0.25 or 0.75(auto), -1,0,1
 'fps'             : 30,             # fps
 'fourcc'          : "MJPG",         # cv2 camera only: MJPG, YUY2, YUYV
 'buffersize'      : -1,             # default is 4 for V4L2, max 10,
 'output_res'      : (-1, -1),       # output resolution (-1=no change)
 'flip'            : 0,              # 0=no rotation
 'displayfps'      : 5               # frame rate for display server
}

if configs['displayfps'] >= configs['fps']: display_interval = 0
else: display_interval = 1.0/configs['displayfps']

# Open display window
cv2.namedWindow('Camera', cv2.WINDOW_AUTOSIZE) # or WINDOW_NORMAL

# Setting up logging
logging.basicConfig(level=logging.DEBUG) # options are: DEBUG, INFO, ERROR, WARNING

# Setting up input/output queue
captureQueue = Queue(maxsize=32)
storageQueue = Queue(maxsize=64)

# Setting up storage
from camera.streamer.mkvstorageserver import mkvServer
mkv = mkvServer("C:\\temp\\" + "Test.mkv", configs['fps'], configs['camera_res'])
mkv.start(storageQueue)

# Create camera interface
from camera.capture.cv2capture import cv2Capture
camera = cv2Capture(configs, 0)
camera.start(captureQueue)

while(cv2.getWindowProperty('Camera', 0) >= 0):
   current_time = time.time()

   # Wait for new image
   (frame_time, frame) = captureQueue.get(block=True, timeout=None)

   # Put image into storage queue
   if not storageQueue.full():
      storageQueue.put((frame_time, frame), block=False)

   # Display
   if (current_time - last_display) >= display_interval:
      cv2.imshow('Camera', frame)
      if cv2.waitKey(1) & 0xFF == ord('q'): break
      last_display = current_time

   # Do other things

# Clean up
camera.stop()
mkv.stop()
cv2.destroyAllWindows()

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

camera-util-1.0.2.tar.gz (52.9 kB view details)

Uploaded Source

Built Distribution

camera_util-1.0.2-py2.py3-none-any.whl (43.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file camera-util-1.0.2.tar.gz.

File metadata

  • Download URL: camera-util-1.0.2.tar.gz
  • Upload date:
  • Size: 52.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for camera-util-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9ac0b0d36d7ec2c7a55fd15e02ccd069f2b56276e8976ca8cf20bd7cdac4eabb
MD5 5549c2d9184668f5ccad51a324c8086a
BLAKE2b-256 16ad3615488c0036b2dc764af0e65e6cdacb4a8dc4fc991b48bb1dff5f0db66c

See more details on using hashes here.

File details

Details for the file camera_util-1.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: camera_util-1.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for camera_util-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0c9ea91c01d5b48f1e76fc08fc7f91c2d4cb809c49c686ec4ab80386ae036a99
MD5 ce804c9f9c4e6db2a5c869c905d81324
BLAKE2b-256 7a57c68aa6c31504167676e607e7731e7258e8b9a9229379324852f2ede69e88

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