Esempio n. 1
0
    def recognize(self):
        if not self.filename:
            QtWidgets.QMessageBox.critical(self.centralwidget,
                                           'Selection error',
                                           'You have to load a query image !')
            return None
        queryImage = cv2.imread(self.filename)
        desc = RGBHistogram([8, 8, 8], 5)
        queryFeatures = desc.describe(queryImage)

        # load the index perform the search
        if not os.path.exists("index.pkl"):
            QtWidgets.QMessageBox.critical(
                self.centralwidget, 'Indexing error',
                'You have to Index the images features from the dataset !')
            self.open_indexer()
            return None
        with open("index.pkl", 'rb') as handle:
            index = pickle.load(handle)
        searcher = Searcher(index)
        results = searcher.search(queryFeatures)

        # loop over the top ten results
        images = [x[1] for x in results][:10]
        self.thumbnail.update(images)
    def index_imgs(self):
        self.index_images.setEnabled(False)
        if not self.images:
            QtGui.QMessageBox.critical(self, 'Selection error',
                                       'No image selected')
            return

        self.overlay.show()
        index = {}

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

        # use glob to grab the image paths and loop over them
        for imagePath in self.images:

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

        # we are now done indexing our image -- now we can write our
        # index to disk
        filename = 'index.pkl'
        with open(filename, 'wb') as handle:
            pickle.dump(index, handle)
        self.overlay.hide()
        QtWidgets.QMessageBox.information(
            self, 'Indexing complete',
            '%s images indexed. Indexed file saves as %s' %
            (len(self.images), filename))
Esempio n. 3
0
def Match(queryname,k):
    folder="static"
    queryImage = cv2.imread(os.path.join(folder,queryname))
    desc = RGBHistogram([8, 8, 8])
    # load the index perform the search
    #index = cPickle.loads(open("index.txt").read())
    d = min(division(queryImage),7)
    folder='indexIMG'
    index = shelve.open(os.path.join(folder,'f%d.shelve'%d))
    searcher = Searcher(index)
    
    queryFeatures = desc.describe(queryImage)
    results = searcher.search(queryFeatures)
    l=len(results)
    lastRes=results[:min(k,l)]
    return lastRes
Esempio n. 4
0
    def search(image):
        args = {'dataset': 'images', 'index': 'index.cpickle'}

        queryImage = image

        # cv2.imshow("Query", queryImage)
        # print("query: {}".format(args["query"]))

        desc = RGBHistogram([8, 8, 8])
        queryFeatures = desc.describe(queryImage)

        index = pickle.loads(open(args["index"], "rb").read())
        searcher = Searcher(index)
        results = searcher.search(queryFeatures)

        # montageA = np.zeros((166 * 5, 400, 3), dtype="uint8")
        # montageB = np.zeros((166 * 5, 400, 3), dtype="uint8")

        for j in range(0, 1):
            (score, imageName) = results[j]
            path = os.path.join(args["dataset"], imageName)
            result = cv2.imread(path)
            print("\t{}. {} : {:.3f}".format(j + 1, imageName, score))
Esempio n. 5
0
# 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"] + "/*.*"):
    # extract our unique image ID (i.e. the filename)
    k = imagePath[imagePath.rfind("/") + 1:]

    # 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")
Esempio n. 6
0
ap.add_argument("-i",
                "--index",
                required=True,
                help="Path to where we stored our index")
ap.add_argument("-q", "--query", required=True, help="Path to query image")
args = vars(ap.parse_args())

# load the query image and show it
queryImage = cv2.imread(args["query"])
cv2.imshow("Query", queryImage)
print "query: %s" % (args["query"])

# describe the query in the same way that we did in
# index.py -- a 3D RGB histogram with 8 bins per
# channel
desc = RGBHistogram([8, 8, 8])
queryFeatures = desc.describe(queryImage)

# load the index perform the search
index = cPickle.loads(open(args["index"]).read())
searcher = Searcher(index)
results = searcher.search(queryFeatures)

# initialize the two montages to display our results --
# we have a total of 25 images in the index, but let's only
# display the top 10 results; 5 images per montage, with
# images that are 400x166 pixels
# montageA = np.zeros((166 * 5, 400, 3), dtype = "uint8")
# montageB = np.zeros((166 * 5, 400, 3), dtype = "uint8")

# montageA = np.zeros((40 * 5, 100, 3), dtype = "uint8")
Esempio n. 7
0
    help = "Path to the directory that contains the images we just indexed")
ap.add_argument("-i", "--index", required = True,
    help = "Path to where we stored our index")
ap.add_argument("-q", "--query", required = True,
    help = "Path to query image")
args = vars(ap.parse_args())

# load the query image and show it
queryImage = cv2.imread(args["query"])
cv2.imshow("Query", queryImage)
print "query: %s" % (args["query"])

# describe the query in the same way that we did in
# index.py -- a 3D RGB histogram with 8 bins per
# channel
desc = RGBHistogram([8, 8, 8])
queryFeatures = desc.describe(queryImage)

# load the index perform the search
index = cPickle.loads(open(args["index"]).read())
searcher = Searcher(index)
results = searcher.search(queryFeatures)

# initialize the two montages to display our results --
# we have a total of 25 images in the index, but let's only
# display the top 10 results; 5 images per montage, with
# images that are 400x166 pixels
# montageA = np.zeros((166 * 5, 400, 3), dtype = "uint8")
# montageB = np.zeros((166 * 5, 400, 3), dtype = "uint8")

# montageA = np.zeros((40 * 5, 100, 3), dtype = "uint8")