-
Notifications
You must be signed in to change notification settings - Fork 4
Pi Camera
alademal edited this page Dec 8, 2017
·
3 revisions
(Work in progress)
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"
- Home
- Programming
-
Electrical
- Component Guide
- Single Board Computers
- Design
- Machine Learning/Intelligence
- Systems Engineering