def create(dataset, work_dir): # Find all the pages in the dataset img_dir = Path(Path.cwd().ancestor(1), 'data/hwr_data/pages', dataset) ann_dir = Path(Path.cwd().ancestor(1), 'data/charannotations') images = img_dir.listdir('*.jpg') annotations = ann_dir.listdir(dataset + '*.words') files = merge(images, annotations) # Create character segmentations stats = {} for f in files: # Preprocess logging.info("Preprocessing %s", str(f[0])) pagesPathFolder = Path(work_dir, 'pages') pagesPathFolder.mkdir() pagePath = Path(pagesPathFolder, f[0].stem + '.ppm') img = cv2.imread(f[0], cv2.IMREAD_GRAYSCALE) img = preprocess(img) cv2.imwrite(pagePath, img) # Segment segmentPathFolder = Path(work_dir, 'segments') segmentPathFolder.mkdir() e = ET.parse(f[1]).getroot() logging.info("Segmenting %s", str(f[0])) segment(img, e, segmentPathFolder, stats) print_statistics(stats, dataset)
def fixtures(module, yaml_file): yaml_file = Path.cwd().child(app_name, module, 'tests', 'fixtures', '%s.yml' % yaml_file) with open(yaml_file) as yaml_file: fixtures = yaml.load(yaml_file.read()) def load_fixture(fixture_name): if fixture_name in fixtures: return fixtures[fixture_name] else: raise LookupError('%s doesnt exists in this fixture file' % fixture_name) return load_fixture
def setup_report_dir(app_name, random_dir=True): if random_dir: date_dir = time.strftime('%y-%m-%d') date_dir += "-" date_dir += ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(6)) else: date_dir = "" report_dir = Path(Path.cwd(), [app_name, date_dir]) report_dir.mkdir(parents=True) return report_dir
def make_ota_package(self, *, kbuild_image_dir: Optional[Path]="", output_dir: Path, source_dir: Path=Path.cwd()) -> Path: """Create an Over the Air (OTA) package that can be installed via recovery. Keyword Args: output_dir: Where the otapackage will be stored source_dir: The directory to be zipped (default cwd) kbuild_image_dir: Optional path to to copy kbuild image into; relative to source_dir Returns: the path to the zip file created. """ if kbuild_image_dir: shutil.copy(self.kbuild_image.as_posix(), (source_dir / kbuild_image_dir).as_posix()) archive_path = output_dir / self.custom_release.lower() archive_name = archive_path.as_posix() return Path(shutil.make_archive(archive_name, 'zip', source_dir))
def create_own_lexicon(): lexicon = {} for dataset in ['KNMP', 'Stanford']: # Find all the annotated pages in the dataset ann_dir = Path(Path.cwd().ancestor(1), 'data/hwr_data/words/' + dataset) annotations = ann_dir.listdir( '*.words') for f in annotations: # Segment annotation = ET.parse(f).getroot() for word in annotation.iter('Word'): text = word.get('text') # Add word to lexicon if lexicon.has_key(text): lexicon[text] += 1 else : lexicon[text] = 1 return lexicon
For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # Importando Unipath from unipath import Path RUTA_PROYECTO = Path.cwd() # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '*(xh=qj(!$9nrj42bz742k*75hv$^x==m)zc@3rc21i4mw_qy@' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] SITE_ID = 1 # Application definition
else: raise ValueError("invalid default answer: '%s'" % default) while True: sys.stdout.write(question + prompt) choice = raw_input().lower() if default is not None and choice == "": return valid[default] elif choice in valid: return valid[choice] else: sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n") # mypath = '/home/gavin/Code/destapi/djangomedia/images/' mypath = Path.cwd().ancestor(1) + "/djangomedia/images/" def count_files(): global f, onlyfiles onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] count_files() con = None image_list = [] queries = [ ("SELECT img_url FROM core_page WHERE LENGTH (img_url)>1", "Page"), ("SELECT img_url2 FROM core_sector WHERE LENGTH (img_url2)>1", "Sector"),
# -*- coding: utf-8 -*- import json import toml from unipath import Path defdir = Path.cwd().child('tiledefs') for orig_file in defdir.listdir('*.toml'): with open(orig_file) as orig_f: content = toml.load(orig_f) content['paths'] = [] try: for path in content['path']: if "start" in path.keys(): path['start'] = {'Named': path['start']} elif "start_pos" in path.keys(): path['start'] = {'HexSpace': path['start_pos']} del path['start_pos'] if "end" in path.keys(): path['end'] = {'Named': path['end']} elif "end_pos" in path.keys(): path['end'] = {'HexSpace': path['end_pos']} del path['end_pos'] content['paths'].append(path) del content['path'] except KeyError: pass # There are no paths defined if not content['paths']: # Remove if key was empty del content['paths']
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'eyw5spd)&u1gkzwxjarmul#&aj3axf6=emkc204e*6-di_a&8r' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True from unipath import Path RUTA_PROYECTO = Path.cwd() ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'cliente',
# Django settings for tango project. from unipath import Path import dj_database_url PROJECT_PATH = Path.cwd() TEMPLATE_PATH = Path(PROJECT_PATH, 'templates') STATIC_PATH = Path(PROJECT_PATH, 'static') MEDIA_ROOT = Path(PROJECT_PATH, 'media') DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', '*****@*****.**'), ) MANAGERS = ADMINS DATABASES = { 'default': dj_database_url.config(default="postgres://jonathan@localhost:5432/rango") } LOGIN_URL = '/rango/login/' # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts ALLOWED_HOSTS = [] # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name