Ask Your Question

Rafajafar's profile - activity

2015-09-01 12:07:39 -0600 received badge  Nice Question (source)
2013-10-18 14:34:33 -0600 asked a question Any consideration for a D language version of OpenCV?

Hey,

I've been really digging into the D language and I feel that OpenCV could benefit a lot from its features. I was wondering if there's any interest in creating a D port of OpenCV?

2013-04-18 02:03:58 -0600 received badge  Editor (source)
2013-04-18 01:33:10 -0600 received badge  Student (source)
2013-04-18 01:22:35 -0600 asked a question Why doesn't OpenCV complain when you address out of bounds?

I just spent half a day debugging a very large problem for a memory issue. The memory issue was weird for a lot of reasons, to the point that guys on #c++ where saying, "I dunno man, that's ... weird."

What was happening, I found after a lot of valgrind and gdb, is that I was able to address outside of the space of Mat.

Here's the code in question that caused the problem:

    vector< Mat > dripped_img, line_img, pixel;
    for(int i = 0; i < TESTS ; i++){
            dripped_img.push_back(src_img);
            transpose(src_img, src_img);
            line_img.push_back(Mat::zeros(src_img.cols, 1, CV_8UC3));
            pixel.push_back(Mat::zeros(1,1, CV_8UC3));
    }

See what might cause the problem? Here's the simple fix I was looking for:

    vector< Mat > dripped_img, line_img, pixel;
    for(int i = 0; i < TESTS ; i++){
            dripped_img.push_back(src_img);
            line_img.push_back(Mat::zeros(src_img.cols, 1, CV_8UC3));
            pixel.push_back(Mat::zeros(1,1, CV_8UC3));
            transpose(src_img, src_img);
    }

Might be a bit ambiguous, but dripped_img and line_img are related. This means that when I iterate through dripped_img and stored into line_img, if those columns don't match, whoops.

Total logic error on my part, I know. However, what was weird was how little error reporting happened when I did this. What I saw the error as was a function which segfaulted on return. I'm of the mind you should be able to direct-index past the bounds of the Matrix, though.

Is there a reason why this behaviour is allowed in OpenCV?

EDIT: I said "direct-index" makes sense. But I was using Mat.at(). Maybe that needs some checking.