pip install -r requirements.txt
# 隐写信息
import cv2
import os
from gstego import Steganography
# 初始化隐写器
stego_opt = Steganography()
# 读取载体信息
carrier_path = r"**.png"
image_file = cv2.imread(carrier_path)
# 设置隐写消息
hide_info = "我好像曾经见过你"
# 隐写
carrier_data = stego_opt.hide_message(image_file, hide_info)
# 保存隐写的载体
cv2.imwrite("output.png", carrier_data)
# 读取载体
img_in = cv2.imread(r"output.png")
# 提取隐写信息
extract_info = stego_opt.extract(img_in)
# 展示隐写消息
print(extract_info["message"])
# 隐写文件
import cv2
import os
from gstego import Steganography
# 初始化隐写器
stego_opt = Steganography()
# 读取载体信息
carrier_path = r"**.png"
image_file = cv2.imread(carrier_path)
# 读取隐写文件
hide_file_path = r"**.txt"
hide_buffer = open(hide_file_path, "rb")
# 隐写
carrier_data = stego_opt.hide_file(image_file, hide_buffer)
cv2.imwrite("output.png", carrier_data)
# 读取载体
img_in = cv2.imread(r"output.png")
extract_info = stego_opt.extract(img_in)
# 保存提取出的文件
with open("out." + extract_info["file"]["suffix"], "wb") as fw:
fw.write(extract_info["file"]["bytes_data"])