Giter Site home page Giter Site logo

raspicam-rs's Introduction

raspicam-rs

docs.rs Crates.io

Rust bindings to the amazing C++ raspicam library (with optional OpenCV utilities)!

This is a followup to a Rust-based robotics project I worked where high FPS low latency and full color support was a requirement: ez-aquarii

Prerequisites

You MUST be on a 32-bit install. The raspberry pi camera libraries do NOT work on a 64-bit installation. See: raspberrypi/userland#688


A prerequisite is you have to compile the raspicam library and install it. This repo has a install script for convenience that'll do everything for you:

curl https://raw.githubusercontent.com/bluskript/raspicam-rs/master/install.sh | sudo bash

Install dependencies:

sudo apt install clang libclang-dev

If you are using opencv integration, also install libopencv-dev and enable the opencv feature in the crate:

raspicam-rs = { version = "0.1.2", features = ["opencv"] }
opencv = "0.70.0"

Example usage showing how to capture a single image and save it:

use image::RgbImage;
use raspicam_rs::{
    bindings::{RASPICAM_EXPOSURE, RASPICAM_FORMAT},
    RaspiCam,
};

fn main() {
    RaspiCam::new();
    let mut raspicam = raspicam_rs::RaspiCam::new();
    raspicam
        .set_capture_size(480, 480)
        .set_frame_rate(90)
        .set_format(RASPICAM_FORMAT::RASPICAM_FORMAT_RGB)
        .open(true)
        .unwrap();
    let img = RgbImage::from_raw(480, 480, raspicam.grab().unwrap().to_vec()).unwrap();
    img.save("frame.png").unwrap();
}

How to configure

These bindings use something similar to a builder pattern to configure the camera. You can chain configuration commands together:

let mut raspicam = raspicam_rs::RaspiCam::new();
raspicam
    .set_brightness(50)
    .set_contrast(0)
    .set_exposure(RASPICAM_EXPOSURE::RASPICAM_EXPOSURE_OFF)
    .set_format(RASPICAM_FORMAT::RASPICAM_FORMAT_RGB)
    .set_sensor_mode(7)
    .open(true);

If there is a method that isn't available directly, you can call methods on the internal C++ object like so:

let mut camera = raspicam_rs::RaspiCam::new();
raspicam.obj.pin_mut().startCapture();

Achieving high FPS low latency fullcolor

In my experience, high FPS fullcolor realtime processing can be achieved using low resolutions (480x480 as an example), sensor mode 7, shutter speed 15000, and setting the framerate 90.

A real-world demo of low latency camera capturing (predates this library but same result can be achieved): Check Here

raspicam-rs's People

Contributors

bluskript avatar

Stargazers

Valerio Viperino avatar Ankush Singh avatar  avatar  avatar  avatar Jer avatar Willi Kappler avatar Bob avatar dusk avatar  avatar

Watchers

 avatar  avatar

raspicam-rs's Issues

install.sh does not work - part 2

after changing the checkout directory to raspicam-build, cmake complains:

Could not find mmal libraries

Could you add to the docs how to install?

libcamera

Hey,

Any thoughts on integrating libcamera as opposed to raspicam? The raspberry pi group seems to be moving away from raspicam...

Thanks!

install.sh not working

the install.sh downloads the repo to directory raspicam but tries to work in raspicam-build.

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.