def put(self, data): """ Put object in CAS pool - If exists, increase refcount. - If not exists, create with refcount=1 and compression set on CAS object init Return fingerprint (= object name) of `data` in any case """ algo, fp = fingerprint(data) self.log.debug("PUT [%s:%r]: %d bytes", algo, fp, len(data)) meta = { "fp_algo": algo, "lib": self.__version__, } algo, fp = fingerprint(data) compression_meta, compressed_data = self.compressor.compress(data) meta.update(compression_meta) self.log.debug("PUT [%s:%r]: %d bytes, %d compressed with \"%s\"", algo, fp, len(data), len(compressed_data), compression_meta["compression"]) jargs = self._make_cas_put_arg(compressed_data, meta) ret, _ = self.ioctx.execute(fp, "cas", "put", jargs) if ret == 0: return fp else: raise CASError("PUT failed")
def fingerprint_worker(self, files, sql_connection, output): for filename, extension in files: # if there are already fingerprints in database, don't re-fingerprint or convert song_name = os.path.basename(filename).split(".")[0] if DEBUG and song_name in self.songnames_set: print("-> Already fingerprinted, continuing...") continue # convert to WAV wavout_path = self.converter.convert(filename, extension, Converter.WAV, output, song_name) # insert song name into database song_id = sql_connection.insert_song(song_name) # for each channel perform FFT analysis and fingerprinting channels, Fs = self.extract_channels(wavout_path) for c in range(len(channels)): channel = channels[c] print "-> Fingerprinting channel %d of song %s..." % (c+1, song_name) hashes = fingerprint.fingerprint(channel, Fs=Fs) sql_connection.insert_hashes(song_id, hashes) # only after done fingerprinting do confirm sql_connection.set_song_fingerprinted(song_id)
def generate_fingerprint(audio, sr): print = fingerprint.fingerprint(audio, sr, wsize=1024, wratio=0.5, amp_min=10, peak_neighborhood=10) return print
def _fingerprint_worker(filename, limit=None, song_name=None): # Pool.imap sends arguments as tuples so we have to unpack # them ourself. try: filename, limit = filename except ValueError: pass songname, extension = os.path.splitext(os.path.basename(filename)) song_name = song_name or songname channels, Fs = decoder.read(filename, limit) result = set() channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=Fs) print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) result |= set(hashes) return song_name, result
def portscanwrite(self,values): self.isap.print_out("Writing PortScan Values to DB\r\n", 0) self.isap.print_out("Ports Open :\r\n", 1) for value in values.iterkeys(): self.isap.print_out(value+":" + str(values[value]) + "\r\n", 1) fp1 = fingerprint.fingerprint(values, self.isap) fp1.starts()
def _fingerprint_worker(filename, db, limit): song_name, extension = os.path.splitext(os.path.basename(filename)) channels, Fs = decoder.read(filename, limit) # insert song into database sid = db.insert_song(song_name) channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=Fs) print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) print("Inserting fingerprints for channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) db.insert_hashes(sid, hashes) print("Finished inserting for channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) print("Marking %s finished" % (filename,)) db.set_song_fingerprinted(sid) print("%s finished" % (filename,))
def portscanwrite(self, values): self.isap.print_out("Writing PortScan Values to DB\r\n", 0) self.isap.print_out("Ports Open :\r\n", 1) for value in values.iterkeys(): self.isap.print_out(value + ":" + str(values[value]) + "\r\n", 1) fp1 = fingerprint.fingerprint(values, self.isap) fp1.starts()
def _fingerprint_worker(filename, limit=None, song_name=None): # Pool.imap sends arguments as tuples so we have to unpack # them ourself. try: filename, limit = filename except ValueError: pass songname, extension = os.path.splitext(os.path.basename(filename)) song_name = song_name or songname channels, Fs, file_hash = decoder.read(filename, limit) result = set() channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=Fs) print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) result |= set(hashes) return song_name, result, file_hash
def generate_fingerprint(filename): audio, sr = librosa.load(filename) print = fingerprint.fingerprint(audio, sr, wsize=4096, wratio=0.5, amp_min=10, peak_neighborhood=10) return print
def find_matches(self, samples, Fs=fingerprint.DEFAULT_FS): hashes = fingerprint.fingerprint(samples, Fs=Fs) mapper = {} total_hashes = 0 for hash, offset in hashes: mapper[hash.upper()[:fingerprint.FINGERPRINT_REDUCTION]] = offset total_hashes += 1 return (self.db.return_matches(mapper), total_hashes)
def fingerprint_file(self, filepath, song_name=None): # TODO: replace with something that handles all audio formats channels, Fs = self.extract_channels(path) if not song_name: song_name = os.path.basename(filename).split(".")[0] song_id = self.db.insert_song(song_name) for data in channels: hashes = fingerprint.fingerprint(data, Fs=Fs) self.db.insert_hashes(song_id, hashes)
def fingerprint_file(self, filepath, song_name=None): channels, Fs = decoder.read(filepath) if not song_name: print "Song name: %s" % song_name song_name = decoder.path_to_songname(filepath) song_id = self.db.insert_song(song_name) for data in channels: hashes = fingerprint.fingerprint(data, Fs=Fs) self.db.insert_hashes(song_id, hashes)
def _fingerprint_worker(arg): try: song, limit = arg except ValueError: pass channels, frameRate, fileHash = decoder.read(song['songPath'], limit) result = set() for channeln, channel in enumerate(channels): hashes = fingerprint.fingerprint(channel, Fs=frameRate) result |= set(hashes) return song, fileHash, result
def run(): _, example = wavfile.read(EXAMPLE) example_hash = set(x[0] for x in fingerprint(example)) request_stream = requests.get(URL, stream=True) request_stream.raw.decode_content = True stream_iter = request_stream.iter_content(2 ** 17) for chunk in stream_iter: filename = strftime("tmp/%H-%M-%S.mp3") f = open(filename, "wb") f.write(chunk) f.close() p = Process(target=recognize, args=(filename, example_hash)) p.start()
def run(self): db = SQLDatabase() channels, fs = decoder.read(self.filename) result = set() for i in range(len(channels)): print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), self.filename)) hashes = fingerprint.fingerprint(channels[i], fs=fs) print("Finished channel %d/%d for %s" % (i + 1, len(channels), self.filename)) result |= set(hashes) # check matches = db.return_matches(result) song = db.align_matches(matches) print song self.signal.emit(song)
def addto_db_click(self): db = SQLDatabase() filename = self.show_file.text() song_name, extension = os.path.splitext(os.path.basename(filename)) channels, fs = decoder.read(filename) result = set() for i in range(len(channels)): print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), filename)) hashes = fingerprint.fingerprint(channels[i], fs=fs) print("Finished channel %d/%d for %s" % (i + 1, len(channels), filename)) result |= set(hashes) # add to db table songs and fingerprints sid = db.insert_song(song_name) db.insert_fingerprints(sid, result) self.show_db_message.setText('添加完成')
def run(self): db = SQLDatabase() channels, fs = decoder.read(self.filename) result = set() for i in range(len(channels)): print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), self.filename)) hashes = fingerprint.fingerprint(channels[i], fs=fs) print("Finished channel %d/%d for %s" % (i + 1, len(channels), self.filename)) result |= set(hashes) # check matches = db.return_matches(result) song = db.align_matches(matches) print song self.signal.emit(song)
def _fingerprint_worker(filename, limit=None, song_name=None): songname, extension = os.path.splitext(os.path.basename(filename)) song_name = song_name or songname channels, Fs = decoder.read(filename, limit) result = set() channel_amount = len(channels) for i in range(channel_amount): print("Fingerprinting channel %d/%d for %s" % (i + 1,channel_amount,filename)) hashes = fingerprint.fingerprint(channels[i], Fs=Fs) print("Finished channel %d/%d for %s" % (i + 1, channel_amount,filename)) result |= set(hashes) return song_name, result
def addto_db_click(self): db = SQLDatabase() filename = self.show_file.text() song_name, extension = os.path.splitext(os.path.basename(filename)) channels, fs = decoder.read(filename) result = set() for i in range(len(channels)): print("Fingerprinting channel %d/%d for %s" % (i + 1, len(channels), filename)) hashes = fingerprint.fingerprint(channels[i], fs=fs) print("Finished channel %d/%d for %s" % (i + 1, len(channels), filename)) result |= set(hashes) # add to db table songs and fingerprints sid = db.insert_song(song_name) db.insert_fingerprints(sid, result) self.show_db_message.setText('添加完成')
def recognize(filename, example_hash): wavname = filename[:-3] + "wav" record = convert(filename, wavname) density = np.array([len(example_hash.intersection( set(x[0] for x in fingerprint(chunk)))) for chunk in chunks(record, 2048)]) logging.info("Density mean: " + str(np.mean(density)) + " Max Value: " + str(np.max(density))) print strftime("%H-%M-%S") + " - Density mean: " + str(np.mean(density)) +\ " Max Value: " + str(np.max(density)) if np.max(density) >= 4: logging.warning( strftime("%H-%M-%S") + " - SIGNAAAAAAAAAAAAAAAAL!!!!!!!!!!!") print strftime("%H-%M-%S") + " - SIGNAAAAAAAAAAAAAAAAL!!!!!!!!!!!" send_message(filename) else: call(["rm", filename], stdout=FNULL, stderr=STDOUT)
def portscanwrite(self, values): #self.isap.print_out("Writing PortScan values to DB\r\n", 0) self.isap.print_out( "\r\nPort Scan Result (arranged by the associated service) :\r\n", 1) port_count = 0 for value in values.iterkeys(): if value != "ip" and value != "actid": port_count = port_count + len(values[value]) self.isap.print_out( value + ": " + self.port_list_to_str(values[value]), 1) if port_count > 0: fp1 = fingerprint.fingerprint(values, self.isap) fp1.starts() else: self.isap.print_out( "\r\nNo open ports found. Cannot proceed further.", 1) self.isap.stopper()
def recognize(filename, example_hash): wavname = filename[:-3] + "wav" record = convert(filename, wavname) density = np.array([ len(example_hash.intersection(set(x[0] for x in fingerprint(chunk)))) for chunk in chunks(record, 2048) ]) logging.info("Density mean: " + str(np.mean(density)) + " Max Value: " + str(np.max(density))) print strftime("%H-%M-%S") + " - Density mean: " + str(np.mean(density)) +\ " Max Value: " + str(np.max(density)) if np.max(density) >= 4: logging.warning( strftime("%H-%M-%S") + " - SIGNAAAAAAAAAAAAAAAAL!!!!!!!!!!!") print strftime("%H-%M-%S") + " - SIGNAAAAAAAAAAAAAAAAL!!!!!!!!!!!" send_message(filename) else: call(["rm", filename], stdout=FNULL, stderr=STDOUT)
def _fingerprint_worker(filename, limit=None, song_name=None): songname, extension = os.path.splitext(os.path.basename(filename)) song_name = song_name or songname channels, Fs = decoder.read(filename, limit) result = set() channel_amount = len(channels) for i in range(channel_amount): print("Fingerprinting channel %d/%d for %s" % (i + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channels[i], Fs=Fs) print("Finished channel %d/%d for %s" % (i + 1, channel_amount, filename)) result |= set(hashes) return song_name, result
def log_population_mix(tick,agents,k): #Records the sorted population mix ravens=0 starlings=0 doves=0 hawks=0 others=0 for agent in agents: total+=1 fprint=fingerprint(agent.genes,k) if fprint==(1,1,1,2,2,2): ravens+=1 elif fprint[0],fprint[1],fprint[2]!=1 and fprint[4],fprint[5]==2: starlings+=1 elif fprint[0],fprint[1],fprint[2],fprint[3],fprint[4],fprint[5]!=1: doves+=1
def detect(now, wave_bytes) -> None: """ 判定 """ wave = np.frombuffer(wave_bytes, dtype="int16") # -32768 ~ +32767 target_hashes = list(fingerprint.fingerprint(wave)) # hashの計算 matched_master = fingerprint.find_masters_hashes( target_hashes) # DBから探すreturn_matches(hashes) detected_master = fingerprint.align_matches( matched_master) # 時間差ごとにmaster_idをまとめる 最終結果を返す if detected_master != None: master_id = detected_master.master_id confidence = detected_master.confidence logger.info('master_id: %s, confidence: %s', master_id, confidence) # slack投稿 message = now.strftime('%Y-%m-%d %H:%M:%S') + ' CONFIDENCE: ' + str( confidence) slack.post_slack(message, channel=CONFIG.CHANNEL)
def login(): content = request.get_json() print(content) sys.stdout.flush() image_content = b64decode(content['image']) profile = { 'name': 'Visitante', 'role': 'guest' } for user in users: print(user) result = fingerprint(image_content, user['image']) if result['status']: profile = user['profile'] break sys.stdout.flush() return profile
def work_audio(audiofile, filename): data = np.fromstring(audiofile._data, np.int16) channels = [] for chn in xrange(audiofile.channels): channels.append(data[chn::audiofile.channels]) fs = audiofile.frame_rate result = set() channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=fs) print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) result |= set(hashes) return [result, fs]
def my_enrich_slow_logs(events): for event in events: messages = [] sql = '' for line in event['message'].split("\n"): if line.startswith("#"): messages.append(line) elif line.startswith("SET timestamp="): pass elif line.startswith("use "): pass else: sql = sql + line messages.append(fingerprint.fingerprint(sql)) event['message'] = "\n".join(messages) lambda_function.add_metadata_to_lambda_log(event) return events
def _fingerprint_worker(filename, limit=None): # I only want the hashes. This function should not has any songdata otherwise try: filename, limit = filename except ValueError: pass channels, Fs, file_hash = decoder.read(filename, limit) result = set() channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=Fs) print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) result |= set(hashes) return result, file_hash
def find_matches(self, index, samples, Fs=fingerprint.DEFAULT_FS): msg = "find_matches self" msg = "[" + datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") + "]" + msg print msg self.logger.info(msg) hashes = fingerprint.fingerprint(samples, Fs=Fs) #custom #1 ''' f = open("hashes_samples.log", "a+") for hash_local, offset in hashes: msg = ("%s|%s|%s\r\n" % (index, hash_local, offset)) print msg f.write(msg) for hash_local, offset in hashes: msg = ("find_matches hash %s, offset %s" % (hash_local, offset)) msg = "[" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "]" + msg print msg self.logger.info(msg) f.close() ''' return self.db.return_matches(hashes)
def _fingerprint_worker(self, filename, limit=None, song_name=None): # Pool.imap sends arguments as tuples so we have to unpack # them ourself. songname, extension = os.path.splitext(os.path.basename(filename)) song_name = song_name or songname channels, Fs, file_hash = decoder.read(filename, limit) result = set() channel_amount = len(channels) for channeln, channel in enumerate(channels): # TODO: Remove prints or change them into optional logging. print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename)) hashes = fingerprint.fingerprint(channel, Fs=Fs) print("Finished channel %d/%d for %s" % (channeln + 1, \ channel_amount, filename)) result |= set(hashes) sid = self.insert_song(song_name, file_hash) # add song data to songs dataframe self.insert_hashes(sid, list(result)) # add fingerprints of the song to fingerprints dataframe self.get_fingerprinted_songs() print('Song added to database')
def get_file_info(fname): print "identifying",fname #sys.stdout.write("identifying "+os.path.basename(fname)+"\r\x1B[K") #sys.stdout.flush() fhash = md5.md5(open(fname,"r").read()).hexdigest() if fhash in fileinfocache: return fileinfocache[fhash] # While testing this uses a fixed name in /tmp # and checks if it exists, and doesn't decode if it does. # This is for speed while debugging, should be changed with # tmpname later toname=os.path.join("/tmp/fingerprint.wav") if not os.path.exists(toname): sys.stdout.write("decoding"+os.path.basename(fname)+"\r\x1B[K") sys.stdout.flush() decode(fname,toname) sys.stdout.write("Generating fingerprint\r") sys.stdout.flush() (fp, dur) = fingerprint.fingerprint(toname) os.unlink(toname) sys.stdout.write("Fetching fingerprint info\r") sys.stdout.flush() (trackname, artist, puid) = musicdns.lookup_fingerprint(fp, dur, key) print "***",`artist`,`trackname`,puid if puid is None: raise FingerprintFailed() sys.stdout.write("Looking up PUID\r") sys.stdout.flush() tracks = lookups.get_tracks_by_puid(puid) data=(fname,artist,trackname,dur,tracks,puid) if tracks!=[]: fileinfocache[fhash]=data else: print "Musicbrainz doesn't know about this track, not caching" return data
def find_matches(self, samples, Fs=fingerprint.DEFAULT_FS): hashes = fingerprint.fingerprint(samples, Fs=Fs) hashes_list = list(hashes) matches = self.db.return_matches(hashes_list) return hashes_list, matches
#!/usr/bin/env python from fingerprint import fingerprint from subprocess import call os = fingerprint() #Gets epm keyword correct epm_keyword = {"ubuntu":"dpkg", "redhat":"rpm", "SunOS":"pkg", "osx":"osx"} if epm_keyword.has_key(os): platform_cmd = epm_keyword[os] subprocess.call("epm -f %s helloEPM hello_epm.list" % platform_cmd, shell=True)
#!/usr/bin/env python2.5 # # Test out the various components of audio-fingerprinting # import fingerprint import musicdns import flacnamer import sys key = 'a7f6063296c0f1c9b75c7f511861b89b' filename = sys.argv[1] print "Fingerprinting..." (fp, dur) = fingerprint.fingerprint(filename) print "Duration: " + str(dur) + "ms" print "Fingerprint: " + fp print print "MusicDNS lookup..." (artist, trackname, puid) = musicdns.lookup_fingerprint(fp, dur, key) print "Artist: " + artist print "Title: " + trackname print "PUID: " + puid print print "Musicbrainz lookup by PUID..." tracks = flacnamer.get_tracks_by_puid(puid) for track in tracks:
#Test images for count, atoms in enumerate(valid_images): f = atoms.get_forces( )[80: 144] #In this case we get the forces on the H atoms. For Pt and O this should be changed. f = f.flatten() if count == 0: forces_valid = f else: forces_valid = np.concatenate((forces_valid, f), axis=0) ########### FINGERPRINTS ##################### fingerprints = fingerprint( images, cutoff, etas, Rc, 'H', cutoff_function=False ) #fingerprints are calculated with function from fingerprint.py. if preprocess == True: ssc = StandardScaler() fingerprints = ssc.fit_transform(fingerprints) fingerprints_train = fingerprints[ 0:N_train * 3 * 64, :] #The number 64 should be changed to 32 or 48 for the case of O or Pt. fingerprints_valid = fingerprints[ N_train * 3 * 64:] #The number 64 should be changed to 32 or 48 for the case of O or Pt. ########### FEED-FORWARD NEURAL NETWORK ################
if hash_count > 0: msg = ' already exists (%d hashes), skip' % hash_count print (colored(msg, 'red')) continue print (colored(' new song, going to analyze..', 'green')) hashes = set() channel_amount = len(audio['channels']) for channeln, channel in enumerate(audio['channels']): msg = ' fingerprinting channel %d/%d' print (colored(msg, attrs=['dark']) % (channeln+1, channel_amount)) channel_hashes = fingerprint.fingerprint(channel, Fs=audio['Fs'], plots=config['fingerprint.show_plots']) channel_hashes = set(channel_hashes) msg = ' finished channel %d/%d, got %d hashes' print (colored(msg, attrs=['dark']) % ( channeln+1, channel_amount, len(channel_hashes) )) hashes |= channel_hashes msg = ' finished fingerprinting, got %d unique hashes' values = [] for hash, offset in hashes: values.append((song_id, hash, offset))
r = requests.get(query_url, headers=headers) json_result = r.json() if r.ok: return json_result else: raise Exception("Error executing API search query") # Check if input URL is valid if (is_valid_url(args.url)==False) and (args.url[-4:].lower() != '.pdf'): sys.exit("Input URL is invalid") else: # 1. Formulate API query components api_query = {} if (args.url[-4:].lower() == '.pdf'): # a) PDF file: get unique PDF fingerprint api_query['uri'] = "urn:x-pdf:" + str(fingerprint(args.url)) print("urn:x-pdf:"+str(api_query['uri'])) else: # a) Input URL to extract annotations from api_query['uri'] = args.url # b) API base URL hypothesis_api_base_url = 'https://hypothes.is/api/' hypothesis_search_api_endpoint = hypothesis_api_base_url + 'search?' # c) OPTIONAL: only extract annotations from this Hypothes.is user. I.e., the Hypothes.is username of the annotator. if args.username: api_query['user'] = args.username # d) OPTIONAL: only extract annotations from this Hypothes.is annotation group. I.e., the Hypothes.is group ID from which to extract annotations. if args.groupid: api_query['group'] = args.groupid
def main(): # parse arguments stl_files, mode, destroyDB = _hp.parseArgs() # Delete database if the flag is set if destroyDB: _db.destroy_db('./avocado_db') if mode == 'search': sys.exit(0) # Open (or create) database db = _db.Database('./avocado_db') if _hp.VERBOSE: print('Generating fingerprint of', stl_files, 'with:', '\n\tNumber of matches to return :', str(_hp.NUMBER_OF_MATCHES), '\n\tFan value :', str(_hp.FAN_VALUE), '\n\tNumber of slices :', str(_hp.NUM_OF_SLICES), '\n\tNumber of peaks :', str(_hp.NUM_OF_PEAKS), '\n\tGrid size :', str(_hp.GRID_SIZE), '\n\tRotate flag :', str(_hp.ROTATE), '\n\tStar rotate :', str(_hp.STAR_ROTATE), '\n\tInterpolation flag :', str(_hp.INTERP), '\n\tMin number of signatures to match within a neighborhood :', str(_hp.MIN_SIGNATURES_TO_MATCH), '\n') # Disable progress bar if only one disable_tqdm = False if len(stl_files) < 2: disable_tqdm = True if mode == 'learn': print('Enrolling fingerprint(s) to the database...') # For each file for stl_file in tqdm(stl_files, ncols=100, bar_format='[{n_fmt}/{total_fmt}] {l_bar}{bar}|', disable=disable_tqdm): # generate fingerprint of the file neighborhoods = _fp.fingerprint(stl_file, _hp.NUM_OF_SLICES, _hp.NUM_OF_PEAKS, _hp.FAN_VALUE, _hp.ROTATE, _hp.INTERP, _hp.STAR_ROTATE) # Add fingerprint to database if mode == 'learn': db.add_signatures(neighborhoods, stl_file) # Search in database for potential matches else: # mode == 'search': anchor_matches, signatures_matches = _db.feedback_search_signatures1(db, neighborhoods) matches = None if _hp.PRINT_NAIVE: print('\nFiles matched with ' + stl_file + ' using the number of signatures : ', end='') matches = signatures_matches _hp.print_lst_of_tuples(matches) print("Signature Match Score: ", _sc.score(matches, stl_file, 100), "\n") if _hp.NEIGHBORHOODS: print('\nFiles matched with ' + stl_file + ' using the number of neighborhoods : ', end='') matches = anchor_matches _hp.print_lst_of_tuples(matches) print("Neighborhood Match Score: ", _sc.score(matches, stl_file, 100), "\n") if _hp.EXPORT_PNGS or _hp.SHOW_PNGS: _hp.export_pngs([i[0] for i in matches], _hp.SHOW_PNGS) # Close the database db.close_db()
def find_matches(self, samples): hashes = fingerprint.fingerprint(samples, self.config) return self.db.return_matches(hashes)
# gets all files in the given directory into a list m = [i for i in os.listdir(path) if i.endswith(".txt")] if "output.txt" in m: m.remove("output.txt") os.chdir(path) for filename in m: f = open(filename, "r") # create an object of lcs class f1 = lcsClass.Lcs(f, filename) # creates a finger print object for the given file o = fingerprint.fingerprint(filename) # creates a Bag Of Words object for the given file x = BagOfWords.BagOfWords(filename) # appends each object to their respective lists b.append(x) fin.append(o) l.append(f1) print("Using LCS method\n") matsetter(l) print("\nUsing Finger printing method") matsetter(fin) print("\nUsing Bag of Words method")
def find_matches(self, samples, Fs=fingerprint.DEFAULT_FS): hashes = fingerprint.fingerprint(samples, Fs=Fs) hashes_list = list(hashes) matches = self.db.return_matches(hashes_list) return hashes_list, matches
def find_matches(self, samples, Fs=fingerprint.DEFAULT_FS): hashes = fingerprint.fingerprint(samples, Fs=Fs) return self.db.return_matches(hashes)
PATH = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(PATH, '../db')) import mysql_intercom # 対象wavファイルを設定 TARGET_FILES = [ '../master/intercom_1.wav', '../master/intercom_2.wav', '../master/intercom_3.wav' ] if __name__ == '__main__': # masterの追加 for filename in TARGET_FILES: print(filename, end=': ') wavefile = decoder.read(os.path.join(PATH, filename)) if wavefile == None: print('cannot extract wav') continue with mysql_intercom.Database_intercom(CONFIG.DB_CONFIG) as db: master_id = db.insert_master(filename.split('/')[-1]) if master_id > 0: print() print('sampling_rate =', wavefile.sampling_rate) target_hashes = fingerprint.fingerprint(wavefile.sounds) # hashの計算 fingerprint.add_masters_hashes(master_id, target_hashes) # hashの追加 else: print('cannot insert to masters') continue
def find_matches(self, samples, Fs=fingerprint.DEFAULT_FS): hashes = fingerprint.fingerprint(samples, Fs=Fs) return self.db.return_matches(hashes)
def feedback_search_signatures3(self, neighborhood): anch, signa = search_signatures(self, neighborhood) anch_dict = {} sig_dict = {} #iterate through code for fi, score in signa: sig_dict[fi] = score for fi, score in anch: anch_dict[fi] = score wgt_scale = 1 total_anch_wgt = 1 total_sig_wgt = 1 for fi, score in anch: wgt = score/wgt_scale if wgt < 0.01: break new_neigh = _fp.fingerprint(fi, _hp.NUM_OF_SLICES, _hp.NUM_OF_PEAKS, _hp.FAN_VALUE, _hp.ROTATE, _hp.INTERP, _hp.STAR_ROTATE) new_anch, new_sig = search_signatures(self, new_neigh) for nfi, nsc in new_anch: if nfi not in anch_dict: anch_dict[nfi] = wgt*nsc else: anch_dict[nfi] += wgt*nsc for nfi, nsc in new_sig: if nfi not in sig_dict: sig_dict[nfi] = wgt*nsc else: sig_dict[nfi] += wgt*nsc total_sig_wgt += wgt total_anch_wgt += wgt wgt_scale+=0.1 wgt_scale=1 for fi, score in signa: wgt = score/wgt_scale if wgt < 0.01: break new_neigh = _fp.fingerprint(fi, _hp.NUM_OF_SLICES, _hp.NUM_OF_PEAKS, _hp.FAN_VALUE, _hp.ROTATE, _hp.INTERP, _hp.STAR_ROTATE) new_anch, new_sig = search_signatures(self, new_neigh) for nfi, nsc in new_sig: if nfi not in sig_dict: sig_dict[nfi] = wgt*nsc else: sig_dict[nfi] += wgt*nsc for nfi, nsc in new_anch: if nfi not in anch_dict: anch_dict[nfi] = wgt*nsc else: anch_dict[nfi] += wgt*nsc total_sig_wgt += wgt total_anch_wgt += wgt wgt_scale+=0.1 for fi in anch_dict: anch_dict[fi] /= total_anch_wgt for fi in sig_dict: sig_dict[fi] /= total_sig_wgt #now sort anch = sorted(anch_dict.items(), key=lambda x: x[1], reverse=True)[:_hp.NUMBER_OF_MATCHES] signa = sorted(sig_dict.items(), key=lambda x: x[1], reverse=True)[:_hp.NUMBER_OF_MATCHES] return anch, signa