Opencv基于文字检测去图片水印

做了一个简单的去水印功能,基于文字检测去图片水印。效果如下:

插件功能代码参考如下:

cpp 复制代码
using namespace cv::dnn;
TextDetectionModel_DB *textDetector=0;
void getTextDetector()
{
     if(textDetector)return;
     String modelPath = "text_detection_DB_TD500_resnet18_2021sep.onnx";  //模型权重文件

    textDetector=new TextDetectionModel_DB(modelPath);

    float binThresh = 0.3;                                      //二值图的置信度阈值
    float polyThresh  = 0.5 ;                                   //文本多边形阈值
    double unclipRatio = 2.0;      //检测到的文本区域的未压缩比率,gai比率确定输出大小
    uint maxCandidates = 200;

    textDetector->setBinaryThreshold(binThresh)
        .setPolygonThreshold(polyThresh)
        .setUnclipRatio(unclipRatio)
        .setMaxCandidates(maxCandidates);

    double scale = 1.0 / 255.0;
    int height = 736;                                                   //输出图片长宽
    int width = 736;
    Size inputSize = Size(width, height);
    Scalar mean = Scalar(122.67891434, 116.66876762, 104.00698793);
    textDetector->setInputParams(scale, inputSize, mean);

}


void deWaterMarkTextDetection(Mat &input,Mat &output,Mat &src,string)
{
    getTextDetector();
    // 推理
    std::vector<std::vector<Point>> results;
    textDetector->detect(input, results);

    Mat mask = Mat::zeros(input.size(), CV_8U);
    fillPoly(mask, results,Scalar::all(255));


    //将掩模进行膨胀,使其能够覆盖图像更大区域
    Mat kernel = getStructuringElement(MORPH_RECT, Size(5, 5));
    dilate(mask, mask, kernel);

    //使用inpaint进行图像修复
    Mat result;
    inpaint(src, mask, output, 1, INPAINT_NS);
}
相关推荐
AI前沿资讯20 小时前
AI3D角色生产如何减少返工?用 V2Fun 前移建模与动画流程
人工智能·3d
aqi0020 小时前
15天学会AI应用开发(十一)从TXT文件构建RAG知识库
人工智能·python·大模型·ai编程·ai应用
AIJWAI20 小时前
朱雀 AI 检测的核心逻辑是什么?
人工智能
汤姆yu20 小时前
macOS系统下Aider完整安装、配置与实战使用教程
大数据·人工智能·算法·macos·github·copilot
阿部多瑞 ABU20 小时前
软权力:先行植入的意义置换 ——文化殖民的结构逻辑与资本剥削的后续包装
人工智能
Sam092720 小时前
【AI 算法精讲 14】TF-IDF:词频与逆文档频率
人工智能·python·算法·ai
2601_9516599920 小时前
YOLOv11 改进 - 主干网络 EfficientRep:一种旨在提高硬件效率的RepVGG风格卷积神经网络架构
深度学习·yolo·计算机视觉
m0_6265352020 小时前
MRR(Mean Reciprocal Rank)和 NDCG(Normalized Discounted Cumulative Gain)
人工智能·机器学习
长和信泰光伏储能20 小时前
探索未来能源:光伏储能技术解析
大数据·人工智能·能源
寻道码路20 小时前
LangChain4j Java AI 应用开发实战(二十六):多模型集成策略 —— OpenAI、DeepSeek、阿里百炼混合使用
java·开发语言·人工智能·ai