svm_train.exe has stopped working

asked 2017-09-13 18:12:15 -0500

I am trying to train SVM classifier using SIFT feature and Bag Of Word (BOW). But my program is not running, but it is showing no error in my code. I am not able to figure out my faults. Can anybody give me any suggestion? Thanks in advance. Here is a piece of code by which I have declared variables and SVM classifier parameter.

Ptr<FeatureDetector> features = FeatureDetector::create("SIFT");
Ptr<DescriptorExtractor> descriptor = DescriptorExtractor::create("SIFT");
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");

std::vector<KeyPoint> keypoints;
Mat desc;

//defining terms for bowkmeans trainer
int cluster = 5;
int retries = 1;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.00001);
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(cluster, tc, retries, flags);
Mat vocubulary;
BOWImgDescriptorExtractor bowDE(descriptor, matcher);

CvSVMParams params;
params.svm_type    = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);

Mat features1, features2;
Mat bowDescriptor, bowDescriptor2;

int dictionarySize=100 ;
string folder= argv[1];
glob(folder, names);
Mat trainme(0, dictionarySize, CV_32FC1);
Mat labels(0, 1, CV_32FC1);

By the following part I tried to obtain features from images.

for(unsigned int i =0; i<names.size();i++)
    Mat img = imread( names[i], CV_LOAD_IMAGE_GRAYSCALE );

    { cout<< " --(!) Error reading images " << endl; return -1; }

    features->detect(img, keypoints);
    descriptor->compute(img, keypoints, features1);
    bowDE.compute(img, keypoints, bowDescriptor);
    float label = 1.0;
    cout<<"Program is running"<<endl;

By the following part, I trained SVM classifier

Mat dictionary = bowTrainer.cluster();


Mat tryme(0, dictionarySize, CV_32FC1);
Mat tryDescriptor;
Mat test = imread("C:\\Users\\ASHRAF\\Desktop\\Oslo\\ResizedSamples\\24.bmp", 0);
vector<KeyPoint> keypoints3;
features->detect(test, keypoints3);
bowDE.compute(test, keypoints3, tryDescriptor);


edit retag flag offensive close merge delete


the labels should be integer, not float

(unfortunately, i cannot test your outdated 2.4 code)

berak gravatar imageberak ( 2017-09-13 19:56:08 -0500 )edit

try to set: cv::setBreakOnError(true);

maybe this gives you some more information

VxW gravatar imageVxW ( 2017-09-14 02:28:21 -0500 )edit