主要參考這篇文章http://www.cnblogs.com/liu-jun/p/3489675.html
在完成opencv編譯,安裝之後。使用攝像頭。
g++編譯的代碼main.cpp如下:
#include <cv.h>
#include <opencv/highgui.h>
#include<stdio.h>
#include<opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
CvCapture* pCapture = cvCreateCameraCapture(0);
cvNamedWindow("Video", 1);
while(1)
{
IplImage* pFrame=cvQueryFrame( pCapture );
if(!pFrame)break;
cvShowImage("Video",pFrame);
char c=cvWaitKey(33);
if(c==27)break;
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("Video");
return 0;
}
g++ `pkg-config opencv --cflags` main.cpp -o main `pkg-config opencv --libs`
讀取攝像頭結果如下圖:
More Information
- If you encounter problems installing OpenCV, see the companion guide, “A Comprehensive OpenCV Installation Troubleshooting Guide.”
- Utkarsh Sinha runs AiShack, a site that has easy-to-understand tutorials using OpenCV to solve real-world problems: http://www.aishack.in/topics/tutorials/
- Sebastian Montabone has several articles on installing OpenCV and image processing. His web site is http://www.samontab.com/
- FakeOutdoorsman’s posted an excellent dependency install guide, which is located on the Ubuntu forums: http://ubuntuforums.org/showthread.php?t=786095