4

Source image:

Destination image:

Code:

cv::Mat sharpenedLena;
cv::Mat kernel = (cv::Mat_<float>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
cv::filter2D(matGrey, sharpenedLena, matGrey.depth(), kernel);
cv::adaptiveThreshold(sharpenedLena, matBinary, 255,    cv::ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 55, 30);
cv::Mat dst_img1;
//cv::GaussianBlur(matBinary, dst_img1, cv::Size(3,3), 0, 0);
cv::medianBlur(matBinary, dst_img1, 3);

UIImage *addrUIImage = [ImageUtil UIImageFromCVMat:dst_img1];
[self recognizeImageWithTesseract:addrUIImage withLauange:1];

Result:

三胡南省慈利昙龙三覃河镇文

I think it should be a picture deal with the problem. Here there is a treatment effect of others. How to achieve this effect?

Target image:

Alex
  • 781
  • 10
  • 23
hnzlk2015
  • 43
  • 3

3 Answers3

1

Here is my results & Code Snippet: enter image description here

Mat mSource_Bgr,mSource_Gray,mSource_Hsv,mThreshold;
mSource_Bgr= imread(FileName_S.c_str(),1);

namedWindow("Source Image",WINDOW_AUTOSIZE);
imshow("Source Image",mSource_Bgr);

cvtColor(mSource_Bgr,mSource_Hsv,COLOR_BGR2HSV);

mSource_Hsv = mSource_Hsv + Scalar(0,0,-25); //Subtracting 25 from all the Pixel Values
cvtColor(mSource_Hsv,mSource_Bgr,COLOR_HSV2BGR);// Back to BGR Just for Debug purpose

enter image description here

imshow("Improved Darkness",mSource_Bgr);
imwrite(FileName_S+"_Res.bmp",mSource_Bgr);

cvtColor(mSource_Bgr,mSource_Gray,COLOR_BGR2GRAY); // for Adaptive Thresholding the input Image

adaptiveThreshold(mSource_Gray,mThreshold,255,ADAPTIVE_THRESH_GAUSSIAN_C,THRESH_BINARY,59,10);

enter image description here

imshow("Adaptive Thres",mThreshold);
imwrite(FileName_S+"_Thres.bmp",mThreshold);

You can remove the Noise i.e small dots by using contour Area or by Morphological Processing.Hope this helps you!

Balaji R
  • 1,805
  • 22
  • 41
  • Thand you!Indeed been greatly improved. cv::Mat kernel2(3, 3, CV_8UC1, 0); cv::morphologyEx(matBinary, matBinary, cv::MORPH_CLOSE, kernel2, cv::Point(1, 1), 1); – hnzlk2015 Apr 24 '15 at 02:17
0

You can try using adaptiveThreshold() or algorithms such as MSER OpenCV.

These will perform better, especially MSER and its variant CSER are designed to detect text-like structures.

mirosval
  • 6,671
  • 3
  • 32
  • 46
  • I am now using adaptiveThreshold() ,I do not know how to start,Achieve the effect of the third picture. – hnzlk2015 Apr 23 '15 at 09:11
0

You can try using Binary thresholding with a OPEN Morphology operation.

OpenCV User
  • 139
  • 1
  • 1
  • 8