Ask Your Question

Shadow's profile - activity

2016-03-03 03:58:04 -0600 received badge  Supporter (source)
2016-03-03 03:52:24 -0600 asked a question Insufficient Memory Error: Bag of Words OpenCV 2.4.6 Visual Studio 2010

I am implementing the Bag of words Model using SURF and SIFT features and SVM Classifier. I want to train(80% of 2876 images) and test(20% of 2876 images) it. I have kept dictionarySize set to 1000. My Computer configuration is intel Xeon(2 processors)/ 32GB RAM/ 500GB HDD. Here, images are read whenever necessary instead of storing them. like,

std::ifstream file("C:\\testFiles\\caltech4\\train0.csv", ifstream::in);
if (!file) 
{
    string error_message = "No valid input file was given, please check the given filename.";
    CV_Error(CV_StsBadArg, error_message);
}
string line, path, classlabel;
printf("\nReading Training images................\n");
while (getline(file, line)) 
{
    stringstream liness(line);
    getline(liness, path, separator);
    getline(liness,classlabel);
    if(!path.empty()) 
    {
        Mat image = imread(path, 0);


        cout << " " << path << "\n";
        detector.detect(image, keypoints1);
        detector.compute(image, keypoints1,descriptor1);
        featuresUnclustered.push_back(descriptor1); 
    }
}

Here, the train0.csv contains the paths to the images with the labels. It stops from this loop while reading the images, computing the descriptor and adding it to the features to be clustered. Following error apprears on the console:

image description

2016-03-03 03:45:37 -0600 received badge  Scholar (source)
2015-12-13 03:29:46 -0600 asked a question Hi, I am trying to use bowtrainer for image classification(opencv 2.4.6 + VS2010). I am getting an error.

"OpenCV Error: Assertion failed (N >=k) in unknown function, file ......\src\opencv\modules\core\src\matrix.cpp, line 2717"

Here is the code:

cv::initModule_nonfree();
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
SurfFeatureDetector detector(500);

TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.001);
int dictionarySize = 1500;
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(extractor, matcher);

Mat im1 = imread("image1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat im2 = imread("image2.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat descriptor1,descriptor2;
vector<KeyPoint> keypoints1,keypoints2;

detector.detect(im1, keypoints1);
detector.compute(im1, keypoints1,descriptor1);
detector.detect(im2, keypoints2);
extractor->compute(im2, keypoints2,descriptor2);
bowTrainer.add(descriptor1);
bowTrainer.add(descriptor2);
Mat dictionary = bowTrainer.cluster();
bowDE.setVocabulary(dictionary);