Opencv has an adaptive threshold function. With OpenCV4Android it is something like this:
Imgproc.adaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, C);
Example:
Imgproc.adaptiveThreshold(mInput, mInput, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 15, 4);
Regarding the choice of parameters, you should read the documents for more details. Choosing the right threshold for each image is a completely different matter.
source share