Skip to content

Commit

Permalink
New usage: use in bash
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Jul 17, 2021
1 parent c8b0a71 commit f7dbce2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ pip install .

## How to use

### Use in bash
```bash
cd examples
# embed watermark into image:
blind_watermark --embed -p 1x1 pic/ori_img.jpg pic/watermark.png output/embedded.png
# extract watermark from image:
blind_watermark --extract -p 1x1 --wm_shape 128x128 output/embedded.png output/wm_extract.png
```

### Use in Python
How to embed watermark:
```python
from blind_watermark import WaterMark
Expand Down
13 changes: 12 additions & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ cd blind_watermark
pip install .
```

# 如何使用
## 如何使用

### 命令行中使用

```bash
cd examples
# 嵌入水印:
blind_watermark --embed -p 1x1 pic/ori_img.jpg pic/watermark.png output/embedded.png
# 提取水印:
blind_watermark --extract -p 1x1 --wm_shape 128x128 output/embedded.png output/wm_extract.png
```

### Python 中使用
嵌入水印
```python
from blind_watermark import WaterMark
Expand Down
2 changes: 1 addition & 1 deletion blind_watermark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .blind_watermark import WaterMark
from .att import *

__version__ = '0.0.7'
__version__ = '0.1.1'
1 change: 0 additions & 1 deletion blind_watermark/blind_watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import copy
import cv2
from pywt import dwt2, idwt2
from multiprocessing.dummy import Pool as ThreadPool
from .pool import AutoPool


Expand Down
55 changes: 55 additions & 0 deletions blind_watermark/cli_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from optparse import OptionParser
from .blind_watermark import WaterMark

usage1 = 'blind_watermark --embed -p [pwd1]x[pwd2] image.jpg watermark.png embed.png'
usage2 = 'blind_watermark --extract -p [pwd1]x[pwd2] --wm_shape 128x128 embed.png wm_extract.png'
optParser = OptionParser(usage=usage1 + '\n' + usage2)

optParser.add_option('--embed', dest='work_mode', action='store_const', const='embed'
, help='Embed watermark into images')
optParser.add_option('--extract', dest='work_mode', action='store_const', const='extract'
, help='Extract watermark from images')

optParser.add_option('-p', '--pwd', dest='password', help='2 passwords, like 1x1')
optParser.add_option('--wm_shape', dest='wm_shape', help='Watermark shape, like 128x128')

(opts, args) = optParser.parse_args()


def main():
print(opts)
print(args)
p1, p2 = opts.password.split('x')
bwm1 = WaterMark(password_wm=int(p1), password_img=int(p2))
if opts.work_mode == 'embed':
if not len(args) == 3:
print('Error! Usage: ')
print(usage1)
return
else:
bwm1.read_img(args[0])
bwm1.read_wm(args[1])
bwm1.embed(args[2])
print('Embed succeed! to file ', args[2])

if opts.work_mode == 'extract':
if not len(args) == 2:
print('Error! Usage: ')
print(usage2)
return

else:
shape1, shape2 = opts.wm_shape.split('x')
bwm1.extract(filename=args[0], wm_shape=(int(shape1), int(shape2)), out_wm_name=args[1])
print('Extract succeed! to file ', args[1])


'''
python -m blind_watermark.cli_tools --embed -p 1x1 examples/pic/ori_img.jpg examples/pic/watermark.png examples/output/embedded.png
python -m blind_watermark.cli_tools --extract -p 1x1 --wm_shape 128x128 examples/output/embedded.png examples/output/wm_extract.png
cd examples
blind_watermark --embed -p 1x1 pic/ori_img.jpg pic/watermark.png output/embedded.png
blind_watermark --extract -p 1x1 --wm_shape 128x128 output/embedded.png output/wm_extract.png
'''
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ def read_requirements(filename):
packages=find_packages(),
platforms=['linux', 'windows', 'macos'],
install_requires=['numpy', 'opencv-python'],
zip_safe=False)
zip_safe=False,
entry_points={
'console_scripts': [
'blind_watermark = blind_watermark.cli_tools:main'
]
})

0 comments on commit f7dbce2

Please sign in to comment.