使用opencv怎么實(shí)現(xiàn)定時(shí)錄像功能

這篇文章將為大家詳細(xì)講解有關(guān)使用opencv怎么實(shí)現(xiàn)定時(shí)錄像功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)公司是專業(yè)的虹口網(wǎng)站建設(shè)公司,虹口接單;提供網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行虹口網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

  #include "cv.h"  
  #include "cxcore.h"  
  #include "highgui.h"  
  #include <iostream>  
  #include <time.h> 
  #include <Windows.h> 
  #include <Mmsystem.h> 
  #include "stdio.h"  
  int timea=100000;  
  using namespace std;  
/*void times() 
{ 
  SYSTEMTIME sys_time; 
 
  //將變量值設(shè)置為本地時(shí)間 
  GetLocalTime( &sys_time ); 
 
  //輸出時(shí)間 
  printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n",sys_time.wYear, 
    sys_time.wMonth, 
    sys_time.wDay, 
    sys_time.wHour, 
    sys_time.wMinute, 
    sys_time.wSecond, 
    sys_time.wMilliseconds, 
    sys_time.wDayOfWeek); 
 
 // system("time"); 
  // 
 // system("pause"); 
  return 0; 
 
 
} */ 
  int main()  
  {  
    CvCapture* capture=cvCaptureFromCAM(0);  
    CvVideoWriter* video=NULL;  
    IplImage* frame=NULL;  
    int n;  
    if(!capture) //如果不能打開攝像頭給出警告  
    {  
     cout<<"Can not open the camera."<<endl;  
     return -1;  
    }  
    else  
    {  
     frame=cvQueryFrame(capture); //首先取得攝像頭中的一幀  
    int c=0; 
    SYSTEMTIME sys_time; 
 
  //將變量值設(shè)置為本地時(shí)間 
    GetLocalTime( &sys_time ); 
    char buf[1024]; 
    sprintf(buf,"camera-%4d-%2d-%02d-%02d-%02d-%02d.avi",sys_time.wYear,sys_time.wMonth,sys_time.wDay, 
    sys_time.wHour,sys_time.wMinute, sys_time.wSecond);  
 
      video=cvCreateVideoWriter(buf, CV_FOURCC('X', 'V', 'I', 'D'), 25,  
     cvSize(frame->width,frame->height)); //創(chuàng)建CvVideoWriter對象并分配空間  
  //保存的文件名為camera.avi,編碼要在運(yùn)行程序時(shí)選擇,大小就是攝像頭視頻的大小,幀頻率是32  
     if(video) //如果能創(chuàng)建CvVideoWriter對象則表明成功  
      {  
       cout<<"VideoWriter has created."<<endl;  
     }  
   cout<<"set the record time\n"<<endl;//設(shè)置錄像時(shí)間 
   cin>>timea; 
   int ti=timea*25; 
    
    
     cvNamedWindow("Camera Video",1); //新建一個(gè)窗口  
      int i = 0;  
     while(i <= ti) // 讓它循環(huán)ti次自動停止錄取  
      {  
       frame=cvQueryFrame(capture); //從CvCapture中獲得一幀  
       if(!frame)  
       {  
        cout<<"Can not get frame from the capture."<<endl;  
        break;  
       }  
       n=cvWriteFrame(video,frame); //判斷是否寫入成功,如果返回的是1,表示寫入成功  
       // cout<<n<<endl;  
       cvShowImage("Camera Video",frame); //顯示視頻內(nèi)容的圖片  
       i++;  
       if(cvWaitKey(2)>0)   
        break; //有其他鍵盤響應(yīng),則退出  
     }  
    
     cvReleaseVideoWriter(&video); //如果不釋放則春不上 
     cvReleaseCapture(&capture);  
     cvDestroyWindow("Camera Video");  
    }  
    return 0;  
  }

關(guān)于使用opencv怎么實(shí)現(xiàn)定時(shí)錄像功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

當(dāng)前標(biāo)題:使用opencv怎么實(shí)現(xiàn)定時(shí)錄像功能
分享網(wǎng)址:http://www.muchs.cn/article6/ghgsig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站排名、ChatGPT、電子商務(wù)、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)