使用opencv(Java)的阈值图像 [英] Threshold image using opencv (Java)

查看:717
本文介绍了使用opencv(Java)的阈值图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我试过这个函数:

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

但结果不太好,如下所示

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

所以我尝试了 adaptiveThreshold函数

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

结果:

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

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.

此外,我使用 Tesseract 进行日语识别,但准确率不高。您对日本的更好OCR或任何提高Tesseract质量的方法有什么建议吗?

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?

推荐答案

adaptiveThreshold 是正确的选择。 只需要一个小小的调整
使用这些参数(它是C ++,但你可以很容易地翻译成Java)

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

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

生成的图片是:

< img src =https://i.stack.imgur.com/QZxPX.pngalt =在此处输入图像说明>

这篇关于使用opencv(Java)的阈值图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