0

I am currently working on training and testing greyscale images. So far I've trained the images using the svm.train() method.

However, I fail at testing the images. So far My Code for Testing the Images:

for (int i = 0; i < test_files.size(); i++){
    temporary_image = imread(test_files[i], 0);
    Mat image1d(1, temporary_image.cols, CV_32FC1);
    //Mat row_image = temporary_distance.reshape(1, 1);
    float result = svm.predict(image1d);
    printf("\n%d\n", result);
} 

Could you please tell me, how can I fix the problem?

svm.predict(image1d) --> This gives the error.

Whether I make it float result = svm.predict(image1d) or svm.predict(image1d) simply same problem occurs.

Before Asking this question I read

Error on SVM using images

using OpenCV and SVM with images

Ahmet
  • 7,527
  • 3
  • 23
  • 47
  • `image1d` must be a matrix with one sample per row (so in your case 1 row), and number of columns equal to the size of your descriptor. Do you used in training and testing image with the same size? – Miki Dec 21 '15 at 17:11
  • And you usually don't use classifiers directly on the image, but on some features extracted from the image – Miki Dec 21 '15 at 17:12
  • @Miki Thanks for the reply! Yes I exactly use training and testing image with the same size. About your 2nd comment, could you please show me how do you do feature extraction from image? of course related with svm. – Ahmet Dec 21 '15 at 17:16
  • Have a look at Bag of (Visual) Words for example, this is too broad for a comment (and even for a single answer :D) – Miki Dec 21 '15 at 17:19
  • 1
    What error do you have? You probably need to convert your image to CV_32F. You can use `convertTo` – Miki Dec 21 '15 at 17:20

0 Answers0