/*
- */
+ * Core OCR algorithm (first exact bitmap match)
+ */
+/*
+ * This is part of ypp-sc-tools, a set of third-party tools for assisting
+ * players of Yohoho Puzzle Pirates.
+ *
+ * Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
+ * are used without permission. This program is not endorsed or
+ * sponsored by Three Rings.
+ */
#include "ocr.h"
"Upper",
"Digit"
};
+struct OcrCellTypeInfo {
+ /* bitmaps of indices into context_names: */
+ unsigned initial, nextword, midword;
+ int space_spaces;
+ const char *name;
+};
+const struct OcrCellTypeInfo ocr_celltype_number= {
+ 4,4,4,
+ .space_spaces= 5,
+ .name= "number"
+};
+const struct OcrCellTypeInfo ocr_celltype_text= {
+ .initial=2, /* Uppercase */
+ .nextword=3, /* Either */
+ .midword=1, /* Lower only */
+ .space_spaces= 4,
+ .name= "text"
+};
-#define NCONTEXTS (sizeof(context_names)/sizeof(context_names[0]))
-#define SPACE_SPACES 4
+#define NCONTEXTS (sizeof(context_names)/sizeof(context_names[0]))
struct OcrReader {
int h;
/* we know donepipe[1] is >= 4 and we have dealt with all the others
* so we aren't in any danger of overwriting some other fd 4: */
sysassert( dup2(donepipe[1],4) ==4 );
- execlp("./show-thing.tcl", "./show-thing.tcl",
+ execlp("./yppsc-ocr-resolver", "yppsc-ocr-resolver",
DEBUGP(callout) ? "--debug" : "--noop-arg",
"--automatic-1",
(char*)0);
rd->nresults++;
}
-struct OcrCellTypeInfo {
- unsigned initial, nextword, midword;
- const char *name;
-};
-const struct OcrCellTypeInfo ocr_celltype_number= {
- 4,4,4,
- .name= "number"
-};
-const struct OcrCellTypeInfo ocr_celltype_text= {
- .initial=2, /* Uppercase */
- .nextword=3, /* Either */
- .midword=1, /* Lower only */
- .name= "text"
-};
const char *ocr_celltype_name(OcrCellType ct) { return ct->name; }
if (!cols[x]) {
nspaces++;
x++;
- if (nspaces==SPACE_SPACES) {
+ if (nspaces == ct->space_spaces) {
debugf("OCR x=%x nspaces=%d space\n",x,nspaces);
ctxmap= ct->nextword;
}
}
/* something here, so we need to add the spaces */
- if (nspaces>=SPACE_SPACES)
+ if (nspaces >= ct->space_spaces)
add_result(rd," ",x-nspaces,x+1,0);
nspaces=0;
if (uniquematch->s[0]) ctxmap= ct->midword;
else debugf(" (empty)");
if (uniquematch->endsword) {
- nspaces= SPACE_SPACES;
+ nspaces= ct->space_spaces;
debugf("_");
ctxmap= ct->nextword;
}