Hawk-Rust Series: Actuation of Raspberry Pi Camera

Raspberry Pi provides a set of GPIO (general purpose input/output) pins that allow you to control electronic components for physical computing and explore the Internet of Things (IoT).
And the Camera Module is a great accessory for the Raspberry Pi, it allows users to take still pictures and record video in full HD.

In this project, we have used Raspberry Pi and its camera to authenticate whether the RFID card is punched by the card’s owner or not.
HAWK is a Rust based Image Recognition project, which implements a two-factor authentication by using the RFID card for user identification and Image for user validation.

In this blog, I’ll show you how to trigger RPi’s camera using Rust Programming Language. To know more about HAWK click here

Trigger RPi Camera using CMD

raspistill is the command line tool for capturing still photographs with the camera module.
You can click image using this command and its options like:
* –output, -o: Output filename
* –timeout, -t: Time before the camera takes picture and shuts down, etc or you can check all option here.

This is all about to capture image from RPi camera, now let’s look at the actuation of the camera using Rust Program.

Trigger RPi Camera using Rust

In Hawk, we have used Rust‘s system commands to invoke RPi camera.
System Commands helps users to communicate with the Operating System and with the help of that commands a user can operate the whole Operating System(OS).

use std::process::Command;
fn main() {
   let output = Command::new(raspistill)
        .args(&[
            "-t",
            "1000",
            "-w",
            100,
            "-h",
            100,
            "-o",
            "image.jpg"
        ])
.output()
};
}

Above code shows the integration of system commands in Rust program to click the user’s image using Raspberry Pi’s camera.
In above program I have used some options of raspistill command :
=> -t : (timeout) Time before the camera takes picture and shuts down
=> -w : (width) Width of the clicked image
=> -h : (height) Height of the clicked image
=> -o : (output) Output filename
To explore more use of system commands in Rust program click here

This program will not run in our system because we don’t have RPi camera connected or enabled, and we can not run this program directly into the Raspberry Pi, because we need to cross-compile our program first for armv7 (which is raspberry pi based architecture), after cross compilation you’ll able to run this piece of code to click image from Raspberry Pi camera.
For cross compilation, you can refer this blog.

Thank You for reading this blog.
For more reference and contributing to our open source project Hawk, you can visit here.


Knoldus-blog-footer-image

Written by 

Pawan Singh Bisht is the Trainee Software Consultant at Knoldus Software LLP. He has good knowledge of languages C++ and Java, and currently working on Rust. He is always ready to accept new challenges. As a fresher, he always tries to explore the different type of software and tools.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!