# 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 index dictionary to store our our quantifed
# images, with the 'key' of the dictionary being the image
# filename and the 'value' our computed features
index = {}

# initialize our image descriptor -- a 3D RGB histogram with
# 8 bins per channel
desc = RGBHistogram([8, 8, 8])

# use glob to grab the image paths and loop over them
for imagePath in glob.glob(args["dataset"] + "/*.jpg"):
	# extract our unique image ID (i.e. the filename)
	k = imagePath[imagePath.rfind("/") + 1:];print("k "+k)

	# load the image, describe it using our RGB histogram
	# descriptor, and update the index
	image = cv2.imread(imagePath)
	features = desc.describe(image)
	index[k] = features

# we are now done indexing our image -- now we can write our
# index to disk
f = open(args["index"], "w")
Beispiel #2
0
    search = 0

directory = args["query"]
for filename in os.listdir(directory):
    if filename.endswith(".png"):
        queryPath = os.path.join(directory, filename)
        print(queryPath)
        queryImage = cv2.imread(queryPath)
        queryImage = cv2.resize(queryImage, (450, 360))
        cv2.putText(queryImage, queryPath, (10, 30), cv2.FONT_HERSHEY_SIMPLEX,
                    1.0, (0, 0, 255), 3)
        cv2.imshow("Query", queryImage)
        print("query: %s" % queryPath)
        if search == 0:
            if args["descriptor"] == "rgb":
                desc = RGBHistogram([8, 8, 8])
                queryFeatures = desc.describe(queryImage)
            elif args["descriptor"] == "lbp":
                desc = LocalBinaryPatterns(24, 8)
                gray = cv2.cvtColor(queryImage, cv2.COLOR_BGR2GRAY)
                queryFeatures = desc.describe(gray)
            elif args["descriptor"] == "hog":
                winSize = (64, 64)
                blockSize = (16, 16)
                blockStride = (8, 8)
                cellSize = (8, 8)
                nbins = 9
                derivAperture = 1
                winSigma = 4.
                histogramNormType = 0
                L2HysThreshold = 2.0000000000000001e-01