# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass
# 
# def printStatus(trace, message):
#     printMessage('INFO', trace, message)


import os, sys, array
import numpy as np
from basic.common import ROOT_PATH, checkToSkip, makedirsforfile, printStatus
from basic.util import readImageSet
    from optparse import OptionParser
        printStatus(INFO, 'failed to load %s, will merge all features in %s' % (querysetfile, ';'.join(srcCollections)))
        query_set = None
    
    makedirsforfile(resfile)
    fw = open(resfile, 'wb')
    printStatus(INFO, 'writing results to %s' % resfile)
    seen = set()
    newimset = []
    
    for collection in srcCollections:
        feat_dir = os.path.join(rootpath, collection, 'FeatureData', feature)
        with open(os.path.join(feat_dir, 'shape.txt')) as fr:
            nr_of_images, feat_dim = map(int, fr.readline().strip().split())
            fr.close()
        
        srcimset = open(os.path.join(feat_dir,'id.txt')).readline().strip().split()
        res = array.array('f')
        fr = open(os.path.join(feat_dir,'feature.bin'), 'rb')
        
        for i,im in enumerate(srcimset):
            res.fromfile(fr, feat_dim)
            if im not in seen:
                seen.add(im)
                if not query_set or im in query_set:
                    vec = res
                    vec = np.array(vec, dtype=np.float32)
                    vec.tofile(fw)
                    newimset.append(im)
            del res[:]
            if i%1e5 == 0:

# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass
# 
# def printStatus(trace, message):
#     printMessage('INFO', trace, message)


# Path: simpleknn/merge_feat.py
import os, sys, array
import numpy as np
from basic.common import ROOT_PATH, checkToSkip, makedirsforfile, printStatus
from basic.util import readImageSet
    from optparse import OptionParser

        printStatus(INFO, 'failed to load %s, will merge all features in %s' % (querysetfile, ';'.join(srcCollections)))
        query_set = None
    
    makedirsforfile(resfile)
    fw = open(resfile, 'wb')
    printStatus(INFO, 'writing results to %s' % resfile)
    seen = set()
    newimset = []
    
    for collection in srcCollections:
        feat_dir = os.path.join(rootpath, collection, 'FeatureData', feature)
        with open(os.path.join(feat_dir, 'shape.txt')) as fr:
            nr_of_images, feat_dim = map(int, fr.readline().strip().split())
            fr.close()
        
        srcimset = open(os.path.join(feat_dir,'id.txt')).readline().strip().split()
        res = array.array('f')
        fr = open(os.path.join(feat_dir,'feature.bin'), 'rb')
        
        for i,im in enumerate(srcimset):
            res.fromfile(fr, feat_dim)
            if im not in seen:
                seen.add(im)
                if not query_set or im in query_set:
                    vec = res
                    vec = np.array(vec, dtype=np.float32)
                    vec.tofile(fw)
                    newimset.append(im)
            del res[:]
            if i%1e5 == 0:

                printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))