我发现我的代码无法运行,因为"在#34;开始的线程中出现了MemoryErrorUnhandled异常。错误。
这是我的代码:
def waterMark(surface,hidden,structure=(2,1,5)):
if sum(structure) == 8 and len(structure) == 3:
B = int(structure[0])
G = int(structure[1])
R = int(structure[2])
for i in xrange(surface.shape[1]):
for j in xrange(surface.shape[0]):
if i < hidden.shape[0] and j < hidden.shape[1]:
surface[i,j][0] = surface[i,j][0][:8-B] + hidden[i,j][:B]
surface[i,j][1] = surface[i,j][2][:8-G] + hidden[i,j][:G]
surface[i,j][2] = surface[i,j][2][:8-R] + hidden[i,j][:R]
else:
print 'the param must be 3-dim list or turtle ,and its sum is 8'
return surface
def to_Bin(array):
b_list = []
if len(array.shape) == 2:
for i in range(array.shape[0]):
InterVariable = []
for j in range(array.shape[1]):
binnum = bin(array[i,j])[2:]
InterVariable.append((8-len(binnum))*'0'+ binnum)
b_list.append(InterVariable)
elif len(array.shape) == 3:
for i in xrange(array.shape[0]):
InterVariable = []
for j in xrange(array.shape[1]):
InterVariable.append(
[(8-len(bin(array[i,j][c])[2:]))*'0'+ \
bin(array[i,j][c])[2:] for c in range(3)]
)
b_list.append(InterVariable)
return np.array(b_list)
def MED(orgpath,datapath):
base_img = cv2.imread(orgpath)
hidden_img = cv2.imread(datapath)
gray_hidden = cv2.cvtColor(hidden_img,cv2.COLOR_BGR2GRAY)
while base_img.size < 2*hidden_img.size:
base_img = cv2.pyrUp(base_img)
print 'base_img%d' %(base_img.size)
gray_b_hidden = to_Bin(gray_hidden)
bgr_b_base = to_Bin(base_img)
wm = waterMark(bgr_b_base,gray_b_hidden,(3,2,3))
encry_img = to_Dec(wm)
return encry_img
file1 = 'im.jpg'
file2 = 'IMG_0284.jpg'
img = MED(file1,file2)
file2的大小只有1.2M,file1是20K,我不知道为什么内存不够。我想知道如何将它放入记忆中。谢谢。
反馈意见: Traceback(最近一次调用最后一次): 文件&#34; H:\ signature.py&#34;,第146行,in img = MED(file1,file2) MED中的文件&#34; H:\ signature.py&#34;,第139行 bgr_b_base = to_Bin(base_img) 的MemoryError