ap.add_argument( "-b", "--bovw-db", required=True, help="Path to where the bag-of-visual-words database will be stored") ap.add_argument( "-s", "--max-buffer-size", type=int, default=500, help="Maximum buffer size for # of features to be stored in memory") args = vars(ap.parse_args()) # load the codebook vocabulary and initialize the bag-of-visual-words transformer vocab = pickle.loads(open(args["codebook"], "rb").read()) bovw = BagOfVisualWords(vocab) # open the features database and initialize the bag-of-visual-words indexer featuresDB = h5py.File(args["features_db"], mode="r") bi = BOVWIndexer(bovw.codebook.shape[0], args["bovw_db"], estNumImages=featuresDB["image_ids"].shape[0], maxBufferSize=args["max_buffer_size"]) # loop over the image IDs and index for (i, (imageID, offset)) in enumerate(zip(featuresDB["image_ids"], featuresDB["index"])): # check to see if progress should be displayed if i > 0 and i % 10 == 0: bi._debug("processed {} images".format(i), msgType="[PROGRESS]")
"--relevant", required=True, help="Path to relevant dictionary") ap.add_argument("-q", "--query", required=True, help="Path to the query image") args = vars(ap.parse_args()) # initialize the keypoint detector, local invariant descriptor, and descriptor detector = FeatureDetector_create("SURF") descriptor = DescriptorExtractor_create("RootSIFT") dad = DetectAndDescribe(detector, descriptor) # load the inverted document frequency array and codebook vocabulary, then # initialize the bag-of-visual-words transformer idf = pickle.loads(open(args["idf"], "rb").read()) vocab = pickle.loads(open(args["codebook"], "rb").read()) bovw = BagOfVisualWords(vocab) # load the relevant queries dictionary and lookup the relevant results for the # query image relevant = json.loads(open(args["relevant"]).read()) queryFilename = args["query"][args["query"].rfind("/") + 1:] queryRelevant = relevant[queryFilename] # load the query image and process it queryImage = cv2.imread(args["query"]) cv2.imshow("Query", imutils.resize(queryImage, width=320)) queryImage = imutils.resize(queryImage, width=320) queryImage = cv2.cvtColor(queryImage, cv2.COLOR_BGR2GRAY) # extract features from the query image and construct a bag-of-visual-words from it (queryKps, queryDescs) = dad.describe(queryImage)
"--images", required=True, help="Path to input images directory") ap.add_argument("-c", "--codebook", required=True, help="Path to the codebook") ap.add_argument("-m", "--model", required=True, help="Path to the classifier") args = vars(ap.parse_args()) # initialize the keypoint detector, local invariant descriptor, and the descriptor # pipeline detector = FeatureDetector_create("GFTT") descriptor = DescriptorExtractor_create("RootSIFT") dad = DetectAndDescribe(detector, descriptor) # load the codebook vocabulary and initialize the bag-of-visual-words transformer vocab = pickle.loads(open(args["codebook"], "rb").read()) bovw = BagOfVisualWords(vocab) # load the classifier model = pickle.loads(open(args["model"], "rb").read()) num_tests = len(list(paths.list_images(args["images"]))) montage = ResultsMontage((240, 320), 3, num_tests) # loop over the image paths for imagePath in paths.list_images(args["images"]): # load the image and prepare it from description image = cv2.imread(imagePath) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = imutils.resize(gray, width=min(320, image.shape[1])) # describe the image and classify it