opencv实现摄像头的实时图像采集与显示

环境配置:vs2010+opencv2.3.1(注:opencv2.4.9读取摄像头出现问题--原因还没找到,望指教)

code

// Camera.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"  
#include <cv.h>
#include <cxcore.h>  
#include <highgui.h> 
#include <opencv2/core/core_c.h>
   
int main( int argc, char** argv )  
{  
  //声明IplImage指针  
  IplImage* pFrame = NULL;  
  
 //获取摄像头  
  CvCapture* pCapture = cvCreateCameraCapture(-1);  
  if(pCapture ==NULL)
  {
		printf("Get Capture false!\n");
  }
  //创建窗口  
  cvNamedWindow("video", 1);  
    
  //显示视屏  
  while(1)  
  {  
      pFrame=cvQueryFrame( pCapture );  
      if(!pFrame)
	  {
		  printf("The frame is null!\n");
		  break; 
	  }
      cvShowImage("video",pFrame);  
      char c=cvWaitKey(10);  
      if(c==27)break;  
  }  
  cvReleaseCapture(&pCapture);  
  cvDestroyWindow("video");
}   


你可能感兴趣的:(opencv摄像头)