我正在尝试将几幅图像聚焦堆叠,但是我仍然收到以下错误。为什么会收到此错误,该如何解决?
任何有关如何解决此问题的建议和代码段将不胜感激。
我看过this post,但仍不确定该错误在我的情况下的含义。
文件“ / Users / ...”,第32行,在堆栈中 最大= abs_laps.max(轴= 0)
_amax中的文件“ /anaconda3/lib/python3.5/site-packages/numpy/core/_methods.py”,第26行 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]
答案 0 :(得分:2)
您的输入数据中有错误。您应该打印出代码在哪张图像上中断并检查数据。您最有可能要堆叠一堆图像。