Opencv removes image watermark based on text detection

I made a simple watermark removal function to remove image watermarks based on text detection. The effect is as follows:

The plug-in function code reference is as follows:

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);
}

Other contents of "QT Plug-in Image Algorithm Research Platform":

Opencv image pyramid----Gaussian and Laplacian

OpenCV imitates Photoshop curve to adjust image brightness and color

QT plug-in image algorithm software architecture

Opencv image dark channel tuning and dehazing

opencv extracts the watermark of the specified hsv color in the selected area

Opencv manually selects image area to remove watermark

Opencv removes image watermarks based on text detection

QT plug-in image algorithm research platform

Several ways to adjust Opencv image brightness

Things to note when using QT threads in Opencv

Welcome friends to communicate, WeChat/QQ: 23245175, add friends, please note: plug-in software.

Guess you like

Origin blog.csdn.net/stonewu/article/details/132614519