【发布时间】:2018-08-01 21:17:57
【问题描述】:
我正在尝试使用 cv2.imshow() 显示图像,但是在我将它与数据(所有图像的集合)连接后,batch_data(原始图像)发生了变化。我注意到原始图像是如何改变的。
data = np.array([]).reshape([0, IMG_WIDTH , IMG_HEIGHT ,IMG_DEPTH ])
label = np.array([])
batch_label = np.array([255]).reshape(1) #label number represent background
x = True
for (n,address) in enumerate(address_list):
print("Reading all images with background from ", address)
batch_data = cv2.imread(image_dir + address)
dim = (IMG_WIDTH ,IMG_HEIGHT)
if batch_data is not None:
batch_data = cv2.resize(batch_data,dim, interpolation = cv2.INTER_NEAREST)
else:
print("batch_data is not read.")
batch_data = np.expand_dims(batch_data, axis= 0)
data = np.concatenate((data,batch_data))
label = np.concatenate((label,batch_label))
while x:
print("batch_data.shape",batch_data.shape)
print("data.shape", data.shape)
print((np.squeeze(batch_data, axis=0) == data[n,...]).all()) # return true
cv2.imshow('image', np.squeeze(batch_data, axis= 0)) # show original image
cv2.imshow('image2', data[n,...]) #show original image but color is alter to white and red
cv2.waitKey(0)
cv2.destroyAllWindows()
x = False
我认为 cv2.imshow('image2', data[n,...]) 显示原始图像,因为我尝试使用转置将轴 = 1 交换为轴 = 2,并且红点相应移动。我可能错了。
谁能发现错误?我觉得这将是一个非常愚蠢的错误,但我就是找不到。
【问题讨论】: