Exemplo n.º 1
0
 std::string GetStem(const bfs::path& path) {
     #if defined(USE_BOOST_FILESYSTEM_V3)
         if (!HasExtension(path)) {
             // if no extension return empty string
             return "";
         }
         else {
             return path.stem().string();
         }
     #else
         if (!HasExtension(path)) {
             // if no extension, return empty string
             return "";
         }
         else {
             return path.stem();
         }
     #endif
 }
Exemplo n.º 2
0
// 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);
}