How to use OpenCV to process image so that the text become sharp and clear?

前端 未结 2 1062
逝去的感伤
逝去的感伤 2021-01-30 14:52

Wanted to achieve something like this: http://www.leptonica.com/binarization.html

While searching for solutions, most of the answers were general instructions such as ad

相关标签:
2条回答
  • 2021-01-30 15:17

    Instead of using Imgproc.THRESH_BINARY_INV use Imgproc.THRESH_BINARY only as _INV is inverting your image after binarisations and resulted is the said output shown above in your example.

    correct code:

    Imgproc.adaptiveThreshold(imageMat, imageMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 4);
    
    0 讨论(0)
  • 2021-01-30 15:30

    Well, you're almost there. Just try these modifications:

    Instead of

        Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0);
    

    try:

         cvSmooth(imageMat, imageMat, CV_MEDIAN, new Size(3, 3), 0);
    

    check the syntax, may not exactly match

    The link you posted uses thresholding of Otsu, so try this:

     Imgproc.threshold(imageMat, imageMat, 0, 255, Imgproc.THRESH_OTSU);
    

    for thresholding.

    Try tweaking the parameters here and there, you should get something pretty close to your desired outcome.

    0 讨论(0)
提交回复
热议问题