Getting error using SVM with SURF [closed]

asked 2013-08-23 04:54:03 -0500

FLY gravatar image

updated 2013-08-24 02:07:14 -0500

Below is my code , which is running fine but after a long processing it show me the run time error

//FlannBasedMatcher matcher;
std::vector< DMatch > matches;
double max_dist = 0; 
double min_dist = 100;

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();

//SurfDescriptorExtractor extractor;
SurfFeatureDetector detector(500);
std::vector<KeyPoint> keypoints;
int dictionarySize = 1500;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.001);
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bow(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor dextract(extractor,matcher);
// Initialize your training set.
cv::Mat training_mat(num_img,image_area,CV_32FC1);
cv::Mat labels(num_img,1,CV_32FC1);
cv::Mat tmp_dst( 500, 450, CV_8UC1 ); // to the right size for resize    
std::vector<string> all_names;

all_names.assign(files.begin(),files.end());
all_names.insert(all_names.end(), files_no.begin(), files_no.end());

// Load image and add them to the training set
int count = 0;
vector<string>::const_iterator i;
string Dir;
for (i = all_names.begin(); i != all_names.end(); ++i)
{
    Dir=( (count < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);

    tmp_img = cv::imread( Dir +*i, 0 );

    resize( tmp_img, tmp_dst, tmp_dst.size() );

    Mat row_img = tmp_dst;

    detector.detect( row_img, keypoints);

    extractor->compute( row_img, keypoints, descriptors_1);

    bow.add(descriptors_1);

    ++count;
}

int count_2=0;
vector<string>::const_iterator k;
Mat vocabulary = bow.cluster();
dextract.setVocabulary(vocabulary);
for (k = all_names.begin(); k != all_names.end(); ++k)
{
    Dir=( (count_2 < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);

    tmp_img = cv::imread( Dir +*k, 0 );

    resize( tmp_img, tmp_dst, tmp_dst.size() );

    Mat row_img = tmp_dst;

    detector.detect( row_img, keypoints);

    dextract.compute( row_img, keypoints, descriptors_1);

    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;
}

Error :

enter image description here

This code is implemented with the help of pseudo code given by @Mathieu Barnachon here

and how do i know that now my data is trained according to my need and now i can implement on my real time app to detect objects from video

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by SR
close date 2013-08-23 06:42:19.475592

Comments

This is a duplicate of http://answers.opencv.org/question/19325/how-to-know-my-svm-is-trained-accordingly/. It is still not a real question as it does not (1) provide a small piece of code or a minimal example and it further (2) does not narrow the problem down to a specific problem and thus a specific question.

SR gravatar imageSR ( 2013-08-23 06:38:56 -0500 )edit

Long questions waste the time of those people willing to help you. This indicates you are not willing to invest your time to address the problem but expect others to do so.

SR gravatar imageSR ( 2013-08-23 06:40:22 -0500 )edit

Last note: Your formatting and tagging might also be improved.

SR gravatar imageSR ( 2013-08-23 06:41:45 -0500 )edit