コード例 #1
0
ファイル: qsnapper.cpp プロジェクト: kwplummer/QCompanion
/*!
 * \brief Takes a picture
 * \details Checks if it is allowed to check pictures, and if the save directory
 * exists, and if so takes a picture.
 * If the picture is different from the last one, it gets a name from
 * getNextFileName() and saves it.
 * It then sets the next time another screen shot should occur.
 * If saveDifferenceImage is true, a difference between the current image and
 * the previous image is stored instead of a whole copy. This reduces size, and
 * makes changes more noticable.
 * \return If a picture was taken.
 */
bool QSnapper::snap()
{
  if(canSnap && !saveDir.isNull() && QDir(saveDir).exists() &&
     !screensaverIsActive())
  {
    QString saveFileName = getNextFileName();
#if QT_VERSION < 0x050000
    QPixmap desktop = QPixmap::grabWindow(QApplication::desktop()->winId());
#else
    QPixmap desktop = QGuiApplication::primaryScreen()->grabWindow(
        QApplication::desktop()->winId());
#endif
    QImage newImage = desktop.toImage();
    nextWakeup = QDateTime::currentDateTime().addSecs(60);
    if(lenient && saveDifferenceImage &&
       imagesDiffer(oldImage, newImage, getNextFileName()))
    {
      oldImage = newImage;
    }
    else if((!lenient && oldImage != newImage) ||
            (lenient && imagesDiffer(oldImage, newImage)))
    {
      oldImage = newImage;
      oldImage.save(saveFileName);
      saveFileName = getNextFileName();
      return true;
    }
  }
  return false;
}
コード例 #2
0
ファイル: Movie.cpp プロジェクト: williamedwardhahn/OpenPV
//Image readImage reads the same thing to every batch
//This call is here since this is the entry point called from allocate
//Movie overwrites this function to define how it wants to load into batches
int Movie::retrieveData(double timef, double dt)
{
   int status = PV_SUCCESS;
   bool init = false;
   for(int b = 0; b < parent->getNBatch(); b++){
      if(parent->icCommunicator()->commRank() == 0){
         if(framePath[b]!= NULL) free(framePath[b]);
         if(!initFlag){
            framePath[b] = strdup(getNextFileName(startFrameIndex[b]+1, b));
            init = true;
         }
         else{
            framePath[b] = strdup(getNextFileName(skipFrameIndex[b], b));
         }
         std::cout << "Reading frame " << framePath[b] << " into batch " << b << " at time " << timef << "\n";
         status = readImage(framePath[b], b, offsets[0], offsets[1], offsetAnchor);
      }
      else{
         status = readImage(NULL, b, offsets[0], offsets[1], offsetAnchor);
      }

      if( status != PV_SUCCESS ) {
         fprintf(stderr, "Movie %s: Error reading file \"%s\"\n", name, framePath[b]);
         abort();
      }
   }
   if(init){
      initFlag = true;
   }
   return status;
}
コード例 #3
0
ファイル: heatMapSaver.cpp プロジェクト: zgsxwsdxg/openpose
    void HeatMapSaver::saveHeatMaps(const std::vector<Array<float>>& heatMaps, const std::string& fileName) const
    {
        try
        {
            // Record cv::mat
            if (!heatMaps.empty())
            {
                // File path (no extension)
                const auto fileNameNoExtension = getNextFileName(fileName) + "_heatmaps";

                // Get names for each heatMap
                std::vector<std::string> fileNames(heatMaps.size());
                for (auto i = 0; i < fileNames.size(); i++)
                    fileNames[i] = {fileNameNoExtension + (i != 0 ? "_" + std::to_string(i) : "") + "." + mImageFormat};

                // heatMaps -> cvOutputDatas
                std::vector<cv::Mat> cvOutputDatas(heatMaps.size());
                for (auto i = 0; i < cvOutputDatas.size(); i++)
                    unrollArrayToUCharCvMat(cvOutputDatas[i], heatMaps[i]);

                // Save each heatMap
                for (auto i = 0; i < cvOutputDatas.size(); i++)
                    saveImage(cvOutputDatas[i], fileNames[i]);
            }
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }
コード例 #4
0
bool DisparityMovie::updateImage(double timef, double dt){
   InterColComm * icComm = getParent()->icCommunicator();
   assert(!readPvpFile);

   if(fabs(timef - (parent->getStartTime() + parent->getDeltaTime())) > (parent->getDeltaTime()/2)){
      //If disparity is over numDisparity, read new image and reset index
      if(disparityIndex >= numDisparity - 1){
         if (filename != NULL) free(filename);
         filename = strdup(getNextFileName(skipFrameIndex));
         disparityIndex = 0;
         frameCount++;
      }
      else{
         disparityIndex++;
      }
   }
   assert(filename != NULL);

   //Set frame number (member variable in Image)
   int newOffsetX;
   if((frameCount + frameOffset) % 2 == 0){
      newOffsetX = this->offsets[0];
   }
   else{
      newOffsetX = this->offsets[0] + (disparityIndex * dPixelDisparity);
   }
   int status = readImage(filename, newOffsetX, this->offsets[1], this->offsetAnchor);
   if( status != PV_SUCCESS ) {
      fprintf(stderr, "Movie %s: Error reading file \"%s\"\n", name, filename);
      abort();
   }
   //Write to timestamp file here when updated
   if( icComm->commRank()==0 ) {
      //Only write if the parameter is set
      if(timestampFile){
         std::ostringstream outStrStream;
         outStrStream.precision(15);
         outStrStream << frameNumber << "," << timef << "," << filename << "\n";
         size_t len = outStrStream.str().length();
         int status = PV_fwrite(outStrStream.str().c_str(), sizeof(char), len, timestampFile)==len ? PV_SUCCESS : PV_FAILURE;
         if (status != PV_SUCCESS) {
            fprintf(stderr, "%s \"%s\" error: Movie::updateState failed to write to timestamp file.\n", parent->parameters()->groupKeywordFromName(name), name);
            exit(EXIT_FAILURE);
         }
         //Flush buffer
         fflush(timestampFile->fp);
      }
   }
   return true;
}