问题描述
我正在尝试使用OpenCV清除图像中的文本.我正在使用下面的代码
I am trying to clear text in the image using OpenCV. i am using code below
cv::Mat original = [MAOpenCV cvMatGrayFromAdjustedUIImage:image];
cv::GaussianBlur(original, original, cvSize(11,11), 0);
cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 5, 2);
image = [MAOpenCV UIImageFromCVMat:original];
original.release();
这可以正常工作,但也可以消除文本颜色.只显示大文本的边框.在此示例中,如何保留文本的颜色.
This working fine but its also removing text color. just display border of large text. How can i preserve color of text in this example.
这是原始图片
这是使用此代码转换的图像
Here is the image that converted using this code
推荐答案
对于像您这样的较大字母的图片,请尝试增加传递给adaptiveThreshold函数的块大小"参数.
For pictures of larger letters like yours, try to increase the 'Block Size' parameter passing into the adaptiveThreshold function.
来自您的5
cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 5, 2);
尝试将其增加(例如增加到15个),直到字母不再被挖空为止.
try to increase it (e.g. to 15) until the letters are not hollowed anymore.
cv::adaptiveThreshold(original, original, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 15, 2);
请记住,块大小"参数必须为奇数.
Remember that the Block Size parameter has to be an odd number.
这篇关于OpenCV代码还可以使用backgraound颜色删除文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!