如何使用OpenCV的处理图像,文字变得锐利和清晰?锐利、如何使用、图像、清晰

2023-09-05 09:26:10 作者:动感光波biubiubiu

想实现这样的事情: http://www.leptonica.com/binarization.html

在寻找解决方案,大部分的答案是一般的指令,例如提醒一下自适应滤波器,高斯模糊,膨胀和腐蚀,但他们没有提供任何样本code下手(这样可以玩弄值)。

While searching for solutions, most of the answers were general instructions such as advise to look at adaptive filter, gaussian blur, dilation and erosion but none of them provide any sample code to start with (so can play around with the values)..

我知道不同的图像需要不同的方法和价值观,以达到​​最佳的清晰度,但我只是需要一些普通过滤器,使图像至少稍微更清晰,减少噪音比较原始的,做任何OCR就可以了。

I know different image require different methods and values to achieve optimum clarity, but I just need some general filter so that the image at least slightly sharper and less noisy compare to the original, before doing any OCR on it.

这是我到目前为止已经试过..

this is what I've tried so far..

Mat imageMat = new Mat();
Utils.bitmapToMat(photo, imageMat);
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY);
Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0);
Imgproc.adaptiveThreshold(imageMat, imageMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 5, 4);

但作为图像处理福利局,很明显,我不知道我在做什么XD

but being an image processing newb, obviously I don't know what I'm doing XD

原始图像:

original image:

应用上述后:

after applying the above:

如何正确地做到这一点?

How to do it correctly?

更新:得到它的metsburg,berak和奥勒留更接近感谢

UPDATE: got it much closer thanks to metsburg, berak and Aurelius

使用medianBlur方法​​,因为cvSmooth与CV_MEDIAN是pcated和medianBlur替换德$ P $:

Using the medianBlur method since cvSmooth with CV_MEDIAN is deprecated and replaced with medianBlur:

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

结果:

Result:

使用回GaussianBlur方法​​,结果居然是稍微好一点:

Using back the GaussianBlur method, the result actually is slightly better:

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

结果:

Result:

有关这一形象的差别并不noticable,所以我尝试另一种形象是采取关闭计算机屏幕上的照片。电脑屏幕给出了大量的噪音(波浪线),所以它是非常难以去除噪声。

For this image the difference is not noticable, so I tried another image which is a photo taken off the computer screen. Computer screen gives a lot of noises (wavy lines) so it is very hard to remove the noise.

例如原始图像:

Example original image:

直接申请大津:

Directly applying otsu:

使用medianBlur大津之前:

using medianBlur before otsu:

使用GaussianBlur大津之前:

using GaussianBlur before otsu:

好像高斯模糊是稍微好一点,但我仍与设置打.. 如果任何人都可以就如何改善电脑屏幕的照片。此外,请让我们知道劝:) 还有一件事..使用顶部链接的产量里面的图像上这种方法可怕的结果:(这里看看吧:的http:// imgur .COM / vOZAaE0

Seems like gaussian blur is slightly better, however I'm still playing with the settings.. If anyone can advise on how to improve the computer screen photo further, please, let us know :) One more thing.. using this method on the image inside the top link yields horrible results :( see it here: http://imgur.com/vOZAaE0

推荐答案

那么,你几乎没有。刚刚尝试这些修改:

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

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

尝试:

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

检查语法,可能不完全匹配的

您发布的链接使用大津的阈值,那么试试这个:

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

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

有关阈值。

尝试在这里和那里调整的参数,你应该得到的东西pretty的接近你想要的结果。

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