def _get_lat_long(self, addr): geolocator = Nominatim(user_agent="annotation_locations") try: geolocator.geocode(addr, timeout=10, exactly_one=False) except Exception as e: logger.error('geopy exception {0}'.format(e)) return None
def _generate_output_file(self, filename): try: logger.info('json file generated successfully') with open( os.path.join( os.path.dirname( os.path.normpath(self.configs_input_dir)), 'maps', self.image_name.replace('.png', '.json')), 'w') as f: f.write(json.dumps(self.tool_input, indent=4)) except Exception: logger.error('Unable to create config json file. Contact support!')
def main(): parser = argparse.ArgumentParser() parser.add_argument('--version', '-V', action='store_true', help='show version') parser.add_argument('filename', nargs='?', help='image or label filename') parser.add_argument('--output', '-O', '-o', help='output label name') parser.add_argument('--config', dest='config_file', help='config file') # config parser.add_argument('--nodata', dest='store_data', action='store_false', help='stop storing image data to JSON file') parser.add_argument('--autosave', dest='auto_save', action='store_true', help='auto save') parser.add_argument('--labels', help='comma separated list of labels OR file ' 'containing one label per line') parser.add_argument('--nosortlabels', dest='sort_labels', action='store_false', help='stop sorting labels') parser.add_argument('--validatelabel', dest='validate_label', choices=['exact', 'instance'], help='label validation types') args = parser.parse_args() if args.version: print('{0} {1}'.format(__appname__, __version__)) sys.exit(0) if args.labels is None: if args.validate_label is not None: logger.error('--labels must be specified with --validatelabel or ' 'validate_label: true in the config file ' '(ex. ~/.labelmerc).') sys.exit(1) else: if os.path.isfile(args.labels): args.labels = [l.strip() for l in open(args.labels, 'r') if l.strip()] else: args.labels = [l for l in args.labels.split(',') if l] config_from_args = args.__dict__ config_from_args.pop('version') filename = config_from_args.pop('filename') output = config_from_args.pop('output') config_file = config_from_args.pop('config_file') config = get_config(config_from_args, config_file) app = QtWidgets.QApplication(sys.argv) app.setApplicationName(__appname__) app.setWindowIcon(newIcon('icon')) win = MainWindow(config=config, filename=filename, output=output) win.show() win.raise_() sys.exit(app.exec_())
def _check_image_height_and_width(imageData, imageHeight, imageWidth): img_arr = img_b64_to_arr(imageData) if imageHeight is not None and img_arr.shape[0] != imageHeight: logger.error( "imageHeight does not match with imageData or imagePath, " "so getting imageHeight from actual image.") imageHeight = img_arr.shape[0] if imageWidth is not None and img_arr.shape[1] != imageWidth: logger.error( "imageWidth does not match with imageData or imagePath, " "so getting imageWidth from actual image.") imageWidth = img_arr.shape[1] return imageHeight, imageWidth
def main(): """Standard boilerplate Qt application code.""" parser = argparse.ArgumentParser() parser.add_argument('filename', nargs='?', help='image or label filename') parser.add_argument('--output', '-O', '-o', help='output label name') parser.add_argument('--nodata', dest='store_data', action='store_false', help='stop storing image data to JSON file') parser.add_argument('--autosave', action='store_true', help='auto save') parser.add_argument('--labels', help='comma separated list of labels OR file ' 'containing one label per line') parser.add_argument('--nosortlabels', dest='sort_labels', action='store_false', help='stop sorting labels') parser.add_argument('--validatelabel', choices=['exact', 'instance'], help='label validation types') args = parser.parse_args() if args.labels is None: if args.validatelabel is not None: logger.error('--labels must be specified with --validatelabel') sys.exit(1) else: if os.path.isfile(args.labels): args.labels = [ l.strip() for l in open(args.labels, 'r') if l.strip() ] else: args.labels = [l for l in args.labels.split(',') if l] app = QtWidgets.QApplication(sys.argv) app.setApplicationName(__appname__) app.setWindowIcon(newIcon("icon")) win = MainWindow( filename=args.filename, output=args.output, store_data=args.store_data, labels=args.labels, sort_labels=args.sort_labels, auto_save=args.autosave, validate_label=args.validatelabel, ) win.show() win.raise_() sys.exit(app.exec_())
def main(): parser = argparse.ArgumentParser() parser.add_argument('in_file', help='Input file or directory.') parser.add_argument('-O', '--output') args = parser.parse_args() if not distutils.spawn.find_executable('docker'): logger.error('Please install docker.') sys.exit(1) try: out_file = labelme_on_docker(args.in_file, args.output) if out_file: print('Saved to: %s' % out_file) except RuntimeError as e: sys.stderr.write(e.__str__() + '\n') sys.exit(1)
def load_image_file(filename): try: image_pil = PIL.Image.open(filename) except IOError: logger.error("Failed opening image file: {}".format(filename)) return # apply orientation to image according to exif image_pil = apply_exif_orientation(image_pil) with io.BytesIO() as f: ext = osp.splitext(filename)[1].lower() if ext in [".jpg", ".jpeg"]: format = "JPEG" else: format = "PNG" image_pil.save(f, format=format) f.seek(0) return f.read()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--version', '-V', action='store_true', help='show version') parser.add_argument('filename', nargs='?', help='image or label filename') parser.add_argument('--output', '-O', '-o', help='output label name') default_config_file = os.path.join(os.path.expanduser('~'), '.labelmerc') parser.add_argument( '--config', dest='config_file', help='config file (default: %s)' % default_config_file, default=default_config_file, ) # config for the gui parser.add_argument( '--nodata', dest='store_data', action='store_false', help='stop storing image data to JSON file', default=argparse.SUPPRESS, ) parser.add_argument( '--autosave', dest='auto_save', action='store_true', help='auto save', default=argparse.SUPPRESS, ) parser.add_argument( '--nosortlabels', dest='sort_labels', action='store_false', help='stop sorting labels', default=argparse.SUPPRESS, ) parser.add_argument( '--flags', help='comma separated list of flags OR file containing flags', default=argparse.SUPPRESS, ) parser.add_argument( '--labels', help='comma separated list of labels OR file containing labels', default=argparse.SUPPRESS, ) parser.add_argument( '--validatelabel', dest='validate_label', choices=['exact', 'instance'], help='label validation types', default=argparse.SUPPRESS, ) parser.add_argument( '--keep-prev', action='store_true', help='keep annotation of previous frame', default=argparse.SUPPRESS, ) parser.add_argument( '--epsilon', type=float, help='epsilon to find nearest vertex on canvas', default=argparse.SUPPRESS, ) args = parser.parse_args() if args.version: print('{0} {1}'.format(__appname__, __version__)) sys.exit(0) if hasattr(args, 'flags'): if os.path.isfile(args.flags): with codecs.open(args.flags, 'r', encoding='utf-8') as f: args.flags = [l.strip() for l in f if l.strip()] else: args.flags = [l for l in args.flags.split(',') if l] if hasattr(args, 'labels'): if os.path.isfile(args.labels): with codecs.open(args.labels, 'r', encoding='utf-8') as f: args.labels = [l.strip() for l in f if l.strip()] else: args.labels = [l for l in args.labels.split(',') if l] config_from_args = args.__dict__ config_from_args.pop('version') filename = config_from_args.pop('filename') output = config_from_args.pop('output') config_file = config_from_args.pop('config_file') config = get_config(config_from_args, config_file) if not config['labels'] and config['validate_label']: logger.error('--labels must be specified with --validatelabel or ' 'validate_label: true in the config file ' '(ex. ~/.labelmerc).') sys.exit(1) app = QtWidgets.QApplication(sys.argv) app.setApplicationName(__appname__) app.setWindowIcon(newIcon('icon')) win = MainWindow(config=config, filename=filename, output=output) win.show() win.raise_() sys.exit(app.exec_())
def close(self): if len(self.points) <= 2: logger.error('Polygon should be created with points >2') return self._closed = True
def main(): parser = argparse.ArgumentParser() parser.add_argument('--version', '-V', action='store_true', help='show version') parser.add_argument('filename', nargs='?', help='image or label filename') parser.add_argument('--output', '-O', '-o', help='output label name') parser.add_argument('--config', dest='config_file', help='config file') # config parser.add_argument('--nodata', dest='store_data', action='store_false', help='stop storing image data to JSON file') parser.add_argument('--autosave', dest='auto_save', action='store_true', help='auto save') parser.add_argument('--labels', help='comma separated list of labels OR file ' 'containing one label per line') parser.add_argument('--nosortlabels', dest='sort_labels', action='store_false', help='stop sorting labels') parser.add_argument('--validatelabel', dest='validate_label', choices=['exact', 'instance'], help='label validation types') args = parser.parse_args() if args.version: print('{0} {1}'.format(__appname__, __version__)) sys.exit(0) if args.labels is None: if args.validate_label is not None: logger.error('--labels must be specified with --validatelabel or ' 'validate_label: true in the config file ' '(ex. ~/.labelmerc).') sys.exit(1) else: if os.path.isfile(args.labels): with codecs.open(args.labels, 'r', encoding='utf-8') as f: args.labels = [l.strip() for l in f if l.strip()] else: args.labels = [l for l in args.labels.split(',') if l] config_from_args = args.__dict__ config_from_args.pop('version') filename = config_from_args.pop('filename') output = config_from_args.pop('output') config_file = config_from_args.pop('config_file') # drop the default config if not config_from_args['auto_save']: config_from_args.pop('auto_save') if config_from_args['store_data']: config_from_args.pop('store_data') if not config_from_args['labels']: config_from_args.pop('labels') if not config_from_args['sort_labels']: config_from_args.pop('sort_labels') if not config_from_args['validate_label']: config_from_args.pop('validate_label') config = get_config(config_from_args, config_file) app = QtWidgets.QApplication(sys.argv) app.setApplicationName(__appname__) app.setWindowIcon(newIcon('icon')) win = MainWindow(config=config, filename=filename, output=output) win.show() win.raise_() sys.exit(app.exec_())