Coder Social home page Coder Social logo

psomers3 / nanocamera Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thehapyone/nanocamera

0.0 0.0 0.0 40 KB

A simple to use camera interface for the Jetson Nano for working with USB and CSI cameras in Python.

License: MIT License

Python 100.00%

nanocamera's Introduction

NanoCamera MIT License

A simple to use camera interface for the Jetson Nano for working with USB and CSI cameras in Python.

It currently supports the following types of camera:

  • Works with CSI Cameras (Tested and Works)
  • Works with various USB cameras (Tested with Logitech USB camera)
  • Works with IP Cameras (Future version)

Features

  • It is OpenCV ready. Image file can be called directly with OpenCV imshow
  • Image file is a numpy RGB array.
  • Support different Camera Flip Mode (Counterclockwise, Rotate 180 degress, Clockwise - 90 degrees, Horizontal Flip, Vertical Flip)
  • Can be used with multiple cameras
  • Support Frame rate enforcement. *Only available for USB cameras.
  • Frame rate enforcement ensures the cameras work at the given frame rate using gstreamer videorate plugin
  • It is based on Accelerated GStreamer Plugins
  • Should work with other Jetson boards like Jetson TX1, TX2 and others (Not tested)
  • Easily read images as numpy arrays with image = camera.read()
  • Supports threaded read - available to all camera types. To enable a fast threaded read, you will to enable the enforce_fps: enforce_fps = True

Requirements

This library requires OpenCV to be installed to work. If you don't have OpenCV, you can install one with pip:

pip3 install opencv-python 

Install

Installation is simple. Can be installed in two ways with Pip or Manually.

Pip Installation
pip3 install nanocamera 
Manual Installation
git clone https://github.com/thehapyone/NanoCamera
cd NanoCamera
sudo python3 setup.py install

Usage & Example

Using NanoCamera is super easy. Below we show some usage examples. You can find more in the examples.

Working with CSI Camera

For CSI Cameras, the camera_type = 0.

Find here for full CSI camera example

Python Example - Create CSI camera using default FPS=30, default image size: 640 by 480 and with no rotation (flip=0)

import nanocamera as nano
# Create the Camera instance for 640 by 480
camera = nano.Camera()

Customizing the width and height

import nanocamera as nano
# Create the Camera instance for No rotation (flip=0) with size of 1280 by 800
camera = nano.Camera(flip=0, width=1280, height=800, fps=30)

if image is inverted, set flip = 2

Working with USB Camera

For USB Cameras, set the camera_type = 1, and set the device_id as well Find here for full USB camera example

Python Example - Create USB camera connected to /dev/video1

import nanocamera as nano
# Create the Camera instance for No rotation (flip=0) with size of 640 by 480
camera = nano.Camera(camera_type=1, device_id=1, width=640, height=480, fps=30)

Enable frame rate enforcement i.e force the camera to work at the given frame rate

import nanocamera as nano
# enforce the capture frame rate with the enforce_fps=True
camera = nano.Camera(camera_type=1, device_id=1, width=640, height=480, fps=30, enforce_fps=True)

You can see connected USB cameras by running :

ls /dev/video*
# for usb camera /dev/video2, the device_id will be 2

Reading Camera

Call read() to read the latest image as a numpy.ndarray. The color format is BGR8.

frame = camera.read()

A Simple program to read from the CSI camera and display with OpenCV

import cv2
#from nanocamera.NanoCam import Camera
import nanocamera as nano

if __name__ == '__main__':
    # Create the Camera instance
    camera = nano.Camera(flip=0, width=640, height=480, fps=30)
    print('CSI Camera is now ready')
    while True:
        try:
            # read the camera image
            frame = camera.read()
            # display the frame
            cv2.imshow("Video Frame", frame)
            if cv2.waitKey(25) & 0xFF == ord('q'):
                break
        except KeyboardInterrupt:
            break

    # close the camera instance
    camera.release()

    # remove camera object
    del camera

See also

nanocamera's People

Contributors

thehapyone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.