Ask Your Question
0

OpenCV Error: Assertion failed (size and height = 0) in imshow following adaptiveThreshold.

asked 2015-03-24 16:03:25 -0600

ClintFromVa gravatar image

This is a weird one.

adaptiveThreshold(src_grn, scratch, max_BINARY_value, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 3, weight); imshow(output_window_name2, scratch);

gives 'unhandled exception' in debug mode, with the second line being indicated as the next to execute after the break. In release mode, the command line shows:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, fi le C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\highgui\src\windo w.cpp, line 266

with the same input file.

src_grn is an image of CV_8UC1 type (green channel extracted from an RGB image with mixChannels earlier). Mat scratch is declared earlier but not initialized to any particular size or type.

If I continue instead of breaking after the exception it looks like the top 1/3 of the image gets filtered. Commenting out the imshow prevents the error (not that that is helpful).

Putting the imshow back in and setting the window to autosize spits out: image description

(sorry for the screen grab, it won't let me copy the text) something about 'Bad flag' in core\src\array.cpp, line 2489.

Commenting the adaptiveThreshold line gives my source image back again, displayed normally.

This is OpenCV3.0 under VS13 express.

Ideas?

edit retag flag offensive close merge delete

Comments

Do I understand it correctly: In release mode all is fine, but in debug mode you get this error? If so, do you use the correct libraries (such ones with the "d" at the end) in debug mode?

matman gravatar imagematman ( 2015-03-24 17:00:29 -0600 )edit

No, neither mode works. Release mode, invoked from the command line, fails with a windows 'program has stopped working' popup and the quoted text on the command line, '... line 266.' Debug mode pops up the 'unhandled exception' window, indicates the imshow is the next to execute, and opens a second console window. This second window today matches the release mode one, blaming an assert in window.cpp line 266, yesterday was different (screenshot above). I rebooted the PC and cleaned the project prior to this, no other changes.

I just checked, I'm definitely using the 'd' version libraries in debug mode.

Off to try a demo straight from the documentation...

ClintFromVa gravatar imageClintFromVa ( 2015-03-25 07:17:31 -0600 )edit

Can you post your code please. 1/3 of the image looks like it is still a 3 channel image.

matman gravatar imagematman ( 2015-03-25 14:45:02 -0600 )edit

OK, I'm working on a cleaned up version to isolate the problem.

When I said 1/3 of the image I meant the top 1/3 with the remaining pixels being unchanged. And that number was approximate anyway.

I was trying to set this up so I could use a trackbar to set the threshold. I just copied a tutorial example and dropped in a different function. The examples use global variables liberally (bad form but hey, it is a tutorial). In this case, inside the function the data Mat was blank. That makes sense with the assert that threw the error but I don't know how the global variable didn't work.

This has moved far away from where I started - what is good form here for this question? Retag it? Close it and ask again better?

ClintFromVa gravatar imageClintFromVa ( 2015-03-26 09:39:50 -0600 )edit

It will be easier for me to check your code, than to guess what it could be. When you say, you use an example and dropped it in an function there could be a problem when you pass a 'cv::Mat src' inside. In this case pass 'cv::Mat &src' in the function.

matman gravatar imagematman ( 2015-03-26 14:09:27 -0600 )edit

Trying to post code...too long for comment window.
Putting it below.

ClintFromVa gravatar imageClintFromVa ( 2015-03-30 12:46:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-03-30 12:47:29 -0600

ClintFromVa gravatar image

updated 2015-03-30 13:37:29 -0600

@matman, Thanks for the attention to this.

EDIT - problem was, I redefined "src" in main so the global variable used in other functions was still blank (hangs head in newbie shame).

I'm deleting the rest of this...

Thanks.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-03-24 16:03:25 -0600

Seen: 4,854 times

Last updated: Mar 30 '15