def get_similar_images_from_featuresfile(self,
                                             featurefilename,
                                             ratio,
                                             near_dup_th=-1.0):
        """ Get similar images of the images with features in 'featurefilename'.

        :param featurefilename: features of the query images.
        :type featurefilename: string
        :param ratio: ratio of images retrieved with hashing that will be reranked.
        :type ratio: float
        :param near_dup_th: near dup threshold, if positive, only images below this distance value will be returned.
        :type near_dup_th: float
        :returns simname: filename of the simname text file.
        """

        hop.HasherObjectPy_set_ratio(self.hasher, ratio)
        # needed?
        sys.stdout = sys.stderr
        print "[HasherSwig.get_similar_images: log] preparing search for {}".format(
            featurefilename)
        hop.HasherObjectPy_set_near_dup_th(self.hasher, near_dup_th)
        hop.HasherObjectPy_set_query_feats_from_disk(self.hasher,
                                                     featurefilename)
        hop.HasherObjectPy_set_outputfile(self.hasher, featurefilename[:-4])
        hop.HasherObjectPy_find_knn(self.hasher)
        initname = featurefilename[:-4] + '-sim.txt'
        simname = featurefilename[:-4] + '-sim_' + str(ratio) + '.txt'
        print "[HasherSwig.get_similar_images: log] try to rename {} to {}".format(
            initname, simname)
        # this would raise an error if results have not been computed
        os.rename(initname, simname)
        return simname
Esempio n. 2
0
    def get_similar_images_from_featuresfile(self,
                                             featurefilename,
                                             ratio,
                                             demote=False):
        """ Get similar images of the images with features in 'featurefilename'.

        :param featurefilename: features of the query images.
        :type featurefilename: string
        :param ratio: ratio of images retrieved with hashing that will be reranked.
        :type ratio: float
        :returns simname: filename of the simname text file.
        """

        hop.HasherObjectPy_set_ratio(self.hasher, ratio)
        # needed?
        sys.stdout = sys.stderr
        hop.HasherObjectPy_set_query_feats_from_disk(self.hasher,
                                                     featurefilename)
        hop.HasherObjectPy_set_outputfile(self.hasher, featurefilename[:-4])
        hop.HasherObjectPy_find_knn(self.hasher)
        initname = featurefilename[:-4] + '-sim.txt'
        simname = featurefilename[:-4] + '-sim_' + str(ratio) + '.txt'
        print "[HasherSwig.get_similar_images: log] try to rename {} to {}".format(
            initname, simname)
        # this would raise an error if results have not been computed
        os.rename(initname, simname)
        return simname
    def get_similar_images_from_featuresfile_nodiskout(self,
                                                       featurefilename,
                                                       ratio,
                                                       demote=False):
        """ Get similar images of the images with features in 'featurefilename'.

        :param featurefilename: features of the query images.
        :type featurefilename: string
        :param ratio: ratio of images retrieved with hashing that will be reranked.
        :type ratio: float
        :returns simlist: list of nearest neighbors of each query
        """

        hop.HasherObjectPy_set_ratio(self.hasher, ratio)
        # needed?
        sys.stdout = sys.stderr
        hop.HasherObjectPy_set_query_feats_from_disk(self.hasher,
                                                     featurefilename)
        hop.HasherObjectPy_set_outputfile(self.hasher, featurefilename[:-4])
        out_res = hop.HasherObjectPy_find_knn_nodiskout(self.hasher)
        print "[HasherSwig.get_similar_images_from_featuresfile_nodiskout: log] out_res: {}".format(
            out_res)
        return out_res
Esempio n. 4
0
 def set_outputfile(self, *args):
     """set_outputfile(HasherObjectPy self, std::string _outname)"""
     return _hasher_obj_py.HasherObjectPy_set_outputfile(self, *args)
import _hasher_obj_py as hop
import sys

if __name__ == "__main__":
    hasher = hop.new_HasherObjectPy()
    # setters are not working?
    up_path = hop.HasherObjectPy_get_base_updatepath(hasher)
    print(up_path)
    hop.HasherObjectPy_set_base_updatepath(
        hasher, "/home/ubuntu/memex/update/indexing/")
    up_path = hop.HasherObjectPy_get_base_updatepath(hasher)
    print(up_path)
    hop.HasherObjectPy_set_base_modelpath(hasher, "/home/ubuntu/memex/data/")
    status = hop.HasherObjectPy_initialize(hasher)
    if status != 0:
        print("Hasher was not able to initialize")
        sys.exit(-1)
    featurefilename = "/home/ubuntu/memex/DeepSentiBank_memex/cu_image_search/www/1480830128.81.dat"
    hop.HasherObjectPy_set_query_feats_from_disk(hasher, featurefilename)
    hop.HasherObjectPy_set_outputfile(hasher, featurefilename[:-4])
    out_res = hop.HasherObjectPy_find_knn_nodiskout(hasher)
    #delete_HasherObjectPy(hasher)