gpt4 book ai didi

python - 有没有办法从Python中包含多个图像的文件夹中读取前N个图像,执行操作并读取下N个图像

转载 作者:行者123 更新时间:2023-12-02 17:22:43 25 4
gpt4 key购买 nike

我正在使用一种图像处理算法,该算法涉及拍摄三张图像以比较错误。我对从文件夹中读取一组3张图像的基本步骤感到困惑,该步骤执行某些操作(例如特征提取)并读取下一组3张图像以执行操作等

我编写了从1500张图像中提取前3张图像的代码。为了执行特征提取,我必须将图像的三元组一起作为算法的输入,提取特征并将其存储到矩阵中。当我从3张图像中提取特征时,我需要获得3 * 37的特征矩阵,假设我有37个特征。如何获得所有图像的特征矩阵?


imageDir_meas = #specify your path here
image_path_list = []
valid_image_extensions = [".jpg", ".jpeg", ".png", ".tif", ".tiff"] #specify your vald extensions here
valid_image_extensions = [item.lower() for item in valid_image_extensions]

#create a list all files in directory and
#append files with a vaild extention to image_path_list

for file in os.listdir(imageDir_meas):
extension = os.path.splitext(file)[1]
if extension.lower() not in valid_image_extensions:
continue
image_path_list.append(os.path.join(imageDir_meas, file))

for imagePath in image_path_list[:3]:
image = cv2.imread(imagePath)

# display the image on screen with imshow()
# after checking that it loaded
if image is not None:
cv2.imshow(imagePath, image)
elif image is None:
print ("Error loading: " + imagePath)
#end this loop iteration and move on to next image
continue
key = cv2.waitKey(0)
if key == 27: # escape
break
cv2.destroyAllWindows()

最佳答案

n_input = 3 # your algorithm needs 3 images
image_path_list_sub = [image_path_list[x:x+n_input] for x in range(0, len(image_path_list), n_input)]
for imagePath in image_path_list_sub:
if len(imagePath) == 3:
img0 = cv2.imread(imagePath[0])
img1 = cv2.imread(imagePath[1])
img2 = cv2.imread(imagePath[2])
# your_algorithm(img0, img1, img2)
else:
continue

关于python - 有没有办法从Python中包含多个图像的文件夹中读取前N个图像,执行操作并读取下N个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61363603/

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