OpenCV SVM HOG检测器svm.predict()异常

时间:2016-02-25 19:28:12

标签: c++ opencv svm descriptor

我正在使用Visual Studio 2013和OpenCV 2.4.11 我训练了svm与positiv和负样本的XML文件。 这是我想要与某些图像进行比较的代码。构建是可以的,但是当我运行调试时,它会在svm.predict()上中断。

  

ConsoleApplication2.exe中0x00007FFF43148A5C处的未处理异常:Microsoft C ++异常:cv ::内存位置0x000000AF2D16ECA0的异常。

svm附近有局部变量

  

信息不可用,没有为opencv_ml2411d.dll加载符号

任何想法或线索有什么不对?

void compare()
{

    //variables  
    char FullFileName[100];
    char FirstFileName[100] = "E:\Dropbox/DIP/Images/Train/";  
    int FileNum = 5; //262;  

    //Load trained SVM xml data  

    CvSVM svm;
    svm.load("E:/Dropbox/DIP/Images/Train/trainedSVM.xml");

    //count variable  
    int nnn = 0, ppp = 0;

    for (int i = 1; i< FileNum; ++i)
    {
        sprintf_s(FullFileName, "%s%d.jpg", FirstFileName, i + 1);
        //printf("%s\n", FullFileName);  

        //read image file  
        Mat img, img_gray;
        img = imread(FullFileName);

        //resizing  
        resize(img, img, Size(64, 48)); //Size(32*2,16*2)); //Size(80,72) );   
        //gray  
        cvtColor(img, img_gray, CV_RGB2GRAY);

        //Extract HogFeature  
        HOGDescriptor d(Size(32, 16), Size(8, 8), Size(4, 4), Size(4, 4), 9);
        vector< float> descriptorsValues;
        vector< Point> locations;
        d.compute(img_gray, descriptorsValues, Size(0, 0), Size(0, 0), locations);
        //vector to Mat  
        Mat fm = Mat(descriptorsValues);

        //Classification whether data is positive or negative   HERE COME PROBLEM
        int result = svm.predict(fm); //svm.predict(fm);
        printf("%s - > %d\n", FullFileName, result);

        //Count data  
        if (result == 1)
            ppp++;
        else
            nnn++;

        //show image  
        imshow("origin", img);

        waitKey(5);
    }

    printf(" positive/negative = (%d/%d) \n", ppp, nnn);
}

0 个答案:

没有答案