1.0.3-學習Opencv與MFC混合編程之—開啟本地網路攝影機

來源:互聯網
上載者:User

 

原始碼: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);

      }

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.