示例#1
0



# ----------- GENERATE ALL FEATURES & SAVE ------------ #

# GEN SIFT
sift_features_limit = SIFT_FEATURES_LIMIT
lowe_ratio = LOWE_RATIO
predictions_count = SIFT_PREDICTIONS_COUNT

mydataSIFT, mytime1 = ImageSearch_Algo_SIFT.gen_sift_features(
    imagepaths, sift_features_limit)
print("SIFT Feature Generation time :", mytime1)
savefile = 'data/' + TESTNAME + '_PandasDF_SIFT_Features_kp'+ str(sift_features_limit)
ImageSearch_Algo_SIFT.SIFT_SAVE_FEATURES (mydataSIFT, savefile)
print("SIFT Feature saved to : ", savefile)
# -- END

# GEN ORB
orb_features_limit = ORB_FEATURES_LIMIT

mydataORB, mytime1 = ImageSearch_Algo_ORB.GEN_ORB_FEATURES(imagepaths, orb_features_limit)
print("ORB Feature Generation time :", mytime1)
savefile = 'data/' + TESTNAME + '_PandasDF_ORB_Features_kp'+ str(orb_features_limit)
ImageSearch_Algo_ORB.ORB_SAVE_FEATURES (mydataORB, savefile)
print("ORB Feature saved to : ", savefile)
# -- END

