Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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){ ... }

I've taken a few different stabs at it and figured I'd just ask.

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){
...
}

}

I've taken a few different stabs at it and figured I'd just ask.

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.