def run(self):
        print "Starting " + self.name

        while not exitFlag:
            queueLock.acquire()
            if not workQueue.empty():
                currQueue = self.q.get()
                queueLock.release()
                # fn = currQueue['fn']
                # urls = currQueue['urls']
                # kps = []
                # for url in urls:
                #     img = image.loadImageFromUrl(url, cv2.IMREAD_GRAYSCALE, True, 200)
                #     name = image.fileName(url)
                #     kp, des = image.keypointDesCalc(img)
                #     kps.append(image.pack(kp, des, name))
                #     time.sleep(0)
                # image.saveKps(kps, HASH_PATH + fn + KPC_EXT)

                fn = currQueue['fn']
                urls = currQueue['urls']
                kps = []
                for url in urls:
                    img = image.loadImageFromUrl(url, cv2.IMREAD_GRAYSCALE, True, 200)
                    name = image.fileName(url)
                    image.keypointDesCalc(img, HASH_PATH + name)


                # image.saveKps(kps, HASH_PATH + fn + KPC_EXT)
            else:
                queueLock.release()

        print "Exiting " + self.name
Example #2
0
def process_data(threadName, q):
    while not exitFlag:
        queueLock.acquire()
        if not workQueue.empty():
            url = q.get()
            queueLock.release()

            name2 = image.fileName(url)
            img2 = image.loadImageFromUrl(url)

            image.compare(name1, name2, img1.copy(), img2)
            # print "%s processing %s" % (threadName, data)
        else:
            queueLock.release()
Example #3
0
    def run(self):
        print("Starting " + self.name)

        while not exitFlag:
            queueLock.acquire()
            if not workQueue.empty():
                url = self.q.get()
                queueLock.release()

                img = image.loadImageFromUrl(url, cv2.IMREAD_GRAYSCALE, False)
                name = image.fileName(url)
                image.keypointDesCalcDb(self.collection, img, name, 100)
            else:
                queueLock.release()

        print("Exiting " + self.name)
Example #4
0
    def run(self):
        print("Starting " + self.name)

        while not exitFlag:
            self.lock.acquire()
            if not self.queue.empty():
                data = self.queue.get()
                self.lock.release()

                url = data[0]
                folder = '%s%s/' % (HASH_PATH, data[1])

                img = image.loadImageFromUrl(url, resize=True, maxSize=800)
                name = image.fileName(url)
                image.keypointDesCalc(img, folder + name, 100, self.wlock)
            else:
                self.lock.release()

        print("Exiting " + self.name)
Example #5
0
def loadFiles(filesInQueue=10000, hashPath=HASH_PATH, ext=DES_EXT):
    def load_descriptors(bow, hashPath=HASH_PATH, withSubFolders=True, ext=DES_EXT):
        des_list = []
        kp_list = []

        folder = 0
        path = "%s%s/" % (hashPath, folder)
        while os.path.exists(path):
            for imagePath in glob.glob("%s*%s" % (path, '.des')):
                des_list.append(imagePath)
                kp_list.append('%s%s.kp' % (path, im.fileName(imagePath)))
                if len(des_list) == FILES_CHECK:
                    folder = -2
                    break

            folder += 1
            path = "%s%s/" % (hashPath, folder)

        if len(des_list) == 0:
            print("Hash files count is empty")
            return []

        print("Files count: %d " % len(des_list))
        for n in des_list:
            bow.add(im.loadDesFromPath(n))
        # bow.write(HASH_PATH + 'hash.bat')
        print("Loaded")

        images = []
        for n in des_list:
            images.append('http://comicstore.cf/uploads/diamonds/%s.jpg' % im.fileName(n))

        return images, kp_list

    flann = cv2.FlannBasedMatcher(index_params, search_params)

    bow_train = cv2.BOWKMeansTrainer(50)  # toy world, you want more.
    bow_extract = cv2.BOWImgDescriptorExtractor(sift, flann)

    images, kps = load_descriptors(bow_train)

    print 'Getting cluster ...'
    voc = bow_train.cluster()
    print 'Set vocabulary ...'
    bow_extract.setVocabulary(voc)

    traindata, trainlabels = [], []

    j = 0
    for i in images:
        img = im.loadImageFromUrl(i, resize=True, maxSize=800)
        kp = im.loadKeypointFromPath(kps[j])
        traindata.extend(bow_extract.compute(img, kp))
        trainlabels.append(j)
        j += 1

    print 'Training SVM'
    svm = cv2.ml.SVM_create()
    svm.train(np.array(traindata), cv2.ml.ROW_SAMPLE, np.array(trainlabels))

    img = im.loadImageFromPath('%s%s' % (IMG_PATH, 'M2.jpg'), resize=True, maxSize=800)
    kp, des = im.keypointDesCalc(img, count=100)
    fbow = bow_extract.compute(img, kp)

    t_start = cv2.getTickCount()
    p = svm.predict(fbow)
    t_end = cv2.getTickCount()
    print "Time match: %s" % ((t_end - t_start) / cv2.getTickFrequency())
Example #6
0
def downloadImages():
    nameList = sql.allComics()[:1000]
    for i in nameList:
        img = im.loadImageFromUrl(i, color=cv2.IMREAD_COLOR, resize=False, maxSize=800)
        cv2.imwrite('/home/evgeniy/projects/python/open-cv/images/comics/full/%s.jpg' % im.fileName(i), img)