我一直在线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。谢谢。
P.S。我对python很新,我还不太熟悉一些概念在这种语言中的运作方式。
答案 0 :(得分:1)
这看起来像
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)
...并继续,因为你已经在做。