DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

源代码: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

posted on 2014-01-02 09:22  DoubleLi  阅读(506)  评论(0编辑  收藏  举报