免责声明:这是家庭作业的一部分,但是,它已经被传递了。我只是在为将来的专有技术寻找正确的解决方案。
该程序的目标是使用Python OpenCV库来实现图像->图像隐写术(在其他图像内部嵌入/提取图像)。使用最小有效位(LSB)方法对两个大小相等的图像进行此操作。
该程序允许用户选择用于嵌入的位数,因此使用1位嵌入图像几乎是人眼无法察觉的,而使用7位就可以清楚地识别出隐藏图像。
通过从秘密图像中获取每个RGB字节的最高有效位(MSB),并将它们设置在封面图像的LSB位置,我正确地实现了嵌入。
我的问题是在嵌入秘密图像后提取它。代码运行后,剩下的图像似乎只是它的蓝色表示。我不确定哪里出错了,但是我感觉到它与我的位操作技术或OpenCV库的使用有关。非常感谢您的任何帮助,在此先感谢您!
提取代码:
import cv2
import numpy
def extract(img1, bitsUsed):
print "Extracting..."
# Import image & get dimensions
img = cv2.imread(img1)
h = img.shape[0]
w = img.shape[1]
# Create new image to extract secret image
# Same dimensions, and rgb channel
secretImg = numpy.zeros((h,w,3), numpy.uint8)
x, y = 0, 0
# Loop thru each pixel
while x < w:
while y < h:
# Grab the LSB (based on bitsUsed from embedding)
lsb_B = img.item(y,x,0) …Run Code Online (Sandbox Code Playgroud)