1

i'm beginner in programming. I do a face detection project (detect a face, record its result, then save it into output file). I rather naming its result with date&time than with "MyVideo". But I dunno how, anyone can help me? Thanks b4.

Here is my code.

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;


            }
BConic
  • 8,750
  • 2
  • 29
  • 55
alfriaan
  • 11
  • 1
  • you can use a stringstream to easily add numbers to a string. From your stringstream use .str().c_str() to get a const char * which is normally used to specify a filename. – Micka Sep 03 '14 at 08:35
  • i dunno how to replace "K:\\MyVideo.avi" with your suggestion. Can you help me? sorry before, I am very beginner :) – alfriaan Sep 04 '14 at 01:37

1 Answers1

1

What you need is to get date and time as a string and then use this string as your file name. One example you can find here: 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;
}
Community
  • 1
  • 1
tommyk
  • 3,187
  • 7
  • 39
  • 61