def main(argv): ''' ''' #locale.setlocale(locale.LC_ALL,'fr_FR') #logger=logging.getLogger('root') #logger.setLevel(logging.DEBUG) #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input args" return try: file1 = argv[0] file2 = argv[1] # new style print "file1: %s" % (file1) res = pHash.ph_texthash(file1) if type(res) is int: print 'err: return args:', res return None (h1, nb1) = res print "length %d" % (nb1) print "file2: %s" % (file2) res = pHash.ph_texthash(file2) if type(res) is int: print 'err: return args:', res return None (h2, nb2) = res print "length %d" % (nb2) # LISTITEM template doesnt work ! res = pHash.ph_compare_text_hashes(h1, nb1, h2, nb2) if type(res) is int: print "unable to complete compare function" return (matches2, count) = res # we use a Array wrapper for single pointer matches = pHash.TxtMatchArray.frompointer(matches2) print " %d matches" % (count) print " indxA indxB length" for j in range(0, count, 1): # off_t is lld in C code .... print " %d %d %d" % (matches[j].first_index, matches[j].second_index, matches[j].length) return except Exception, e: print e
def main(argv): ''' ''' #locale.setlocale(locale.LC_ALL,'fr_FR') #logger=logging.getLogger('root') #logger.setLevel(logging.DEBUG) #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if(len(argv)<2): print "not enough input args" return try: file1 = argv[0] file2 = argv[1] # new style print "file1: %s" %(file1) res=pHash.ph_texthash(file1) if type(res) is int : print 'err: return args:', res return None (h1,nb1)=res print "length %d"%(nb1) print "file2: %s" %(file2) res=pHash.ph_texthash(file2) if type(res) is int : print 'err: return args:', res return None (h2,nb2)=res print "length %d"%(nb2) # LISTITEM template doesnt work ! res=pHash.ph_compare_text_hashes(h1,nb1,h2,nb2) if type(res) is int : print "unable to complete compare function" return (matches2,count)=res # we use a Array wrapper for single pointer matches=pHash.TxtMatchArray.frompointer(matches2) print " %d matches"%(count) print " indxA indxB length" for j in range(0,count,1): # off_t is lld in C code .... print " %d %d %d"%( matches[j].first_index, matches[j].second_index,matches[j].length) return except Exception,e: print e
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" return -1 file1 = argv[0] file2t = argv[1] file2 = file2t print "file1=%s" % (file1) ret = pHash.ph_dct_videohash(file1) if (type(ret) is int): return 2 hash1, L1 = ret hash1 = pHash.ulong64Array.frompointer(hash1) print "length %d" % (L1) for i in range(0, L1): print "hash1[%d]=%x" % (i, hash1[i]) while (file2 != "exit"): print "file=%s" % (file2) ret = pHash.ph_dct_videohash(file2) if (type(ret) is int): return 3 hash2, L2 = ret hash2 = pHash.ulong64Array.frompointer(hash2) print "length %d" % (L2) sim = pHash.ph_dct_videohash_dist(hash1.cast(), L1, hash2.cast(), L2, 21) print "similarity %f" % (sim) del hash2 hash2 = None file2 = sys.stdin.readline() del hash1 del hash2 hash1 = None hash2 = None file2 = None print "done" return 0
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" print "usage: %s directory dbname [radius] [knearest] [threshold]"%( sys.argv[0]) return -1 dir_name = argv[0]#/* name of files in directory of query images */ filename = argv[1]#/* name of file to save db */ print "using db %s"%( filename) print "using dir %s for query files"%( dir_name) mvp = MVPTree(filename) # IMAGE #test_queryFiles1(mvp,dir_name) #test_queryFiles2(mvp,dir_name) test_addFile1(mvp,dir_name)
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" print "usage: %s directory dbname [radius] [knearest] [threshold]" % ( sys.argv[0]) return -1 dir_name = argv[0] #/* name of files in directory of query images */ filename = argv[1] #/* name of file to save db */ print "using db %s" % (filename) print "using dir %s for query files" % (dir_name) mvp = MVPTree(filename) # IMAGE #test_queryFiles1(mvp,dir_name) #test_queryFiles2(mvp,dir_name) test_addFile1(mvp, dir_name)
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" print "usage: %s directory dbname [radius] [knearest] [threshold]"%( sys.argv[0]) return -1 dir_name = argv[0]#/* name of files in directory of query images */ filename = argv[1]#/* name of file to save db */ mvpfile=pHash.MVPFile() mvpfile.filename = filename #@TODO #mvpfile.hashdist = distancefunc #mvpfile.hashdist = distancefunc #save: ret code 17 pHash.my_set_callback(mvpfile,distancefunc) mvpfile.hash_type = pHash.UINT64ARRAY nbfiles = 0 print "using db %s"%( filename) print "using dir %s for query files"%( dir_name) nbfiles = 0 print "dir name: %s"%( dir_name) nbfiles=0 files=None for root, dirs, filest in os.walk(dir_name): nbfiles=len(filest) files=[os.path.join(root,f) for f in filest] files.sort() print "nb query files = %d"%( nbfiles) #DP *query = pHash.ph_malloc_datapoint(mvpfile.hash_type) query=pHash.ph_malloc_datapoint(mvpfile.hash_type) if (query is None): print "mem alloc error" return -3 query.thisown=0 argc=len(argv)+1 radius = 30.0 threshold = 15.0 knearest = 20 if (argc >= 4): radius = float(argv[3]) if (argc >= 5): knearest = int(argv[4]) if (argc >= 6): threshold = float(argv[5]) print "radius = %f"%( radius) print "knearest = %d"%( knearest) print "threshold = %f"%( threshold) # malloc results = pHash.DPptrArray(knearest) if (results is None): return -3 tmphash = 0x0000000000000000 nbfound = 0 count = 0 sum_calcs = 0 for i in range(0,nbfiles): ret=pHash.ph_dct_imagehash(files[i]) if (type(ret) is int): print "unable to get hash" continue ret2,tmphash=ret print "query[%d]: %s %x"%( i, files[i], tmphash) query.id = files[i] query.hash = pHash.copy_ulong64Ptr(tmphash) query.hash_length = 1 global nb_calcs nb_calcs = 0 nbfound = 0 ret = pHash.ph_query_mvptree(mvpfile,query,knearest,radius,threshold,results.cast()) if (type(ret) is int ): print "could not complete query, %d"%(retcode) continue #print 'pHash.ph_query_mvptree',ret # results DP ** retcode,nbfound = ret #print 'errcodes : pHash.PH_ERRCAP ',pHash.PH_ERRCAP if (retcode != pHash.PH_SUCCESS and retcode != pHash.PH_ERRCAP): print "could not complete query, %d"%(retcode) continue count+=1 sum_calcs += nb_calcs print " %d files found"%( nbfound) for j in range (0,nbfound): d = distancefunc(query, results[j]) print " %d %s distance = %f"%( j, results[j].id, d) print "nb distance calcs: %d"%( nb_calcs) for j in range(0,nbfound): #free(results[j]->id) #del results[j].id results[j].id = None #del results[j].hash results[j].hash = None pHash.ph_free_datapoint(results[j]) #end for i ave_calcs = float(sum_calcs)/float(count) print "ave calcs/query: %f"%( ave_calcs) #for i in range (0, nbfiles): # del files[i] del files pHash.ph_free_datapoint(query) del results #del mvpfile.filename return 0
def main(argv): ''' ''' #locale.setlocale(locale.LC_ALL,'fr_FR') #logger=logging.getLogger('root') #logger.setLevel(logging.DEBUG) #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input args" print "usage: %s dirname filename" % (sys.argv[0]) return -1 dir_name = argv[0] #;/* name of dir to retrieve image files */ filename = argv[1] #;/* name of file to save db */ mvpfile = pHash.MVPFile() mvpfile.branchfactor = 2 mvpfile.pathlength = 5 mvpfile.leafcapacity = 23 #50 mvpfile.pgsize = 4096 #8192 mvpfile.filename = filename #mvpfile.hashdist = distancefunc #save: ret code 17 pHash.my_set_callback(mvpfile, distancefunc) mvpfile.hash_type = pHash.UINT64ARRAY nbfiles = 0 print "dir name: %s" % (dir_name) for root, dirs, files in os.walk(dir_name): nbfiles = len(files) print "nbfiles = %d" % nbfiles #allocate a list of nbfiles elements # hashlist = (DP**)malloc(nbfiles*sizeof(DP*)); hashlist = pHash.DPptrArray(nbfiles) count = 0 for i in range(0, nbfiles): filename = os.path.normpath(os.path.join(root, files[i])) # malloc DP or use pHash.DP() // pHash.ph_malloc_datapoint(mvpfile.hash_type) #tmp=pHash.ph_malloc_datapoint(mvpfile.hash_type) tmp = pHash.DP() if (tmp is None): print "mem alloc error" return -4 tmp.hash_type = mvpfile.hash_type # say to python, to NOT garbage collect DP reference. tmp.thisown = 0 # store the ref. hashlist[count] = tmp # calculate image hash ret, tmphash = pHash.ph_dct_imagehash(filename) if (ret < 0): print "unable to get hash" continue # we can't assign .hash to hashlist[count].hash = tmphash because .hash is a pointer # we use ulong64Ptr instead of voidPtr because .. it's a ulong64 ? casting is dynamic hashlist[count].hash = pHash.copy_ulong64Ptr(tmphash) # print "files[%d]: %s hash = %x" % (i, filename, tmphash) hashlist[count].id = filename hashlist[count].hash_length = 1 count += 1 # method with DPptrArray being a DP ** hashlistf = hashlist.cast() ret = pHash.ph_save_mvptree(mvpfile, hashlistf, count) # ret 11 is null hash distance function # save: ret code 17 has callback func. -> not enought hashdist ? print "save: ret code %d" % (ret) #free is done by GC .. ? #for i in range(0,nbfiles): # pHash.free(hashlist[i].hash) #free is NOT done by GC for i in range(0, nbfiles): pHash.ph_free_datapoint(hashlist[i])
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" print "usage: %s directory dbname [radius] [knearest] [threshold]" % ( sys.argv[0]) return -1 dir_name = argv[0] #/* name of files in directory of query images */ filename = argv[1] #/* name of file to save db */ mvpfile = pHash.MVPFile() mvpfile.filename = filename pHash.my_set_callback(mvpfile, distancefunc) mvpfile.hash_type = pHash.UINT64ARRAY nbfiles = 0 print "dir name: %s" % (dir_name) nbfiles = 0 files = None for root, dirs, filest in os.walk(dir_name): nbfiles = len(filest) files = [os.path.join(root, f) for f in filest] files.sort() print "nbfiles = %d" % (nbfiles) #allocate a list of nbfiles elements # hashlist = (DP**)malloc(nbfiles*sizeof(DP*)); hashlist = pHash.DPptrArray(nbfiles) if (hashlist is None): print "mem alloc error" return -3 count = 0 tmphash = 0x00000000 for i in range(0, nbfiles): tmpdp = pHash.ph_malloc_datapoint(mvpfile.hash_type) if (tmpdp is None): print "mem alloc error" return -4 tmpdp.thisown = 0 hashlist[count] = tmpdp #useless malloc, we use copy_ #hashlist[count].hash=pHash.new_ulong64Ptr() #if (hashlist[count].hash is None): # print "mem alloc error" # return -5 print "file[%d] = %s" % (i, files[i]) ret = pHash.ph_dct_imagehash(files[i]) if (type(ret) is int): print "unable to get hash" hashlist[count].hash = None phash.ph_free_datapoint(hashlist[count]) continue (res, tmphash) = ret hashlist[count].id = files[i] hashlist[count].hash = pHash.copy_ulong64Ptr(tmphash) hashlist[count].hash_length = 1 count += 1 # print "add files to file %s" % (filename) nbsaved = 0 ret = pHash.ph_add_mvptree(mvpfile, hashlist.cast(), count) if (type(ret) is int): print "error on ph_add_mvptree" return -6 (res, nbsaved) = ret print "number saved %d out of %d, ret code %d" % (nbsaved, count, res) # freeeee. we need to add %newobject to ph_readfilesnames #for i in range(0,nbfiles): # free(files[i]) # files = None for i in range(0, nbfiles): hashlist[i].hash = None pHash.ph_free_datapoint(hashlist[i]) hashlist = None return 0
def main(argv): ''' ''' #locale.setlocale(locale.LC_ALL,'fr_FR') #logger=logging.getLogger('root') #logger.setLevel(logging.DEBUG) #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input args" print "usage: %s dirname filename"% (sys.argv[0]) return -1 dirname1 = argv[0] # weird bug in ph_readfilenames ? /* name of dir to retrieve image files */ dirname2 = argv[1] # /* name of file to save db */ alpha = 2 level = 1 nbfiles1=0 files1=None for root, dirs, files in os.walk(dirname1): nbfiles1=len(files) files1=[os.path.join(root,f) for f in files] files1.sort() #nbfiles1=0 #ret = pHash.my_ph_readfilenames(dirname1) #if (ret is None): # print "unable to read files from directory",dirname1 # return -2 #if (type(ret) is int): # print "unable to read files from directory",dirname1 # return -2 #print ret #(tmpfiles1,nbfiles1)=ret #files1=pHash.charPtrArray.frompointer(tmpfiles1) #files1=sort_names(files1,nbfiles1) #list(files1) #print files1 nbfiles2=0 files2=None for root, dirs, files in os.walk(dirname2): nbfiles2=len(files) files2=[os.path.join(root,f) for f in files] files2.sort() if (nbfiles1 != nbfiles2): print "number files in both directories not equal" return 1 #uint8_t **hash1 = (uint8_t**)malloc(nbfiles1*sizeof(uint8_t*)) hash1=pHash.uint8_tPtrPtrArray(nbfiles1) hash2 = 0 hashlen1=0 hashlen2=0 dist = 0 print "intra distances" print "***************" for i in range(0,nbfiles1): print "file1: %s" %(files1[i]) ret = pHash.ph_mh_imagehash(files1[i], alpha, level) if (type(ret) is int): continue (hash1[i],hashlen1)=ret f2=files2[i] print "file2: %s"%(files2[i]) ret = pHash.ph_mh_imagehash(files2[i], alpha, level) if (type(ret) is int): continue (hash2,hashlen2)=ret dist = pHash.ph_hammingdistance2(hash1[i], hashlen1, hash2, hashlen2) print "distance = %f"%( dist) print "-------------" hash2=None print "\n" print "--hit any key--" sys.stdin.readline() print "inter distances" for i in range(0,nbfiles1): for j in range(i+1,nbfiles1): dist = pHash.ph_hammingdistance2(hash1[i], hashlen1, hash1[j], hashlen1) print " %d %d dist = %f"%( i, j, dist) print "----------------" print "done" for i in range(0,nbfiles1): files1[i]=None files2[i]=None hash1[i]=None files1=None files2=None hash1=None return 0
def main(argv): ''' ''' logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input arguments" print "usage: %s directory dbname [radius] [knearest] [threshold]" % ( sys.argv[0]) return -1 dir_name = argv[0] #/* name of files in directory of query images */ filename = argv[1] #/* name of file to save db */ mvpfile = pHash.MVPFile() mvpfile.filename = filename #@TODO #mvpfile.hashdist = distancefunc #mvpfile.hashdist = distancefunc #save: ret code 17 pHash.my_set_callback(mvpfile, distancefunc) mvpfile.hash_type = pHash.UINT64ARRAY nbfiles = 0 print "using db %s" % (filename) print "using dir %s for query files" % (dir_name) nbfiles = 0 print "dir name: %s" % (dir_name) nbfiles = 0 files = None for root, dirs, filest in os.walk(dir_name): nbfiles = len(filest) files = [os.path.join(root, f) for f in filest] files.sort() print "nb query files = %d" % (nbfiles) #DP *query = pHash.ph_malloc_datapoint(mvpfile.hash_type) query = pHash.ph_malloc_datapoint(mvpfile.hash_type) if (query is None): print "mem alloc error" return -3 query.thisown = 0 argc = len(argv) + 1 radius = 30.0 threshold = 15.0 knearest = 20 if (argc >= 4): radius = float(argv[3]) if (argc >= 5): knearest = int(argv[4]) if (argc >= 6): threshold = float(argv[5]) print "radius = %f" % (radius) print "knearest = %d" % (knearest) print "threshold = %f" % (threshold) # malloc results = pHash.DPptrArray(knearest) if (results is None): return -3 tmphash = 0x0000000000000000 nbfound = 0 count = 0 sum_calcs = 0 for i in range(0, nbfiles): ret = pHash.ph_dct_imagehash(files[i]) if (type(ret) is int): print "unable to get hash" continue ret2, tmphash = ret print "query[%d]: %s %x" % (i, files[i], tmphash) query.id = files[i] query.hash = pHash.copy_ulong64Ptr(tmphash) query.hash_length = 1 global nb_calcs nb_calcs = 0 nbfound = 0 ret = pHash.ph_query_mvptree(mvpfile, query, knearest, radius, threshold, results.cast()) if (type(ret) is int): print "could not complete query, %d" % (retcode) continue #print 'pHash.ph_query_mvptree',ret # results DP ** retcode, nbfound = ret #print 'errcodes : pHash.PH_ERRCAP ',pHash.PH_ERRCAP if (retcode != pHash.PH_SUCCESS and retcode != pHash.PH_ERRCAP): print "could not complete query, %d" % (retcode) continue count += 1 sum_calcs += nb_calcs print " %d files found" % (nbfound) for j in range(0, nbfound): d = distancefunc(query, results[j]) print " %d %s distance = %f" % (j, results[j].id, d) print "nb distance calcs: %d" % (nb_calcs) for j in range(0, nbfound): #free(results[j]->id) #del results[j].id results[j].id = None #del results[j].hash results[j].hash = None pHash.ph_free_datapoint(results[j]) #end for i ave_calcs = float(sum_calcs) / float(count) print "ave calcs/query: %f" % (ave_calcs) #for i in range (0, nbfiles): # del files[i] del files pHash.ph_free_datapoint(query) del results #del mvpfile.filename return 0
def main(argv): ''' ''' #locale.setlocale(locale.LC_ALL,'fr_FR') #logger=logging.getLogger('root') #logger.setLevel(logging.DEBUG) #logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) print pHash.ph_about() if (len(argv) < 2): print "not enough input args" print "usage: %s dirname filename"% (sys.argv[0]) return -1 dir_name = argv[0] #;/* name of dir to retrieve image files */ filename = argv[1] #;/* name of file to save db */ mvpfile= pHash.MVPFile() mvpfile.branchfactor = 2 mvpfile.pathlength = 5 mvpfile.leafcapacity = 23 #50 mvpfile.pgsize = 4096 #8192 mvpfile.filename = filename #mvpfile.hashdist = distancefunc #save: ret code 17 pHash.my_set_callback(mvpfile,distancefunc) mvpfile.hash_type = pHash.UINT64ARRAY nbfiles = 0 print "dir name: %s"%( dir_name) for root, dirs, files in os.walk(dir_name): nbfiles=len(files) print "nbfiles = %d"% nbfiles #allocate a list of nbfiles elements # hashlist = (DP**)malloc(nbfiles*sizeof(DP*)); hashlist=pHash.DPptrArray(nbfiles) count = 0 for i in range(0,nbfiles): filename=os.path.normpath(os.path.join(root,files[i]) ) # malloc DP or use pHash.DP() // pHash.ph_malloc_datapoint(mvpfile.hash_type) #tmp=pHash.ph_malloc_datapoint(mvpfile.hash_type) tmp=pHash.DP() if (tmp is None): print "mem alloc error" return -4 tmp.hash_type = mvpfile.hash_type # say to python, to NOT garbage collect DP reference. tmp.thisown = 0 # store the ref. hashlist[count]=tmp # calculate image hash ret,tmphash=pHash.ph_dct_imagehash(filename) if ( ret < 0): print "unable to get hash" continue # we can't assign .hash to hashlist[count].hash = tmphash because .hash is a pointer # we use ulong64Ptr instead of voidPtr because .. it's a ulong64 ? casting is dynamic hashlist[count].hash = pHash.copy_ulong64Ptr(tmphash) # print "files[%d]: %s hash = %x"%( i, filename, tmphash ) hashlist[count].id = filename hashlist[count].hash_length = 1 count+=1 # method with DPptrArray being a DP ** hashlistf=hashlist.cast() ret = pHash.ph_save_mvptree(mvpfile, hashlistf, count) # ret 11 is null hash distance function # save: ret code 17 has callback func. -> not enought hashdist ? print "save: ret code %d"%(ret) #free is done by GC .. ? #for i in range(0,nbfiles): # pHash.free(hashlist[i].hash) #free is NOT done by GC for i in range(0,nbfiles): pHash.ph_free_datapoint(hashlist[i])