使用 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
Threshold image using opencv (Java)
提问by Bee Bee
I am working with Opencv for my project. I need to convert the image below to threshold image
我正在为我的项目使用 Opencv。我需要将下面的图像转换为阈值图像
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
但结果并不是那么好,如下所示
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:
结果是:
I just expect a binary image with white background and black text only, no black area or noise ( I do not prefer using Photo.fastNlMeansDenoising
because it takes a lot of time). Please help me with a solution for this.
我只是期望一个只有白色背景和黑色文本的二进制图像,没有黑色区域或噪音(我不喜欢使用,Photo.fastNlMeansDenoising
因为它需要很多时间)。请帮我解决这个问题。
Also, I am using Tesseract
for 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
adaptiveThreshold
is 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:
结果图像是: