<div>
</div>
<p>我想使用for循环提取目录中的2张照片。在每次迭代中,它都会带来一张照片。获取两张照片后,将触发另一个if语句,并将打印“成功从目录中提取的两张图像”。这是代码==></p>
<pre><code>import cv2
import os
import re
from skimage.io import imread,imshow,imsave
images =os.listdir('D:\programs python/regeneration\Mi3_Aligned/1')
img = None
ref_img = None
for i in images:
if i == "1.bmp":
img = imread('D:\programs python/regeneration\Mi3_Aligned/1/' + i)
img = cv2.resize(img, (980, 980), cv2.INTER_AREA)
if i == "2.bmp":
ref_img = imread('D:\programs python/regeneration\Mi3_Aligned/1/'+ i)
ref_img = cv2.resize(img, (980, 980), cv2.INTER_AREA)
if (img!=None and ref_img!=None):
print("Both images extracted from directory successfully")
</code></pre>
<p>但它产生了一个错误,我无法理解问题是什么</p>
<pre><code>if (img!=None and ref_img!=None):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
</code></pre>
<p>请帮忙</p>