2014-09-03 53 views
0

我是編程初學者。我做了一個臉部檢測項目(檢測臉部,記錄其結果,然後將其保存到輸出文件中)。我寧願用&時間比「MyVideo」命名它的結果。但我不知道如何,任何人都可以幫助我?謝謝b4。用日期和時間命名輸出文件

這是我的代碼。

void rekamwajah(){ 
      double nBaris = cap.get(CV_CAP_PROP_FRAME_HEIGHT); 
      double nKolom = cap.get(CV_CAP_PROP_FRAME_WIDTH); 
      cv::Size frameSize(static_cast<int>(nKolom), static_cast<int>(nBaris)); 

      if (!rekam.isOpened()) //if not intialize the VideoWriter successfully 
       { 
        rekam.open ("K:\\MyVideo.avi", CV_FOURCC('M','J','P','G'), 20, frameSize, true); 
        } 

       bool bSuccess = cap.read(framewarna); 

       if (!bSuccess) //if not success, break loop 
       { 
        MessageBox::Show("ERROR: Cannot read a frame from video file"); 
        return; 
       } 
        rekam.write(framewarna); //writer the frame into the file 
        timer1->Enabled = true; 


      } 
+0

你可以使用一個字符串流輕鬆號碼添加到字符串。在你的stringstream中使用.str().c_str()來獲得一個常用於指定文件名的const char *。 – Micka 2014-09-03 08:35:33

+0

我不知道如何用你的建議來替換「K:\\ MyVideo.avi」。你可以幫我嗎?對不起之前,我很初學:) – alfriaan 2014-09-04 01:37:30

回答

1

您需要的是將日期和時間作爲字符串獲取,然後將此字符串用作文件名。其中一個例子,你可以在這裏找到: https://stackoverflow.com/a/16358111/137261

#include <iostream> 
#include <iomanip> 
#include <ctime> 

int main() 
{ 
    auto t = std::time(nullptr); 
    auto tm = *std::localtime(&t); 
    std::cout << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << std::endl; 
} 
相關問題