diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 44d255336a..15375ae090 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -684,7 +684,6 @@ protected: vector<vector<int> >& dotTemplateIndices ) const; TrainParams trainParams; - //bool isAddImageAndGradientMask; std::vector<std::string> objectClassNames; std::vector<DOTTemplate> dotTemplates; diff --git a/modules/objdetect/src/dotdetector.cpp b/modules/objdetect/src/dotdetector.cpp index b4dbed2040..408ca36099 100644 --- a/modules/objdetect/src/dotdetector.cpp +++ b/modules/objdetect/src/dotdetector.cpp @@ -424,8 +424,8 @@ void DOTDetector::TrainParams::isConsistent() const 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"]; @@ -441,8 +441,8 @@ void DOTDetector::TrainParams::write( FileStorage& fs ) const { 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; @@ -557,14 +557,22 @@ float DOTDetector::DOTTemplate::computeTexturelessRatio( const cv::Mat& quantize 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; } @@ -601,8 +609,8 @@ void DOTDetector::read( FileNode& fn ) 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; @@ -612,11 +620,12 @@ void DOTDetector::read( FileNode& fn ) // 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 ); } } @@ -629,8 +638,8 @@ void DOTDetector::write( FileStorage& fs ) const 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]; @@ -639,12 +648,16 @@ void DOTDetector::write( FileStorage& fs ) const // 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 ) diff --git a/samples/cpp/dot.cpp b/samples/cpp/dot.cpp index 2bcdfd84e4..d1d3f30e78 100644 --- a/samples/cpp/dot.cpp +++ b/samples/cpp/dot.cpp @@ -41,15 +41,15 @@ int main( int argc, char **argv ) { 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 { @@ -71,6 +71,9 @@ int main( int argc, char **argv ) 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(); diff --git a/samples/cpp/dot_data/test/image_00002.png b/samples/cpp/dot_data/test/image_00002.png new file mode 100644 index 0000000000..e08ee234ef Binary files /dev/null and b/samples/cpp/dot_data/test/image_00002.png differ diff --git a/samples/cpp/dot_data/test/images.txt b/samples/cpp/dot_data/test/images.txt new file mode 100644 index 0000000000..9838dae6ad --- /dev/null +++ b/samples/cpp/dot_data/test/images.txt @@ -0,0 +1,2 @@ +image_00002.png + diff --git a/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png b/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png new file mode 100644 index 0000000000..ce0c2589e4 Binary files /dev/null and b/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png differ diff --git a/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png.mask.png b/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png.mask.png new file mode 100644 index 0000000000..526279682d Binary files /dev/null and b/samples/cpp/dot_data/train/black_coffee_cup/image_00000.png.mask.png differ diff --git a/samples/cpp/dot_data/train/black_coffee_cup/images.txt b/samples/cpp/dot_data/train/black_coffee_cup/images.txt new file mode 100644 index 0000000000..788ecbf905 --- /dev/null +++ b/samples/cpp/dot_data/train/black_coffee_cup/images.txt @@ -0,0 +1,2 @@ +image_00000.png + diff --git a/samples/cpp/dot_data/train/objects.txt b/samples/cpp/dot_data/train/objects.txt new file mode 100644 index 0000000000..91b2e6a408 --- /dev/null +++ b/samples/cpp/dot_data/train/objects.txt @@ -0,0 +1,7 @@ +black_coffee_cup +#blue_bowl +#blue_cup +#nvidia_cup +#rose_cup +#white_bowl +