Python:“由启动的线程中的MemoryErrorUnhandled异常”
我发现我的代码无法运行,因为错误启动的线程中存在MemoryErrorUnhandled异常 这是我的代码:Python:“由启动的线程中的MemoryErrorUnhandled异常”,python,list,memory,Python,List,Memory,我发现我的代码无法运行,因为错误启动的线程中存在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])
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,我不知道为什么内存不够。我想知道如何把它放在记忆中。多谢各位
反馈意见:
回溯最近一次呼叫上次: 文件H:\signature.py,第146行,在 img=MEDfile1,file2 文件H:\signature.py,第139行,MED格式 bgr_b_base=to_Binbase_img
MemoryError你能给出整个回溯吗?回溯最近的一次呼叫最后:文件H:\py\u app\dataforstudy\图片签名\signature.py,第146行,在img=MEDfile1,file2文件H:\py\u app\dataforstudy中\图片签名\signature.py,第139行,在MED bgr_b_base=to_Binbase_img MemoryError中,在to_Bin的方法中感谢您:您正在迭代图像的像素吗?我假设变量b_列表的大小随着可用内存的增长而增长。虽然图像本身可能只有1.2M,但您在此列表中存储的内容很容易变大。你到底在做什么?您在b_列表中存储了什么?1.2M图像有多少像素?>>>base_img=cv2.imread'img_0284.jpg'>>>base_img.size 23970816