OpenCV Error: Assertion failed (size and height = 0) in imshow following adaptiveThreshold.
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:
(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?
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?
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...
Can you post your code please. 1/3 of the image looks like it is still a 3 channel image.
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?
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.
Trying to post code...too long for comment window.
Putting it below.