Search.py下的相应局部代码修改为:
cd = ColorDescriptor.ColorDescriptor((8,12,3))
# load the query image and describe it
temp_query=args["query"]
#编码使其可以读中文命名的文件,imread必须要为'gbk'码
temp_query=temp_query.encode('gbk')
#解码:temp_query.decode()
query = cv2.imread(temp_query.decode())
-----------------------
index.py下的相应局部代码修改为:
imageID = imagePath[imagePath.rfind("\\")+1:]
imagePath=imagePath.encode('gbk')
image = cv2.imread(imagePath.decode())
cd = ColorDescriptor.ColorDescriptor((8,12,3))
# load the query image and describe it
temp_query=args["query"]
#编码使其可以读中文命名的文件,imread必须要为'gbk'码
temp_query=temp_query.encode('gbk')
#解码:temp_query.decode()
query = cv2.imread(temp_query.decode())
features = cd.describe(query)
#coding:utf-8
# -*- coding: utf-8 -*-
"CBIR(Content-Base Image Retrieval)--Search"
import argparse
import cv2
import ColorDescriptor
import Searcher
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--index", required=True, help="Path to where the computed index will be stored")
ap.add_argument("-q", "--query", required=True, help="Path to query image")
ap.add_argument("-r", "--result_path", required = True, help="Path to the result Path")
args = vars(ap.parse_args())
cd = ColorDescriptor.ColorDescriptor((8,12,3))
# load the query image and describe it
temp_query=args["query"]
#编码使其可以读中文命名的文件,imread必须要为'gbk'码
temp_query=temp_query.encode('gbk')
#解码:temp_query.decode()
query = cv2.imread(temp_query.decode())
features = cd.describe(query)
# perform the search
searcher = Searcher.Searcher(args["index"])
results = searcher.search(features)
# display the query
# cv2.imshow("Query", query)
# loop over the results
for(score, resultID) in results:
# load the result image and display it
print(args["index"]+"/"+resultID)
# result = cv2.imread(args["result_path"]+"/"+resultID)
# cv2.imshow("Result",result)
# cv2.waitKey(0)
-----------------------
index.py下的相应局部代码修改为:
imageID = imagePath[imagePath.rfind("\\")+1:]
imagePath=imagePath.encode('gbk')
image = cv2.imread(imagePath.decode())
即可实现读取中文命名的文件名。
# -*- coding: UTF-8 -*-
"CBIR(Content-Base Image Retrieval)--Extract Features and Indexing"
import ColorDescriptor
import argparse
import glob
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True, help="Path to the directory that cntains 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())
cd = ColorDescriptor.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"]+"/*.jpg"):
# extract the image ID from the image
imageID = imagePath[imagePath.rfind("\\")+1:]
imagePath=imagePath.encode('gbk')
image = cv2.imread(imagePath.decode())
# describe the image
features = cd.describe(image)
# write feature to file
features = [str(f) for f in features]
output.write("%s,%s\n" %(imageID,",".join(features)))
# close index file
output.close()