网站首页 > 物联资讯 > 技术分享

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

2016-09-28 00:00:00 广州睿丰德信息科技有限公司 阅读
睿丰德科技 专注RFID识别技术和条码识别技术与管理软件的集成项目。质量追溯系统、MES系统、金蝶与条码系统对接、用友与条码系统对接

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

RFID管理系统集成商 RFID中间件 条码系统中间层 物联网软件集成