Ask Your Question
0

CV_Assert fail error in ximgproc module

asked 2015-06-16 02:02:31 -0600

Devansh Dalal gravatar image

updated 2015-06-16 02:51:01 -0600

Problem : I have opencv 3.0 configured with extra modules on my system. I want to use the structured edge detector implemented in module ximgproc module. link : http://docs.opencv.org/trunk/d0/da5/t...

But it is giving following assert fail error on every image I tried till now.

512 512
OpenCV Error: Assertion failed (y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0])) in cv::Mat::ptr, file C:\Program Files\OpenCV\opencv3.0\sources\modules\core\include\opencv2/core/mat.inl.hpp, line 750
Press any key to continue . . .

This error is caused by the function

detectEdges(src,dst)

Actual file path on my system is opencv3.0\sources\modules\core\include\opencv2/core/mat.inl.hpp . I am using the model file given in samples ('model.yml.gz')

Thanks

Code used:

#include <algorithm>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include "opencv2/core/utility.hpp"
#include "ximgproc/include/opencv2/ximgproc.hpp"
#include "ximgproc\include\opencv2\ximgproc\structured_edge_detection.hpp"

using namespace std;
using namespace cv;
using namespace cv::ximgproc;

int main(int argc, const char** argv)
{
    std::string modelFilename = "model.yml.gz";
    std::string inFilename = "01.png"; // "lena.jpg"
    std::string outFilename = "" ;//parser.get<std::string>("o");
    Mat image = imread(inFilename,1);
    if (image.empty())
    {
        printf("Cannot read image file: %s\n", inFilename.c_str());
        return -1;
    }
    Size size = image.size();
    std::cout << size.height << " " << size.width << std::endl;
    if ((size.height < 31) || (size.width < 20)) {
        if (size.height < 31)
            size.height = 31;
        if (size.width < 15)
            size.width = 15;
        resize(image, image, size, 0.0, 0.0, INTER_AREA);
    }
    size.width = 400;
    size.height = 213;
    resize(image, image, size, 0.0, 0.0, INTER_AREA);
    image.convertTo(image, DataType<float>::type, 1.0 / 255.0);

    Mat edges = Mat(image.rows,image.cols , image.type(), float(0.0));
    Ptr<RFFeatureGetter> rfptr = createRFFeatureGetter();

    Ptr<StructuredEdgeDetection> pDollar =
        createStructuredEdgeDetection(modelFilename, rfptr);
    //cerr << "reaching till here " << endl;

    pDollar->detectEdges((const Mat)image , edges);
    //cerr << " unreached " << endl;
    if (outFilename == "")
    {
        namedWindow("edges", 1);
        imshow("edges", edges);
        waitKey(0);
    }
    else
        imwrite(outFilename, 255 * edges);
    return 0;
}
edit retag flag offensive close merge delete

Comments

Since this happens for every image, there is probably something wrong in your code.

boaz001 gravatar imageboaz001 ( 2015-06-16 02:34:29 -0600 )edit

i cannot reproduce your error.

berak gravatar imageberak ( 2015-06-16 03:06:05 -0600 )edit

You mean this code is running properly on your system?

Devansh Dalal gravatar imageDevansh Dalal ( 2015-06-16 04:00:16 -0600 )edit

ok, buffer overflow in structured_edge_detection.cpp, line 243 (probably due to your weird resize())

it seems to have a problem if height < width

berak gravatar imageberak ( 2015-06-16 04:12:54 -0600 )edit

So what is the solution ? Changing the input image(where width < height) doesn't improves the situation .

Devansh Dalal gravatar imageDevansh Dalal ( 2015-06-16 05:06:00 -0600 )edit

^^ hmm, true. 1st idea was wrong.

i'm now assuming, it's a rounding error.

changing cvRound to cvCeil in line 191 made it work for me. could you try ?

berak gravatar imageberak ( 2015-06-16 06:54:34 -0600 )edit

So Is it a bug or something is wrong with my approach or model or image due to which cvRound is required to change to cvCeil ? And if not a bug can you provide the correct way for doing it ?

Devansh Dalal gravatar imageDevansh Dalal ( 2015-06-17 00:39:39 -0600 )edit

i think it is a bug.

(unfortunately, i do not understand enough of it yet, to know, if the cvCeil fix is the correct one)

berak gravatar imageberak ( 2015-06-17 00:57:40 -0600 )edit

"Is there any good explanation or tutorial online ?" - sorry, i don't know. you could try to read the paper

berak gravatar imageberak ( 2015-06-18 01:19:02 -0600 )edit

How to make the modelFile like "model.yml"?

Sheng Liu gravatar imageSheng Liu ( 2015-09-18 22:48:27 -0600 )edit

StructuredEdgeDetection and createRFFeatureGetter are too hard for me. I don't know how to use them to solve my own program. So could you give me some advice?

Sheng Liu gravatar imageSheng Liu ( 2015-09-19 03:28:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-06-18 01:13:11 -0600

Devansh Dalal gravatar image

Thanks @berak , it worked for me also. So Is there any good explanation or tutorial online to learn how this structured edge detection works?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-06-16 02:02:31 -0600

Seen: 954 times

Last updated: Jun 16 '15