0
私はthis tutorialをオンラインでフォローして逆画像検索エンジンを作成していますが、画像のインデックスは検索しませんが、JSONで取得する画像URLの配列のみを検索します10枚の画像、すべてが密接に関連します)。私は現在、この配列を作成する最善の方法を検討していますが、インデックスに置き換えられる単純な配列だけではなく、検索に使用されている最初のイメージと、アレイ。チュートリアルからのインデックスクラスは以下の通りです:インデックスをPythonのイメージURLの配列に置き換えるにはどうすればいいですか?
# 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()
私は最終的にシステムのためのGUIを追加し、また、JSON形式で検索結果を出力するつもりです。ありがとうございました。
P.S.私はかなり新しいPythonですが、私はまだいくつかのコンセプトがこの言語でどのように機能するかに慣れていません。
これは、次のように置き換えます。#出力用のインデックスファイルを書き込み用に開きます。 output = open(args ["index"]、 "w")?私はこの機能をどのように置き換えるのかについてはあまりよく分かりません。 – QQuestions
あなたの問題を正しく理解している場合、はい:このコードは、入力派生インデックスを単にURLのリストで置き換えます。 – Prune