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);
}
相关推荐
njsgcs21 分钟前
ai流水线式调用命令
人工智能·python
IT_陈寒40 分钟前
Redis性能翻倍的5个冷门技巧:从每秒10万到20万的实战优化之路
前端·人工智能·后端
Salt_07281 小时前
DAY 54 对抗生成网络
网络·python·神经网络·机器学习·计算机视觉
鹿鸣天涯1 小时前
DeepSeek发布新论文提出更为高效的AI开发方法
人工智能
酌沧1 小时前
拆解GUI Agent大模型利用PPO强化学习
人工智能·智能手机
Coder_Boy_1 小时前
基于SpringAI的企业级智能教学考试平台模块四:优化迭代模块内容
人工智能·spring boot
我是宝库1 小时前
SCI论文在哪些情况下可以不查AI率?
人工智能·aigc·sci论文·turnitin系统·英文查重·aigc检测·sci发表
专注前端30年1 小时前
AI工程化_MLOps实战:模型部署+FastAPI+ONNX Runtime+TensorRT加速全解析
人工智能·fastapi
编码小哥1 小时前
OpenCV角点检测:Harris与ShiTomasi算法
人工智能·opencv·算法
杨建允1 小时前
杨建允:AI搜索优化对工业品行业的影响
人工智能·ai