opencv linux 打开摄像头视频

利用已经编译好的opencv2.4.2来在fedora14 下打开zc301p摄像头,由于linux下有摄像头驱动所以不需要再编译驱动了。
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
   CvCapture *capture;
   IplImage *frame;
   capture=cvCreateCameraCapture(0);
   cvNamedWindow("Webcam",0);
  CvVideoWriter *writer;
  char AviFileName[]="Output.avi";
  int AviForamt = -1;
  int FPS = 25;
  CvSize AviSize = cvSize(640,480);
  int AviColor = 1;
   writer=cvCreateVideoWriter(AviFileName,AviForamt,FPS,AviSize,AviColor);
  int i=0;
  while(true)
   {
     frame = cvQueryFrame(capture);
     cvWriteFrame(writer,frame);
     cvShowImage("Webcam",frame);
   printf("%d/n",i);
    if(cvWaitKey(20)>0)
        break;
        i++;
   }
    cvReleaseCapture(&capture);
   cvReleaseVideoWriter(&writer);
    cvDestroyWindow("Webcam");
}
编译:g++ -o avi avi.cpp -I /usr/local/opencv2.4.2/include/opencv -L /usr/local/opencv2.4.2/lib/ -lopencv_core -lopencv_highgui
./avi运行起来可以的

没有更多推荐了,返回首页