Getting error in mat.hpp while training data
I am doing feature extraction using surf and bow , but after i add descriptors in loop
for (i = all_names.begin(); i != all_names.end(); ++i)
{
Dir=( (count < files.size() ) ? ImagesDirectory : ImagesDirectory_2);
Mat row_img = cv::imread( Dir +*i, 0 );
detector.detect( img, keypoints);
CollectBestKeypoints(keypoints, 10); // getting 10 best keypoints
extractor->compute( img, keypoints, descriptors);
descriptors.resize(1,1);
bow.add(descriptors);
++count;
}
than after loop this is my code and i am getting runtime error here :
Mat vocabulary = bowTrainer.cluster();
dextract.setVocabulary(vocabulary);
//may getting error here
Mat training_mat(num_img,dictionarySize,CV_32FC1);
Mat labels(0,1,CV_32FC1);
Second loop for training data :
for (k = all_names.begin(); k != all_names.end(); ++k)
{
Dir=( (count_2 < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);
Mat row_img_2 = cv::imread( Dir +*k, 0 );
detector.detect( row_img_2, keypoints);
RetainBestKeypoints(keypoints, 20);
dextract.compute( row_img_2, keypoints, descriptors_1);
descriptors_1.reshape(1,1);
// Getting Error Here
training_mat.push_back(descriptors_1);
labels.at< float >(count_2, 0) = (count_2<nb_cars)?1:-1; // 1 for car, -1 otherwise*/
++count_2;
}
here is initialization :
int dictionarySize = 1500;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.001);
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor dextract(extractor,matcher);
Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
Error :
OpenCV Error: Assertion failed (dims<=2 && data data && (unsigned) i < (unsigned)size..p[0] && (unsigned) (i1*DataType<_Tp>::channels) < (unsigned) size.[p1] * channels()) && ((((sizeof(size_t)<<28)|0x8442211)>>((DataType<_Tp>::depth)&((1<<3)-1))*4)&15)==eleSize1()) in unknown function, file c:\opencv\2.4.4\build\include\opencv2\core\mat.hpp, line 537
I'm really not sure, but it seems to me that you have too few keypoints (smaller then the number of clusters). Is that the possible problem?
Im still having the idea that this is the same problem illustrated in http://answers.opencv.org/question/18448/how-to-detect-object-from-video-using-svm/, @Guanta, I think more code can be found there. @FLY Can you please orden your questions more like this one? The other question is quite unclear on what you try to achieve and updating it every day just to bump it, is not the way things get handled here...
@StevenPuttemans Sir , i am not updating it every day to give it bump , when i get solve something than i update it here , so that i didn't get answer for that , The link you mention is edit because i remove some code from it because the user SR suggest me to mention only the important part of the code and that code was completely different from here , that code take images as input, i am new to forum , new to opencv , and new to c++ , thats why i may take time to settle completely , but every new take some time to learn and start.