static int ocr_recognizeTextClips_spaceDist = 7; static L ocr_recognizeTextClips(BWImage bw, L clips) { SimpleRecognizer sr = filledSimpleRecognizer_cached(); final L rects = autoSegment(bw); new L lines; for (Rect clip: clips) { S s = diamond(); pcall { BWImage clipImg = autoCroppedBWImage(bw.clip(clip)); new L gclips; // glyph clips L groups = sr.recognizeGrouped(clipImg, gclips); int n = l(groups); if (l(gclips) != n) print("huh? " + n + "/" + l(gclips)); else { //print("Finding spaces. " + n + " characters"); for (int i = 0; i < l(groups)-1; i++) { Rect a = gclips.get(i); Rect b = gclips.get(i+1); if (a != null && b != null) { int dist = b.x-a.x2(); //print("Space dist between " + groups.get(i) + " and " + groups.get(i+1) + ": " + dist); if (dist >= ocr_recognizeTextClips_spaceDist) { groups.add(i+1, " "); gclips.add(i+1, null); ++i; } } } } s = ocr_joinGroups(groups); } lines.add(s); } ret lines; }