def func3(command): findresult = [] cd = ColorDescriptor((8, 12, 3)) query = cv2.imread(command) features = cd.descriptor(query) searcher1 = Searcher("index.csv") results = searcher1.search(features) for (score, resultID) in results: findresult.append(resultID[:-4]) STORE_DIR = "index1" vm_env = lucene.getVMEnv() vm_env.attachCurrentThread() directory = SimpleFSDirectory(File(STORE_DIR)) searcher = IndexSearcher(DirectoryReader.open(directory)) analyzer = WhitespaceAnalyzer(Version.LUCENE_CURRENT) res = [] for imgID in findresult: if imgID == '': return query = QueryParser(Version.LUCENE_CURRENT, "name", analyzer).parse(imgID) scoreDocs = searcher.search(query, 9).scoreDocs for scoreDoc in scoreDocs: doc = searcher.doc(scoreDoc.doc) try: res.append([ doc.get("name"), doc.get("collect_num"), doc.get("zhuliao").split(' '), doc.get("zuofa").split('\n'), doc.get("img_url"), doc.get("url") ]) except: pass return res
#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"] + "/*.jpg"): #extract the image ID (i.e. the unique filename) from the image path and load the image itself imageID = imagePath[imagePath.rfind("/") + 1:] imageID = imageID.replace('########', '/') if (imageID[-5] == ')'): imageID = imageID[:-7] + imageID[-4:] print("正在建立图片" + imageID + "的索引") try: image = cv2.imread(imagePath) #descriptor the image features = cd.descriptor(image) except: print("建立失败") else: #write the features to file features = [str(f) for f in features] output.write("%s,%s\n" % (imageID, ",".join(features))) print("建立成功") 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:] imageID = imageID.replace('########', '/') if (imageID[-5] == ')'): imageID = imageID[:-7] + imageID[-4:] print("正在建立图片" + imageID + "的索引") try: