Ask Your Question

Hi, I am trying to use bowtrainer for image classification(opencv 2.4.6 + VS2010). I am getting an error.

asked 2015-12-13 03:24:05 -0600

Shadow gravatar image

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

Here is the code:

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);
Mat dictionary = bowTrainer.cluster();
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-12-13 03:33:52 -0600

berak gravatar image

updated 2015-12-13 03:34:31 -0600

to do kmeans clustering, you need more input features(N) than desired clusters(K)

since you only got 2 images, you likely get less than 1500 descriptors.

ofc. you need more images, but for now try to reduce dictionarySize to like 100

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-12-13 03:24:05 -0600

Seen: 313 times

Last updated: Dec 13 '15