void Video::loadVideos() { const char *path = "/Users/Jobs/Documents/Xcode/HolumV0.1/HolumV0.1/Resource Files"; string videoPath(path); struct dirent *entry; DIR *dp; dp = opendir(path); if(dp == NULL) { cout << "Errore 004: Il percorso della directory video non esiste o non รจ definito."; return -1; } while((entry = readdir(dp))) { string videoName = string(entry->d_name); int videoNameLen = strlen(videoName.c_str()); if(checkExtension(videoName, videoNameLen)) { videoPath += "/" + videoName; FileVideo fv(videoPath, videoName.substr(0, videoName.find("."))); videoFiles.push_back(fv); } } closedir(dp); }
/* images will be saved in the current directory by default */ std::vector<string> capture(int startFrame, int endFrame, bool output = false, const char* path = "", string filename = "") { /* total number of frames */ size_t total = endFrame - startFrame; /* dynamical array of images for storing all the frames */ /* store string rather than Image objects because those objects will eat all the memory */ std::vector<string> images; this->setFrames(startFrame, false); #ifdef FFMPEG /* use ffmpeg to improve speed */ string videoPath(this->path); string framePath(path); string cmd = "ffmpeg -r \"" + Common::doubleToStr(this->getVideo().get(CV_CAP_PROP_FPS)) + "\" -ss " + Common::doubleToStr(startFrame / this->getVideo().get(CV_CAP_PROP_FPS)) + " -i " + videoPath + " -vframes \"" + Common::intToStr(total + 1) + "\" \"" + framePath + "f" + filename + "_%1d.png\""; /* excute the command */ FILE* captureProcess = popen(cmd.c_str(), "w"); if (captureProcess == NULL) { ostringstream os; os << "Failed to capture frames from the video"; Common::errorPrint(os.str().c_str()); /* exit */ exit(-1); } pclose(captureProcess); size_t i = 1; for (; i <= total + 1; i++) { /* save the image when output is [true] */ if (output && i >= startFrame) { string num = Common::intToStr(i); string reserved(path); images.push_back(reserved + "f" + filename + "_" + num + ".png"); } } #endif #ifndef FFMPEG /* this loop will cost too much time */ size_t i = startFrame; for (; i <= endFrame; i++) { Mat reservedImg; this->vdo.read(reservedImg); /* save the image when output is [true] */ if (output && i >= startFrame) { string num = Common::intToStr(i); string reserved(path); imwrite((reserved + filename + num + ".png").c_str(), reservedImg); images.push_back(reserved + "f" + filename + "_" + num + ".png"); cout << "save image: " + num << endl; } } #endif return images; }