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);
}
相关推荐
SEO_juper12 分钟前
用Google Search Console数据做内容审计:找出网站上哪些页面在“吃白饭“
大数据·人工智能·外贸独立站
余俊晖13 分钟前
多模态大模型细粒度视觉理解:Vision-OPD在线策略自蒸馏技术方案概述
人工智能·深度学习·算法·多模态·opd
付玉祥16 分钟前
以业务语义网为中心:企业本体端到端智能构建与 Agent 执行实践
人工智能
dozenyaoyida18 分钟前
AI与大模型新闻日报 | 2026-08-01
人工智能·ai·大模型·新闻
大伟先生29 分钟前
OpenClaw 数据采集实战入门
人工智能·深度学习
智塑未来32 分钟前
金融 AIOps 选型指南:银行证券智能运维平台怎么选
运维·人工智能·金融
余俊晖1 小时前
再看多模态OCR视觉token裁剪思路-LayoutLite基于token的隐式布局分析
人工智能·ocr·多模态
二狗PPT1 小时前
AI做PPT提示词怎么写,换个写法效果差很多
人工智能·powerpoint
段一凡-华北理工大学1 小时前
AI推动工业智能化转型~系列文章07:分类与诊断算法体系:故障识别的完整工具箱
数据库·人工智能·算法·机器学习·分类·数据挖掘·高炉炼铁智能化
cxr8281 小时前
第 7 章 . 设计哲学回顾与最终说明
人工智能