gpt4 book ai didi

python - 在python中堆叠图像时出现ValueError

转载 作者:太空宇宙 更新时间:2023-11-03 21:31:53 24 4
gpt4 key购买 nike

我正在尝试聚焦堆叠多张图像,但我不断收到以下错误消息。为什么我会收到此错误以及我应该如何解决它?

如有任何关于如何解决此问题的建议和代码片段,我们将不胜感激。

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

File "/Users/...", line 32, in stack maximum = abs_laps.max(axis=0)

File "/anaconda3/lib/python3.5/site-packages/numpy/core/_methods.py", line 26, in _amax return umr_maximum(a, axis, None, out, keepdims)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or 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]

最佳答案

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

关于python - 在python中堆叠图像时出现ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51092720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com