Pi Camera - vanderbiltrobotics/RoboticsIntelligenceDatabase GitHub Wiki

(Work in progress)

Implementing the Pi Cam using OpenCV

OpenCV is a free library of programming functions used for image processing and computer vision. Here we will use it to get image data from the Pi camera.

Step 1: Once OpenCV has been installed on the Raspberry Pi, go to the terminal and type the following: "sudo nano newFile.cpp". (This creates a new C++ files name newFile. Feel free to change the name)

Type the following code into newFile:

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)

{

VideoCapture cap(0); // open the default camera

if(!cap.isOpened())  // check if we succeeded

    return -1;

while(true)
{
    Mat image; // creates empty matrix that will hold image data
    cap >> image; // get a new frame from camera
    imshow("image", image); // displays camera image on window titled “image”
    if(waitKey(30) >= 0) break;  // gives “imshow” enough time to process event before loop repeats 
}

}

Save the file and go back to the terminal. Compile this file and create an executable by typing the following:"g++ newFile.cpp -o newFile".

Final Step: To run your file, type the following: "./newFile"

OpenCV Documentation:

Functions for reading/writing images/video

Classes and Methods for Image Processing