1.0.3-学习Opencv与MFC混合编程之---打开本地摄像头

源代码:http://download.csdn.net/detail/nuptboyzhb/3961643

版本1.0.3新增内容

打开摄像头

Ø 新建菜单项,Learning OpenCV——> OpenCVr入门——>打开摄像头(c)

Ø 菜单项设置如下:

Ø 建立类向导

Ø 编辑代码

void CCVMFCView::OnMyOpenCamera()

{

      // TODO: Add your command handler code here

      //Alt+F8 整理代码

      int   i=1;//截图个数

      CvCapture* capture;

      CString WindowName1="摄像机";

      IplImage *frame = 0;

      capture = cvCreateCameraCapture(0);//打开摄像头

      if(capture==NULL)

      {

             MessageBox("未检测到摄像头,请检查摄像头安装是否正确");

      }

      else

      {

             assert(capture != NULL );//如果没有打开,中断

             cvNamedWindow(WindowName1,CV_WINDOW_AUTOSIZE);

             while(1)

             {

                    frame= cvQueryFrame(capture);

                    if(!frame)

                    {

                           break;

                    }

                    cvShowImage(WindowName1, frame );

                    char c = cvWaitKey(10);

                    if( c == 27 )

                    {

                           break;

                    }

                    else if(c=='c'||c=='C')

                    {

                           CString str;

                           str.Format( "%d ",i);

                           CString WindowName2="Capture"+str;

                           cvNamedWindow(WindowName2,CV_WINDOW_AUTOSIZE);

                           cvShowImage(WindowName2, frame);

                           cvWaitKey(0);

                           cvDestroyWindow(WindowName2);

                           i++;

                    }

                   

             }

             cvReleaseCapture( &capture );

             cvDestroyWindow(WindowName1);

      }

}

 

 

from:http://blog.csdn.net/nupt123456789/article/details/7097900

你可能感兴趣的:(opencv)