Ask Your Question
0

Getting error in mat.hpp while training data

asked 2013-08-27 15:09:16 -0500

FLY gravatar image

updated 2013-08-29 08:41:41 -0500

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
edit retag flag offensive close merge delete

Comments

1

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?

GilLevi gravatar imageGilLevi ( 2013-08-28 02:38:23 -0500 )edit
1

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 gravatar imageStevenPuttemans ( 2013-08-28 03:46:04 -0500 )edit
1

@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.

FLY gravatar imageFLY ( 2013-08-28 09:50:15 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-08-29 12:28:21 -0500

FLY gravatar image

updated 2013-08-29 12:31:07 -0500

As @Guanta and @GilLevi mentions , they are also the causes of error's . Thanks to them

I find out some error's on my own , the one main error is in labeling , here

Mat labels(0,1,CV_32FC1);

This should be used as :

Mat labels(num_img,1,CV_32FC1);

After this the error is here :

training_mat.push_back(descriptors_1);

this should be used as

my_img.convertTo( training_mat.row(count_2), CV_32FC1 );

Changing these two works for me , but to be honest i have a little difficultly in understanding why this gives error :

training_mat.push_back(descriptors_1);
edit flag offensive delete link more
2

answered 2013-08-28 03:35:29 -0500

Guanta gravatar image

As @GilLevi pointed out, the error tells you that you try to cluster with less features than number of clusters. Since you haven't showed the whole code it's also not clear how your bow and bowTrainer are related. I'd also add an assertion after imread if your row_img-mat isn't empty.

edit flag offensive delete link more

Comments

@Guanta +1 ,Sorry , it is bow.cluster not bowTrainer.cluster , i am not going to update it , otherwise community members going to said that i want to bump it , as i check line by i got that i am getting error here training_mat.push_back(descriptors_1);

FLY gravatar imageFLY ( 2013-08-28 10:06:30 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-08-27 15:09:16 -0500

Seen: 1,590 times

Last updated: Aug 29 '13