I have written the Doxa binarization library for this purpose:
https://github.com/brandonmpetty/Doxa/blob/master/Demo/Cpp/demoOpenCV.cpp
You can look at the algorithms for Sauvola, Niblack, Wolf, etc. I have a draft PR of AdOtsu that I am almost ready to push, for supporting Adaptive Otsu.
All written in C++ with no 3rd party dependencies, and bindings for Python and JavaScript. The above link show how to tie it into OpenCV.