DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.79k stars 391 forks source link

Method findSkew returns incorrectr angle #622

Open atgorvi opened 2 years ago

atgorvi commented 2 years ago

Before doing OCR i need to detect angle of text, and possibly rotate image but using findSkew function i get incorrect angle, what do I do wrong?

val skewImage: Pix = Binarize.otsuAdaptiveThreshold(Convert.convertTo8(ReadFile.readBitmap(bitmap))) val skew: Float = Skew.findSkew(skewImage) Log.i("skew", skew.toString()

findSkew_Issue Screenshot_20220525-083146_DocScanner )

DanBloomberg commented 2 years ago

The method works on binary images, typically text or graphics. pixFindSkew, by default, only finds skew angles between -7 and +7 degrees. It may have failed in your case either because the image wasn't binarized properly to extract the inverted text (white text on dark background), or because the skew angle is larger than 7 degrees (it is), or both.