Exemplo n.º 1
0
class VideoFrame:
    def __init__(self, filepath):
        self.cap = cv2.VideoCapture(filepath)
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)
        self.size = (int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
                     int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
        self.bwm = WaterMark(password_wm=1, password_img=1)

    def video2image_encode(self):
        succeed = self.cap.isOpened()
        frame_count = 0
        while succeed:
            frame_count += 1
            succeed, frame = self.cap.read()
            if frame is not None:
                if frame_count % 17 == 0:
                    self.bwm.read_img_frame(frame)
                    self.bwm.read_wm('./watermark/qr_img_04.png')
                    self.bwm.embed('../frame/%d.jpg' % frame_count)
                else:
                    cv2.imwrite('../frame/%d.jpg' % frame_count, frame)
        self.cap.release()
        print('processed {} images'.format(frame_count))

    def video2image_decode(self):
        succeed = self.cap.isOpened()
        frame_count = 0
        while succeed:
            frame_count += 1
            succeed, frame = self.cap.read()
            if frame is not None:
                if frame_count % 17 == 0:
                    self.bwm.read_img_frame(frame)
                    self.bwm.extract(
                        '../frame/%d.jpg' % frame_count,
                        wm_shape=(155, 155),
                        out_wm_name='../output/video_extracted_{}.jpg'.format(
                            frame_count),
                    )
        self.cap.release()
        print('processed {} images'.format(frame_count))

    def image2video(self, filepath):
        forrcc = cv2.VideoWriter_fourcc(*'mp4v')
        images = os.listdir('../frame')
        im = Image.open('../frame/' + images[0])
        vw = cv2.VideoWriter(filepath, forrcc, self.fps, im.size)

        os.chdir('../frame')
        for image in range(len(images)):
            image_file = str(image + 1) + '.jpg'
            try:
                frame = cv2.imread(image_file)
                vw.write(frame)
            except Exception as exc:
                print(image_file, exc)
        vw.release()
        print(filepath, 'Synthetic success!')
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image

from digital_watermark import attck_check
from digital_watermark import WaterMark

# 缩放攻击
attck_check.resize_att('output/embedded.png',
                       'output/缩放攻击.png',
                       out_shape=(800, 600))
attck_check.resize_att('output/缩放攻击.png',
                       'output/缩放攻击_还原.png',
                       out_shape=(1920, 1200))
# out_shape 是分辨率,需要颠倒一下
# %%提取水印
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename="output/缩放攻击_还原.png",
             wm_shape=(128, 128),
             out_wm_name="output/缩放攻击_提取水印.png")
Exemplo n.º 3
0
# coding=utf-8
# run origin.py to generate the embedded image
import sys
sys.path.append('../')
from digital_watermark import attck_check
from digital_watermark import WaterMark

# %%
# 攻击
attck_check.shelter_att('../output/encoded_file.png',
                        '../output/hide.png',
                        ratio=0.1,
                        n=10)

# %% 提取水印
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename='../output/hide.png',
             wm_shape=(117, 117),
             out_wm_name='../output/hide_wm.png')
Exemplo n.º 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from digital_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# 读取原图
bwm1.read_img('pic/ori_img_2.png')
# 读取水印
bwm1.read_wm(wm_content='digital_watermark/watermark/qr_img_04.png')
# 打上盲水印
bwm1.embed('output/embedded_7.png')

# %% 解水印


bwm1 = WaterMark(password_wm=1, password_img=1)
# 注意需要设定水印的长宽wm_shape
bwm1.extract(filename='output/embedded_7.png', wm_shape=(155, 155), out_wm_name='output/wm_extracted_6.png', )
Exemplo n.º 5
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image

from digital_watermark import attck_check
from digital_watermark import WaterMark

# 亮度调高攻击
attck_check.bright_att('../output/embedded_4.png',
                       '../output/high_light.png',
                       ratio=1.1)

# %% 提取水印
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename='../output/high_light.png',
             wm_shape=(100, 300),
             out_wm_name='../output/high_light_wm.png')
Exemplo n.º 6
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image

from digital_watermark import attck_check
from digital_watermark import WaterMark

