2017-01-16 82 views
0

我正在嘗試創建一個OCR應用程序。我需要使用輪廓來定位文本。但是,我的圖像有很多噪音,我想知道是否有辦法將其刪除。OpenCV - 使用Java去除圖像中的噪點

我當前的代碼:

// 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

+0

怎麼沒改造後的圖像看一下嗎?你可以上傳那張圖片嗎? –

+0

第二張圖片是我轉換後的圖片 –

+0

我明白了,但它是黑/白(二進制)。我想在原始色彩空間(RGB)中轉換圖像, –

回答

1

我對你的問題的解決方案。但是,在這種情況下不涉及消除噪音。

第1步:

我已經從你上傳的原始圖像獲得我自己變換的圖像:

enter image description here

我想你知道如何執行上的圖像轉換爲在規定你的問題。不過要了解更多關於他們的信息,請訪問THIS。要了解同形投影,請訪問THIS SITE

我獲得該圖像的灰度:

enter image description here

步驟2:

向該圖像I進行使用高斯濾波器自適應閾值:

enter image description here

步驟3:

此步驟涉及了幾個形態運算的:

首先,爲了去除圖像中的不希望的斑點,我使用形態操作:

enter image description here

其次,我用形態膨脹操作(你可能不需要,除非你想突出你的文字):

enter image description here