opencv 如何读取摄像头

<span style="font-size:18px;">c++</span>
<span style="font-size:18px;">	VideoCapture cap(0);
	if(!cap.isOpened())
		return -1;
	Mat edges;
	for(;;)
	{
		Mat frame;
		cap>>frame;
		cvtColor(frame,edges, CV_BGR2GRAY);
		GaussianBlur(edges, edges,Size(7,7),1.5,1.5);
		Canny(edges, edges,0,90,3);
		imshow("qq",edges);
		int c=waitKey(33);
		if(c==27)  break;
	}
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>

c语言

<span style="font-size:18px;">#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
 
int main( int argc, char** argv )
{
  //声明IplImage指针
  IplImage* pFrame = NULL;

 //获取摄像头
  CvCapture* pCapture = cvCreateCameraCapture(0);
 
  //创建窗口
  cvNamedWindow("video", 1);
 
  //显示视屏
  while(1)
  {
      pFrame=cvQueryFrame( pCapture );
      if(!pFrame)break;
      cvShowImage("video",pFrame);
      char c=cvWaitKey(33);
      if(c==27)break;
  }
  cvReleaseCapture(&pCapture);
  cvDestroyWindow("video");
} </span>


你可能感兴趣的:(opencv 如何读取摄像头)