void DOTDetector::TrainParams::read( FileNode& fn )
{
- winSize.width = fn["winSize.width"];
- winSize.height = fn["winSize.height"];
+ winSize.width = fn["winSize_width"];
+ winSize.height = fn["winSize_height"];
regionSize = fn["regionSize"];
minMagnitude = fn["minMagnitude"];
{
CV_Assert( fs.isOpened() );
- fs << "winSize.width" << winSize.width;
- fs << "winSize.height" << winSize.height;
+ fs << "winSize_width" << winSize.width;
+ fs << "winSize_height" << winSize.height;
fs << "regionSize" << regionSize;
fs << "minMagnitude" << minMagnitude;
void DOTDetector::DOTTemplate::read( FileNode& fn )
{
fn["template"] >> quantizedImage;
- fn["objectClassIDs"] >> objectClassIDs;
+ for( FileNodeIterator fni = fn["objectClassIDs"].begin(); fni != fn["objectClassIDs"].end(); fni++ )
+ {
+ objectClassIDs.push_back( *fni );
+ }
texturelessRatio = fn["texturelessRatio"];
}
void DOTDetector::DOTTemplate::write( FileStorage& fs ) const
{
fs << "template" << quantizedImage;
- fs << "objectClassIDs" << objectClassIDs;
+ fs << "objectClassIDs" << "[";
+ for( size_t i = 0; i < objectClassIDs.size(); i++ )
+ {
+ fs << objectClassIDs[i];
+ }
+ fs << "]";
fs << "texturelessRatio" << texturelessRatio;
}
trainParams.read( fn_params );
// read class names
- int classCount = fn["class_count"];
- FileNodeIterator fni = fn["class_names"].begin();
+ int classCount = fn["object_class_count"];
+ FileNodeIterator fni = fn["object_class_names"].begin();
for( int i = 0; i < classCount; i++ )
{
string name;
// read DOT templates
int templatesCount = fn["templates_count"];
- fni = fn["templates"].begin();
for( int i = 0; i < templatesCount; i++ )
{
+ stringstream ss;
+ ss << "template_" << i;
dotTemplates.push_back( DOTTemplate() );
- FileNode cur_fn = *fni;
+ FileNode cur_fn = fn["templates"][ss.str()];
dotTemplates.rbegin()->read( cur_fn );
}
}
fs << "}"; //params
// write class names
- fs << "class_count" << (int)objectClassNames.size();
- fs << "class_names" << "[";
+ fs << "object_class_count" << (int)objectClassNames.size();
+ fs << "object_class_names" << "[";
for( size_t i = 0; i < objectClassNames.size(); i++ )
{
fs << objectClassNames[i];
// write dot templates
fs << "templates_count" << (int)dotTemplates.size();
- fs << "templates" << "[";
+ fs << "templates" << "{";
for( size_t i = 0; i < dotTemplates.size(); i++ )
{
+ stringstream ss;
+ ss << "template_" << i;
+ fs << ss.str() << "{";
dotTemplates[i].write( fs );
+ fs << "}";
}
- fs << "]";
+ fs << "}";
}
void DOTDetector::load( const std::string& filename )
{
if( argc != 1 && argc != 3 )
{
- cout << "Format: base; " << endl << "or without arguments to use default data" << endl;
+ cout << "Format: train_data test_data; " << endl << "or without arguments to use default data" << endl;
return -1;
}
string baseDirName, testDirName;
if( argc == 1 )
{
- baseDirName = "../MultiScaleDOT/Data/train/";
- testDirName = "../MultiScaleDOT/Data/test/";
+ baseDirName = "../../opencv/samples/cpp/dot_data/train/";
+ testDirName = "../../opencv/samples/cpp/dot_data/test/";
}
else
{
DOTDetector dotDetector;
dotDetector.train( baseDirName, trainParams, true );
+// dotDetector.save( "../../dot.xml.gz" );
+// dotDetector.load( "../../dot.xml.gz" );
+
const vector<string>& objectClassNames = dotDetector.getObjectClassNames();
const vector<DOTDetector::DOTTemplate>& dotTemplates = dotDetector.getDOTTemplates();