c++ - 用日期时间命名输出文件

标签 c++ datetime opencv

我是编程初学者。我做了一个人脸检测项目(检测人脸,记录结果,然后将其保存到输出文件中)。我宁愿用日期和时间命名它的结果,而不是用“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;


            }

最佳答案

您需要将日期和时间作为字符串获取,然后将此字符串用作您的文件名。您可以在此处找到一个示例: 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;
}

关于c++ - 用日期时间命名输出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25636597/

相关文章:

c++ - 用/拆分 C++ 字符串

ruby-on-rails - 事件记录 : milliseconds aren't taken into account when using a where clause

python - pytesseract不适用于数字图像

python - 将视频保存为帧 OpenCV{PY}

python - 打开cv2读写视频错误1287

c++ - 有没有一种方法可以将数字作为字符串,并且不使用 float 或 double,将其四舍五入到精确的位数?

c++ - 获取在 C++ 中创建/修改注册表项的日期

c++ - (C++) 错误 : 'invalid_argument' was not declared in this scope

php - 用于检查一个日期是否接近当前日期的 MySQL 查询

python - 如何在 Python 中获取文件的 ctime 和/或 mtime,包括时区?