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);
}
相关推荐
阿维的博客日记6 小时前
保姆级教程介绍分词算法BPE
人工智能·算法·分词算法·bpe
工业设备方案笔记6 小时前
RK3588工业视觉检测方案详解:AI如何赋能智能制造?
arm开发·人工智能·计算机视觉·目标跟踪·视觉检测·边缘计算·制造
FlyWIHTSKY6 小时前
在智能体系统中,什么是多模态,举例详细说明
人工智能·python·langchain
fivebliss6 小时前
AI模型最新方向梳理
人工智能
阿图灵6 小时前
Agentic AI 架构入门(十二·完结):ADLC、AgentOps 与企业级平台蓝图
人工智能·架构·ai agent·智能体·agentops·agentic ai·adlc
达达尼昂6 小时前
Flutter AI Harness 如何让 Agent 参与软件开发全流程
android·人工智能·后端
人工智能研究所6 小时前
GitHub 10k+ Star:用自然语言描述系统,AI 帮你生成可交互架构图
人工智能·github·交互·自然语言·系统架构图·archify
王六米。6 小时前
武汉自动意志科技有限公司:人工智能应用软件开发:OpenClaw 企业部署怎样配置权限、日志和回滚
人工智能·科技·企业ai落地·ai智能体开发·openclaw部署·武汉自动意志科技·智钳claw
yangmu32036 小时前
脑机接口:当意识越过肉身的边界
人工智能·科技
Warren2Lynch6 小时前
从文本到架构:Visual Paradigm AI Chatbot V2 深度评测与实战指南引言
人工智能·架构