gpt4 book ai didi

java - OpenCV - 使用 Java 去除图像中的噪声

转载 作者:太空宇宙 更新时间:2023-11-03 22:10:12 41 4
gpt4 key购买 nike

我正在尝试创建一个 OCR 应用程序。我需要使用轮廓定位文本。但是,我的图像有很多噪点,我想知道是否有办法将其移除。

我当前的代码:

// Input image already converted to a matrix
Imgproc.cvtColor(matrixImage, matrixImage, Imgproc.COLOR_BGR2GRAY);

// Gaussian blur
Imgproc.GaussianBlur(matrixImage, matrixImage, new Size(7,7), 0);

Imgproc.threshold(matrixImage, matrixImage, 125, 255, Imgproc.THRESH_BINARY_INV);

// This is my current approach for removing noise. However, there is still
// a lot of random areas that can be removed.

// Remove specs from image
Mat morphingMatrix = Mat.ones(3,3, CV_8UC1);
Imgproc.morphologyEx(matrixImage, matrixImage, Imgproc.MORPH_OPEN, morphingMatrix);

// Image denoising
Photo.fastNlMeansDenoising(matrixImage, matrixImage);

我的输入图像。我允许用户手动标记角,因此下面的转换图像仅将转换应用于中间的白纸。

input image

image after transformation

最佳答案

我有解决你问题的办法。但是,在这种情况下,它不涉及去除噪声。

第 1 步:

我从你上传的原图得到了我自己的变形图:

enter image description here

我假设您知道如何按照问题中所述对图像执行转换。尽管如此,要了解更多关于它们的信息,请访问 THIS .要了解单应投影,请访问 THIS SITE .

我得到了这张图片的灰度:

enter image description here

第 2 步:

对于这张图片,我使用高斯滤波器执行了自适应阈值:

enter image description here

第 3 步:

这一步涉及几个形态学操作:

首先,为了去除图像中不需要的 Blob ,我使用了形态学闭合操作:

enter image description here

其次,我使用了形态学膨胀操作(除非您想突出显示文本,否则您可能不需要):

enter image description here

关于java - OpenCV - 使用 Java 去除图像中的噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41675245/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com