def read_temp_bib(self): """Read content of temporary bibliography. """ path = self.wf.cachefile('temp_bibliography.html') bib = utils.read_path(path) text = self.export_formatted(bib) bib = self._bib_sort(text, '\n\n') utils.set_clipboard(bib) return self.zotquery.output_format
def scan_codepath(self): """Scan Markdown document for reference """ if self.flag == 'temp_bib': return self.read_temp_bib() else: md_text = utils.read_path(self.flag) key_dicts = self.reference_scan(md_text) self.generate_bibliography(key_dicts, md_text)
def read_temp_bib(wf): """Read content of temporary bibliography. """ path = wf.cachefile('temp_bibliography.html') bib = utils.read_path(path) text = export.export_formatted(bib) bib = export._bib_sort(text, '\n\n') utils.set_clipboard(bib) return zq.backend.output_format
def scan(flag, arg, wf): """Scan Markdown document for reference """ if flag == 'temp_bib': return read_temp_bib(wf) else: md_text = utils.read_path(flag) key_dicts = reference_scan(md_text) generate_bibliography(key_dicts, md_text)
def main(prefix, path_dic, method): for tar in path_dic: paths = read_path(path_dic[tar]) datas = [] miss_cnt = 0 for path in paths: feature = face.feat(path, method) if feature is None: miss_cnt += 1 continue else: datas.append(feature) datas = np.array(datas) np.save('./datas/new_' + prefix + '_' + tar + '_' + method, datas) print('there is(are) %d picture(s) cannot be detected' % miss_cnt)
def _get_group_name(self): """Get name of group from stored result. :returns: name of group from it's ID :rtype: :class:`unicode` """ # get group type (`collection` vs `tag`) flag = self.flag.split('-')[1] # Read saved group info path = self.wf.cachefile('{}_query_result.txt'.format(flag)) group_id = utils.read_path(path) # Split group type from group ID kind, uid = group_id.split('_') if kind == 'c': group = self._get_collection_name(uid) elif kind == 't': group = self._get_tag_name(uid) return group
def get_pref(self, pref): """Retrieve the value for ``pref`` in Zotero's preferences. :param pref: name of desired Zotero preference :type pref: ``unicode`` or ``str`` :returns: Zotero preference value :rtype: ``unicode`` """ dirs = self.find_name('prefs.js') for path in dirs: if 'Zotero' or 'Firefox' in path: # Read text from file at `path` prefs = utils.read_path(path) pref_re = r'{}",\s"(.*?)"'.format(pref) data_dir = re.search(pref_re, prefs) try: return data_dir.group(1) except AttributeError: pass return None
def search_within_group(scope, query): group_type = scope.split('-')[-1] # Read saved group info path = config.WF.cachefile('{}_query_result.txt'.format(group_type)) group_id = utils.read_path(path) group_name = get_group_name(group_id) sqlite_query = make_in_group_sqlite_query(scope, query, group_name) config.log.info('Item sqlite query : {}'.format(sqlite_query)) # Run sqlite query and get back item keys item_keys = run_item_sqlite_query(sqlite_query) # Get JSON data of user's Zotero library data = utils.read_json(zq.backend.json_data) results_dict = [] for key in item_keys: item = data.get(key, None) if item: # Prepare dictionary for Alfred formatter = ResultsFormatter(item) alfred_dict = formatter.prepare_item_feedback() results_dict.append(alfred_dict) return results_dict
if __name__ == '__main__': method = 'uniform' data, label = load_data('training', method) clf = svm.SVC(C=1.0, gamma=0.1) clf.fit(data, label) #data, label = load_data('testing', method) #score = clf.score(data, label) #print(score) #exit(0) # formal testing(full data, including those whose face cannot be deteceted) posi_paths = read_path(posi_test) nega_paths = read_path(nega_test) paths = posi_paths + nega_paths labels = [1] * len(posi_paths) + [-1] * len(nega_paths) total = len(labels) correct = 0 ind = 0 for path, label in zip(paths, labels): feature = feat(path, method) if feature is None: # print('None') pred = -1 else: pred = clf.predict(np.expand_dims(feature, axis=0))
import cv2 import numpy as np from lib import face from lib.get_LBP_from_Image import LBP from matplotlib import pyplot as plt from lib.utils import read_path import os import numpy as np posi_test = 'client_test_raw.txt' nega_test = 'imposter_test_raw.txt' paths = read_path(nega_test) for path in paths[:10]: image = cv2.imread(path) gray = face.detect(image) w, h = gray.shape #croped = gray[int(w/2-32):int(w/2+32),int(h/2-32):int(h/2+32)] croped = gray[int(w * 0.15):int(w * 0.95), int(h * 0.15):int(h * 0.85)] croped = cv2.resize(croped, (64, 64)) cv2.imshow('', croped) cv2.waitKey(0) ''' #faceCascade = cv2.CascadeClassifier("./haarcascade_frontalface_alt.xml") #pimage = cv2.imread('./raw/ImposterRaw/0001/0001_00_00_01_0.jpg') nima ge = cv2.imread('/raw/ClientRaw/0006/0006_00_00_01_169.jpg') #crop = face.detect(pimage) cv2.imshow('',nimage)