Giter Site home page Giter Site logo

nowatermark's Introduction

nowatermark

PyPI Version Build Status Wheel Status Coverage report Powered by SixQuant

Overview

remove watermark. 根据水印模板图片自动寻找并去除图片中对应的水印,利用 Python 和 OpenCV 快速实现。

Install

Mac OS Install OpenCV for Python3

  • with-python3用来告诉homebrew用来让opencv支持python3,
  • C++11 用来告诉homebrew提供c++11支持,
  • with-contrib 用来安装opencv的contrib支持。
$ brew install opencv3 --without-python --with-python3 --c++11 --with-contrib  

Verifying the installation:

import cv2
print(cv2.__version__)

If you got this error: "ImportError: No module named 'cv2'", then your symlink might be corrupted, you need to link your opencv to python site-packages:

$ brew link --force opencv3

Install nowatermark

$ pip3 install nowatermark

Usage

from nowatermark import WatermarkRemover

path = './data/'

watermark_template_filename = path + 'anjuke-watermark-template.jpg'
remover = WatermarkRemover()
remover.load_watermark_template(watermark_template_filename)

remover.remove_watermark(path + 'anjuke3.jpg', path + 'anjuke3-result.jpg')
remover.remove_watermark(path + 'anjuke4.jpg', path + 'anjuke4-result.jpg')

Original

Original

Removed watermark

Removed watermark


Procedure

Feature Matching(特征匹配)

  • 对水印模板图片进行了一些初始化处理,比如二值化后去除非文字部分等
  • 尝试了 OpenCV 的多种算法
    • 比如 ORB + Brute-Force,即蛮力匹配,对应 cv2.BFMatcher() 方法
    • 比如 SIFT + FLANN,即快速最近邻匹配,对应 cv2.BFMatcher() 方法
    • 比如 Template Matching,即模板匹配,对应 cv2.matchTemplate() 方法
  • 最后发现 Template Matching 最简单方便,效果也最好。
  • 如果水印位置固定的话则可以跳过Feature Matching(特征匹配),直接进行下一步的Inpainting(图片修复)

Inpainting(图片修复)

  • 修复图片前需要做一些前置处理
    • 首先要得到图片的去水印 Mask 图片,即和待处理图片一样大小的除了水印部分的文字部分外其他部分全部是黑色的位图
    • 因为前面对水印做了二值化等处理,最终效果发现会有水印轮廓,所以需要对 Mask 图片做一次膨胀处理覆盖掉轮廓
  • 选用了Telea在2004年提出的Telea算法,即基于快速行进(FMM)的修复算法

Todo

  • 由于某些图片的水印和背景图片相似程度太高,如何提高水印位置的识别正确率
  • 改进修复图片算法,可以考虑用深度学习来做做看?
  • Google CVPR 2017, 《On the Effectiveness of Visible Watermarks》这个据说很牛的,回头可以读一读

License

MIT

nowatermark's People

Contributors

sixquant avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.