GaussianBlur crashes

OCV 4.5.3; C++; Visual Studio 2017; Windows 10

I am beating my head against the wall trying to figure this out. I have other places in my app that uses GaussianBlur and they all work fine. However, I am trying it in another place and I get a crash. Trying to tack it down I have simplified it down to this and it still crashes.

cv::Mat mPhoto = imread(“NightTarget.jpg”, IMREAD_COLOR);
if (!mPhoto.data) {
// Error
}
cv::Mat mBlured;
cv::GaussianBlur(mPhoto, mBlured, cv::Size(10, 10), 0, 0); // Crashes

Any ideas whatsoever? I have followed the GaussianBlur code in Debug mode for more than 100 lines and finally gave up trying to track it. GetLastError just returns 0.

PS. A quick follow up as I keep trying to figure out the problem. If, instead of GaussianBlur is use either of these:

cv::blur(mPhoto, mBlured, cv::Size(10, 10), cv::Point(-1,-1), BORDER_DEFAULT);
// OR
cv::medianBlur(mPhoto, mBlured, 11);

I get no error.

Ed

@ehardin

From docs: kernel size must be positive and odd. Please try with Size(9,9).

https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaabe8c836e97159a9193fb0b11ac52cf1

I knew medianBlur had to be odd but I forgot that GaussianBlur had to odd as well.

Here is the unusual thing. Before you replied I went to another area in my program that used Gaussian and the size there was 3, 3. I tried that in the line that was crashing, and all of a sudden it worked. I then, not realizing yet about the odd requirement, changed it back to 10, 10 and it continued to work.

I’ll make sure to keep it odd from now on but why it is now, all of a sudden, working with 10 when just previously, before testing with 3, it was crashing. Seems like switching from 3 and then back to 10 jiggled something loose. God knows but I really appreciate you pointing out the odd requirement It was tucked in the middle of a sentence that was not re-reading. Thanks again.

It crash with an error message :

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.4-pre) Error: Assertion failed (ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1) in cv::createGaussianKernels, file G:\Lib\opencv\modules\imgproc\src\smooth.dispatch.cpp, line 294

What does this error mean do you think.

I spoke too soon. This was all going to be a test and my original memory variable for the size was 100. So after it was working again, I changed the memory variable to 101 and tried again. It crashed. I reset it back to a hard coded 3 and it continues to crash.

This cv::Size is the only thing that I changed but it seems that having crashed once, it will continue to crash no matter what. It seems that I will have to keep changing the size to odd number until it works again.

Actually I should ask how did you get this error message. I was just using Windows GetLastError.

I see now that it is what the debugger is showing. I’m just too exasperated at this point to think straight…

With size 3, 3 I’m getting the error"

static void cv_terminate_handler() {
std::cerr << “OpenCV: terminate handler is called! The last OpenCV error is:\n”;
dumpException(cv_terminate_handler_exception);
if (false /cv_old_terminate_handler/) // buggy behavior is observed with doubled “abort/retry/ignore” windows
cv_old_terminate_handler();
abort();
}

Still doesn’t mean anything to me other than it crashed

Assertion shows the formula that triggered the error, in this case ksize.width % 2 == 1 && ksize.height % 2 == 1 means odd size.

Not a friendly error message, for sure. There is a lot of room for improvement in error messages in OpenCV and in C++ in general (btw, C++20 begun working on this).

Meanwhile, we can thanks the open source programmers for using assertion, otherwise it is pretty difficult to pinpoint the cause.

If the problem persist, please paste it here. Ii would be appreciate a cout message showing the size right before GaussianBlur, so we can see the actual size triggering the error (if that is the cause).

I just run your code and error message is written in console mode (release mode). I think you can catch this error

This is not the error message itself, it is the code asking for termination because of an error.

The actual message is something like @laurent.berger posted.

Take it back. This latest crash is not with the GaussianBlur but with the next line

minMaxLoc(mBlured, &dMinVal, &dMaxVal, &pMinLoc, &pMaxLoc);

Jeeeeze, this has not been one of my better days.