【问题标题】:ValueError when stacking images in python在python中堆叠图像时出现ValueError
【发布时间】:2018-06-29 00:22:02
【问题描述】:

我正在尝试集中堆叠多个图像,但我不断收到以下错误。为什么我会收到此错误,我应该如何解决?

任何有关如何解决此问题的建议和代码 sn-ps 将不胜感激。

我查看了this post,但我仍然不确定这个错误在我的场景中的含义。

文件“/Users/...”,第 32 行,在堆栈中 最大值 = abs_laps.max(axis=0)

文件“/anaconda3/lib/python3.5/site-packages/numpy/core/_methods.py”,第 26 行,在 _amax return umr_maximum(a, axis, None, out, keepdims)

ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()

下面提供了上面错误中指示的堆栈方法,堆栈器方法也是如此。

def stacker(folder, num):
    images = []
    for filename in os.listdir(folder):
        img = cv2.imread(os.path.join(folder,filename))
        if img is not None:
            images.append(img)
    stacked = stack(images)
    newpath = "key-frames" #destination of final image
    os.chdir(newpath)
    cv2.imwrite("Stacked%d.png" % num, stacked)

栈方法如下

def stack(imgs):
    #aligns the images
    images = imageAlignment(imgs)
    laps = []

    #loop through images and compute lap
    for i in range(len(images)):
        grayImg = cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)
        laps.append(findLap(grayImg))

    #converts input to array
    laps = np.asarray(laps)

    #creates empty array
    output = np.zeros(shape=images[0].shape, dtype=images[0].dtype)

    #find absolute value of laps
    abs_laps = np.absolute(laps)

    #find maximum of laps
    maximum = abs_laps.max(axis=0)

    #boolean to determine if lap for image is max
    booleanChecker = abs_laps == maximum

    #pixels are unit8 and uint8 will wrap
    mask = booleanChecker.astype(np.uint8)

    #inverts every bit of array using mask that specifies of output array 
    #to be changed
    for i in range(0,len(images)):
        output = cv2.bitwise_not(images[i],output, mask=mask[i])

    return 255 - output

编辑

下面是 abs_laps 的组成示例。

[0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 >0.000e+00 0.000e+00 0.000e+00 2.000e+00 1.600e+01 6.400e+01 1.800e+02 >3.800e+02]

【问题讨论】:

  • related 发帖。
  • 你能告诉我们abs_laps的样子吗?描述它的形状和里面有什么,或者打印出来?
  • @JayCalamari 它是 26 x 540 数组的所有圈数绝对值的列表。
  • @JayCalamari 我添加了一个示例,它看起来像一个编辑。

标签: python python-3.x opencv image-processing


【解决方案1】:

您的输入数据有误。您应该打印出代码中断的图像并检查数据。您很可能在要堆叠的图像集中有一个空图像。

【讨论】:

    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 2019-05-23
    • 2012-03-04
    • 2020-12-10
    • 2018-02-07
    • 2019-06-03
    • 1970-01-01
    • 2017-10-17
    相关资源
    最近更新 更多