Using OpenCV with the Raspberry Pi camera
// Using OpenCV with the Raspberry Pi camera
// 2015.11.21 created by Huangtao
raspi-config
“camera” and select “enable”
install Pi Camera:
===================
http://www.raspberrypi.org/archives/3890
test Pi Camera:
===============
raspistill -t 10000
ok.
https://github.com/robidouille/robidouille/tree/master/raspicam_cv
===================================================================
Prerequisites
First make sure you have cmake and git installed:
sudo apt-get install cmake git
You might also need gcc/g++ in case it's not already installed, along with some other libraries:
sudo apt-get install gcc g++ libx11-dev libxt-dev libxext-dev libgraphicsmagick1-dev libcv-dev libhighgui-dev
You need the raspberry pi userland libraries:
mkdir -p ~/git/raspberrypi
cd ~/git/raspberrypi
git clone https://github.com/raspberrypi/userland.git
cd userland
./buildme
Build the raspicam library
mkdir -p ~/git
cd ~/git
git clone https://github.com/robidouille/robidouille.git
cd robidouille/raspicam_cv
mkdir objs
make
This will create:
libraspicamcv.a: A static raspberry cam library which provides an opencv like interface
libraspicamcv.so: A shared library of the above
raspicamtest: A small test app which uses the static library. Execute with ./raspicamtest. Press Esc to exit.
Using the static library
Add the include path
-I$(HOME)/git/robidouille/raspicam_cv
Link with the raspicamcv library
-L$(HOME)/git/robidouille/raspicam_cv -lraspicamcv
Link with the userland libraries:
-L$(HOME)/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
In your code add #include "RaspiCamCV.h" and replace:
CvCapture -> RaspiCamCvCapture
cvCreateCameraCapture -> raspiCamCvCreateCameraCapture
cvQueryFrame -> raspiCamCvQueryFrame
cvReleaseCapture -> raspiCamCvReleaseCapture
cvGetCaptureProperty -> raspiCamCvGetCaptureProperty
cvSetCaptureProperty does not currently work. Use the raspiCamCvCreateCameraCapture2 method to specify width, height, framerate, bitrate and monochrome settings.
I use in this way:
===================
e.g.
#include <opencv2/opencv.hpp>
#include "RaspiCamCV.h"
...
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` -I/root/git/robidouille/raspicam_cv
-L/root/git/robidouille/raspicam_cv -lraspicamcv
-L/root/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
-o main main.cpp
ok,success!
some problem:
=============
error while loading shared libraries: libraspicamcv.so: cannot open shared object file: No such file or directory
use:
sudo cp ~/git/robidouille/raspicam_cv/libraspicamcv.so /usr/lib