使用 opencv (Java) 的阈值图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31289895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:53:10  来源:igfitidea点击:

Threshold image using opencv (Java)

javaandroidopencvimage-processingtesseract

提问by Bee Bee

I am working with Opencv for my project. I need to convert the image below to threshold image

我正在为我的项目使用 Opencv。我需要将下面的图像转换为阈值图像

Original Image

Original Image

I tried this function:

我试过这个功能:

Imgproc.threshold(imgGray, imgThreshold, 0, 255, Imgproc.THRESH_BINARY + Imgproc.THRESH_OTSU); 

But the result was not so good, as you see below

但结果并不是那么好,如下所示

threshold

threshold

So I tried the adaptiveThreshold function:

所以我尝试了adaptiveThreshold function

Imgproc.adaptiveThreshold(imgGray, imgThreshold, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 11, 2); 

and it resulted:

结果是:

adaptiveThreshold

adaptiveThreshold

I just expect a binary image with white background and black text only, no black area or noise ( I do not prefer using Photo.fastNlMeansDenoisingbecause it takes a lot of time). Please help me with a solution for this.

我只是期望一个只有白色背景和黑色文本的二进制图像,没有黑色区域或噪音(我不喜欢使用,Photo.fastNlMeansDenoising因为它需要很多时间)。请帮我解决这个问题。

Also, I am using Tesseractfor Japanese recognization but the accuracy rate is not good. Do you have any suggestion on better OCR for Japanese, or any method to improve Tesseract quality?

另外,我Tesseract用于日语识别,但准确率不好。您对日语更好的 OCR 有什么建议,或者有什么方法可以提高 Tesseract 的质量?

采纳答案by Miki

adaptiveThresholdis the right choice here. Just need a litte tuning. With these parameters (it's C++, but you can easily translate to Java)

adaptiveThreshold这里是正确的选择。只需要一点点调整。使用这些参数(它是 C++,但您可以轻松转换为 Java)

Mat1b gray= imread("path_to_image", IMREAD_GRAYSCALE);
Mat1b result;
adaptiveThreshold(gray, result, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, 40);

the resulting image is:

结果图像是:

enter image description here

enter image description here