outputDir = '/tmp' edgeThreshold = 13 ft = FASTex(edgeThreshold=edgeThreshold, nlevels=-1, minCompSize=4) imgName = '/datagrid/personal/TextSpotter/evaluation-sets/bornDigital/img_100.png' if len(sys.argv) > 1: if sys.argv[1].endswith(".png") or sys.argv[1].endswith(".jpg"): imgName = sys.argv[1] img = cv2.imread(imgName, 0) imgc = cv2.imread(imgName) #print(out) segmentations = ft.getCharSegmentations(img, outputDir, 'base') print segmentations for i in range(segmentations.shape[0]): rectn = segmentations[i, :] rectn[2] += rectn[0] rectn[3] += rectn[1] lines = ft.findTextLines(outputDir, 'base') for i in range(lines.shape[0]): line = lines[i] lineSegm = ft.getNormalizedLine(i) cv2.imshow("textLine", lineSegm) cv2.waitKey(0)
# Verify image if not os.path.isfile(args.image): sys.exit("Image not found") if not args.image.endswith(".png") and not args.image.endswith(".jpg"): sys.exit("Not valid image") settings = settings("config.json") output_dir = settings['debug_dir'] ft = FASTex(edgeThreshold=13, nlevels=-1, minCompSize=4) # Read image as numpy array img = cv2.imread(args.image, 0) # load image in grayscale, i.e. 1 channel img_o = cv2.imread(args.image) img3 = cv2.imread(args.image) # Get boxes of characters # Elem in rows:: [bbox.x, bbox.y, bbox.width, bbox.height, keyPoint.pt.x, keyPoint.pt.y, octave, ?, duplicate, quality, [keypointsIds]] segmentations = ft.getCharSegmentations(img, output_dir, 'base') viz_location(img3, ft, segmentations, cumulative=True, max_chars=2000) # drawCharMasks(img3, ft, segmentations, 100) # drawCharBoxes(img3, segmentations, 100) # cv2.imwrite(output_dir + "/mask.jpg", img3) # Get boxes of text lines, should be a lot less than characters # Elem in rows [bbox.x, bbox.y, bbox.width, bbox.height, rotated rectangle points (pt1.x, pt1.y, ... pt3.y) ] txt_lines = ft.findTextLines(output_dir, 'txt_lines') pass