Ask Your Question

f1x's profile - activity

2020-12-14 16:51:11 -0600 received badge  Popular Question (source)
2014-08-28 00:06:30 -0600 received badge  Editor (source)
2014-08-27 22:45:25 -0600 asked a question HOGDescriptor OpenCV dsize.area() assertion failed

I'm trying to train SVM and use it inside HOGDescrpitor from OpenCV.

The xml file was succesfully generated and loaded by HOGDescriptor but when I try to detect some object, then assertion is occurred:

OpenCV Error: Assertion failed (dsize.area() || (inv_scale_x > 0 && inv_scale_y > 0)) in resize, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/imgwarp.cpp, line 1825 terminate called after throwing an instance of 'tbb::captured_exception' what(): /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/imgwarp.cpp:1825: error: (-215) dsize.area() || (inv_scale_x > 0 && inv_scale_y > 0) in function resize

To implement SVM trainer I used hints from http://stackoverflow.com/questions/14694810/using-opencv-and-svm-with-images

Generated XML file has about 144Kbytes. For positive and negative samples I used images of size 64x128 (2000 for positive and 2000 for negative)

Parameter for SVM trainer:

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

Code for detection:

int main()
{
    HOGDescriptor hog();
    if(!hog.load("/home/bin/hogdescriptor.xml"))
    {
        std::cout << "Failed to load file!" << std::endl;
        return -1;
    }

    VideoCapture cap(0);
    if(!cap.isOpened())
    {
        std::cout << "Error opening camera!" << std::endl;
        return 1;
    }

    Mat testImage;

    while ((cvWaitKey(30) & 255) != 27)
    {
        cap >> testImage;
        detectTest(hog, testImage);
        imshow("HOG custom detection", testImage);
    }

    return EXIT_SUCCESS;
}

void showDetections(const vector<Rect>& found, Mat& imageData) {
    for (const Rect& rect : found)
    {
        Point rectPoint1;
    rectPoint1.x = rect.x;
        rectPoint1.y = rect.y;

        Point rectPoint2;
        rectPoint2.x = rect.x + rect.width;
        rectPoint2.y = rect.y + rect.height;

        std::cout << "detection x: " << rect.x << ", y: " << rect.y << std::endl;

        rectangle(imageData, rectPoint1, rectPoint2, Scalar(0, 255, 0));
    }
}

void detectTest(const HOGDescriptor& hog, Mat& imageData)
{
    std::cout << "Trying to detect" << std::endl;

    vector<Rect> found;
    int groupThreshold = 2;
    Size padding(Size(32, 32));
    Size winStride(Size(8, 8));
    double hitThreshold = 0.; // tolerance
    hog.detectMultiScale(imageData, found, hitThreshold, winStride, padding, 1.05, groupThreshold);
//    hog.detectMultiScale(imageData, found);

    std::cout << "Trying to show detections" << std::endl;
    showDetections(found, imageData);
}

Generated XML:

<?xml version="1.0"?>
<opencv_storage>
<my_svm type_id="opencv-ml-svm">
  <svm_type>C_SVC</svm_type>
  <kernel><type>LINEAR</type></kernel>
  <C>1.</C>
  <term_criteria><epsilon>2.2204460492503131e-16</epsilon>
    <iterations>10000</iterations></term_criteria>
  <var_all>8192</var_all>
  <var_count>8192</var_count>
  <class_count>2</class_count>
  <class_labels type_id="opencv-matrix">
    <rows>1</rows>
    <cols>2</cols>
    <dt>i</dt>
    <data>
      -1 1</data></class_labels>
  <sv_total>1</sv_total>
  <support_vectors>
    <_>
      -9.25376153e-05 -9.25376153e-05 -9.25376153e-05 -9.25376153e-05 ...and many, many...</_></support_vectors>
  <decision_functions>
    <_>
      <sv_count>1</sv_count>
      <rho>-1.</rho>
      <alpha>
        1.</alpha>
      <index>
        0</index></_></decision_functions></my_svm>
</opencv_storage>

Can someone explain me this assertion or maybe can provide some solution for this problem? I spent almost 3 days to fix this but without any success... Thanks in advance!