我试图用OCR翻译图像,但是水印在路上。有没有办法去除橙色水印图片,或至少使它更轻?还可以批量地(对文件夹中的所有图像)执行此操作吗?
这是在去除水印后应该是什么样子的图片。举个例子。
发布于 2021-09-21 05:40:10
您可能只是阈值,但切断平滑的低像素计数文本实际上会损害后续的ocr相当严重。因此,我创建了一个掩码来消除水印,然后将其应用于原始图像(这也会拉出灰色文本边界)。另一个有帮助的技巧是使用红色通道,因为水印是最饱和的红色~245)。请注意,这需要opencv和c++17
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
bool debugFlag = true;
std::string path = "C:/Local Software/voyDICOM/resources/images/wmTesting/";
for (const auto& entry : fs::directory_iterator(path))
{
std::string fileName = entry.path().string();
Mat original = imread(fileName, cv::IMREAD_COLOR);
if (debugFlag) { imshow("original", original); }
Mat inverted;
bitwise_not(original, inverted);
std::vector<Mat> channels;
split(inverted, channels);
for (int i = 0; i < 3; i++)
{
if (debugFlag) { imshow("chan" + std::to_string(i), channels[i]); }
}
Mat bwImg;
cv::threshold(channels[2], bwImg, 50, 255, cv::THRESH_BINARY);
if (debugFlag) { imshow("thresh", bwImg); }
Mat outputImg;
inverted.copyTo(outputImg, bwImg);
bitwise_not(outputImg, outputImg);
if (debugFlag) { imshow("output", outputImg); }
if (debugFlag) { waitKey(0); }
else { imwrite(fileName, outputImg); }
}
}
显示掩蔽而不只是阈值的好处的图像:
参考文献:How can I get the list of files in a directory using C or C++?
编辑(添加debugFlag以帮助调试),调试输出示例:
https://stackoverflow.com/questions/69261023
复制相似问题