【问题标题】:imshow seems to show the wrong image (not duplicate)imshow 似乎显示了错误的图像(不重复)
【发布时间】: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,并且红点相应移动。我可能错了。

谁能发现错误?我觉得这将是一个非常愚蠢的错误,但我就是找不到。

【问题讨论】:

    标签: opencv image-processing


    【解决方案1】:

    我认为这是一个数据类型问题。

    尝试将datafloat64更改为uint8

    data = np.array([], dtype=np.uint8).reshape([0, IMG_WIDTH , IMG_HEIGHT ,IMG_DEPTH])
    

    白色和红色是表示饱和的标志。 float64 范围预计为[0, 1],而uint8 预计为[0, 255]。你可以在here找到更多关于这个问题的信息。

    【讨论】:

      猜你喜欢
      • 2019-09-17
      • 2020-08-04
      • 2014-06-06
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2014-06-19
      • 2017-11-30
      相关资源
      最近更新 更多