From b3f68d29e725861c0b535ee665ea712823f8d363 Mon Sep 17 00:00:00 2001 From: Maria Dimashova Date: Mon, 2 Jul 2012 09:21:55 +0000 Subject: [PATCH] fixed bow sample --- samples/cpp/bagofwords_classification.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/cpp/bagofwords_classification.cpp b/samples/cpp/bagofwords_classification.cpp index 100467d8ad..559e77bfcf 100644 --- a/samples/cpp/bagofwords_classification.cpp +++ b/samples/cpp/bagofwords_classification.cpp @@ -2014,7 +2014,7 @@ struct VocabTrainParams // It shouldn't matter which object class is specified here - visual vocab will still be the same. int vocabSize; //number of visual words in vocabulary to train int memoryUse; // Memory to preallocate (in MB) when training vocab. - // Change this depending on the size of the dataset/available memory. + // Change this depending on the size of the dataset/available memory. float descProportion; // Specifies the number of descriptors to use from each image as a proportion of the total num descs. }; @@ -2126,8 +2126,10 @@ static Mat trainVocabulary( const string& filename, VocData& vocData, const Voca if( !readVocabulary( filename, vocabulary) ) { CV_Assert( dextractor->descriptorType() == CV_32FC1 ); - const int descByteSize = dextractor->descriptorSize()*4; - const int maxDescCount = (trainParams.memoryUse * 1048576) / descByteSize; // Total number of descs to use for training. + const int elemSize = CV_ELEM_SIZE(dextractor->descriptorType()); + const int descByteSize = dextractor->descriptorSize() * elemSize; + const int bytesInMB = 1048576; + const int maxDescCount = (trainParams.memoryUse * bytesInMB) / descByteSize; // Total number of descs to use for training. cout << "Extracting VOC data..." << endl; vector images; @@ -2142,9 +2144,8 @@ static Mat trainVocabulary( const string& filename, VocData& vocData, const Voca while( images.size() > 0 ) { - if( bowTrainer.descripotorsCount() >= maxDescCount ) + if( bowTrainer.descripotorsCount() > maxDescCount ) { - assert( bowTrainer.descripotorsCount() == maxDescCount ); #ifdef DEBUG_DESC_PROGRESS cout << "Breaking due to full memory ( descriptors count = " << bowTrainer.descripotorsCount() << "; descriptor size in bytes = " << descByteSize << "; all used memory = "