def read_image(data, args): try: from cross2sheet.image import ImageGrid except ImportError as e: if e.name in ('cv2', 'numpy'): raise NotRecognized( 'Image detection disabled because the module %s was not found.' % e.name) else: raise e try: img = ImageGrid(data) except ValueError: raise NotRecognized grid = img.grid() if args.detect_background: grid.features.extend(img.read_background(args.color_levels)) if args.detect_bars: grid.features.extend(img.read_bars()) if args.autonumber_cells_with_text: grid.features.extend(img.autonumber_if_text_found()) if args.ocr_text: grid.features.extend(img.read_text_ocr()) if args.autonumber is None: args.autonumber = not (args.autonumber_cells_with_text or args.ocr_text) return grid
def the_wicked_switch(): req=urlopen('http://web.mit.edu/puzzle/www/2012/puzzles/a_circus_line/the_wicked_switch/1.png') data=req.read() req.close() img=ImageGrid(data) grid=img.grid() grid.features.extend(img.read_background()) grid.features.extend(img.read_text_ocr()) grid.features.extend(outside_bars(grid)) save_xlsx(grid,'the_wicked_switch.xlsx')
def read_image(data,args): try: from cross2sheet.image import ImageGrid except ImportError as e: if e.name in ('cv2','numpy'): raise NotRecognized('Image detection disabled because the module %s was not found.'%e.name) else: raise e try: img=ImageGrid(data) except ValueError: raise NotRecognized grid=img.grid() if args.detect_background: grid.features.extend(img.read_background(args.color_levels)) if args.detect_bars: grid.features.extend(img.read_bars()) if args.autonumber_cells_with_text: grid.features.extend(img.autonumber_if_text_found()) if args.ocr_text: grid.features.extend(img.read_text_ocr()) if args.autonumber is None: args.autonumber=not (args.autonumber_cells_with_text or args.ocr_text) return grid