gpt4 book ai didi

python - 如何在Python中使用图片网址数组替换索引?

转载 作者:行者123 更新时间:2023-12-02 17:42:29 26 4
gpt4 key购买 nike

我一直在线遵循this tutorial创建反向图像搜索引擎,但是,我不想搜索图像索引,而只搜索图像URL的数组,我将使用JSON检索(我将仅搜索10张图像,这些都将密切相关)。我目前正在寻找创建此数组的最佳方法,但我不知道如何用循环的简单数组替换索引,以将搜索中使用的初始图像与数组。本教程中的索引类如下:

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
help="Path to the directory that contains the images to be indexed")
ap.add_argument("-i", "--index", required=True,
help="Path to where the computed index will be stored")
args = vars(ap.parse_args())

# initialize the color descriptor
cd = ColorDescriptor((8, 12, 3))

# open the output index file for writing
output = open(args["index"], "w")

# use glob to grab the image paths and loop over them
for imagePath in glob.glob(args["dataset"] + "/*.png"):
# extract the image ID (i.e. the unique filename) from the image
# path and load the image itself
imageID = imagePath[imagePath.rfind("/") + 1:]
image = cv2.imread(imagePath)

# describe the image
features = cd.describe(image)

# write the features to file
features = [str(f) for f in features]
output.write("%s,%s\n" % (imageID, ",".join(features)))

# close the index file
output.close()

我最终还将以JSON形式输出搜索结果,从而为系统添加GUI。谢谢。

附言我对python还是很陌生,但我仍然不太熟悉这种语言中一些概念的工作方式。

最佳答案

这看起来像

image_list = [
"http://www.photo_location1.com/local_dir/photo_name1.png",
"http://www.photo_location2.com/local_dir/photo_name2.png",
...
]

for imagePath in image_list:
image = cv2.imread(imagePath)

...,然后继续做下去。

关于python - 如何在Python中使用图片网址数组替换索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42726993/

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