问 题

Wanted to achieve something like this: http://www.leptonica.com/binarization.html

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)..

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);

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?

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

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: 

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: 

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: 

using medianBlur before otsu: 

using GaussianBlur before otsu: 

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:

Instead of

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

try:

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

check the syntax, may not exactly match

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

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

for thresholding.

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

本文地址:IT屋 » How to use OpenCV to process image so that the text become sharp and clear?

如何使用OpenCV的处理图像,文字变得锐利和清晰?(How to use OpenCV to process image so that the text become sharp and clea相关推荐

  1. 《OpenCv视觉之眼》Python图像处理二十一:Opencv图像处理之图像线性变换和非线性变换的方法及原理

    本专栏主要介绍如果通过OpenCv-Python进行图像处理,通过原理理解OpenCv-Python的函数处理原型,在具体情况中,针对不同的图像进行不同等级的.不同方法的处理,以达到对图像进行去噪.锐 ...

  2. OpenCV+python:图像金字塔

    1,图像金字塔的概念 图像金字塔是一种以多分辨率来解释图像的有效但概念简单的结构.应用于图像分割,机器视觉和图像压缩.一幅图像的金字塔是一系列以金字塔形状排列的分辨率逐步降低,且来源于同一张原始图的图 ...

  3. Python 对图像进行base64编码及解码读取为numpy、opencv、matplot需要的格式

    Python 对图像进行base64编码及解码读取为numpy.opencv.matplot需要的格式 1. 效果图 2. 源码 参考 这篇博客将介绍Python如何对图像进行base64编解码及读取 ...

  4. OpenCV优化:图像的遍历4种方式

    小知识:反色 反色原理很简单,在一个rgb色彩空间中,可将任何一种颜色看成笛卡尔坐标中的一个点,对于任意点,反色就是计算以(128, 128,128)为中心时该点的对称点,比如rgb(100, 150 ...

  5. OpenCV之core 模块. 核心功能(1)Mat - 基本图像容器 OpenCV如何扫描图像、利用查找表和计时 矩阵的掩码操作 使用OpenCV对两幅图像求和(求混合(blending))

    Mat - 基本图像容器 目的 从真实世界中获取数字图像有很多方法,比如数码相机.扫描仪.CT或者磁共振成像.无论哪种方法,我们(人类)看到的是图像,而让数字设备来"看"的时候,则 ...

  6. 【OpenCV】扫描图像、查找表、计时

    扫描图像   扫描图像有四种方法:C指针访问方法.迭代器方法.即时地址计算方法.LUT函数.实现方法及用时比较可参考下方代码. 参考链接:https://docs.opencv.org/master/ ...

  7. 12.QT + OpenCV打包成应用(以及QT图标问题详细) --- OpenCV从零开始到图像(人脸 + 物体)识别系列

    本文作者:小嗷 微信公众号:aoxiaoji 关键词:QT + OpenCV打包成应用(接着第11篇) QT开发的程序发布的时候经常采用两种方式: 静态编译,可生成单一的可执行文件. 动态编译,需同时 ...

  8. opencv 锐化 java_如何在OpenCV中锐化图像?

    如何在OpenCV中锐化图像? 如何使用OpenCV锐化图像? 有许多平滑或模糊的方法,但没有我能看到的锐化. 7个解决方案 147 votes 关于反锐化掩蔽的维基百科文章中列出了一个通用程序:您使 ...

  9. 如何使用Python实现图像文字识别OCR

    要使用Python实现图像文字识别OCR,可以使用以下步骤: 安装Tesseract OCR引擎 Tesseract是一种开源OCR引擎,可以处理多种语言和字体.要使用Python进行OCR,需要安装 ...

最新文章

  1. 轻松理解vuex的运用和常见问题,顺便学会vue企业必备实例
  2. centos7 通过kvm+vnc 实现远程桌面虚拟化和创建windows、Linux虚拟机
  3. Elasticsearch7.15.2 ik中文分词器 定制化分词器之扩展词库(远程)
  4. iPhone 13 系列不再齐「芯」,苹果为什么要造三款不同的 A15 处理器?
  5. AppCompatActivity中使用SearchView
  6. 56. 合并区间(javascript)
  7. Tab与TabHost
  8. mqtt发布json数据_mqtt应用于进程间通信
  9. 交换局域网(链路层+以太网+交换机)
  10. raw socket编程实例
  11. APP调用微信授权登录-JAVA后台实现
  12. 计算机excel求四分位数,四分位数怎么算excel?
  13. 3D目标检测方案总结
  14. 时间转换 Wed Sep 16 2020 00:00:00 GMT+0800 (中国标准时间)
  15. python携程怎么做数据同步_利用python yielding创建协程将异步编程同步化
  16. TSCH协议及WIA-PA系统芯片
  17. python可视化迷宫求解_如何用 Python 制作一个迷宫游戏
  18. 香港特首到访阿里_她是来看几个年轻人的……
  19. 一、TF2 常用命令
  20. db.properties 之 root 之空格

热门文章

  1. 怎么取消微信送票服务器,微信抢火车票怎么取消?有什么要注意的吗?
  2. Java核心类库之(常用API、字符串类、集合类、泛型)
  3. 2018C语言自考答案,2018年中考语文试题解析
  4. Bezier曲线原理及实现代码(c++)
  5. 滚动条 scrollbar 和scrollbar-thumb 样式
  6. SwiftUI macOS源码大全之倒计时App基于coredata(教程含源码)
  7. IOS面试攻略(1.0)
  8. 苏门答腊岛地震 苏门答腊9.1级地震 2004年苏门答腊地震 印尼苏门答腊地震 印尼苏门答腊岛地震
  9. linux文件编辑--vi
  10. 我欢喜,为着时光所有的馈赠