Comments (2)
最好用原版代码来恢复,默认的那个命令行不好用,重点是“要把图片恢复成原始尺寸”,再进行解密对比,成功率在80%以上:
最重要的是要把图片恢复成原始尺寸后解密:
# recover from attack:
recover_crop(template_file='output/2022-09-30_15-20.png', output_file_name='output/截屏攻击2_还原.png',
loc=(x1, y1, x2, y2), image_o_shape=image_o_shape)
https://github.com/guofei9987/blind_watermark/blob/master/examples/example_str.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# embed string
import numpy as np
from blind_watermark import WaterMark
from blind_watermark import att
from blind_watermark.recover import estimate_crop_parameters, recover_crop
import cv2
bwm = WaterMark(password_img=77782589, password_wm=7758258)
bwm.read_img('pic/1648799417649ee7d05.png')
wm = '1998-2022 Yafe Co., Limited'
bwm.read_wm(wm, mode='str')
bwm.embed('output/embedded.png')
len_wm = len(bwm.wm_bit) # 解水印需要用到长度
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))
ori_img_shape = cv2.imread('pic/1648799417649ee7d05.png').shape[:2] # 抗攻击有时需要知道原图的shape
# %% 解水印
bwm1 = WaterMark(password_img=77782589, password_wm=7758258)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print("不攻击的提取结果:", wm_extract)
assert wm == wm_extract, '提取水印和原水印不一致'
# %% 截屏攻击 = 剪切攻击 + 缩放攻击 + 不知道攻击参数
'''
loc_r = ((0.1, 0.1), (0.7, 0.6))
scale = 0.7
_, (x1, y1, x2, y2) = att.cut_att2(input_filename='output/embedded.png', output_file_name='output/截屏攻击2.png',
loc_r=loc_r, scale=scale)
print(f'Crop attack\'s real parameters: x1={x1},y1={y1},x2={x2},y2={y2}')
'''
# estimate crop attack parameters:
(x1, y1, x2, y2), image_o_shape, score, scale_infer = estimate_crop_parameters(original_file='pic/1648799417649ee7d05.png',
template_file='output/2022-09-30_15-20.png',
scale=(0.5, 2), search_num=200)
print(f'Crop attack\'s estimate parameters: x1={x1},y1={y1},x2={x2},y2={y2}. score={score}')
# recover from attack:
recover_crop(template_file='output/2022-09-30_15-20.png', output_file_name='output/截屏攻击2_还原.png',
loc=(x1, y1, x2, y2), image_o_shape=image_o_shape)
bwm1 = WaterMark(password_wm=7758258, password_img=77782589)
wm_extract = bwm1.extract('output/截屏攻击2_还原.png', wm_shape=len_wm, mode='str')
print("截屏攻击,不知道攻击参数。提取结果:", wm_extract)
assert wm == wm_extract, '提取水印和原水印不一致'
'''
# %%缩放攻击
#att.resize_att(input_filename='output/embedded.png', output_file_name='output/缩放攻击.png', out_shape=(400, 300))
att.resize_att(input_filename='output/embedded1.png', output_file_name='output/缩放攻击_还原.png',
out_shape=ori_img_shape[::-1])
# out_shape 是分辨率,需要颠倒一下
bwm1 = WaterMark(password_wm=7758258, password_img=77782589)
wm_extract = bwm1.extract('output/缩放攻击_还原.png', wm_shape=len_wm, mode='str')
print("缩放攻击后的提取结果:", wm_extract)
assert np.all(wm == wm_extract), '提取水印和原水印不一致'
# %%
'''
from blind_watermark.
谢谢大佬
from blind_watermark.
Related Issues (20)
- 解码时乱码,数字也乱码 HOT 2
- 这个项目是什么用途? HOT 1
- 可否直接用于视频添加水印? HOT 4
- 解码的时候wm_shape该怎么填,难不成要我自己存起来吗
- 当打上水印的图片再次打上水印时的问题 HOT 2
- 请问有相关论文说明原理吗? HOT 4
- 文档链接404
- 弄个docker版本吧
- 这个项目真的很好,不知道能不能打包成exe文件呢?想用GUI桌面工具来调用这个批量给图片添加水印 HOT 1
- 如果原图解密是能根据两个密码解出来,但是一截图或者画图本缩放就不行了 HOT 1
- 没能抵挡多少个攻击,你文档怎么瞎写?
- 没能抵挡多少个攻击,你文档怎么瞎写? HOT 3
- 剪切攻击 + 缩放攻击 + 不知道攻击参数 能否在没有原始的加完水印后的图的时候提取参数 HOT 4
- 解码需要提供wm_shape这个参数,正确的使用方法是怎样的?谢谢 HOT 5
- 求算法论文分享 HOT 1
- 图片过大 添加水印 提示warning: iCCP: known incorrect sRGB profile
- extract ERROR HOT 2
- Taking a screenshot of a picture with a watermark, garbled characters appear when extracting it. HOT 4
- Significatelly drops image quality HOT 2
- 尝试编辑图片之后无法正确解码
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blind_watermark.