www.pudn.com > firev0.01.rar > blobworldfeature.cpp
/* This file is part of the FIRE -- Flexible Image Retrieval System FIRE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. FIRE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRE; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "blobworldfeature.hpp" #include "basetools.hpp" #include#include "gzstream.hpp" using namespace std; void BlobWorldFeature::load(::std::string filename) { DBG(DBG_VERBOSE) << "loading blobs from " << filename << endl; igzstream ifs(filename.c_str()); if(!ifs) { ERR << "Cannot open '" << filename << "' to read blobs." << endl; } string keyword; int i; while(!ifs.eof()) { ifs >> keyword; if(!ifs.eof()) { if(keyword=="#") { char devnull[1024]; ifs.getline(devnull,1024); } else if(keyword=="region") { Blob *tmp=new Blob(); ifs >> i; for(unsigned int k=0;k<235;++k) { ifs >> tmp->operator[](k); } regions_.push_back(tmp); if(i!=int(regions_.size())) { //numbering starts with 1 DBG(DBG_MESSAGE) << "Expected " << i<<"-th blob, but got " << regions_.size() <<"-th" << endl; } } else { DBG(DBG_MESSAGE) << "Unknown keyword '" << keyword << "'. " << endl; } } } } void BlobWorldFeature::save(::std::string filename) const { ofstream ofs(filename.c_str()); if(!ofs) { ERR << "Cannot open '" << filename << "' to save region feature." << endl; } ofs << "# region feature" << endl << "nofregions " << this->nOfRegions() << endl; for(unsigned int i=0;i nOfRegions();++i) { const Blob *tmp=this->region(i); ofs <<"region " << i; for(unsigned int i=0;i<235;++i) { ofs << " " << tmp->operator[](i); } ofs << endl; } }