Exemple #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!')
Exemple #2
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', )
Exemple #3
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, '提取水印和原水印不一致'
Exemple #4
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)), '提取水印和原水印不一致'
Exemple #5
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',
)