Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Svm error unsupported format or combination of formats ..

I'm trying to do object detection, training the SVM. The part of training is ok, he read the 2 images and create a file with the learned information. But when the code execute the predict function, he crash and below i post the error message (that i don't understand).

Do you have any idea why this happen?

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 ml="" ml.hpp="">

include <io.h>

using namespace cv;

int main() {

if(access("learned.svm",0)){
// Set up training data
int width = 1920, height = 1080;

int num_files=2;
std::string files[2]={"tonno1.jpg",
    "tonno2.jpg"};;

int img_area=width*height;
Mat training_mat(num_files,img_area,CV_32FC1);

for(int z=0;z<num_files;z++){
    Mat img_mat = imread(files[z],CV_32FC1);
    int ii = 0; // Current column in training_mat
    for (int i = 0; i<img_mat.rows; i++) {
        for (int j = 0; j < img_mat.cols; j++) {
            training_mat.at<float>(z,ii++) = img_mat.at<uchar>(i,j);
        }
    }
}

Mat labels(num_files,1,CV_32FC1);
labels.at<float>(0,0)=1.0;
labels.at<float>(1,0)=0.0;

// Set up SVM's parameters
CvSVMParams params;
params.svm_type    = CvSVM::C_SVC;
params.kernel_type = CvSVM::POLY;
params.gamma = 3;
params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
params.degree=10;

// Train the SVM
CvSVM svm;
svm.train(training_mat, labels, Mat(), Mat(), params);
svm.save("learned.svm");

return 1;

}

CvSVM svm;
svm.load("learned.svm");

Mat img;
img=imread("Sequenza 01.Immagine001.jpg",CV_32FC1);

float f=svm.predict(img);
std::cout<<f<<std::endl;

waitKey(0);

}

Here is the image:

image description

click to hide/show revision 2
No.2 Revision

updated 2013-09-18 07:21:14 -0600

berak gravatar image

Svm error unsupported format or combination of formats ..

I'm trying to do object detection, training the SVM. The part of training is ok, he read the 2 images and create a file with the learned information. But when the code execute the predict function, he crash and below i post the error message (that i don't understand).

Do you have any idea why this happen?

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 ml="" ml.hpp="">

include <io.h>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>

#include <io.h>

using namespace cv;

cv; int main() {

{

    if(access("learned.svm",0)){
 // Set up training data
 int width = 1920, height = 1080;

 int num_files=2;
 std::string files[2]={"tonno1.jpg",
     "tonno2.jpg"};;

 int img_area=width*height;
 Mat training_mat(num_files,img_area,CV_32FC1);

 for(int z=0;z<num_files;z++){
     Mat img_mat = imread(files[z],CV_32FC1);
     int ii = 0; // Current column in training_mat
     for (int i = 0; i<img_mat.rows; i++) {
         for (int j = 0; j < img_mat.cols; j++) {
             training_mat.at<float>(z,ii++) = img_mat.at<uchar>(i,j);
         }
     }
 }

 Mat labels(num_files,1,CV_32FC1);
 labels.at<float>(0,0)=1.0;
 labels.at<float>(1,0)=0.0;

 // Set up SVM's parameters
 CvSVMParams params;
 params.svm_type    = CvSVM::C_SVC;
 params.kernel_type = CvSVM::POLY;
 params.gamma = 3;
 params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
 params.degree=10;

 // Train the SVM
 CvSVM svm;
 svm.train(training_mat, labels, Mat(), Mat(), params);
 svm.save("learned.svm");

 return 1;

 }

 CvSVM svm;
 svm.load("learned.svm");

 Mat img;
 img=imread("Sequenza 01.Immagine001.jpg",CV_32FC1);

 float f=svm.predict(img);
 std::cout<<f<<std::endl;

 waitKey(0);

}

}

Here is the image:

image description