基于automatic-watermark-detection进行修改和升级。
效果:B2.mp4 -> video/output4.avi 我用腾讯视频可以打开
- 修改:支持选位置进行去水印 (过滤掉原图冗余位置信息)
- 升级:python2 -> python3
- 升级:支持视频去水印并保存 (在知乎, B站视频, 好看视频 测试过)
cmd : python main_video.py
args:
video: 输入视频地址
out_video: 输出视频保存地址
_GAP: 处理视频帧的频率,越小效果越好速度越慢,最小为1
img_size: 处理时图片放缩的大小,为0时代表不放缩效果好,但是慢
最好的效果配置是 _GAP=1, img_size=0
效果和速度平均是 _GAP=5, img_size=320
建议_GAP和img_size 都放小点
cmd: python main.py
没有具体调接口,路径信息对应图像文件夹
最终效果其实不如直接用ffmpeg处理, 项目地址.
This was a project that was built as part of project for CS663 (Digital Image Processing). This is a crude Python implementation of the paper "On The Effectiveness Of Visible Watermarks", Tali Dekel, Michael Rubinstein, Ce Liu and William T. Freeman, Conference on Computer Vision and Pattern Recongnition (CVPR), 2017.
A watermarked image J
is obtained by imposing a watermark W
over an unwatermarked image I
with a blend factor . Specifically, we have the following equation:
Where p = (x, y)
is the pixel location. For a set of K
images, we have:
Although we have a lot of unknown quantities (), we can make use of the structural properties of the image to determine its location and estimate its structure. The coherency of and W over all the images can be exploited to solve the above problem with good accuracy. The steps followed to determine these values are:
- Initial watermark estimation and detection
- Estimating the matted watermark
- Compute the median of the watermarked image gradients, independently in the
x
andy
directions, at every pixel locationp
.
- Crop
W_m
to remove boundary regions by computing its magnitude and taking the bounding box of the edge map. The initial estimated watermark is estimated using Poisson reconstruction. Here is an estimated watermark using a dataset of 450+ Fotolia images.
- Watermark detection: Obtain a verbose edge map (using Canny edge detector) and compute its Euclidean distance transform, which is then correlated with to get the Chamfer distance from each pixel to the closest edge. Lastly, the watermark position is taken to be the pixel with minimum distance in the map.
- Estimate keeping fixed.
- Watermark update - Update the value of keeping the rest fixed.
- Matte update - Update the value of keeping the rest fixed.
Please refer to the paper and supplementary for a more in-depth description and derivation of the algorithm.
Here are some of the results for watermarked and watermark removed images:
However, this is a rough implementation and the removal of watermark leaves some "traces" in form of texture distortion or artifacts. I believe this can be corrected by appropriate parameter tuning.
For more information, refer to the original paper here
I do not encourage or endorse piracy by making this project public. The code is free for academic/research purpose. Please feel free to send pull requests for bug fixes/optimizations, etc.