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);
}
相关推荐
海边夕阳200631 分钟前
【每天一个AI小知识】:什么是生成对抗网络?
人工智能·经验分享·深度学习·神经网络·机器学习·生成对抗网络
Wise玩转AI39 分钟前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
youcans_1 小时前
【youcans论文精读】VM-UNet:面向医学图像分割的视觉 Mamba UNet 架构
论文阅读·人工智能·计算机视觉·图像分割·状态空间模型
铮铭1 小时前
扩散模型简介:The Annotated Diffusion Model
人工智能·机器人·强化学习·世界模型
轻竹办公PPT1 小时前
轻竹论文:毕业论文AI写作教程
人工智能·ai·ai写作
呵呵哒( ̄▽ ̄)"1 小时前
专项智能练习(课程类型)
人工智能
2501_918126912 小时前
如何用ai把特定领域的生活成本归零
人工智能·生活·个人开发
Brianna Home2 小时前
[鸿蒙2025领航者闯关] 鸿蒙 6.0 星盾安全架构 + AI 防窥:金融级支付安全实战与深度踩坑实录
人工智能·安全·harmonyos·安全架构
飞哥数智坊3 小时前
V4/R4 没来,但 DeepSeek-V3.2 好像又便宜又好用?
人工智能·deepseek