# GEN RGB
parametercorrelationthreshold = 0.70 # not needed for generation
def GENERATE(TESTNAME, IMGDIR):
    '''Sequesnce of tests
        TESTNAME    : name of the test (suffix to all the pickles, csv dumped)
        IMGDIR      : DIRECTORY PATH CONTAINING IMAGES
    '''

    # --------------- CONFIG PARAMETERS ----------------------#

    ORB_FEATURES_LIMIT = 100
    ORB_FEATURES_LIMIT2 = 500
    ORB_N_CLUSTERS = 500
    ORB_N_CLUSTERS2 = 50  # 500 # (option2) #optimal = 50 for 500 features

    SIFT_FEATURES_LIMIT = 100
    SIFT_FEATURES_LIMIT2 = 300
    SIFT_N_CLUSTERS = 500
    SIFT_N_CLUSTERS2 = 50  # 100 # (option2) #optimal = 50 for 300 features

    LOWE_RATIO = 0.7
    SIFT_PREDICTIONS_COUNT = 100
    RGB_PARAMETERCORRELATIONTHRESHOLD = 0.70  # not needed for generation
    kneeHSV = 2
    kneeRGB = 2
    kneeORB = 2
    kneeSIFT = 2
    HASHLENGTH = 16

    # --------------- IMAGES  ----------------------#
    imagepaths = (list(paths.list_images(IMGDIR)))
    myDataFiles = pd.DataFrame({'file': imagepaths})

    # ----------- GENERATE ALL FEATURES & SAVE ------------ #
    print('Testname: ', TESTNAME)
    print("Generating Features for ", len(imagepaths), "images in", IMGDIR)

    # GEN SIFT
    sift_features_limit = SIFT_FEATURES_LIMIT
    lowe_ratio = LOWE_RATIO
    predictions_count = SIFT_PREDICTIONS_COUNT

    mydataSIFT, mytime1 = ImageSearch_Algo_SIFT.gen_sift_features(
        imagepaths, sift_features_limit)
    print("SIFT Feature Generation time :", mytime1)
    savefile = 'data/' + TESTNAME + '_PandasDF_SIFT_Features_kp' + str(
        sift_features_limit)
    ImageSearch_Algo_SIFT.SIFT_SAVE_FEATURES(mydataSIFT, savefile)
    print("SIFT Feature saved to : ", savefile)
    # -- END

    # GEN SIFT 2 # for TREE kp=300, n_cluster=50
    sift_features_limit = SIFT_FEATURES_LIMIT2
    lowe_ratio = LOWE_RATIO
    predictions_count = SIFT_PREDICTIONS_COUNT

    mydataSIFT2, mytime1 = ImageSearch_Algo_SIFT.gen_sift_features(
        imagepaths, sift_features_limit)
    print("SIFT Feature Generation time :", mytime1)
    savefile = 'data/' + TESTNAME + '_PandasDF_SIFT_Features_kp' + str(
        sift_features_limit)
    ImageSearch_Algo_SIFT.SIFT_SAVE_FEATURES(mydataSIFT2, savefile)
    print("SIFT Feature saved to : ", savefile)
    # -- END

    # GEN ORB
    orb_features_limit = ORB_FEATURES_LIMIT

    mydataORB, mytime1 = ImageSearch_Algo_ORB.GEN_ORB_FEATURES(
        imagepaths, orb_features_limit)
    print("ORB Feature Generation time :", mytime1)
    savefile = 'data/' + TESTNAME + '_PandasDF_ORB_Features_kp' + str(
        orb_features_limit)
    ImageSearch_Algo_ORB.ORB_SAVE_FEATURES(mydataORB, savefile)
    print("ORB Feature saved to : ", savefile)
    # -- END

    # GEN ORB 2 # for TREE kp=500, n_cluster=50
    orb_features_limit = ORB_FEATURES_LIMIT2

    mydataORB2, mytime1 = ImageSearch_Algo_ORB.GEN_ORB_FEATURES(
        imagepaths, orb_features_limit)
    print("ORB Feature Generation time :", mytime1)
    savefile = 'data/' + TESTNAME + '_PandasDF_ORB_Features_kp' + str(
        orb_features_limit)
    ImageSearch_Algo_ORB.ORB_SAVE_FEATURES(mydataORB2, savefile)
    print("ORB Feature saved to : ", savefile)
    # -- END

    # GEN RGB
    parametercorrelationthreshold = 0.70  # not needed for generation

    mydataRGB, mytime = ImageSearch_Algo_RGB.RGB_GEN(imagepaths)
    print('RGB Feature Generation time', mytime)
    savefile = 'data/' + TESTNAME + '_PandasDF_RGB_Features'
    ImageSearch_Algo_RGB.RGB_SAVE_FEATURES(mydataRGB, savefile)
    print("RGB Feature saved to : ", savefile)
    # -- END

    # GEN HSV
    mydataHSV, mytime = ImageSearch_Algo_HSV.HSV_GEN(imagepaths)
    print('HSV Feature Generation time', mytime)
    savefile = 'data/' + TESTNAME + '_PandasDF_HSV_Features'
    ImageSearch_Algo_HSV.HSV_SAVE_FEATURES(mydataHSV, savefile)
    print("HSV Feature saved to : ", savefile)
    # -- END

    # GEN HASH
    mydataHASH, mytime = ImageSearch_Algo_Hash.HASH_GEN(imagepaths, HASHLENGTH)
    print("HASH Features Generation time :", mytime)
    savefile = 'data/' + TESTNAME + '_PandasDF_HASH_Features'
    ImageSearch_Algo_Hash.HASH_SAVE_FEATURES(mydataHASH, savefile)
    # -- END

    print("## Feature Generation Complete.")

    # ----------- GENERATE ALL TREES  ------------ #

    # RGB TREE
    savefile = 'data/' + TESTNAME + '_RGB_Tree'
    myRGBtree = ImageSearch_Algo_RGB.RGB_Create_Tree(mydataRGB,
                                                     savefile=savefile)

    # HSV TREE
    savefile = 'data/' + TESTNAME + '_HSV_Tree'
    myHSVtree = ImageSearch_Algo_HSV.HSV_Create_Tree(mydataHSV,
                                                     savefile=savefile)

    # HASH TREE
    AlgoGenList = ['whash', 'phash', 'dhash', 'ahash']
    for algo in AlgoGenList:
        savefile = 'data/' + TESTNAME + '_HASH_Tree_' + str(algo)
        myHASHTree = ImageSearch_Algo_Hash.HASH_Create_Tree(mydataHASH,
                                                            savefile=savefile,
                                                            hashAlgo=algo)

    # HASH TREE USE HYBRID HASH
    HybridAlgoList = ['whash', 'ahash']
    savefile = 'data/' + TESTNAME + '_HASH_Hybrid_Tree_' + str(
        ('_').join(HybridAlgoList))
    myHybridtree = ImageSearch_Algo_Hash.HASH_CREATE_HYBRIDTREE(
        mydataHASH, savefile, HybridAlgoList)

    # SIFT FV Tree and Cluster
    n_clusters = SIFT_N_CLUSTERS
    savefile = 'data/' + TESTNAME + '_SIFT_Tree_Cluster' + str(n_clusters)
    mySIFTtree, mySIFTmodel, mySIFTFVHist = ImageSearch_Algo_SIFT.SIFT_CREATE_TREE_MODEL(
        mydataSIFT, savefile, n_clusters)

    # SIFT FV Tree and Cluster with kp=300, n_cluster=50
    n_clusters = SIFT_N_CLUSTERS2
    savefile = 'data/' + TESTNAME + '_SIFT_Tree_Cluster' + str(
        n_clusters) + 'kp' + str(SIFT_FEATURES_LIMIT2)
    mySIFTtree2, mySIFTmodel2, mySIFTFVHist2 = ImageSearch_Algo_SIFT.SIFT_CREATE_TREE_MODEL(
        mydataSIFT2, savefile, n_clusters)

    # ORB FV Tree and Cluster
    n_clusters = ORB_N_CLUSTERS
    savefile = 'data/' + TESTNAME + '_ORB_Tree_Cluster' + str(n_clusters)
    myORBtree, myORBmodel, myORBFVHist = ImageSearch_Algo_ORB.ORB_CREATE_TREE_MODEL(
        mydataORB, savefile, n_clusters)

    # ORB FV Tree and Cluster with kp=500, n_cluster=50
    n_clusters = ORB_N_CLUSTERS2
    savefile = 'data/' + TESTNAME + '_ORB_Tree_Cluster' + str(
        n_clusters) + 'kp' + str(ORB_FEATURES_LIMIT2)
    myORBtree2, myORBmodel2, myORBFVHist2 = ImageSearch_Algo_ORB.ORB_CREATE_TREE_MODEL(
        mydataORB2, savefile, n_clusters)

    print("## Tree Generation Complete.")