Android counting white pixels in binary Mat.
I'm trying to count all non-black pixels in an ROI. Clearly I'm doing something wrong as it causes an exception when I try to use it.
rect = new Rect(touchX-100, touchY-100, 200, 200);
Mat roi = grayMat.submat(rect);
Imgproc.threshold(roi, roi, 240, 255, Imgproc.THRESH_BINARY);
if (Core.countNonZero(roi) > 0){
...
}
The countNonZero throws the exception
OpenCV Error: Assertion failed (src.channels() == 1 && func != 0) in int cv::countNonZero(cv::InputArray), file /home/reports/ci/slave/50-SDK/opencv/modules/core/src/stat.cpp, line 496
I'm too dumb to interpret the exception :P. I've taken a few different stabs at it and figured I'd just ask.
blind stab in the dark, here :
are you sure, something like (touchX-100), or (touchY-100) does not give negative values ? do some checks, if the rect is actually totally inside the grayMat
Thank you for the suggestion, but that doesn't appear to be it. Cheers :-)