2014-09-03 54 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; 
} 
相关问题