参考:http://blog.csdn.net/xukai871105/article/details/40988101
http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/
安装完毕后测试。连接罗技C110和树莓派,
简单写一段调用摄像头的代码test_cam:
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc,char ** argv)
{
VideoCapture capture;
capture.open(0);
if(!capture.isOpened())
{
cerr << "open camera failed..." <<endl;
}
Mat frame;
while(capture.read(frame))
{
imshow("cam",frame);
waitKey(1);
}
return 0;
}
编写makefile:
INCLUDE =$(shell pkg-config --cflags opencv)
LIBS =$(shell pkg-config --libs opencv)
SOURCES =test_cam.cpp
#目标文件
OBJECTS =$(SOURCES:.cpp =.o)
#可执行文件
TARGET =test_cam
$(TARGET):$(OBJECTS)
g++ -o $(TARGET) $(OBJECTS) -I $(INCLUDE) $(LIBS)
$(OBJECTS):$(SOURCES)
g++ -c $(SOURCES)
clean:
rm $(OBJECTS) $(TARGET)
%.o:%.cpp
g++ -I $(INCLUDE) -o $@ -c $<
用装了ubuntu的laptop远程登陆树莓派(注意要用ssh -X pi@xxxx,否则运行程序时会报gtk-warning :cannot open display)。
在树莓派中直接make,编译cpp文件。编译后运行:./test_cam,就可以看到摄像头的实时拍摄视频了。