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);
}
相关推荐
袁庭新3 分钟前
人人都能学AI,人人都要学AI
人工智能·aigc
Tzarevich4 分钟前
前端调用大语言模型:基于 Vite 的工程化实践与 HTTP 请求详解
人工智能
Soonyang Zhang14 分钟前
MoeDistributeDispatch算子代码阅读
人工智能·算子·ascendc
sanggou17 分钟前
Windsurf AI IDE 完全使用指南
ide·人工智能
2501_941870561 小时前
人工智能与未来的工作:自动化与人类协作的新时代
大数据·人工智能
Blurpath1 小时前
2025 年用ChatGPT+代理构建AI驱动的智能爬虫
人工智能·爬虫·chatgpt·ip代理·住宅ip·动态住宅代理·轮换ip
极客BIM工作室2 小时前
大模型中的Scaling Law:AI的“增长密码“
人工智能
纪伊路上盛名在2 小时前
Alphafold实用指南—官网教程3
数据库·人工智能·机器学习·alphafold·计算生物学·结构生物学
茶杯6752 小时前
数字孪生厂商推荐:跨行业通用型平台与垂直领域专精企业对比指南
人工智能