Search code examples
c++imageimage-processingimread

How to monitor a directory and read image in this directory in C++


First of all, I am new to C++. I am using Visual Studio 2010. I worked on a project that includes an camera. Camera send an image(bitmap) to a specific folder location in my computer. I want to monitor the directory consistenly. When a new bitmap image is obtained in the directory, I want to process this image. The code that I want to use is always monitoring the directory and read the last bitmap image in this directory. What can I use to achieve it? What is your suggestions? Could you write the source code? Thanks for your interest.


Solution

  • I dont agree with the other guy who answered the question, it can be done eaisly with some co-existing libraries that I used below, This code does what you are looking for,

    string processName()
    {
    
       FILETIME bestDate = { 0, 0 };
       FILETIME curDate;
       string name;
       CFileFind finder;
    
    
       BOOL bWorking = finder.FindFile("*.png");
    
       while (bWorking)
       {
    
          bWorking = finder.FindNextFile();
    
         // date = (((ULONGLONG) finder.GetCreationTime(ft).dwHighDateTime) << 32) + finder.GetCreationTime(ft).dwLowDateTime;
    
          finder.GetCreationTime(&curDate);
    
          if (CompareFileTime(&curDate, &bestDate) > 0 )
          {
              bestDate = curDate;
              name = finder.GetFileName().GetString();
              // name = (LPCTSTR) finder.GetFileName();
          }
    
    
    
       }
       return name;
    }
    

    Here I wrote it for the code you, it takes the name of the last entered /.png extension you can check libray for it.

    Please tell me for further question