# 一次横向裁剪打击
attck_check.cut_att_width('../output/embedded_4.png', '../output/hori_ut.png', ratio=0.5)
attck_check.anti_cut_att('../output/hori_ut.png', '../output/hori_ut_fill.png', origin_shape=(1200, 1920))

# %%提取水印
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename="../output/hori_ut_fill.png", wm_shape=(100, 300), out_wm_name="../output/hori_ut_w.png")
Exemplo n.º 7
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image

from digital_watermark import attck_check
from digital_watermark import WaterMark

# %%椒盐攻击
attck_check.salt_pepper_att('output/embedded.png',
                            'output/椒盐攻击.png',
                            ratio=0.05)
# ratio是椒盐概率

# %%纵向裁剪打击.png
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename='output/椒盐攻击.png',
             wm_shape=(128, 128),
             out_wm_name='output/椒盐攻击_提取水印.png')
Exemplo n.º 8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# embed string
import numpy as np
from digital_watermark import WaterMark
import time

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('pic/ori_img_1.jpg')
wm = '@SP-Official' + '--' + time.strftime('%Y-%m-%d', time.localtime())
bwm1.read_wm(wm, mode='str')
bwm1.embed('output/embedded.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))

# %% 解水印
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print(wm_extract)

assert wm == wm_extract, '提取水印和原水印不一致'
Exemplo n.º 9
0
 def __init__(self, filepath):
     self.cap = cv2.VideoCapture(filepath)
     self.fps = self.cap.get(cv2.CAP_PROP_FPS)
     self.size = (int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
                  int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
     self.bwm = WaterMark(password_wm=1, password_img=1)
Exemplo n.º 10
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 除了嵌入图片,也可以嵌入比特类数据
import numpy as np
from digital_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)

# 读取原图
bwm1.read_img('pic/ori_img.jpg')

# 读取水印
wm = [True, False, True, True, True, False, True, True, False, True]
bwm1.read_wm(wm, mode='bit')

# 打上盲水印
bwm1.embed('output/watermark_img.png')

# %% 解水印

# 注意设定水印的长宽wm_shape
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/watermark_img.png', wm_shape=10, mode='bit')
print(wm_extract)

assert np.all(wm == (wm_extract > 0.5)), '提取水印和原水印不一致'
Exemplo n.º 11
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image

from digital_watermark import attck_check
from digital_watermark import WaterMark

# 旋转攻击
attck_check.rot_att('../output/embedded_4.png',
                    '../output/rotate.png',
                    angle=45)
attck_check.rot_att('../output/rotate.png',
                    '../output/rotate_ori.png',
                    angle=-45)

# %%提取水印
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename='../output/rotate_ori.png',
             wm_shape=(100, 300),
             out_wm_name='../output/rotate_w.png')
Exemplo n.º 12
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from digital_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# 读取原图
bwm1.read_img('pic/ori_img_2.png')
# 读取水印
bwm1.read_wm('pic/watermark_3.png')
# 打上盲水印
bwm1.embed('output/embedded_4.png')

# %% 解水印

bwm1 = WaterMark(password_wm=1, password_img=1)
# 注意需要设定水印的长宽wm_shape
bwm1.extract(
    filename='output/embedded_4.png',
    wm_shape=(100, 300),
    out_wm_name='output/wm_extracted_4.png',
)
Exemplo n.º 13
0
# -*- coding: utf-8 -*-
# run origin.py to generate the embedded image
import sys
sys.path.append('../')
from digital_watermark import attck_check
from digital_watermark import WaterMark

# 一次纵向裁剪打击
attck_check.cut_att_height('../output/encoded_file.png', '../output/ver_atk.png', ratio=0.65)
attck_check.anti_cut_att('../output/ver_atk.png', '../output/ver_atk_fill.png', origin_shape=(1200, 1920))

# %%纵向裁剪打击.png
bwm1 = WaterMark(password_wm=1, password_img=1)
bwm1.extract(filename="../output/ver_atk_fill.png", wm_shape=(117, 117), out_wm_name="../output/ver_atk_wm.png")