VideoAsset::VideoAsset(bfs::path videoFile, bfs::path path, bool copy) : path(path) { try { name = path.filename().string(); if(!bfs::exists(videoFile)) throw VideoAssetException("video File doesn't exist!"); if(!bfs::exists(path) || !bfs::is_directory(path)) throw VideoAssetException("Destination folder doesn't exist"); if(copy) { video_path = path; video_path /= videoFile.filename(); bfs::copy_file(videoFile, video_path, bfs::copy_option::overwrite_if_exists); } else video_path = videoFile; isExternal = !copy; loadPlayerSync(); writeInfoFile(); hasTimetable = false; hasShotBoundaries = false; hasHistograms = false; hasMeans = false; isReady = false; } catch (const bfs::filesystem_error& ex) { (*Tobago.log)(Log::ERROR) << "Error creating video asset " << path.string() << ": " << ex.what(); throw VideoAssetException(ex.what()); } }
std::string GetFilenameFromPath(const bfs::path& path) { #if defined(USE_BOOST_FILESYSTEM_V3) // boost version 1.46 and above uses // boost filesystem version 3 as the default // which has yet a different way of getting // a filename string return path.filename().string(); #elif defined(USE_NON_DEPRECATED_BOOST_FILESYSTEM_V2) // the new way in boost filesystem version 2 // to get a filename string //(this is for boost version 1.36 and above) return path.filename(); #else // the old way in boost filesystem version 2 // to get a filename string //(this is for boost version 1.35 and below) return path.leaf(); #endif }
// Analysis routine void Crawler::analyse_image(const bfs::path& path) { std::ostringstream msg; msg << "Running image analysis on " << path; logger->message(msg.str(), traceLevel); // Construct and segment picture std::auto_ptr<ImageAnalyst> \ analyst(new ImageAnalyst(bfs::absolute(path.filename()), analyst_settings)); analyst->segment(); // Get centroids and dump to file if required if (settings.output) { std::ostringstream msg; msg << "Dumping segment centroids to " << settings.outputfile; logger->message(msg.str(), traceLevel); // Get segmentation window size blitz::TinyVector<int, 4> wsize = analyst->get_window_size(); // Open dumpfile as stream, add path, altered path and image and // window sizes std::fstream dumpFileStream; dumpFileStream.open(settings.outputfile.string().c_str(), std::fstream::out | std::fstream::app); dumpFileStream << "{'original_file': '" << path.string() << "', 'segmented_file': '" << path.stem() << "_segments" << bfs::extension(path) << "', 'image_size': (" << analyst->columns() << ", " << analyst->rows() << "), 'window_size': (" << wsize[0] << ", " << wsize[1] << ", " << wsize[2] << ", " << wsize[3] << "), "; // Get centroids, push to file std::vector<Index> centroids; analyst->get_centroids(centroids); dumpFileStream << "'centroids': ["; foreach(Index index, centroids) dumpFileStream << "(" << index[0] << "," << index[1] << "), "; dumpFileStream << "]}" << std::endl; // Clean up dumpFileStream.flush(); dumpFileStream.close(); } // Exit logger->message("Done!", traceLevel); }
// Operator for given path void Crawler::operator()(const bfs::path& path) { // Check argument type: only directories or regex-matched files allowed if (bfs::is_directory(path)) { std::ostringstream msg; msg << "Traversing " << path; logger->message(msg.str(), traceLevel); for(bfs::directory_iterator it(path), end; it != end; it++) { // Traverse directory: First check whether path points to a directory, // and call function recursively if recurse flag is set. Otherwise // path points to a file, so call function recursively on it. if (bfs::is_directory(it->path()) && not(settings.recursive)) { _ignore_message(it->path()); continue; } (*this)(it->path()); } } else if (_match_regex(path.filename())) analyse_image(path); else _ignore_message(path); }
VideoAsset::VideoAsset(bfs::path path) : path(path) { try { name = path.filename().string(); readInfoFile(); readTimetable(); readShotBoundaries(); readHistograms(); readMeans(); isReady = false; if(hasTimetable && hasShotBoundaries && hasHistograms && hasMeans) { if(frame2Timestamp.size() != histograms.size() || frame2Timestamp.size() != rgbMeans.size()) { throw VideoAssetException("Info files have wrong format."); } isReady = true; } loadPlayerSync(); } catch (const bfs::filesystem_error& ex) { (*Tobago.log)(Log::ERROR) << "Error loading video asset " << path.string() << ": " << ex.what(); throw VideoAssetException(ex.what()); } }