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);
}
相关推荐
Elastic 中国社区官方博客2 分钟前
在 Google MCP Toolbox for Databases 中引入 Elasticsearch 支持
大数据·人工智能·elasticsearch·搜索引擎·ai·语言模型·全文检索
非著名架构师4 分钟前
从预测到预调:疾风大模型如何驱动能源电力系统实现“气象自适应”调度?
大数据·人工智能·风光功率预测·高精度光伏功率预测模型·高精度气象数据·高精度天气预报数据·galeweather.cn
chen_jared4 分钟前
opencv和matlab中相机内参标定模型
opencv·matlab·相机内参标定
cici158745 分钟前
含风电场的十机24时系统机组出力优化算法
人工智能·算法·机器学习
Yeats_Liao6 分钟前
CANN Samples(十九):特色场景:机器人 AI 绘画 手写识别等
人工智能·目标跟踪·机器人
亿坊电商8 分钟前
AI数字人交互系统架构全解析:从多模态输入到实时渲染的闭环设计!
人工智能·系统架构·交互
热点速递10 分钟前
AI成广告新引擎:从百度、快手到Meta,智能技术如何拯救互联网广告下滑!
人工智能·百度
fishfuck12 分钟前
MMEvol: Empowering Multimodal Large Language Models with Evol-Instruct
人工智能·语言模型·自然语言处理
技术支持者python,php16 分钟前
USB摄像头采集数据
人工智能·c#
言之。17 分钟前
豆包手机AI Agent技术深度解析
人工智能·智能手机