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);
}
相关推荐
vvzh20266 小时前
2026南京初创企业GEO知识库落地思路:一站式结构化知识库搭建落地参考
人工智能
澄旭7 小时前
一篇讲清 Agent Skills:把经验变成可调用的能力
人工智能
合合技术团队7 小时前
2026中国图像图形大会召开,合合信息推出多模态可信AI鉴伪系统
图像处理·人工智能·aigc鉴伪
俊哥V7 小时前
AI一周事件 · 2026-05-27 至 2026-06-02
人工智能·ai
G***技7 小时前
极寒也能跑AI?LM2-100-V0算力模组为电网巡检终端注入AI动能
人工智能
行业研究员7 小时前
腾讯云AgentMemory产品介绍与核心痛点解决
人工智能·机器学习·腾讯云·agentmem
钓了猫的鱼儿7 小时前
基于深度学习+AI的蚕病害目标检测与预警系统(Python源码+数据集+UI可视化界面+YOLOv11训练结果)
人工智能·深度学习·目标检测
MY_TEUCK7 小时前
【MY_TRUCK - AI 应用】2026 AI 编程工具全景:Copilot 线与 Cursor 线两大主流、行业现状与人群选型
人工智能·ai·copilot·ai编程
janeysj7 小时前
langgraph学习笔记(一)
人工智能·langchain
阿里云大数据AI技术7 小时前
EMR Serverless Spark 数据湖上新能力:一条 SQL 实现标量向量混合检索
人工智能·sql·spark