├── .gitattributes
├── .gitignore
├── Handwriting Input Recognition.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcshareddata
│ └── xcschemes
│ └── Handwriting Input Recognition.xcscheme
├── Handwriting Input Recognition
├── AppDelegate.swift
├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── Contents.json
├── Base.lproj
│ └── Main.storyboard
├── External
│ └── Tesseract
│ │ ├── SLTesseract.h
│ │ ├── SLTesseract.mm
│ │ ├── include
│ │ ├── jconfig.h
│ │ ├── jerror.h
│ │ ├── jmorecfg.h
│ │ ├── jpeglib.h
│ │ ├── leptonica
│ │ │ ├── allheaders.h
│ │ │ ├── alltypes.h
│ │ │ ├── array.h
│ │ │ ├── arrayaccess.h
│ │ │ ├── bbuffer.h
│ │ │ ├── bilateral.h
│ │ │ ├── bmf.h
│ │ │ ├── bmfdata.h
│ │ │ ├── bmp.h
│ │ │ ├── ccbord.h
│ │ │ ├── dewarp.h
│ │ │ ├── endianness.h
│ │ │ ├── environ.h
│ │ │ ├── gplot.h
│ │ │ ├── heap.h
│ │ │ ├── imageio.h
│ │ │ ├── jbclass.h
│ │ │ ├── leptwin.h
│ │ │ ├── list.h
│ │ │ ├── morph.h
│ │ │ ├── pix.h
│ │ │ ├── ptra.h
│ │ │ ├── queue.h
│ │ │ ├── readbarcode.h
│ │ │ ├── recog.h
│ │ │ ├── regutils.h
│ │ │ ├── stack.h
│ │ │ ├── stringcode.h
│ │ │ ├── sudoku.h
│ │ │ └── watershed.h
│ │ ├── png.h
│ │ ├── pngconf.h
│ │ ├── pnglibconf.h
│ │ ├── tesseract
│ │ │ ├── apitypes.h
│ │ │ ├── baseapi.h
│ │ │ ├── capi.h
│ │ │ ├── genericvector.h
│ │ │ ├── helpers.h
│ │ │ ├── host.h
│ │ │ ├── ltrresultiterator.h
│ │ │ ├── ocrclass.h
│ │ │ ├── pageiterator.h
│ │ │ ├── platform.h
│ │ │ ├── publictypes.h
│ │ │ ├── renderer.h
│ │ │ ├── resultiterator.h
│ │ │ ├── serialis.h
│ │ │ ├── strngs.h
│ │ │ ├── tess_version.h
│ │ │ ├── tesscallback.h
│ │ │ ├── thresholder.h
│ │ │ └── unichar.h
│ │ ├── tiff.h
│ │ ├── tiffconf.h
│ │ ├── tiffio.h
│ │ └── tiffvers.h
│ │ └── lib
│ │ ├── libjpeg.a
│ │ ├── liblept.a
│ │ ├── libpng.a
│ │ ├── libtesseract.4.dylib
│ │ ├── libtesseract.a
│ │ ├── libtesseract.dylib
│ │ ├── libtiff.a
│ │ └── libz.a
├── Handwriting Input Recognition-Bridging-Header.h
├── Handwriting_Input_Recognition.entitlements
├── Info.plist
├── MainViewController.swift
├── Models
│ └── TesseractData.swift
├── Views
│ ├── CharacterOptionCollectionView.swift
│ ├── CharacterOptionItem.swift
│ ├── CharacterOptionItem.xib
│ └── DrawCanvasView.swift
└── tessdata
│ ├── eng.traineddata
│ ├── jpn.traineddata
│ └── jpn_vert.traineddata
├── Handwriting Input RecognitionTests
├── Handwriting_Input_RecognitionTests.swift
└── Info.plist
├── LICENSE.txt
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | Handwriting?Input?Recognition/External/Tesseract/** linguist-vendored
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | ## Playgrounds
32 | timeline.xctimeline
33 | playground.xcworkspace
34 |
35 | # Swift Package Manager
36 | #
37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38 | # Packages/
39 | # Package.pins
40 | # Package.resolved
41 | .build/
42 |
43 | # CocoaPods
44 | #
45 | # We recommend against adding the Pods directory to your .gitignore. However
46 | # you should judge for yourself, the pros and cons are mentioned at:
47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
48 | #
49 | # Pods/
50 | #
51 | # Add this line if you want to avoid checking in source code from the Xcode workspace
52 | # *.xcworkspace
53 |
54 | # Carthage
55 | #
56 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
57 | # Carthage/Checkouts
58 |
59 | Carthage/Build
60 |
61 | # fastlane
62 | #
63 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
64 | # screenshots whenever they are needed.
65 | # For more information about the recommended setup visit:
66 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
67 |
68 | fastlane/report.xml
69 | fastlane/Preview.html
70 | fastlane/screenshots/**/*.png
71 | fastlane/test_output
72 |
73 | # Code Injection
74 | #
75 | # After new code Injection tools there's a generated folder /iOSInjectionProject
76 | # https://github.com/johnno1962/injectionforxcode
77 |
78 | iOSInjectionProject/
79 |
80 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition.xcodeproj/xcshareddata/xcschemes/Handwriting Input Recognition.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
79 |
80 |
84 |
85 |
86 |
87 |
93 |
95 |
101 |
102 |
103 |
104 |
106 |
107 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 11/10/18.
6 | // Copyright © 2018 chargeflux. All rights reserved.
7 | //
8 |
9 | import Cocoa
10 |
11 | @NSApplicationMain
12 | class AppDelegate: NSObject, NSApplicationDelegate {
13 |
14 | func applicationDidFinishLaunching(_ aNotification: Notification) {
15 | // Insert code here to initialize your application
16 | }
17 |
18 | func applicationWillTerminate(_ aNotification: Notification) {
19 | // Insert code here to tear down your application
20 | }
21 |
22 |
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "mac",
5 | "size" : "16x16",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "mac",
10 | "size" : "16x16",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "mac",
15 | "size" : "32x32",
16 | "scale" : "1x"
17 | },
18 | {
19 | "idiom" : "mac",
20 | "size" : "32x32",
21 | "scale" : "2x"
22 | },
23 | {
24 | "idiom" : "mac",
25 | "size" : "128x128",
26 | "scale" : "1x"
27 | },
28 | {
29 | "idiom" : "mac",
30 | "size" : "128x128",
31 | "scale" : "2x"
32 | },
33 | {
34 | "idiom" : "mac",
35 | "size" : "256x256",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "mac",
40 | "size" : "256x256",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "mac",
45 | "size" : "512x512",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "mac",
50 | "size" : "512x512",
51 | "scale" : "2x"
52 | }
53 | ],
54 | "info" : {
55 | "version" : 1,
56 | "author" : "xcode"
57 | }
58 | }
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/SLTesseract.h:
--------------------------------------------------------------------------------
1 | //
2 | // SLTesseract.h
3 | // testOCR
4 | //
5 | // Created by Scott Liu on 4/27/18.
6 | // Copyright © 2018 Scott Liu. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SLTesseract : NSObject
12 |
13 | // language can take values such as "eng", "ita", "eng+ita", or even nil (defaults to eng)
14 | @property (nonatomic, copy) NSString* language;
15 | @property (nonatomic, copy) NSString *charWhitelist;
16 | @property (nonatomic, copy) NSString *charBlacklist;
17 | // @property (nonatomic, assign) NSTimeInterval maximumRecognitionTime; // No longer supporting monitoring
18 |
19 | #pragma mark Core Functions
20 | // Core recognition function: returns the closest possible NSString
21 | // match as interpreted by Tesseract for the given NSImage
22 | - (NSString*)recognize:(NSImage*)image;
23 |
24 |
25 |
26 | #pragma mark Optional Functions
27 | // returns a 3D NSArray of all possible choices as interpreted by
28 | // Tesseract per symbol with corresponding confidence intervals (0-1)
29 | //
30 | // Example:
31 | // Assume an image that contains the symbols/characters "A B C"
32 | // Tesseract would recognize 3 symbols in this image and the following
33 | // function will return an array that has the all classifier choices
34 | // per symbol with corresponding confidence intervals
35 | //
36 | // Example return value:
37 | // [[["A",0.96],["O",0.84],["D",0.72]],
38 | // [["B",0.99],["D",0.87]],
39 | // [["O",0.92], ["C",0.91],["D",0.82],["Q",0.72],["@",0.65]]]
40 | //
41 | // Notice on the third symbol ("C"), Tesseract recognizes it as "O"
42 | // as it has the highest CI but the right answer is "C",
43 | // which has the next highest CI.
44 | - (NSArray*)getClassiferChoicesPerSymbol:(NSImage*)image;
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/SLTesseract.mm:
--------------------------------------------------------------------------------
1 | //
2 | // SLTesseract.mm
3 | // testOCR
4 | //
5 | // Created by Scott Liu on 4/27/18.
6 | // Copyright © 2018 Scott Liu. All rights reserved.
7 | // Inspired by Loïs Di Qual (24/09/12)
8 |
9 | #import
10 | #import "SLTesseract.h"
11 | #include "include/tesseract/baseapi.h" // contains the base API
12 | #include "include/tesseract/ocrclass.h" // defines the ETEXT_DESC class
13 |
14 | #import "include/leptonica/environ.h" // defines the l_int types that pix needs
15 | #import "include/leptonica/pix.h" // required for the pix class
16 | #include "include/tesseract/publictypes.h" // required for engine mode enums
17 | #import "include/leptonica/allheaders.h" // required for pix related functions
18 |
19 |
20 | @interface SLTesseract ()
21 |
22 | // representation of the base API
23 | @property (nonatomic, assign, readonly) tesseract::TessBaseAPI *tesseract;
24 | // @property (nonatomic, assign, readonly) ETEXT_DESC *monitor; // No longer supporting monitoring
25 |
26 | // data path to the tessdata folder
27 | @property (nonatomic, readonly, copy) NSString *absoluteDataPath;
28 |
29 | @end
30 |
31 | @implementation SLTesseract
32 |
33 | - (instancetype)init {
34 | self = [super init];
35 | _tesseract = new tesseract::TessBaseAPI();
36 | // _monitor = new ETEXT_DESC(); // No longer supporting monitoring
37 | _absoluteDataPath = [[NSBundle mainBundle].bundlePath stringByAppendingString:@"/Contents/Resources/tessdata"];
38 |
39 | setenv("TESSDATA_PREFIX", _absoluteDataPath.fileSystemRepresentation, 1);
40 |
41 | return self;
42 | }
43 |
44 |
45 | - (NSString*)recognize:(NSImage*)image {
46 |
47 | // initiallize the tesseract
48 | _tesseract->Init(_absoluteDataPath.fileSystemRepresentation, self.language.UTF8String);
49 |
50 | /* No longer supporting monitoring
51 | // set the maximum recognition time
52 | if (self.maximumRecognitionTime > FLT_EPSILON) {
53 | _monitor->set_deadline_msecs((inT32)(self.maximumRecognitionTime * 1000));
54 | }
55 | */
56 |
57 | if(self.charWhitelist != nil){
58 | _tesseract->SetVariable("tessedit_char_whitelist", self.charWhitelist.UTF8String);
59 | }
60 | if(self.charBlacklist != nil){
61 | _tesseract->SetVariable("tessedit_char_blacklist", self.charBlacklist.UTF8String);
62 | }
63 |
64 | // set the image
65 | [self setEngineImage:image];
66 |
67 | // uncomment the following line to save image to desktop (mostly for debugging purposes)
68 | //[self saveThresholdedImage];
69 |
70 | int returnCode = 0;
71 | // call the recognize function
72 | // returnCode = _tesseract->Recognize(_monitor); // No longer supporting monitoring
73 | returnCode = _tesseract->Recognize(nullptr);
74 |
75 | if(returnCode != 0) printf("recognition function failed\n");
76 |
77 | // retrieve the recognized text
78 | char *utf8Text = _tesseract->GetUTF8Text();
79 | NSString *text;
80 | if(utf8Text != NULL){
81 | // convert the utf8 text to NSString, and then
82 | // trim off the newlines at the beginning and end
83 | text = [[NSString stringWithUTF8String:utf8Text]
84 | stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
85 | } else {
86 | text = @"";
87 | }
88 | delete[] utf8Text;
89 | return text;
90 | }
91 |
92 | - (NSArray*)getClassiferChoicesPerSymbol:(NSImage*)image {
93 | // returns a 3D array of all possible choices as interpreted by
94 | // Tesseract per symbol/character with corresponding confidence
95 | // intervals (0-1)
96 |
97 | // initialize the tesseract
98 | _tesseract->Init(_absoluteDataPath.fileSystemRepresentation, self.language.UTF8String);
99 |
100 | if(self.charWhitelist != nil){
101 | _tesseract->SetVariable("tessedit_char_whitelist", self.charWhitelist.UTF8String);
102 | }
103 | if(self.charBlacklist != nil){
104 | _tesseract->SetVariable("tessedit_char_blacklist", self.charBlacklist.UTF8String);
105 | }
106 |
107 | // set the image
108 | [self setEngineImage:image];
109 |
110 | int returnCode = 0;
111 | // call the recognize function
112 | // returnCode = _tesseract->Recognize(_monitor); // No longer supporting monitoring
113 | returnCode = _tesseract->Recognize(nullptr);
114 |
115 | if(returnCode != 0) printf("recognition function failed\n");
116 |
117 | // Result iterator object to be iterated through
118 | tesseract::ResultIterator* ri = _tesseract->GetIterator();
119 |
120 | // Iterator `level`, will go through each recognized symbol
121 | tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
122 |
123 | // Holds array of array of symbols where each symbol has all
124 | // possible classifier choices with corresponding CI
125 | NSMutableArray *result = [NSMutableArray array];
126 | if(ri != 0) {
127 | do {
128 | // Holds current array for current symbol and its classifier choices
129 | NSMutableArray *symbol_result = [NSMutableArray array];
130 | const char* symbol = ri->GetUTF8Text(level);
131 | if(symbol != 0) {
132 | // Iterate through all classifer choices for symbol
133 | tesseract::ChoiceIterator ci(*ri);
134 | do {
135 | // Array to hold current symbol + CI in iterator
136 | NSMutableArray *character = [NSMutableArray array];
137 | const char* choice = ci.GetUTF8Text();
138 | [character addObject:@(choice)];
139 | [character addObject:@(ci.Confidence()/100)];
140 | [symbol_result addObject:character];
141 | } while(ci.Next());
142 | }
143 | [result addObject:symbol_result];
144 | delete[] symbol;
145 | } while((ri->Next(level)));
146 | }
147 | delete ri;
148 | NSArray *resultFinal = [result copy];
149 | return resultFinal;
150 | }
151 |
152 |
153 |
154 | - (void)setEngineImage:(NSImage *)image {
155 |
156 | if (image.size.width <= 0 || image.size.height <= 0) {
157 | NSLog(@"ERROR: Image has invalid size!");
158 | return;
159 | }
160 |
161 | Pix *pix = nullptr;
162 |
163 | pix = [self pixForImage:image];
164 |
165 | @try {
166 | _tesseract->SetImage(pix);
167 | }
168 | //LCOV_EXCL_START
169 | @catch (NSException *exception) {
170 | NSLog(@"ERROR: Can't set image: %@", exception);
171 | }
172 | //LCOV_EXCL_STOP
173 | pixDestroy(&pix);
174 |
175 | }
176 |
177 | /*
178 | * Debug feature: save the thresholded image to desktop
179 | */
180 | - (void)saveThresholdedImage {
181 | Pix* thresh = _tesseract->GetThresholdedImage();
182 | NSString *fileName = @"~/Desktop/thresh.png";
183 | NSString *filePath = [[fileName stringByExpandingTildeInPath] stringByStandardizingPath];
184 | pixWrite(filePath.UTF8String, thresh, IFF_DEFAULT);
185 | pixDestroy(&thresh);
186 | }
187 |
188 | - (void)setLanguage:(NSString *)language {
189 | if ([language isEqualToString:_language] == NO || (!language && _language) ) {
190 |
191 | _language = language.copy;
192 | }
193 | }
194 |
195 | - (void)setCharWhitelist:(NSString *)charWhitelist {
196 | if ([_charWhitelist isEqualToString:charWhitelist] == NO) {
197 | _charWhitelist = charWhitelist.copy;
198 |
199 | _tesseract->SetVariable("tessedit_char_whitelist", charWhitelist.UTF8String);
200 | }
201 | }
202 |
203 | - (void)setCharBlacklist:(NSString *)charBlacklist {
204 | if ([_charBlacklist isEqualToString:charBlacklist] == NO) {
205 | _charBlacklist = charBlacklist.copy;
206 |
207 | _tesseract->SetVariable("tessedit_char_blacklist", charBlacklist.UTF8String);
208 | }
209 | }
210 |
211 |
212 |
213 | - (Pix *)pixForImage:(NSImage *)image
214 | {
215 | CGImageRef cg = [image CGImageForProposedRect:NULL context:NULL hints:NULL];
216 | unsigned long width = CGImageGetWidth (cg),
217 | height = CGImageGetHeight (cg);
218 |
219 | l_uint32* pixels;
220 | pixels = (l_uint32 *) malloc(width * height * sizeof(l_uint32));
221 | memset(pixels, 0, width * height * sizeof(l_uint32));
222 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
223 | CGContextRef context =
224 | CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
225 | kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
226 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), cg);
227 |
228 | CGContextRelease(context);
229 | CGColorSpaceRelease(colorSpace);
230 |
231 | Pix* pix = pixCreate((l_uint32)width, (l_uint32)height, (l_uint32)CGImageGetBitsPerPixel(cg));
232 | pixFreeData(pix);
233 | pixSetData(pix, pixels);
234 | pixSetYRes(pix, (l_int32)300);
235 |
236 | return pix;
237 | }
238 |
239 | - (void)dealloc {
240 | /* No longer supporting monitoring
241 | if (_monitor != nullptr) {
242 | delete _monitor;
243 | _monitor = nullptr;
244 | }
245 | */
246 | [self freeTesseract];
247 | }
248 |
249 | - (void)freeTesseract {
250 | if (_tesseract != nullptr) {
251 | // There is no needs to call Clear() and End() explicitly.
252 | // End() is sufficient to free up all memory of TessBaseAPI.
253 | // End() is called in destructor of TessBaseAPI.
254 | delete _tesseract;
255 | _tesseract = nullptr;
256 | }
257 | }
258 |
259 | @end
260 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/jconfig.h:
--------------------------------------------------------------------------------
1 | /* jconfig.h. Generated from jconfig.cfg by configure. */
2 | /* jconfig.cfg --- source file edited by configure script */
3 | /* see jconfig.txt for explanations */
4 |
5 | #define HAVE_PROTOTYPES 1
6 | #define HAVE_UNSIGNED_CHAR 1
7 | #define HAVE_UNSIGNED_SHORT 1
8 | /* #undef void */
9 | /* #undef const */
10 | /* #undef CHAR_IS_UNSIGNED */
11 | #define HAVE_STDDEF_H 1
12 | #define HAVE_STDLIB_H 1
13 | #define HAVE_LOCALE_H 1
14 | /* #undef NEED_BSD_STRINGS */
15 | /* #undef NEED_SYS_TYPES_H */
16 | /* #undef NEED_FAR_POINTERS */
17 | /* #undef NEED_SHORT_EXTERNAL_NAMES */
18 | /* Define this if you get warnings about undefined structures. */
19 | /* #undef INCOMPLETE_TYPES_BROKEN */
20 |
21 | /* Define "boolean" as unsigned char, not enum, on Windows systems. */
22 | #ifdef _WIN32
23 | #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
24 | typedef unsigned char boolean;
25 | #endif
26 | #ifndef FALSE /* in case these macros already exist */
27 | #define FALSE 0 /* values of boolean */
28 | #endif
29 | #ifndef TRUE
30 | #define TRUE 1
31 | #endif
32 | #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
33 | #endif
34 |
35 | #ifdef JPEG_INTERNALS
36 |
37 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */
38 | #define INLINE __inline__
39 | /* These are for configuring the JPEG memory manager. */
40 | /* #undef DEFAULT_MAX_MEM */
41 | /* #undef NO_MKTEMP */
42 |
43 | #endif /* JPEG_INTERNALS */
44 |
45 | #ifdef JPEG_CJPEG_DJPEG
46 |
47 | #define BMP_SUPPORTED /* BMP image file format */
48 | #define GIF_SUPPORTED /* GIF image file format */
49 | #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
50 | /* #undef RLE_SUPPORTED */
51 | #define TARGA_SUPPORTED /* Targa image file format */
52 |
53 | /* #undef TWO_FILE_COMMANDLINE */
54 | /* #undef NEED_SIGNAL_CATCHER */
55 | /* #undef DONT_USE_B_MODE */
56 |
57 | /* Define this if you want percent-done progress reports from cjpeg/djpeg. */
58 | /* #undef PROGRESS_REPORT */
59 |
60 | #endif /* JPEG_CJPEG_DJPEG */
61 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/alltypes.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_ALLTYPES_H
28 | #define LEPTONICA_ALLTYPES_H
29 |
30 | /* Standard */
31 | #include
32 | #include
33 | #include
34 |
35 | /* General and configuration defs */
36 | #include "environ.h"
37 |
38 | /* Generic and non-image-specific containers */
39 | #include "array.h"
40 | #include "bbuffer.h"
41 | #include "heap.h"
42 | #include "list.h"
43 | #include "ptra.h"
44 | #include "queue.h"
45 | #include "stack.h"
46 |
47 | /* Imaging */
48 | #include "arrayaccess.h"
49 | #include "bmf.h"
50 | #include "ccbord.h"
51 | #include "dewarp.h"
52 | #include "gplot.h"
53 | #include "imageio.h"
54 | #include "jbclass.h"
55 | #include "morph.h"
56 | #include "pix.h"
57 | #include "recog.h"
58 | #include "regutils.h"
59 | #include "stringcode.h"
60 | #include "sudoku.h"
61 | #include "watershed.h"
62 |
63 |
64 | #endif /* LEPTONICA_ALLTYPES_H */
65 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/array.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_ARRAY_H
28 | #define LEPTONICA_ARRAY_H
29 |
30 | /*
31 | * Contains the following structs:
32 | * struct Numa
33 | * struct Numaa
34 | * struct Numa2d
35 | * struct NumaHash
36 | * struct L_Dna
37 | * struct L_Dnaa
38 | * struct Sarray
39 | * struct L_Bytea
40 | *
41 | * Contains definitions for:
42 | * Numa interpolation flags
43 | * Numa and FPix border flags
44 | * Numa data type conversion to string
45 | */
46 |
47 |
48 | /*------------------------------------------------------------------------*
49 | * Array Structs *
50 | *------------------------------------------------------------------------*/
51 |
52 | #define NUMA_VERSION_NUMBER 1
53 |
54 | /* Number array: an array of floats */
55 | struct Numa
56 | {
57 | l_int32 nalloc; /* size of allocated number array */
58 | l_int32 n; /* number of numbers saved */
59 | l_int32 refcount; /* reference count (1 if no clones) */
60 | l_float32 startx; /* x value assigned to array[0] */
61 | l_float32 delx; /* change in x value as i --> i + 1 */
62 | l_float32 *array; /* number array */
63 | };
64 | typedef struct Numa NUMA;
65 |
66 |
67 | /* Array of number arrays */
68 | struct Numaa
69 | {
70 | l_int32 nalloc; /* size of allocated ptr array */
71 | l_int32 n; /* number of Numa saved */
72 | struct Numa **numa; /* array of Numa */
73 | };
74 | typedef struct Numaa NUMAA;
75 |
76 |
77 | /* Sparse 2-dimensional array of number arrays */
78 | struct Numa2d
79 | {
80 | l_int32 nrows; /* number of rows allocated for ptr array */
81 | l_int32 ncols; /* number of cols allocated for ptr array */
82 | l_int32 initsize; /* initial size of each numa that is made */
83 | struct Numa ***numa; /* 2D array of Numa */
84 | };
85 | typedef struct Numa2d NUMA2D;
86 |
87 |
88 | /* A hash table of Numas */
89 | struct NumaHash
90 | {
91 | l_int32 nbuckets;
92 | l_int32 initsize; /* initial size of each numa that is made */
93 | struct Numa **numa;
94 | };
95 | typedef struct NumaHash NUMAHASH;
96 |
97 |
98 | #define DNA_VERSION_NUMBER 1
99 |
100 | /* Double number array: an array of doubles */
101 | struct L_Dna
102 | {
103 | l_int32 nalloc; /* size of allocated number array */
104 | l_int32 n; /* number of numbers saved */
105 | l_int32 refcount; /* reference count (1 if no clones) */
106 | l_float64 startx; /* x value assigned to array[0] */
107 | l_float64 delx; /* change in x value as i --> i + 1 */
108 | l_float64 *array; /* number array */
109 | };
110 | typedef struct L_Dna L_DNA;
111 |
112 |
113 | /* Array of double number arrays */
114 | struct L_Dnaa
115 | {
116 | l_int32 nalloc; /* size of allocated ptr array */
117 | l_int32 n; /* number of L_Dna saved */
118 | struct L_Dna **dna; /* array of L_Dna */
119 | };
120 | typedef struct L_Dnaa L_DNAA;
121 |
122 |
123 | #define SARRAY_VERSION_NUMBER 1
124 |
125 | /* String array: an array of C strings */
126 | struct Sarray
127 | {
128 | l_int32 nalloc; /* size of allocated ptr array */
129 | l_int32 n; /* number of strings allocated */
130 | l_int32 refcount; /* reference count (1 if no clones) */
131 | char **array; /* string array */
132 | };
133 | typedef struct Sarray SARRAY;
134 |
135 |
136 | /* Byte array (analogous to C++ "string") */
137 | struct L_Bytea
138 | {
139 | size_t nalloc; /* number of bytes allocated in data array */
140 | size_t size; /* number of bytes presently used */
141 | l_int32 refcount; /* reference count (1 if no clones) */
142 | l_uint8 *data; /* data array */
143 | };
144 | typedef struct L_Bytea L_BYTEA;
145 |
146 |
147 | /*------------------------------------------------------------------------*
148 | * Array flags *
149 | *------------------------------------------------------------------------*/
150 | /* Flags for interpolation in Numa */
151 | enum {
152 | L_LINEAR_INTERP = 1, /* linear */
153 | L_QUADRATIC_INTERP = 2 /* quadratic */
154 | };
155 |
156 | /* Flags for added borders in Numa and Fpix */
157 | enum {
158 | L_CONTINUED_BORDER = 1, /* extended with same value */
159 | L_SLOPE_BORDER = 2, /* extended with constant normal derivative */
160 | L_MIRRORED_BORDER = 3 /* mirrored */
161 | };
162 |
163 | /* Flags for data type converted from Numa */
164 | enum {
165 | L_INTEGER_VALUE = 1, /* convert to integer */
166 | L_FLOAT_VALUE = 2 /* convert to float */
167 | };
168 |
169 |
170 | #endif /* LEPTONICA_ARRAY_H */
171 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/arrayaccess.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_ARRAY_ACCESS_H
28 | #define LEPTONICA_ARRAY_ACCESS_H
29 |
30 | /*
31 | * arrayaccess.h
32 | *
33 | * 1, 2, 4, 8, 16 and 32 bit data access within an array of 32-bit words
34 | *
35 | * This is used primarily to access 1, 2, 4, 8, 16 and 32 bit pixels
36 | * in a line of image data, represented as an array of 32-bit words.
37 | *
38 | * pdata: pointer to first 32-bit word in the array
39 | * n: index of the pixel in the array
40 | *
41 | * Function calls for these accessors are defined in arrayaccess.c.
42 | *
43 | * However, for efficiency we use the inline macros for all accesses.
44 | * Even though the 2 and 4 bit set* accessors are more complicated,
45 | * they are about 10% faster than the function calls.
46 | *
47 | * The 32 bit access is just a cast and ptr arithmetic. We include
48 | * it so that the input ptr can be void*.
49 | *
50 | * At the end of this file is code for invoking the function calls
51 | * instead of inlining.
52 | *
53 | * The macro SET_DATA_BIT_VAL(pdata, n, val) is a bit slower than
54 | * if (val == 0)
55 | * CLEAR_DATA_BIT(pdata, n);
56 | * else
57 | * SET_DATA_BIT(pdata, n);
58 | */
59 |
60 |
61 | /* Use the inline accessors (except with _MSC_VER), because they
62 | * are faster. */
63 | #define USE_INLINE_ACCESSORS 1
64 |
65 | #if USE_INLINE_ACCESSORS
66 | #ifndef _MSC_VER
67 |
68 | /*--------------------------------------------------*
69 | * 1 bit access *
70 | *--------------------------------------------------*/
71 | #define GET_DATA_BIT(pdata, n) \
72 | ((*((l_uint32 *)(pdata) + ((n) >> 5)) >> (31 - ((n) & 31))) & 1)
73 |
74 | #define SET_DATA_BIT(pdata, n) \
75 | (*((l_uint32 *)(pdata) + ((n) >> 5)) |= (0x80000000 >> ((n) & 31)))
76 |
77 | #define CLEAR_DATA_BIT(pdata, n) \
78 | (*((l_uint32 *)(pdata) + ((n) >> 5)) &= ~(0x80000000 >> ((n) & 31)))
79 |
80 | #define SET_DATA_BIT_VAL(pdata, n, val) \
81 | ({l_uint32 *_TEMP_WORD_PTR_; \
82 | _TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 5); \
83 | *_TEMP_WORD_PTR_ &= ~(0x80000000 >> ((n) & 31)); \
84 | *_TEMP_WORD_PTR_ |= ((val) << (31 - ((n) & 31))); \
85 | })
86 |
87 |
88 | /*--------------------------------------------------*
89 | * 2 bit access *
90 | *--------------------------------------------------*/
91 | #define GET_DATA_DIBIT(pdata, n) \
92 | ((*((l_uint32 *)(pdata) + ((n) >> 4)) >> (2 * (15 - ((n) & 15)))) & 3)
93 |
94 | #define SET_DATA_DIBIT(pdata, n, val) \
95 | ({l_uint32 *_TEMP_WORD_PTR_; \
96 | _TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 4); \
97 | *_TEMP_WORD_PTR_ &= ~(0xc0000000 >> (2 * ((n) & 15))); \
98 | *_TEMP_WORD_PTR_ |= (((val) & 3) << (30 - 2 * ((n) & 15))); \
99 | })
100 |
101 | #define CLEAR_DATA_DIBIT(pdata, n) \
102 | (*((l_uint32 *)(pdata) + ((n) >> 4)) &= ~(0xc0000000 >> (2 * ((n) & 15))))
103 |
104 |
105 | /*--------------------------------------------------*
106 | * 4 bit access *
107 | *--------------------------------------------------*/
108 | #define GET_DATA_QBIT(pdata, n) \
109 | ((*((l_uint32 *)(pdata) + ((n) >> 3)) >> (4 * (7 - ((n) & 7)))) & 0xf)
110 |
111 | #define SET_DATA_QBIT(pdata, n, val) \
112 | ({l_uint32 *_TEMP_WORD_PTR_; \
113 | _TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 3); \
114 | *_TEMP_WORD_PTR_ &= ~(0xf0000000 >> (4 * ((n) & 7))); \
115 | *_TEMP_WORD_PTR_ |= (((val) & 15) << (28 - 4 * ((n) & 7))); \
116 | })
117 |
118 | #define CLEAR_DATA_QBIT(pdata, n) \
119 | (*((l_uint32 *)(pdata) + ((n) >> 3)) &= ~(0xf0000000 >> (4 * ((n) & 7))))
120 |
121 |
122 | /*--------------------------------------------------*
123 | * 8 bit access *
124 | *--------------------------------------------------*/
125 | #ifdef L_BIG_ENDIAN
126 | #define GET_DATA_BYTE(pdata, n) \
127 | (*((l_uint8 *)(pdata) + (n)))
128 | #else /* L_LITTLE_ENDIAN */
129 | #define GET_DATA_BYTE(pdata, n) \
130 | (*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3))
131 | #endif /* L_BIG_ENDIAN */
132 |
133 | #ifdef L_BIG_ENDIAN
134 | #define SET_DATA_BYTE(pdata, n, val) \
135 | (*((l_uint8 *)(pdata) + (n)) = (val))
136 | #else /* L_LITTLE_ENDIAN */
137 | #define SET_DATA_BYTE(pdata, n, val) \
138 | (*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3) = (val))
139 | #endif /* L_BIG_ENDIAN */
140 |
141 |
142 | /*--------------------------------------------------*
143 | * 16 bit access *
144 | *--------------------------------------------------*/
145 | #ifdef L_BIG_ENDIAN
146 | #define GET_DATA_TWO_BYTES(pdata, n) \
147 | (*((l_uint16 *)(pdata) + (n)))
148 | #else /* L_LITTLE_ENDIAN */
149 | #define GET_DATA_TWO_BYTES(pdata, n) \
150 | (*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2))
151 | #endif /* L_BIG_ENDIAN */
152 |
153 | #ifdef L_BIG_ENDIAN
154 | #define SET_DATA_TWO_BYTES(pdata, n, val) \
155 | (*((l_uint16 *)(pdata) + (n)) = (val))
156 | #else /* L_LITTLE_ENDIAN */
157 | #define SET_DATA_TWO_BYTES(pdata, n, val) \
158 | (*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2) = (val))
159 | #endif /* L_BIG_ENDIAN */
160 |
161 |
162 | /*--------------------------------------------------*
163 | * 32 bit access *
164 | *--------------------------------------------------*/
165 | #define GET_DATA_FOUR_BYTES(pdata, n) \
166 | (*((l_uint32 *)(pdata) + (n)))
167 |
168 | #define SET_DATA_FOUR_BYTES(pdata, n, val) \
169 | (*((l_uint32 *)(pdata) + (n)) = (val))
170 |
171 |
172 | #endif /* ! _MSC_VER */
173 | #endif /* USE_INLINE_ACCESSORS */
174 |
175 |
176 |
177 | /*--------------------------------------------------*
178 | * Slower, using function calls for all accessors *
179 | *--------------------------------------------------*/
180 | #if !USE_INLINE_ACCESSORS || defined(_MSC_VER)
181 | #define GET_DATA_BIT(pdata, n) l_getDataBit(pdata, n)
182 | #define SET_DATA_BIT(pdata, n) l_setDataBit(pdata, n)
183 | #define CLEAR_DATA_BIT(pdata, n) l_clearDataBit(pdata, n)
184 | #define SET_DATA_BIT_VAL(pdata, n, val) l_setDataBitVal(pdata, n, val)
185 |
186 | #define GET_DATA_DIBIT(pdata, n) l_getDataDibit(pdata, n)
187 | #define SET_DATA_DIBIT(pdata, n, val) l_setDataDibit(pdata, n, val)
188 | #define CLEAR_DATA_DIBIT(pdata, n) l_clearDataDibit(pdata, n)
189 |
190 | #define GET_DATA_QBIT(pdata, n) l_getDataQbit(pdata, n)
191 | #define SET_DATA_QBIT(pdata, n, val) l_setDataQbit(pdata, n, val)
192 | #define CLEAR_DATA_QBIT(pdata, n) l_clearDataQbit(pdata, n)
193 |
194 | #define GET_DATA_BYTE(pdata, n) l_getDataByte(pdata, n)
195 | #define SET_DATA_BYTE(pdata, n, val) l_setDataByte(pdata, n, val)
196 |
197 | #define GET_DATA_TWO_BYTES(pdata, n) l_getDataTwoBytes(pdata, n)
198 | #define SET_DATA_TWO_BYTES(pdata, n, val) l_setDataTwoBytes(pdata, n, val)
199 |
200 | #define GET_DATA_FOUR_BYTES(pdata, n) l_getDataFourBytes(pdata, n)
201 | #define SET_DATA_FOUR_BYTES(pdata, n, val) l_setDataFourBytes(pdata, n, val)
202 | #endif /* !USE_INLINE_ACCESSORS || _MSC_VER */
203 |
204 |
205 | #endif /* LEPTONICA_ARRAY_ACCESS_H */
206 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/bbuffer.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_BBUFFER_H
28 | #define LEPTONICA_BBUFFER_H
29 |
30 | /*
31 | * bbuffer.h
32 | *
33 | * Expandable byte buffer for reading data in from memory and
34 | * writing data out to other memory.
35 | *
36 | * This implements a queue of bytes, so data read in is put
37 | * on the "back" of the queue (i.e., the end of the byte array)
38 | * and data written out is taken from the "front" of the queue
39 | * (i.e., from an index marker "nwritten" that is initially set at
40 | * the beginning of the array.) As usual with expandable
41 | * arrays, we keep the size of the allocated array and the
42 | * number of bytes that have been read into the array.
43 | *
44 | * For implementation details, see bbuffer.c.
45 | */
46 |
47 | struct ByteBuffer
48 | {
49 | l_int32 nalloc; /* size of allocated byte array */
50 | l_int32 n; /* number of bytes read into to the array */
51 | l_int32 nwritten; /* number of bytes written from the array */
52 | l_uint8 *array; /* byte array */
53 | };
54 | typedef struct ByteBuffer BBUFFER;
55 |
56 |
57 | #endif /* LEPTONICA_BBUFFER_H */
58 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/bilateral.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_BILATERAL_H
28 | #define LEPTONICA_BILATERAL_H
29 |
30 | /*
31 | * Contains the following struct
32 | * struct L_Bilateral
33 | *
34 | *
35 | * For a tutorial introduction to bilateral filters, which apply a
36 | * gaussian blur to smooth parts of the image while preserving edges, see
37 | * http://people.csail.mit.edu/sparis/bf_course/slides/03_definition_bf.pdf
38 | *
39 | * We give an implementation of a bilateral filtering algorithm given in:
40 | * "Real-Time O(1) Bilateral Filtering," by Yang, Tan and Ahuja, CVPR 2009
41 | * which is at:
42 | * http://vision.ai.uiuc.edu/~qyang6/publications/cvpr-09-qingxiong-yang.pdf
43 | * This is based on an earlier algorithm by Sylvain Paris and Frédo Durand:
44 | * http://people.csail.mit.edu/sparis/publi/2006/eccv/
45 | * Paris_06_Fast_Approximation.pdf
46 | *
47 | * The kernel of the filter is a product of a spatial gaussian and a
48 | * monotonically decreasing function of the difference in intensity
49 | * between the source pixel and the neighboring pixel. The intensity
50 | * part of the filter gives higher influence for pixels with intensities
51 | * that are near to the source pixel, and the spatial part of the
52 | * filter gives higher weight to pixels that are near the source pixel.
53 | * This combination smooths in relatively uniform regions, while
54 | * maintaining edges.
55 | *
56 | * The advantage of the appoach of Yang et al is that it is separable,
57 | * so the computation time is linear in the gaussian filter size.
58 | * Furthermore, it is possible to do much of the computation as a reduced
59 | * scale, which gives a good approximation to the full resolution version
60 | * but greatly speeds it up.
61 | *
62 | * The bilateral filtered value at x is:
63 | *
64 | * sum[y in N(x)]: spatial(|y - x|) * range(|I(x) - I(y)|) * I(y)
65 | * I'(x) = --------------------------------------------------------------
66 | * sum[y in N(x)]: spatial(|y - x|) * range(|I(x) - I(y)|)
67 | *
68 | * where I() is the input image, I'() is the filtered image, N(x) is the
69 | * set of pixels around x in the filter support, and spatial() and range()
70 | * are gaussian functions:
71 | * spatial(x) = exp(-x^2 / (2 * s_s^2))
72 | * range(x) = exp(-x^2 / (2 * s_r^2))
73 | * and s_s and s_r and the standard deviations of the two gaussians.
74 | *
75 | * Yang et al use a separable approximation to this, by defining a set
76 | * of related but separable functions J(k,x), that we call Principal
77 | * Bilateral Components (PBC):
78 | *
79 | * sum[y in N(x)]: spatial(|y - x|) * range(|k - I(y)|) * I(y)
80 | * J(k,x) = -----------------------------------------------------------
81 | * sum[y in N(x)]: spatial(|y - x|) * range(|k - I(y)|)
82 | *
83 | * which are computed quickly for a set of n values k[p], p = 0 ... n-1.
84 | * Then each output pixel is found using a linear interpolation:
85 | *
86 | * I'(x) = (1 - q) * J(k[p],x) + q * J(k[p+1],x)
87 | *
88 | * where J(k[p],x) and J(k[p+1],x) are PBC for which
89 | * k[p] <= I(x) and k[p+1] >= I(x), and
90 | * q = (I(x) - k[p]) / (k[p+1] - k[p]).
91 | *
92 | * We can also subsample I(x), create subsampled versions of J(k,x),
93 | * which are then interpolated between for I'(x).
94 | *
95 | * We generate 'pixsc', by optionally downscaling the input image
96 | * (using area mapping by the factor 'reduction'), and then adding
97 | * a mirrored border to avoid boundary cases. This is then used
98 | * to compute 'ncomps' PBCs.
99 | *
100 | * The 'spatial_stdev' is also downscaled by 'reduction'. The size
101 | * of the 'spatial' array is 4 * (reduced 'spatial_stdev') + 1.
102 | * The size of the 'range' array is 256.
103 | */
104 |
105 |
106 | /*------------------------------------------------------------------------*
107 | * Bilateral filter *
108 | *------------------------------------------------------------------------*/
109 | struct L_Bilateral
110 | {
111 | struct Pix *pixs; /* clone of source pix */
112 | struct Pix *pixsc; /* downscaled pix with mirrored border */
113 | l_int32 reduction; /* 1, 2 or 4x for intermediates */
114 | l_float32 spatial_stdev; /* stdev of spatial gaussian */
115 | l_float32 range_stdev; /* stdev of range gaussian */
116 | l_float32 *spatial; /* 1D gaussian spatial kernel */
117 | l_float32 *range; /* one-sided gaussian range kernel */
118 | l_int32 minval; /* min value in 8 bpp pix */
119 | l_int32 maxval; /* max value in 8 bpp pix */
120 | l_int32 ncomps; /* number of intermediate results */
121 | l_int32 *nc; /* set of k values (size ncomps) */
122 | l_int32 *kindex; /* mapping from intensity to lower k */
123 | l_float32 *kfract; /* mapping from intensity to fract k */
124 | struct Pixa *pixac; /* intermediate result images (PBC) */
125 | l_uint32 ***lineset; /* lineptrs for pixac */
126 | };
127 | typedef struct L_Bilateral L_BILATERAL;
128 |
129 |
130 | #endif /* LEPTONICA_BILATERAL_H */
131 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/bmf.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_BMF_H
28 | #define LEPTONICA_BMF_H
29 |
30 | /*
31 | * bmf.h
32 | *
33 | * Simple data structure to hold bitmap fonts and related data
34 | */
35 |
36 | /* Constants for deciding when text block is divided into paragraphs */
37 | enum {
38 | SPLIT_ON_LEADING_WHITE = 1, /* tab or space at beginning of line */
39 | SPLIT_ON_BLANK_LINE = 2, /* newline with optional white space */
40 | SPLIT_ON_BOTH = 3 /* leading white space or newline */
41 | };
42 |
43 |
44 | struct L_Bmf
45 | {
46 | struct Pixa *pixa; /* pixa of bitmaps for 93 characters */
47 | l_int32 size; /* font size (in points at 300 ppi) */
48 | char *directory; /* directory containing font bitmaps */
49 | l_int32 baseline1; /* baseline offset for ascii 33 - 57 */
50 | l_int32 baseline2; /* baseline offset for ascii 58 - 91 */
51 | l_int32 baseline3; /* baseline offset for ascii 93 - 126 */
52 | l_int32 lineheight; /* max height of line of chars */
53 | l_int32 kernwidth; /* pixel dist between char bitmaps */
54 | l_int32 spacewidth; /* pixel dist between word bitmaps */
55 | l_int32 vertlinesep; /* extra vertical space between text lines */
56 | l_int32 *fonttab; /* table mapping ascii --> font index */
57 | l_int32 *baselinetab; /* table mapping ascii --> baseline offset */
58 | l_int32 *widthtab; /* table mapping ascii --> char width */
59 | };
60 | typedef struct L_Bmf L_BMF;
61 |
62 | #endif /* LEPTONICA_BMF_H */
63 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/bmp.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_BMP_H
28 | #define LEPTONICA_BMP_H
29 |
30 | /*
31 | * This file is here to describe the fields in the header of
32 | * the BMP file. These fields are not used directly in Leptonica.
33 | * The only thing we use are the sizes of these two headers.
34 | * Furthermore, because of potential namespace conflicts with
35 | * the typedefs and defined sizes, we have changed the names
36 | * to protect anyone who may also need to use the original definitions.
37 | * Thanks to J. D. Bryan for pointing out the potential problems when
38 | * developing on Win32 compatible systems.
39 | */
40 |
41 | /*-------------------------------------------------------------*
42 | * BMP file header *
43 | *-------------------------------------------------------------*/
44 | struct BMP_FileHeader
45 | {
46 | l_int16 bfType; /* file type; must be "BM" */
47 | l_int16 bfSize; /* length of the file;
48 | sizeof(BMP_FileHeader) +
49 | sizeof(BMP_InfoHeader) +
50 | size of color table +
51 | size of DIB bits */
52 | l_int16 bfFill1; /* remainder of the bfSize field */
53 | l_int16 bfReserved1; /* don't care (set to 0)*/
54 | l_int16 bfReserved2; /* don't care (set to 0)*/
55 | l_int16 bfOffBits; /* offset from beginning of file */
56 | l_int16 bfFill2; /* remainder of the bfOffBits field */
57 | };
58 | typedef struct BMP_FileHeader BMP_FH;
59 |
60 | #define BMP_FHBYTES sizeof(BMP_FH)
61 |
62 |
63 | /*-------------------------------------------------------------*
64 | * BMP info header *
65 | *-------------------------------------------------------------*/
66 | struct BMP_InfoHeader
67 | {
68 | l_int32 biSize; /* size of the BMP_InfoHeader struct */
69 | l_int32 biWidth; /* bitmap width in pixels */
70 | l_int32 biHeight; /* bitmap height in pixels */
71 | l_int16 biPlanes; /* number of bitmap planes */
72 | l_int16 biBitCount; /* number of bits per pixel */
73 | l_int32 biCompression; /* compression format (0 == uncompressed) */
74 | l_int32 biSizeImage; /* size of image in bytes */
75 | l_int32 biXPelsPerMeter; /* pixels per meter in x direction */
76 | l_int32 biYPelsPerMeter; /* pixels per meter in y direction */
77 | l_int32 biClrUsed; /* number of colors used */
78 | l_int32 biClrImportant; /* number of important colors used */
79 | };
80 | typedef struct BMP_InfoHeader BMP_IH;
81 |
82 | #define BMP_IHBYTES sizeof(BMP_IH)
83 |
84 |
85 | #endif /* LEPTONICA_BMP_H */
86 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/ccbord.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_CCBORD_H
28 | #define LEPTONICA_CCBORD_H
29 |
30 | /*
31 | * ccbord.h
32 | *
33 | * CCBord: represents a single connected component
34 | * CCBorda: an array of CCBord
35 | */
36 |
37 | /* Use in ccbaStepChainsToPixCoords() */
38 | enum {
39 | CCB_LOCAL_COORDS = 1,
40 | CCB_GLOBAL_COORDS = 2
41 | };
42 |
43 | /* Use in ccbaGenerateSPGlobalLocs() */
44 | enum {
45 | CCB_SAVE_ALL_PTS = 1,
46 | CCB_SAVE_TURNING_PTS = 2
47 | };
48 |
49 |
50 | /* CCBord contains:
51 | *
52 | * (1) a minimally-clipped bitmap of the component (pix),
53 | * (2) a boxa consisting of:
54 | * for the primary component:
55 | * (xul, yul) pixel location in global coords
56 | * (w, h) of the bitmap
57 | * for the hole components:
58 | * (x, y) in relative coordinates in primary component
59 | * (w, h) of the hole border (which is 2 pixels
60 | * larger in each direction than the hole itself)
61 | * (3) a pta ('start') of the initial border pixel location for each
62 | * closed curve, all in relative coordinates of the primary
63 | * component. This is given for the primary component,
64 | * followed by the hole components, if any.
65 | * (4) a refcount of the ccbord; used internally when a ccbord
66 | * is accessed from a ccborda (array of ccbord)
67 | * (5) a ptaa for the chain code for the border in relative
68 | * coordinates, where the first pta is the exterior border
69 | * and all other pta are for interior borders (holes)
70 | * (6) a ptaa for the global pixel loc rendition of the border,
71 | * where the first pta is the exterior border and all other
72 | * pta are for interior borders (holes).
73 | * This is derived from the local or step chain code.
74 | * (7) a numaa for the chain code for the border as orientation
75 | * directions between successive border pixels, where
76 | * the first numa is the exterior border and all other
77 | * numa are for interior borders (holes). This is derived
78 | * from the local chain code. The 8 directions are 0 - 7.
79 | * (8) a pta for a single chain for each c.c., comprised of outer
80 | * and hole borders, plus cut paths between them, all in
81 | * local coords.
82 | * (9) a pta for a single chain for each c.c., comprised of outer
83 | * and hole borders, plus cut paths between them, all in
84 | * global coords.
85 | */
86 | struct CCBord
87 | {
88 | struct Pix *pix; /* component bitmap (min size) */
89 | struct Boxa *boxa; /* regions of each closed curve */
90 | struct Pta *start; /* initial border pixel locations */
91 | l_int32 refcount; /* number of handles; start at 1 */
92 | struct Ptaa *local; /* ptaa of chain pixels (local) */
93 | struct Ptaa *global; /* ptaa of chain pixels (global) */
94 | struct Numaa *step; /* numaa of chain code (step dir) */
95 | struct Pta *splocal; /* pta of single chain (local) */
96 | struct Pta *spglobal; /* pta of single chain (global) */
97 | };
98 | typedef struct CCBord CCBORD;
99 |
100 |
101 | struct CCBorda
102 | {
103 | struct Pix *pix; /* input pix (may be null) */
104 | l_int32 w; /* width of pix */
105 | l_int32 h; /* height of pix */
106 | l_int32 n; /* number of ccbord in ptr array */
107 | l_int32 nalloc; /* number of ccbord ptrs allocated */
108 | struct CCBord **ccb; /* ccb ptr array */
109 | };
110 | typedef struct CCBorda CCBORDA;
111 |
112 |
113 | #endif /* LEPTONICA_CCBORD_H */
114 |
115 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/endianness.h:
--------------------------------------------------------------------------------
1 | #if !defined (L_BIG_ENDIAN) && !defined (L_LITTLE_ENDIAN)
2 | # if 0
3 | # ifdef __BIG_ENDIAN__
4 | # define L_BIG_ENDIAN
5 | # else
6 | # define L_LITTLE_ENDIAN
7 | # endif
8 | # else
9 | # define L_LITTLE_ENDIAN
10 | # endif
11 | #endif
12 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/gplot.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_GPLOT_H
28 | #define LEPTONICA_GPLOT_H
29 |
30 | /*
31 | * gplot.h
32 | *
33 | * Data structures and parameters for generating gnuplot files
34 | */
35 |
36 | #define GPLOT_VERSION_NUMBER 1
37 |
38 | #define NUM_GPLOT_STYLES 5
39 | enum GPLOT_STYLE {
40 | GPLOT_LINES = 0,
41 | GPLOT_POINTS = 1,
42 | GPLOT_IMPULSES = 2,
43 | GPLOT_LINESPOINTS = 3,
44 | GPLOT_DOTS = 4
45 | };
46 |
47 | #define NUM_GPLOT_OUTPUTS 6
48 | enum GPLOT_OUTPUT {
49 | GPLOT_NONE = 0,
50 | GPLOT_PNG = 1,
51 | GPLOT_PS = 2,
52 | GPLOT_EPS = 3,
53 | GPLOT_X11 = 4,
54 | GPLOT_LATEX = 5
55 | };
56 |
57 | enum GPLOT_SCALING {
58 | GPLOT_LINEAR_SCALE = 0, /* default */
59 | GPLOT_LOG_SCALE_X = 1,
60 | GPLOT_LOG_SCALE_Y = 2,
61 | GPLOT_LOG_SCALE_X_Y = 3
62 | };
63 |
64 | extern const char *gplotstylenames[]; /* used in gnuplot cmd file */
65 | extern const char *gplotfilestyles[]; /* used in simple file input */
66 | extern const char *gplotfileoutputs[]; /* used in simple file input */
67 |
68 | struct GPlot
69 | {
70 | char *rootname; /* for cmd, data, output */
71 | char *cmdname; /* command file name */
72 | struct Sarray *cmddata; /* command file contents */
73 | struct Sarray *datanames; /* data file names */
74 | struct Sarray *plotdata; /* plot data (1 string/file) */
75 | struct Sarray *plottitles; /* title for each individual plot */
76 | struct Numa *plotstyles; /* plot style for individual plots */
77 | l_int32 nplots; /* current number of plots */
78 | char *outname; /* output file name */
79 | l_int32 outformat; /* GPLOT_OUTPUT values */
80 | l_int32 scaling; /* GPLOT_SCALING values */
81 | char *title; /* optional */
82 | char *xlabel; /* optional x axis label */
83 | char *ylabel; /* optional y axis label */
84 | };
85 | typedef struct GPlot GPLOT;
86 |
87 |
88 | #endif /* LEPTONICA_GPLOT_H */
89 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/heap.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_HEAP_H
28 | #define LEPTONICA_HEAP_H
29 |
30 | /*
31 | * heap.h
32 | *
33 | * Expandable priority queue configured as a heap for arbitrary void* data
34 | *
35 | * The L_Heap is used to implement a priority queue. The elements
36 | * in the heap are ordered in either increasing or decreasing key value.
37 | * The key is a float field 'keyval' that is required to be
38 | * contained in the elements of the queue.
39 | *
40 | * The heap is a simple binary tree with the following constraints:
41 | * - the key of each node is >= the keys of the two children
42 | * - the tree is complete, meaning that each level (1, 2, 4, ...)
43 | * is filled and the last level is filled from left to right
44 | *
45 | * The tree structure is implicit in the queue array, with the
46 | * array elements numbered as a breadth-first search of the tree
47 | * from left to right. It is thus guaranteed that the largest
48 | * (or smallest) key belongs to the first element in the array.
49 | *
50 | * Heap sort is used to sort the array. Once an array has been
51 | * sorted as a heap, it is convenient to use it as a priority queue,
52 | * because the min (or max) elements are always at the root of
53 | * the tree (element 0), and once removed, the heap can be
54 | * resorted in not more than log[n] steps, where n is the number
55 | * of elements on the heap. Likewise, if an arbitrary element is
56 | * added to the end of the array A, the sorted heap can be restored
57 | * in not more than log[n] steps.
58 | *
59 | * A L_Heap differs from a L_Queue in that the elements in the former
60 | * are sorted by a key. Internally, the array is maintained
61 | * as a queue, with a pointer to the end of the array. The
62 | * head of the array always remains at array[0]. The array is
63 | * maintained (sorted) as a heap. When an item is removed from
64 | * the head, the last item takes its place (thus reducing the
65 | * array length by 1), and this is followed by array element
66 | * swaps to restore the heap property. When an item is added,
67 | * it goes at the end of the array, and is swapped up to restore
68 | * the heap. If the ptr array is full, adding another item causes
69 | * the ptr array size to double.
70 | *
71 | * For further implementation details, see heap.c.
72 | */
73 |
74 | struct L_Heap
75 | {
76 | l_int32 nalloc; /* size of allocated ptr array */
77 | l_int32 n; /* number of elements stored in the heap */
78 | void **array; /* ptr array */
79 | l_int32 direction; /* L_SORT_INCREASING or L_SORT_DECREASING */
80 | };
81 | typedef struct L_Heap L_HEAP;
82 |
83 |
84 | #endif /* LEPTONICA_HEAP_H */
85 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/jbclass.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_JBCLASS_H
28 | #define LEPTONICA_JBCLASS_H
29 |
30 | /*
31 | * jbclass.h
32 | *
33 | * JbClasser
34 | * JbData
35 | */
36 |
37 |
38 | /* The JbClasser struct holds all the data accumulated during the
39 | * classification process that can be used for a compressed
40 | * jbig2-type representation of a set of images. This is created
41 | * in an initialization process and added to as the selected components
42 | * on each successive page are analyzed. */
43 | struct JbClasser
44 | {
45 | struct Sarray *safiles; /* input page image file names */
46 | l_int32 method; /* JB_RANKHAUS, JB_CORRELATION */
47 | l_int32 components; /* JB_CONN_COMPS, JB_CHARACTERS or */
48 | /* JB_WORDS */
49 | l_int32 maxwidth; /* max component width allowed */
50 | l_int32 maxheight; /* max component height allowed */
51 | l_int32 npages; /* number of pages already processed */
52 | l_int32 baseindex; /* number of components already processed */
53 | /* on fully processed pages */
54 | struct Numa *nacomps; /* number of components on each page */
55 | l_int32 sizehaus; /* size of square struct element for haus */
56 | l_float32 rankhaus; /* rank val of haus match, each way */
57 | l_float32 thresh; /* thresh value for correlation score */
58 | l_float32 weightfactor; /* corrects thresh value for heaver */
59 | /* components; use 0 for no correction */
60 | struct Numa *naarea; /* w * h of each template, without extra */
61 | /* border pixels */
62 | l_int32 w; /* max width of original src images */
63 | l_int32 h; /* max height of original src images */
64 | l_int32 nclass; /* current number of classes */
65 | l_int32 keep_pixaa; /* If zero, pixaa isn't filled */
66 | struct Pixaa *pixaa; /* instances for each class; unbordered */
67 | struct Pixa *pixat; /* templates for each class; bordered */
68 | /* and not dilated */
69 | struct Pixa *pixatd; /* templates for each class; bordered */
70 | /* and dilated */
71 | struct NumaHash *nahash; /* Hash table to find templates by size */
72 | struct Numa *nafgt; /* fg areas of undilated templates; */
73 | /* only used for rank < 1.0 */
74 | struct Pta *ptac; /* centroids of all bordered cc */
75 | struct Pta *ptact; /* centroids of all bordered template cc */
76 | struct Numa *naclass; /* array of class ids for each component */
77 | struct Numa *napage; /* array of page nums for each component */
78 | struct Pta *ptaul; /* array of UL corners at which the */
79 | /* template is to be placed for each */
80 | /* component */
81 | struct Pta *ptall; /* similar to ptaul, but for LL corners */
82 | };
83 | typedef struct JbClasser JBCLASSER;
84 |
85 |
86 | /* The JbData struct holds all the data required for
87 | * the compressed jbig-type representation of a set of images.
88 | * The data can be written to file, read back, and used
89 | * to regenerate an approximate version of the original,
90 | * which differs in two ways from the original:
91 | * (1) It uses a template image for each c.c. instead of the
92 | * original instance, for each occurrence on each page.
93 | * (2) It discards components with either a height or width larger
94 | * than the maximuma, given here by the lattice dimensions
95 | * used for storing the templates. */
96 | struct JbData
97 | {
98 | struct Pix *pix; /* template composite for all classes */
99 | l_int32 npages; /* number of pages */
100 | l_int32 w; /* max width of original page images */
101 | l_int32 h; /* max height of original page images */
102 | l_int32 nclass; /* number of classes */
103 | l_int32 latticew; /* lattice width for template composite */
104 | l_int32 latticeh; /* lattice height for template composite */
105 | struct Numa *naclass; /* array of class ids for each component */
106 | struct Numa *napage; /* array of page nums for each component */
107 | struct Pta *ptaul; /* array of UL corners at which the */
108 | /* template is to be placed for each */
109 | /* component */
110 | };
111 | typedef struct JbData JBDATA;
112 |
113 |
114 | /* Classifier methods */
115 | enum {
116 | JB_RANKHAUS = 0,
117 | JB_CORRELATION = 1
118 | };
119 |
120 | /* For jbGetComponents(): type of component to extract from images */
121 | enum {
122 | JB_CONN_COMPS = 0,
123 | JB_CHARACTERS = 1,
124 | JB_WORDS = 2
125 | };
126 |
127 | /* These parameters are used for naming the two files
128 | * in which the jbig2-like compressed data is stored. */
129 | #define JB_TEMPLATE_EXT ".templates.png"
130 | #define JB_DATA_EXT ".data"
131 |
132 |
133 | #endif /* LEPTONICA_JBCLASS_H */
134 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/leptwin.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifdef _WIN32
28 | #ifndef LEPTONICA_LEPTWIN_H
29 | #define LEPTONICA_LEPTWIN_H
30 |
31 | #include "allheaders.h"
32 | #include
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif /* __cplusplus */
37 |
38 | LEPT_DLL extern HBITMAP pixGetWindowsHBITMAP( PIX *pixs );
39 |
40 | #ifdef __cplusplus
41 | }
42 | #endif /* __cplusplus */
43 |
44 | #endif /* LEPTONICA_LEPTWIN_H */
45 | #endif /* _WIN32 */
46 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/list.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 |
28 | #ifndef LEPTONICA_LIST_H
29 | #define LEPTONICA_LIST_H
30 |
31 | /*
32 | * list.h
33 | *
34 | * Cell for double-linked lists
35 | *
36 | * This allows composition of a list of cells with
37 | * prev, next and data pointers. Generic data
38 | * structures hang on the list cell data pointers.
39 | *
40 | * The list is not circular because that would add much
41 | * complexity in traversing the list under general
42 | * conditions where list cells can be added and removed.
43 | * The only disadvantage of not having the head point to
44 | * the last cell is that the list must be traversed to
45 | * find its tail. However, this traversal is fast, and
46 | * the listRemoveFromTail() function updates the tail
47 | * so there is no searching overhead with repeated use.
48 | *
49 | * The list macros are used to run through a list, and their
50 | * use is encouraged. They are invoked, e.g., as
51 | *
52 | * DLLIST *head, *elem;
53 | * ...
54 | * L_BEGIN_LIST_FORWARD(head, elem)
55 | * data >
56 | * L_END_LIST
57 | *
58 | */
59 |
60 | struct DoubleLinkedList
61 | {
62 | struct DoubleLinkedList *prev;
63 | struct DoubleLinkedList *next;
64 | void *data;
65 | };
66 | typedef struct DoubleLinkedList DLLIST;
67 |
68 |
69 | /* Simple list traverse macros */
70 | #define L_BEGIN_LIST_FORWARD(head, element) \
71 | { \
72 | DLLIST *_leptvar_nextelem_; \
73 | for ((element) = (head); (element); (element) = _leptvar_nextelem_) { \
74 | _leptvar_nextelem_ = (element)->next;
75 |
76 |
77 | #define L_BEGIN_LIST_REVERSE(tail, element) \
78 | { \
79 | DLLIST *_leptvar_prevelem_; \
80 | for ((element) = (tail); (element); (element) = _leptvar_prevelem_) { \
81 | _leptvar_prevelem_ = (element)->prev;
82 |
83 |
84 | #define L_END_LIST }}
85 |
86 |
87 | #endif /* LEPTONICA_LIST_H */
88 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/morph.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_MORPH_H
28 | #define LEPTONICA_MORPH_H
29 |
30 | /*
31 | * morph.h
32 | *
33 | * Contains the following structs:
34 | * struct Sel
35 | * struct Sela
36 | * struct Kernel
37 | *
38 | * Contains definitions for:
39 | * morphological b.c. flags
40 | * structuring element types
41 | * runlength flags for granulometry
42 | * direction flags for grayscale morphology
43 | * morphological operation flags
44 | * standard border size
45 | * grayscale intensity scaling flags
46 | * morphological tophat flags
47 | * arithmetic and logical operator flags
48 | * grayscale morphology selection flags
49 | * distance function b.c. flags
50 | * image comparison flags
51 | * color content flags
52 | */
53 |
54 | /*-------------------------------------------------------------------------*
55 | * Sel and Sel array *
56 | *-------------------------------------------------------------------------*/
57 | #define SEL_VERSION_NUMBER 1
58 |
59 | struct Sel
60 | {
61 | l_int32 sy; /* sel height */
62 | l_int32 sx; /* sel width */
63 | l_int32 cy; /* y location of sel origin */
64 | l_int32 cx; /* x location of sel origin */
65 | l_int32 **data; /* {0,1,2}; data[i][j] in [row][col] order */
66 | char *name; /* used to find sel by name */
67 | };
68 | typedef struct Sel SEL;
69 |
70 | struct Sela
71 | {
72 | l_int32 n; /* number of sel actually stored */
73 | l_int32 nalloc; /* size of allocated ptr array */
74 | struct Sel **sel; /* sel ptr array */
75 | };
76 | typedef struct Sela SELA;
77 |
78 |
79 | /*-------------------------------------------------------------------------*
80 | * Kernel *
81 | *-------------------------------------------------------------------------*/
82 | #define KERNEL_VERSION_NUMBER 2
83 |
84 | struct L_Kernel
85 | {
86 | l_int32 sy; /* kernel height */
87 | l_int32 sx; /* kernel width */
88 | l_int32 cy; /* y location of kernel origin */
89 | l_int32 cx; /* x location of kernel origin */
90 | l_float32 **data; /* data[i][j] in [row][col] order */
91 | };
92 | typedef struct L_Kernel L_KERNEL;
93 |
94 |
95 | /*-------------------------------------------------------------------------*
96 | * Morphological boundary condition flags *
97 | *
98 | * Two types of boundary condition for erosion.
99 | * The global variable MORPH_BC takes on one of these two values.
100 | * See notes in morph.c for usage.
101 | *-------------------------------------------------------------------------*/
102 | enum {
103 | SYMMETRIC_MORPH_BC = 0,
104 | ASYMMETRIC_MORPH_BC = 1
105 | };
106 |
107 |
108 | /*-------------------------------------------------------------------------*
109 | * Structuring element types *
110 | *-------------------------------------------------------------------------*/
111 | enum {
112 | SEL_DONT_CARE = 0,
113 | SEL_HIT = 1,
114 | SEL_MISS = 2
115 | };
116 |
117 |
118 | /*-------------------------------------------------------------------------*
119 | * Runlength flags for granulometry *
120 | *-------------------------------------------------------------------------*/
121 | enum {
122 | L_RUN_OFF = 0,
123 | L_RUN_ON = 1
124 | };
125 |
126 |
127 | /*-------------------------------------------------------------------------*
128 | * Direction flags for grayscale morphology, granulometry, *
129 | * composable Sels, convolution, etc. *
130 | *-------------------------------------------------------------------------*/
131 | enum {
132 | L_HORIZ = 1,
133 | L_VERT = 2,
134 | L_BOTH_DIRECTIONS = 3
135 | };
136 |
137 |
138 | /*-------------------------------------------------------------------------*
139 | * Morphological operation flags *
140 | *-------------------------------------------------------------------------*/
141 | enum {
142 | L_MORPH_DILATE = 1,
143 | L_MORPH_ERODE = 2,
144 | L_MORPH_OPEN = 3,
145 | L_MORPH_CLOSE = 4,
146 | L_MORPH_HMT = 5
147 | };
148 |
149 |
150 | /*-------------------------------------------------------------------------*
151 | * Grayscale intensity scaling flags *
152 | *-------------------------------------------------------------------------*/
153 | enum {
154 | L_LINEAR_SCALE = 1,
155 | L_LOG_SCALE = 2
156 | };
157 |
158 |
159 | /*-------------------------------------------------------------------------*
160 | * Morphological tophat flags *
161 | *-------------------------------------------------------------------------*/
162 | enum {
163 | L_TOPHAT_WHITE = 0,
164 | L_TOPHAT_BLACK = 1
165 | };
166 |
167 |
168 | /*-------------------------------------------------------------------------*
169 | * Arithmetic and logical operator flags *
170 | * (use on grayscale images and Numas) *
171 | *-------------------------------------------------------------------------*/
172 | enum {
173 | L_ARITH_ADD = 1,
174 | L_ARITH_SUBTRACT = 2,
175 | L_ARITH_MULTIPLY = 3, /* on numas only */
176 | L_ARITH_DIVIDE = 4, /* on numas only */
177 | L_UNION = 5, /* on numas only */
178 | L_INTERSECTION = 6, /* on numas only */
179 | L_SUBTRACTION = 7, /* on numas only */
180 | L_EXCLUSIVE_OR = 8 /* on numas only */
181 | };
182 |
183 |
184 | /*-------------------------------------------------------------------------*
185 | * Min/max selection flags *
186 | *-------------------------------------------------------------------------*/
187 | enum {
188 | L_CHOOSE_MIN = 1, /* useful in a downscaling "erosion" */
189 | L_CHOOSE_MAX = 2, /* useful in a downscaling "dilation" */
190 | L_CHOOSE_MAX_MIN_DIFF = 3 /* useful in a downscaling contrast */
191 | };
192 |
193 |
194 | /*-------------------------------------------------------------------------*
195 | * Distance function b.c. flags *
196 | *-------------------------------------------------------------------------*/
197 | enum {
198 | L_BOUNDARY_BG = 1, /* assume bg outside image */
199 | L_BOUNDARY_FG = 2 /* assume fg outside image */
200 | };
201 |
202 |
203 | /*-------------------------------------------------------------------------*
204 | * Image comparison flags *
205 | *-------------------------------------------------------------------------*/
206 | enum {
207 | L_COMPARE_XOR = 1,
208 | L_COMPARE_SUBTRACT = 2,
209 | L_COMPARE_ABS_DIFF = 3
210 | };
211 |
212 |
213 | /*-------------------------------------------------------------------------*
214 | * Color content flags *
215 | *-------------------------------------------------------------------------*/
216 | enum {
217 | L_MAX_DIFF_FROM_AVERAGE_2 = 1,
218 | L_MAX_MIN_DIFF_FROM_2 = 2,
219 | L_MAX_DIFF = 3
220 | };
221 |
222 |
223 | /*-------------------------------------------------------------------------*
224 | * Standard size of border added around images for special processing *
225 | *-------------------------------------------------------------------------*/
226 | static const l_int32 ADDED_BORDER = 32; /* pixels, not bits */
227 |
228 |
229 | #endif /* LEPTONICA_MORPH_H */
230 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/ptra.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_PTRA_H
28 | #define LEPTONICA_PTRA_H
29 |
30 | /*
31 | * Contains the following structs:
32 | * struct L_Ptra
33 | * struct L_Ptraa
34 | *
35 | * Contains definitions for:
36 | * L_Ptra compaction flags for removal
37 | * L_Ptra shifting flags for insert
38 | * L_Ptraa accessor flags
39 | */
40 |
41 |
42 | /*------------------------------------------------------------------------*
43 | * Generic Ptr Array Structs *
44 | *------------------------------------------------------------------------*/
45 |
46 | /* Generic pointer array */
47 | struct L_Ptra
48 | {
49 | l_int32 nalloc; /* size of allocated ptr array */
50 | l_int32 imax; /* greatest valid index */
51 | l_int32 nactual; /* actual number of stored elements */
52 | void **array; /* ptr array */
53 | };
54 | typedef struct L_Ptra L_PTRA;
55 |
56 |
57 | /* Array of generic pointer arrays */
58 | struct L_Ptraa
59 | {
60 | l_int32 nalloc; /* size of allocated ptr array */
61 | struct L_Ptra **ptra; /* array of ptra */
62 | };
63 | typedef struct L_Ptraa L_PTRAA;
64 |
65 |
66 |
67 | /*------------------------------------------------------------------------*
68 | * Array flags *
69 | *------------------------------------------------------------------------*/
70 |
71 | /* Flags for removal from L_Ptra */
72 | enum {
73 | L_NO_COMPACTION = 1, /* null the pointer only */
74 | L_COMPACTION = 2 /* compact the array */
75 | };
76 |
77 | /* Flags for insertion into L_Ptra */
78 | enum {
79 | L_AUTO_DOWNSHIFT = 0, /* choose based on number of holes */
80 | L_MIN_DOWNSHIFT = 1, /* downshifts min # of ptrs below insert */
81 | L_FULL_DOWNSHIFT = 2 /* downshifts all ptrs below insert */
82 | };
83 |
84 | /* Accessor flags for L_Ptraa */
85 | enum {
86 | L_HANDLE_ONLY = 0, /* ptr to L_Ptra; caller can inspect only */
87 | L_REMOVE = 1 /* caller owns; destroy or save in L_Ptraa */
88 | };
89 |
90 |
91 | #endif /* LEPTONICA_PTRA_H */
92 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/queue.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_QUEUE_H
28 | #define LEPTONICA_QUEUE_H
29 |
30 | /*
31 | * queue.h
32 | *
33 | * Expandable pointer queue for arbitrary void* data.
34 | *
35 | * The L_Queue is a fifo that implements a queue of void* pointers.
36 | * It can be used to hold a queue of any type of struct.
37 | *
38 | * Internally, it maintains two counters:
39 | * nhead: location of head (in ptrs) from the beginning
40 | * of the array.
41 | * nelem: number of ptr elements stored in the queue.
42 | *
43 | * The element at the head of the queue, which is the next to
44 | * be removed, is array[nhead]. The location at the tail of the
45 | * queue to which the next element will be added is
46 | * array[nhead + nelem].
47 | *
48 | * As items are added to the queue, nelem increases.
49 | * As items are removed, nhead increases and nelem decreases.
50 | * Any time the tail reaches the end of the allocated array,
51 | * all the pointers are shifted to the left, so that the head
52 | * is at the beginning of the array.
53 | * If the array becomes more than 3/4 full, it doubles in size.
54 | *
55 | * The auxiliary stack can be used in a wrapper for re-using
56 | * items popped from the queue. It is not made by default.
57 | *
58 | * For further implementation details, see queue.c.
59 | */
60 |
61 | struct L_Queue
62 | {
63 | l_int32 nalloc; /* size of allocated ptr array */
64 | l_int32 nhead; /* location of head (in ptrs) from the */
65 | /* beginning of the array */
66 | l_int32 nelem; /* number of elements stored in the queue */
67 | void **array; /* ptr array */
68 | struct L_Stack *stack; /* auxiliary stack */
69 |
70 | };
71 | typedef struct L_Queue L_QUEUE;
72 |
73 |
74 | #endif /* LEPTONICA_QUEUE_H */
75 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/regutils.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_REGUTILS_H
28 | #define LEPTONICA_REGUTILS_H
29 |
30 | /*
31 | * regutils.h
32 | *
33 | * Contains this regression test parameter packaging struct
34 | * struct L_RegParams
35 | *
36 | * The regression test utility allows you to write regression tests
37 | * that compare results with existing "golden files" and with
38 | * compiled in data.
39 | *
40 | * Regression tests can be called in three ways.
41 | * For example, for distance_reg:
42 | *
43 | * Case 1: distance_reg [generate]
44 | * This generates golden files in /tmp for the reg test.
45 | *
46 | * Case 2: distance_reg compare
47 | * This runs the test against the set of golden files. It
48 | * appends to 'outfile.txt' either "SUCCESS" or "FAILURE",
49 | * as well as the details of any parts of the test that failed.
50 | * It writes to a temporary file stream (fp)
51 | *
52 | * Case 3: distance_reg display
53 | * This runs the test but makes no comparison of the output
54 | * against the set of golden files. In addition, this displays
55 | * images and plots that are specified in the test under
56 | * control of the display variable. Display is enabled only
57 | * for this case. Using 'display' on the command line is optional.
58 | *
59 | * Regression tests follow the pattern given below. Tests are
60 | * automatically numbered sequentially, and it is convenient to
61 | * comment each with a number to keep track (for comparison tests
62 | * and for debugging). In an actual case, comparisons of pix and
63 | * of files can occur in any order. We give a specific order here
64 | * for clarity.
65 | *
66 | * L_REGPARAMS *rp; // holds data required by the test functions
67 | *
68 | * // Setup variables; optionally open stream
69 | * if (regTestSetup(argc, argv, &rp))
70 | * return 1;
71 | *
72 | * // Test pairs of generated pix for identity. This compares
73 | * // two pix; no golden file is generated.
74 | * regTestComparePix(rp, pix1, pix2); // 0
75 | *
76 | * // Test pairs of generated pix for similarity. This compares
77 | * // two pix; no golden file is generated. The last arg determines
78 | * // if stats are to be written to stderr.
79 | * regTestCompareSimilarPix(rp, pix1, pix2, 15, 0.001, 0); // 1
80 | *
81 | * // Generation of outputs and testing for identity
82 | * // These files can be anything, of course.
83 | * regTestCheckFile(rp, ); // 2
84 | * regTestCheckFile(rp, ); // 3
85 | *
86 | * // Test pairs of output golden files for identity. Here we
87 | * // are comparing golden files 2 and 3.
88 | * regTestCompareFiles(rp, 2, 3); // 4
89 | *
90 | * // "Write and check". This writes a pix using a canonical
91 | * // formulation for the local filename and either:
92 | * // case 1: generates a golden file
93 | * // case 2: compares the local file with a golden file
94 | * // case 3: generates local files and displays
95 | * // Here we write the pix compressed with png and jpeg, respectively;
96 | * // Then check against the golden file. The internal @index
97 | * // is incremented; it is embedded in the local filename and,
98 | * // if generating, in the golden file as well.
99 | * regTestWritePixAndCheck(rp, pix1, IFF_PNG); // 5
100 | * regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG); // 6
101 | *
102 | * // Display if reg test was called in 'display' mode
103 | * pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display);
104 | *
105 | * // Clean up and output result
106 | * regTestCleanup(rp);
107 | */
108 |
109 | /*-------------------------------------------------------------------------*
110 | * Regression test parameter packer *
111 | *-------------------------------------------------------------------------*/
112 | struct L_RegParams
113 | {
114 | FILE *fp; /* stream to temporary output file for compare mode */
115 | char *testname; /* name of test, without '_reg' */
116 | char *tempfile; /* name of temp file for compare mode output */
117 | l_int32 mode; /* generate, compare or display */
118 | l_int32 index; /* index into saved files for this test; 0-based */
119 | l_int32 success; /* overall result of the test */
120 | l_int32 display; /* 1 if in display mode; 0 otherwise */
121 | L_TIMER tstart; /* marks beginning of the reg test */
122 | };
123 | typedef struct L_RegParams L_REGPARAMS;
124 |
125 |
126 | /* Running modes for the test */
127 | enum {
128 | L_REG_GENERATE = 0,
129 | L_REG_COMPARE = 1,
130 | L_REG_DISPLAY = 2
131 | };
132 |
133 |
134 | #endif /* LEPTONICA_REGUTILS_H */
135 |
136 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/stack.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_STACK_H
28 | #define LEPTONICA_STACK_H
29 |
30 | /*
31 | * stack.h
32 | *
33 | * Expandable pointer stack for arbitrary void* data.
34 | *
35 | * The L_Stack is an array of void * ptrs, onto which arbitrary
36 | * objects can be stored. At any time, the number of
37 | * stored objects is stack->n. The object at the bottom
38 | * of the stack is at array[0]; the object at the top of
39 | * the stack is at array[n-1]. New objects are added
40 | * to the top of the stack, at the first available location,
41 | * which is array[n]. Objects are removed from the top of the
42 | * stack. When an attempt is made to remove an object from an
43 | * empty stack, the result is null. When the stack becomes
44 | * filled, so that n = nalloc, the size is doubled.
45 | *
46 | * The auxiliary stack can be used to store and remove
47 | * objects for re-use. It must be created by a separate
48 | * call to pstackCreate(). [Just imagine the chaos if
49 | * pstackCreate() created the auxiliary stack!]
50 | * pstackDestroy() checks for the auxiliary stack and removes it.
51 | */
52 |
53 |
54 | /* Note that array[n] is the first null ptr in the array */
55 | struct L_Stack
56 | {
57 | l_int32 nalloc; /* size of ptr array */
58 | l_int32 n; /* number of stored elements */
59 | void **array; /* ptr array */
60 | struct L_Stack *auxstack; /* auxiliary stack */
61 | };
62 | typedef struct L_Stack L_STACK;
63 |
64 |
65 | #endif /* LEPTONICA_STACK_H */
66 |
67 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/stringcode.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_STRINGCODE_H
28 | #define LEPTONICA_STRINGCODE_H
29 |
30 | /*
31 | * stringcode.h
32 | *
33 | * Data structure to hold accumulating generated code for storing
34 | * and extracing serializable leptonica objects (e.g., pixa, recog).
35 | */
36 |
37 | struct L_StrCode
38 | {
39 | l_int32 fileno; /* index for function and output file names */
40 | l_int32 ifunc; /* index into struct currently being stored */
41 | SARRAY *function; /* store case code for extraction */
42 | SARRAY *data; /* store base64 encoded data as strings */
43 | SARRAY *descr; /* store line in description table */
44 | l_int32 n; /* number of data strings */
45 | };
46 | typedef struct L_StrCode L_STRCODE;
47 |
48 | #endif /* LEPTONICA_STRINGCODE_H */
49 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/sudoku.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef SUDOKU_H_INCLUDED
28 | #define SUDOKU_H_INCLUDED
29 |
30 | /*
31 | * sudoku.h
32 | *
33 | * The L_Sudoku holds all the information of the current state.
34 | *
35 | * The input to sudokuCreate() is a file with any number of lines
36 | * starting with '#', followed by 9 lines consisting of 9 numbers
37 | * in each line. These have the known values and use 0 for the unknowns.
38 | * Blank lines are ignored.
39 | *
40 | * The @locs array holds the indices of the unknowns, numbered
41 | * left-to-right and top-to-bottom from 0 to 80. The array size
42 | * is initialized to @num. @current is the index into the @locs
43 | * array of the current guess: locs[current].
44 | *
45 | * The @state array is used to determine the validity of each guess.
46 | * It is of size 81, and is initialized by setting the unknowns to 0
47 | * and the knowns to their input values.
48 | */
49 | struct L_Sudoku
50 | {
51 | l_int32 num; /* number of unknowns */
52 | l_int32 *locs; /* location of unknowns */
53 | l_int32 current; /* index into @locs of current location */
54 | l_int32 *init; /* initial state, with 0 representing */
55 | /* the unknowns */
56 | l_int32 *state; /* present state, including inits and */
57 | /* guesses of unknowns up to @current */
58 | l_int32 nguess; /* shows current number of guesses */
59 | l_int32 finished; /* set to 1 when solved */
60 | l_int32 failure; /* set to 1 if no solution is possible */
61 | };
62 | typedef struct L_Sudoku L_SUDOKU;
63 |
64 |
65 | /* For printing out array data */
66 | enum {
67 | L_SUDOKU_INIT = 0,
68 | L_SUDOKU_STATE = 1
69 | };
70 |
71 | #endif /* SUDOKU_H_INCLUDED */
72 |
73 |
74 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/leptonica/watershed.h:
--------------------------------------------------------------------------------
1 | /*====================================================================*
2 | - Copyright (C) 2001 Leptonica. All rights reserved.
3 | -
4 | - Redistribution and use in source and binary forms, with or without
5 | - modification, are permitted provided that the following conditions
6 | - are met:
7 | - 1. Redistributions of source code must retain the above copyright
8 | - notice, this list of conditions and the following disclaimer.
9 | - 2. Redistributions in binary form must reproduce the above
10 | - copyright notice, this list of conditions and the following
11 | - disclaimer in the documentation and/or other materials
12 | - provided with the distribution.
13 | -
14 | - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 | - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 | - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 | - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 | - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 | - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *====================================================================*/
26 |
27 | #ifndef LEPTONICA_WATERSHED_H
28 | #define LEPTONICA_WATERSHED_H
29 |
30 | /*
31 | * watershed.h
32 | *
33 | * Simple data structure to hold watershed data.
34 | * All data here is owned by the L_WShed and must be freed.
35 | */
36 |
37 | struct L_WShed
38 | {
39 | struct Pix *pixs; /* clone of input 8 bpp pixs */
40 | struct Pix *pixm; /* clone of input 1 bpp seed (marker) pixm */
41 | l_int32 mindepth; /* minimum depth allowed for a watershed */
42 | struct Pix *pixlab; /* 16 bpp label pix */
43 | struct Pix *pixt; /* scratch pix for computing wshed regions */
44 | void **lines8; /* line ptrs for pixs */
45 | void **linem1; /* line ptrs for pixm */
46 | void **linelab32; /* line ptrs for pixlab */
47 | void **linet1; /* line ptrs for pixt */
48 | struct Pixa *pixad; /* result: 1 bpp pixa of watersheds */
49 | struct Pta *ptas; /* pta of initial seed pixels */
50 | struct Numa *nasi; /* numa of seed indicators; 0 if completed */
51 | struct Numa *nash; /* numa of initial seed heights */
52 | struct Numa *namh; /* numa of initial minima heights */
53 | struct Numa *nalevels; /* result: numa of watershed levels */
54 | l_int32 nseeds; /* number of seeds (markers) */
55 | l_int32 nother; /* number of minima different from seeds */
56 | l_int32 *lut; /* lut for pixel indices */
57 | struct Numa **links; /* back-links into lut, for updates */
58 | l_int32 arraysize; /* size of links array */
59 | l_int32 debug; /* set to 1 for debug output */
60 | };
61 | typedef struct L_WShed L_WSHED;
62 |
63 | #endif /* LEPTONICA_WATERSHED_H */
64 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/pnglibconf.h:
--------------------------------------------------------------------------------
1 | /* pnglibconf.h - library build configuration */
2 |
3 | /* libpng version 1.6.20, December 3, 2015 */
4 |
5 | /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */
6 |
7 | /* This code is released under the libpng license. */
8 | /* For conditions of distribution and use, see the disclaimer */
9 | /* and license in png.h */
10 |
11 | /* pnglibconf.h */
12 | /* Machine generated file: DO NOT EDIT */
13 | /* Derived from: scripts/pnglibconf.dfa */
14 | #ifndef PNGLCONF_H
15 | #define PNGLCONF_H
16 | /* options */
17 | #define PNG_16BIT_SUPPORTED
18 | #define PNG_ALIGNED_MEMORY_SUPPORTED
19 | /*#undef PNG_ARM_NEON_API_SUPPORTED*/
20 | /*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/
21 | #define PNG_BENIGN_ERRORS_SUPPORTED
22 | #define PNG_BENIGN_READ_ERRORS_SUPPORTED
23 | /*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/
24 | #define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
25 | #define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
26 | #define PNG_COLORSPACE_SUPPORTED
27 | #define PNG_CONSOLE_IO_SUPPORTED
28 | #define PNG_CONVERT_tIME_SUPPORTED
29 | #define PNG_EASY_ACCESS_SUPPORTED
30 | /*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
31 | #define PNG_ERROR_TEXT_SUPPORTED
32 | #define PNG_FIXED_POINT_SUPPORTED
33 | #define PNG_FLOATING_ARITHMETIC_SUPPORTED
34 | #define PNG_FLOATING_POINT_SUPPORTED
35 | #define PNG_FORMAT_AFIRST_SUPPORTED
36 | #define PNG_FORMAT_BGR_SUPPORTED
37 | #define PNG_GAMMA_SUPPORTED
38 | #define PNG_GET_PALETTE_MAX_SUPPORTED
39 | #define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
40 | #define PNG_INCH_CONVERSIONS_SUPPORTED
41 | #define PNG_INFO_IMAGE_SUPPORTED
42 | #define PNG_IO_STATE_SUPPORTED
43 | #define PNG_MNG_FEATURES_SUPPORTED
44 | #define PNG_POINTER_INDEXING_SUPPORTED
45 | #define PNG_PROGRESSIVE_READ_SUPPORTED
46 | #define PNG_READ_16BIT_SUPPORTED
47 | #define PNG_READ_ALPHA_MODE_SUPPORTED
48 | #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
49 | #define PNG_READ_BACKGROUND_SUPPORTED
50 | #define PNG_READ_BGR_SUPPORTED
51 | #define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
52 | #define PNG_READ_COMPOSITE_NODIV_SUPPORTED
53 | #define PNG_READ_COMPRESSED_TEXT_SUPPORTED
54 | #define PNG_READ_EXPAND_16_SUPPORTED
55 | #define PNG_READ_EXPAND_SUPPORTED
56 | #define PNG_READ_FILLER_SUPPORTED
57 | #define PNG_READ_GAMMA_SUPPORTED
58 | #define PNG_READ_GET_PALETTE_MAX_SUPPORTED
59 | #define PNG_READ_GRAY_TO_RGB_SUPPORTED
60 | #define PNG_READ_INTERLACING_SUPPORTED
61 | #define PNG_READ_INT_FUNCTIONS_SUPPORTED
62 | #define PNG_READ_INVERT_ALPHA_SUPPORTED
63 | #define PNG_READ_INVERT_SUPPORTED
64 | #define PNG_READ_OPT_PLTE_SUPPORTED
65 | #define PNG_READ_PACKSWAP_SUPPORTED
66 | #define PNG_READ_PACK_SUPPORTED
67 | #define PNG_READ_QUANTIZE_SUPPORTED
68 | #define PNG_READ_RGB_TO_GRAY_SUPPORTED
69 | #define PNG_READ_SCALE_16_TO_8_SUPPORTED
70 | #define PNG_READ_SHIFT_SUPPORTED
71 | #define PNG_READ_STRIP_16_TO_8_SUPPORTED
72 | #define PNG_READ_STRIP_ALPHA_SUPPORTED
73 | #define PNG_READ_SUPPORTED
74 | #define PNG_READ_SWAP_ALPHA_SUPPORTED
75 | #define PNG_READ_SWAP_SUPPORTED
76 | #define PNG_READ_TEXT_SUPPORTED
77 | #define PNG_READ_TRANSFORMS_SUPPORTED
78 | #define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
79 | #define PNG_READ_USER_CHUNKS_SUPPORTED
80 | #define PNG_READ_USER_TRANSFORM_SUPPORTED
81 | #define PNG_READ_bKGD_SUPPORTED
82 | #define PNG_READ_cHRM_SUPPORTED
83 | #define PNG_READ_gAMA_SUPPORTED
84 | #define PNG_READ_hIST_SUPPORTED
85 | #define PNG_READ_iCCP_SUPPORTED
86 | #define PNG_READ_iTXt_SUPPORTED
87 | #define PNG_READ_oFFs_SUPPORTED
88 | #define PNG_READ_pCAL_SUPPORTED
89 | #define PNG_READ_pHYs_SUPPORTED
90 | #define PNG_READ_sBIT_SUPPORTED
91 | #define PNG_READ_sCAL_SUPPORTED
92 | #define PNG_READ_sPLT_SUPPORTED
93 | #define PNG_READ_sRGB_SUPPORTED
94 | #define PNG_READ_tEXt_SUPPORTED
95 | #define PNG_READ_tIME_SUPPORTED
96 | #define PNG_READ_tRNS_SUPPORTED
97 | #define PNG_READ_zTXt_SUPPORTED
98 | #define PNG_SAVE_INT_32_SUPPORTED
99 | #define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
100 | #define PNG_SEQUENTIAL_READ_SUPPORTED
101 | #define PNG_SETJMP_SUPPORTED
102 | #define PNG_SET_OPTION_SUPPORTED
103 | #define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
104 | #define PNG_SET_USER_LIMITS_SUPPORTED
105 | #define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
106 | #define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
107 | #define PNG_SIMPLIFIED_READ_SUPPORTED
108 | #define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
109 | #define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
110 | #define PNG_SIMPLIFIED_WRITE_SUPPORTED
111 | #define PNG_STDIO_SUPPORTED
112 | #define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
113 | #define PNG_TEXT_SUPPORTED
114 | #define PNG_TIME_RFC1123_SUPPORTED
115 | #define PNG_UNKNOWN_CHUNKS_SUPPORTED
116 | #define PNG_USER_CHUNKS_SUPPORTED
117 | #define PNG_USER_LIMITS_SUPPORTED
118 | #define PNG_USER_MEM_SUPPORTED
119 | #define PNG_USER_TRANSFORM_INFO_SUPPORTED
120 | #define PNG_USER_TRANSFORM_PTR_SUPPORTED
121 | #define PNG_WARNINGS_SUPPORTED
122 | #define PNG_WRITE_16BIT_SUPPORTED
123 | #define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
124 | #define PNG_WRITE_BGR_SUPPORTED
125 | #define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
126 | #define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
127 | #define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
128 | #define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
129 | #define PNG_WRITE_FILLER_SUPPORTED
130 | #define PNG_WRITE_FILTER_SUPPORTED
131 | #define PNG_WRITE_FLUSH_SUPPORTED
132 | #define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED
133 | #define PNG_WRITE_INTERLACING_SUPPORTED
134 | #define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
135 | #define PNG_WRITE_INVERT_ALPHA_SUPPORTED
136 | #define PNG_WRITE_INVERT_SUPPORTED
137 | #define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
138 | #define PNG_WRITE_PACKSWAP_SUPPORTED
139 | #define PNG_WRITE_PACK_SUPPORTED
140 | #define PNG_WRITE_SHIFT_SUPPORTED
141 | #define PNG_WRITE_SUPPORTED
142 | #define PNG_WRITE_SWAP_ALPHA_SUPPORTED
143 | #define PNG_WRITE_SWAP_SUPPORTED
144 | #define PNG_WRITE_TEXT_SUPPORTED
145 | #define PNG_WRITE_TRANSFORMS_SUPPORTED
146 | #define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
147 | #define PNG_WRITE_USER_TRANSFORM_SUPPORTED
148 | #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
149 | #define PNG_WRITE_bKGD_SUPPORTED
150 | #define PNG_WRITE_cHRM_SUPPORTED
151 | #define PNG_WRITE_gAMA_SUPPORTED
152 | #define PNG_WRITE_hIST_SUPPORTED
153 | #define PNG_WRITE_iCCP_SUPPORTED
154 | #define PNG_WRITE_iTXt_SUPPORTED
155 | #define PNG_WRITE_oFFs_SUPPORTED
156 | #define PNG_WRITE_pCAL_SUPPORTED
157 | #define PNG_WRITE_pHYs_SUPPORTED
158 | #define PNG_WRITE_sBIT_SUPPORTED
159 | #define PNG_WRITE_sCAL_SUPPORTED
160 | #define PNG_WRITE_sPLT_SUPPORTED
161 | #define PNG_WRITE_sRGB_SUPPORTED
162 | #define PNG_WRITE_tEXt_SUPPORTED
163 | #define PNG_WRITE_tIME_SUPPORTED
164 | #define PNG_WRITE_tRNS_SUPPORTED
165 | #define PNG_WRITE_zTXt_SUPPORTED
166 | #define PNG_bKGD_SUPPORTED
167 | #define PNG_cHRM_SUPPORTED
168 | #define PNG_gAMA_SUPPORTED
169 | #define PNG_hIST_SUPPORTED
170 | #define PNG_iCCP_SUPPORTED
171 | #define PNG_iTXt_SUPPORTED
172 | #define PNG_oFFs_SUPPORTED
173 | #define PNG_pCAL_SUPPORTED
174 | #define PNG_pHYs_SUPPORTED
175 | #define PNG_sBIT_SUPPORTED
176 | #define PNG_sCAL_SUPPORTED
177 | #define PNG_sPLT_SUPPORTED
178 | #define PNG_sRGB_SUPPORTED
179 | #define PNG_tEXt_SUPPORTED
180 | #define PNG_tIME_SUPPORTED
181 | #define PNG_tRNS_SUPPORTED
182 | #define PNG_zTXt_SUPPORTED
183 | /* end of options */
184 | /* settings */
185 | #define PNG_API_RULE 0
186 | #define PNG_DEFAULT_READ_MACROS 1
187 | #define PNG_GAMMA_THRESHOLD_FIXED 5000
188 | #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
189 | #define PNG_INFLATE_BUF_SIZE 1024
190 | #define PNG_LINKAGE_API extern
191 | #define PNG_LINKAGE_CALLBACK extern
192 | #define PNG_LINKAGE_DATA extern
193 | #define PNG_LINKAGE_FUNCTION extern
194 | #define PNG_MAX_GAMMA_8 11
195 | #define PNG_QUANTIZE_BLUE_BITS 5
196 | #define PNG_QUANTIZE_GREEN_BITS 5
197 | #define PNG_QUANTIZE_RED_BITS 5
198 | #define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
199 | #define PNG_TEXT_Z_DEFAULT_STRATEGY 0
200 | #define PNG_USER_CHUNK_CACHE_MAX 1000
201 | #define PNG_USER_CHUNK_MALLOC_MAX 8000000
202 | #define PNG_USER_HEIGHT_MAX 1000000
203 | #define PNG_USER_WIDTH_MAX 1000000
204 | #define PNG_ZBUF_SIZE 8192
205 | #define PNG_ZLIB_VERNUM 0x1250
206 | #define PNG_Z_DEFAULT_COMPRESSION (-1)
207 | #define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0
208 | #define PNG_Z_DEFAULT_STRATEGY 1
209 | #define PNG_sCAL_PRECISION 5
210 | #define PNG_sRGB_PROFILE_CHECKS 2
211 | /* end of settings */
212 | #endif /* PNGLCONF_H */
213 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/apitypes.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: apitypes.h
3 | // Description: Types used in both the API and internally
4 | // Author: Ray Smith
5 | // Created: Wed Mar 03 09:22:53 PST 2010
6 | //
7 | // (C) Copyright 2010, Google Inc.
8 | // Licensed under the Apache License, Version 2.0 (the "License");
9 | // you may not use this file except in compliance with the License.
10 | // You may obtain a copy of the License at
11 | // http://www.apache.org/licenses/LICENSE-2.0
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 | //
18 | ///////////////////////////////////////////////////////////////////////
19 |
20 | #ifndef TESSERACT_API_APITYPES_H_
21 | #define TESSERACT_API_APITYPES_H_
22 |
23 | #include "publictypes.h"
24 |
25 | // The types used by the API and Page/ResultIterator can be found in:
26 | // ccstruct/publictypes.h
27 | // ccmain/resultiterator.h
28 | // ccmain/pageiterator.h
29 | // API interfaces and API users should be sure to include this file, rather
30 | // than the lower-level one, and lower-level code should be sure to include
31 | // only the lower-level file.
32 |
33 | #endif // TESSERACT_API_APITYPES_H_
34 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/helpers.h:
--------------------------------------------------------------------------------
1 | /* -*-C-*-
2 | ********************************************************************************
3 | *
4 | * File: helpers.h
5 | * Description: General utility functions
6 | * Author: Daria Antonova
7 | * Created: Wed Apr 8 14:37:00 2009
8 | * Language: C++
9 | * Package: N/A
10 | * Status: Reusable Software Component
11 | *
12 | * (c) Copyright 2009, Google Inc.
13 | ** Licensed under the Apache License, Version 2.0 (the "License");
14 | ** you may not use this file except in compliance with the License.
15 | ** You may obtain a copy of the License at
16 | ** http://www.apache.org/licenses/LICENSE-2.0
17 | ** Unless required by applicable law or agreed to in writing, software
18 | ** distributed under the License is distributed on an "AS IS" BASIS,
19 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 | ** See the License for the specific language governing permissions and
21 | ** limitations under the License.
22 | *
23 | ********************************************************************************/
24 |
25 | #ifndef TESSERACT_CCUTIL_HELPERS_H_
26 | #define TESSERACT_CCUTIL_HELPERS_H_
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #include "host.h"
35 |
36 | // TODO(rays) Put the rest of the helpers in the namespace.
37 | namespace tesseract {
38 |
39 | // A simple linear congruential random number generator, using Knuth's
40 | // constants from:
41 | // http://en.wikipedia.org/wiki/Linear_congruential_generator.
42 | class TRand {
43 | public:
44 | TRand() : seed_(1) {}
45 | // Sets the seed to the given value.
46 | void set_seed(uint64_t seed) {
47 | seed_ = seed;
48 | }
49 | // Sets the seed using a hash of a string.
50 | void set_seed(const std::string& str) {
51 | std::hash hasher;
52 | set_seed(static_cast(hasher(str)));
53 | }
54 |
55 | // Returns an integer in the range 0 to INT32_MAX.
56 | int32_t IntRand() {
57 | Iterate();
58 | return seed_ >> 33;
59 | }
60 | // Returns a floating point value in the range [-range, range].
61 | double SignedRand(double range) {
62 | return range * 2.0 * IntRand() / INT32_MAX - range;
63 | }
64 | // Returns a floating point value in the range [0, range].
65 | double UnsignedRand(double range) {
66 | return range * IntRand() / INT32_MAX;
67 | }
68 |
69 | private:
70 | // Steps the generator to the next value.
71 | void Iterate() {
72 | seed_ *= 6364136223846793005ULL;
73 | seed_ += 1442695040888963407ULL;
74 | }
75 |
76 | // The current value of the seed.
77 | uint64_t seed_;
78 | };
79 |
80 | } // namespace tesseract
81 |
82 | // Remove newline (if any) at the end of the string.
83 | inline void chomp_string(char *str) {
84 | int last_index = static_cast(strlen(str)) - 1;
85 | while (last_index >= 0 &&
86 | (str[last_index] == '\n' || str[last_index] == '\r')) {
87 | str[last_index--] = '\0';
88 | }
89 | }
90 |
91 | // Advance the current pointer of the file if it points to a newline character.
92 | inline void SkipNewline(FILE *file) {
93 | if (fgetc(file) != '\n') fseek(file, -1, SEEK_CUR);
94 | }
95 |
96 | // Swaps the two args pointed to by the pointers.
97 | // Operator= and copy constructor must work on T.
98 | template inline void Swap(T* p1, T* p2) {
99 | T tmp(*p2);
100 | *p2 = *p1;
101 | *p1 = tmp;
102 | }
103 |
104 | // qsort function to sort 2 floats.
105 | inline int sort_floats(const void *arg1, const void *arg2) {
106 | float diff = *((float *) arg1) - *((float *) arg2);
107 | if (diff > 0) {
108 | return 1;
109 | } else if (diff < 0) {
110 | return -1;
111 | } else {
112 | return 0;
113 | }
114 | }
115 |
116 | // return the smallest multiple of block_size greater than or equal to n.
117 | inline int RoundUp(int n, int block_size) {
118 | return block_size * ((n + block_size - 1) / block_size);
119 | }
120 |
121 | // Clip a numeric value to the interval [lower_bound, upper_bound].
122 | template
123 | inline T ClipToRange(const T& x, const T& lower_bound, const T& upper_bound) {
124 | if (x < lower_bound)
125 | return lower_bound;
126 | if (x > upper_bound)
127 | return upper_bound;
128 | return x;
129 | }
130 |
131 | // Extend the range [lower_bound, upper_bound] to include x.
132 | template
133 | inline void UpdateRange(const T1& x, T2* lower_bound, T2* upper_bound) {
134 | if (x < *lower_bound)
135 | *lower_bound = x;
136 | if (x > *upper_bound)
137 | *upper_bound = x;
138 | }
139 |
140 | // Decrease lower_bound to be <= x_lo AND increase upper_bound to be >= x_hi.
141 | template
142 | inline void UpdateRange(const T1& x_lo, const T1& x_hi,
143 | T2* lower_bound, T2* upper_bound) {
144 | if (x_lo < *lower_bound)
145 | *lower_bound = x_lo;
146 | if (x_hi > *upper_bound)
147 | *upper_bound = x_hi;
148 | }
149 |
150 | // Intersect the range [*lower2, *upper2] with the range [lower1, upper1],
151 | // putting the result back in [*lower2, *upper2].
152 | // If non-intersecting ranges are given, we end up with *lower2 > *upper2.
153 | template
154 | inline void IntersectRange(const T& lower1, const T& upper1,
155 | T* lower2, T* upper2) {
156 | if (lower1 > *lower2)
157 | *lower2 = lower1;
158 | if (upper1 < *upper2)
159 | *upper2 = upper1;
160 | }
161 |
162 | // Proper modulo arithmetic operator. Returns a mod b that works for -ve a.
163 | // For any integer a and positive b, returns r : 0<=r= 0 ? (a + b / 2) / b : (a - b / 2) / b;
177 | }
178 |
179 | // Return a double cast to int with rounding.
180 | inline int IntCastRounded(double x) {
181 | return x >= 0.0 ? static_cast(x + 0.5) : -static_cast(-x + 0.5);
182 | }
183 |
184 | // Return a float cast to int with rounding.
185 | inline int IntCastRounded(float x) {
186 | return x >= 0.0f ? static_cast(x + 0.5f) : -static_cast(-x + 0.5f);
187 | }
188 |
189 | // Reverse the order of bytes in a n byte quantity for big/little-endian switch.
190 | inline void ReverseN(void* ptr, int num_bytes) {
191 | assert(num_bytes == 1 || num_bytes == 2 || num_bytes == 4 || num_bytes == 8);
192 | char* cptr = static_cast(ptr);
193 | int halfsize = num_bytes / 2;
194 | for (int i = 0; i < halfsize; ++i) {
195 | char tmp = cptr[i];
196 | cptr[i] = cptr[num_bytes - 1 - i];
197 | cptr[num_bytes - 1 - i] = tmp;
198 | }
199 | }
200 |
201 | // Reverse the order of bytes in a 16 bit quantity for big/little-endian switch.
202 | inline void Reverse16(void *ptr) {
203 | ReverseN(ptr, 2);
204 | }
205 |
206 | // Reverse the order of bytes in a 32 bit quantity for big/little-endian switch.
207 | inline void Reverse32(void *ptr) {
208 | ReverseN(ptr, 4);
209 | }
210 |
211 | // Reverse the order of bytes in a 64 bit quantity for big/little-endian switch.
212 | inline void Reverse64(void* ptr) {
213 | ReverseN(ptr, 8);
214 | }
215 |
216 |
217 | #endif // TESSERACT_CCUTIL_HELPERS_H_
218 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/host.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | ** Filename: host.h
3 | ** Purpose: This is the system independent typedefs and defines
4 | ** Author: MN, JG, MD
5 | **
6 | ** (c) Copyright Hewlett-Packard Company, 1988-1996.
7 | ** Licensed under the Apache License, Version 2.0 (the "License");
8 | ** you may not use this file except in compliance with the License.
9 | ** You may obtain a copy of the License at
10 | ** http://www.apache.org/licenses/LICENSE-2.0
11 | ** Unless required by applicable law or agreed to in writing, software
12 | ** distributed under the License is distributed on an "AS IS" BASIS,
13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | ** See the License for the specific language governing permissions and
15 | ** limitations under the License.
16 | */
17 |
18 | #ifndef TESSERACT_CCUTIL_HOST_H_
19 | #define TESSERACT_CCUTIL_HOST_H_
20 |
21 | #include
22 | #include "platform.h"
23 | /* _WIN32 */
24 | #ifdef _WIN32
25 | #include
26 | #undef min
27 | #undef max
28 | #endif
29 |
30 | #include // PRId32, ...
31 | #include // int32_t, ...
32 |
33 | // definitions of portable data types (numbers and characters)
34 | using FLOAT32 = float;
35 | using FLOAT64 = double;
36 | using BOOL8 = unsigned char;
37 |
38 | #if defined(_WIN32)
39 |
40 | /* MinGW defines the standard PRI... macros, but MSVS doesn't. */
41 |
42 | #if !defined(PRId32)
43 | #define PRId32 "d"
44 | #endif
45 |
46 | #if !defined(PRId64)
47 | #define PRId64 "I64d"
48 | #endif
49 |
50 | #endif /* _WIN32 */
51 |
52 | #define MAX_FLOAT32 std::numeric_limits::max()
53 |
54 | // Minimum positive value ie 1e-37ish.
55 | #define MIN_FLOAT32 std::numeric_limits::min()
56 |
57 | // Defines
58 | #ifndef TRUE
59 | #define TRUE 1
60 | #endif
61 |
62 | #ifndef FALSE
63 | #define FALSE 0
64 | #endif
65 |
66 | // Return true if x is within tolerance of y
67 | template bool NearlyEqual(T x, T y, T tolerance) {
68 | T diff = x - y;
69 | return diff <= tolerance && -diff <= tolerance;
70 | }
71 |
72 | #endif // TESSERACT_CCUTIL_HOST_H_
73 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/ocrclass.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | * File: ocrclass.h
3 | * Description: Class definitions and constants for the OCR API.
4 | * Author: Hewlett-Packard Co
5 | *
6 | * (C) Copyright 1996, Hewlett-Packard Co.
7 | ** Licensed under the Apache License, Version 2.0 (the "License");
8 | ** you may not use this file except in compliance with the License.
9 | ** You may obtain a copy of the License at
10 | ** http://www.apache.org/licenses/LICENSE-2.0
11 | ** Unless required by applicable law or agreed to in writing, software
12 | ** distributed under the License is distributed on an "AS IS" BASIS,
13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | ** See the License for the specific language governing permissions and
15 | ** limitations under the License.
16 | *
17 | **********************************************************************/
18 |
19 | /**********************************************************************
20 | * This file contains typedefs for all the structures used by
21 | * the HP OCR interface.
22 | * The code is designed to be used with either a C or C++ compiler.
23 | * The structures are designed to allow them to be used with any
24 | * structure alignment up to 8.
25 | **********************************************************************/
26 |
27 | #ifndef CCUTIL_OCRCLASS_H_
28 | #define CCUTIL_OCRCLASS_H_
29 |
30 | #ifndef __GNUC__
31 | #ifdef _WIN32
32 | #include "gettimeofday.h"
33 | #endif
34 | #else
35 | #include
36 | #endif
37 | #include
38 | #include "host.h"
39 |
40 | /*Maximum lengths of various strings*/
41 | #define MAX_FONT_NAME 34 /*name of font */
42 | #define MAX_OCR_NAME 32 /*name of engine */
43 | #define MAX_OCR_VERSION 17 /*version code of engine */
44 |
45 | /*pitch set definitions are identical to RTF*/
46 | #define PITCH_DEF 0 /*default */
47 | #define PITCH_FIXED 1 /*fixed pitch */
48 | #define PITCH_VAR 2 /*variable pitch */
49 |
50 | /**********************************************************************
51 | * EANYCODE_CHAR
52 | * Description of a single character. The character code is defined by
53 | * the character set of the current font.
54 | * Output text is sent as an array of these structures.
55 | * Spaces and line endings in the output are represented in the
56 | * structures of the surrounding characters. They are not directly
57 | * represented as characters.
58 | * The first character in a word has a positive value of blanks.
59 | * Missing information should be set to the defaults in the comments.
60 | * If word bounds are known, but not character bounds, then the top and
61 | * bottom of each character should be those of the word. The left of the
62 | * first and right of the last char in each word should be set. All other
63 | * lefts and rights should be set to -1.
64 | * If set, the values of right and bottom are left+width and top+height.
65 | * Most of the members come directly from the parameters to ocr_append_char.
66 | * The formatting member uses the enhancement parameter and combines the
67 | * line direction stuff into the top 3 bits.
68 | * The coding is 0=RL char, 1=LR char, 2=DR NL, 3=UL NL, 4=DR Para,
69 | * 5=UL Para, 6=TB char, 7=BT char. API users do not need to know what
70 | * the coding is, only that it is backwards compatible with the previous
71 | * version.
72 | **********************************************************************/
73 |
74 | typedef struct { /*single character */
75 | // It should be noted that the format for char_code for version 2.0 and beyond
76 | // is UTF8 which means that ASCII characters will come out as one structure but
77 | // other characters will be returned in two or more instances of this structure
78 | // with a single byte of the UTF8 code in each, but each will have the same
79 | // bounding box. Programs which want to handle languagues with different
80 | // characters sets will need to handle extended characters appropriately, but
81 | // *all* code needs to be prepared to receive UTF8 coded characters for
82 | // characters such as bullet and fancy quotes.
83 | uint16_t char_code; /*character itself */
84 | int16_t left; /*of char (-1) */
85 | int16_t right; /*of char (-1) */
86 | int16_t top; /*of char (-1) */
87 | int16_t bottom; /*of char (-1) */
88 | int16_t font_index; /*what font (0) */
89 | uint8_t confidence; /*0=perfect, 100=reject (0/100) */
90 | uint8_t point_size; /*of char, 72=i inch, (10) */
91 | int8_t blanks; /*no of spaces before this char (1) */
92 | uint8_t formatting; /*char formatting (0) */
93 | } EANYCODE_CHAR; /*single character */
94 |
95 | /**********************************************************************
96 | * ETEXT_DESC
97 | * Description of the output of the OCR engine.
98 | * This structure is used as both a progress monitor and the final
99 | * output header, since it needs to be a valid progress monitor while
100 | * the OCR engine is storing its output to shared memory.
101 | * During progress, all the buffer info is -1.
102 | * Progress starts at 0 and increases to 100 during OCR. No other constraint.
103 | * Additionally the progress callback contains the bounding box of the word that
104 | * is currently being processed.
105 | * Every progress callback, the OCR engine must set ocr_alive to 1.
106 | * The HP side will set ocr_alive to 0. Repeated failure to reset
107 | * to 1 indicates that the OCR engine is dead.
108 | * If the cancel function is not null then it is called with the number of
109 | * user words found. If it returns true then operation is cancelled.
110 | **********************************************************************/
111 | class ETEXT_DESC;
112 |
113 | typedef bool (*CANCEL_FUNC)(void* cancel_this, int words);
114 | typedef bool (*PROGRESS_FUNC)(int progress, int left, int right, int top,
115 | int bottom);
116 | typedef bool (*PROGRESS_FUNC2)(ETEXT_DESC* ths, int left, int right, int top,
117 | int bottom);
118 |
119 | class ETEXT_DESC { // output header
120 | public:
121 | int16_t count; /// chars in this buffer(0)
122 | int16_t progress; /// percent complete increasing (0-100)
123 | /** Progress monitor covers word recognition and it does not cover layout
124 | * analysis.
125 | * See Ray comment in https://github.com/tesseract-ocr/tesseract/pull/27 */
126 | int8_t more_to_come; /// true if not last
127 | volatile int8_t ocr_alive; /// ocr sets to 1, HP 0
128 | int8_t err_code; /// for errcode use
129 | CANCEL_FUNC cancel; /// returns true to cancel
130 | PROGRESS_FUNC progress_callback; /// called whenever progress increases
131 | PROGRESS_FUNC2 progress_callback2;/// monitor-aware progress callback
132 | void* cancel_this; /// this or other data for cancel
133 | struct timeval end_time; /// Time to stop. Expected to be set only
134 | /// by call to set_deadline_msecs().
135 | EANYCODE_CHAR text[1]; /// character data
136 |
137 | ETEXT_DESC()
138 | : count(0),
139 | progress(0),
140 | more_to_come(0),
141 | ocr_alive(0),
142 | err_code(0),
143 | cancel(nullptr),
144 | progress_callback(nullptr),
145 | progress_callback2( &default_progress_func ),
146 | cancel_this(nullptr) {
147 | end_time.tv_sec = 0;
148 | end_time.tv_usec = 0;
149 | }
150 |
151 | // Sets the end time to be deadline_msecs milliseconds from now.
152 | void set_deadline_msecs(int32_t deadline_msecs) {
153 | gettimeofday(&end_time, nullptr);
154 | int32_t deadline_secs = deadline_msecs / 1000;
155 | end_time.tv_sec += deadline_secs;
156 | end_time.tv_usec += (deadline_msecs - deadline_secs * 1000) * 1000;
157 | if (end_time.tv_usec > 1000000) {
158 | end_time.tv_usec -= 1000000;
159 | ++end_time.tv_sec;
160 | }
161 | }
162 |
163 | // Returns false if we've not passed the end_time, or have not set a deadline.
164 | bool deadline_exceeded() const {
165 | if (end_time.tv_sec == 0 && end_time.tv_usec == 0) return false;
166 | struct timeval now;
167 | gettimeofday(&now, nullptr);
168 | return (now.tv_sec > end_time.tv_sec || (now.tv_sec == end_time.tv_sec &&
169 | now.tv_usec > end_time.tv_usec));
170 | }
171 |
172 | private:
173 | static bool default_progress_func(ETEXT_DESC* ths, int left, int right, int top,
174 | int bottom)
175 | {
176 | if ( ths->progress_callback ) {
177 | return (*(ths->progress_callback))(ths->progress, left, right, top, bottom);
178 | }
179 | return true;
180 | }
181 |
182 | };
183 |
184 | #endif // CCUTIL_OCRCLASS_H_
185 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/platform.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: platform.h
3 | // Description: Place holder
4 | // Author:
5 | // Created:
6 | //
7 | // (C) Copyright 2006, Google Inc.
8 | // Licensed under the Apache License, Version 2.0 (the "License");
9 | // you may not use this file except in compliance with the License.
10 | // You may obtain a copy of the License at
11 | // http://www.apache.org/licenses/LICENSE-2.0
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 | //
18 | ///////////////////////////////////////////////////////////////////////
19 |
20 | #ifndef TESSERACT_CCUTIL_PLATFORM_H_
21 | #define TESSERACT_CCUTIL_PLATFORM_H_
22 |
23 | #define DLLSYM
24 | #ifdef _WIN32
25 | #ifndef NOMINMAX
26 | #define NOMINMAX
27 | #endif /* NOMINMAX */
28 | #ifndef WIN32_LEAN_AND_MEAN
29 | #define WIN32_LEAN_AND_MEAN
30 | #endif
31 | #ifdef __GNUC__
32 | #define ultoa _ultoa
33 | #endif /* __GNUC__ */
34 | #define SIGNED
35 | #if defined(_MSC_VER)
36 | #if (_MSC_VER < 1900)
37 | #define snprintf _snprintf
38 | #endif
39 | #endif /* defined(_MSC_VER) */
40 | #else
41 | #define __UNIX__
42 | #include
43 | #ifndef PATH_MAX
44 | #define MAX_PATH 4096
45 | #else
46 | #define MAX_PATH PATH_MAX
47 | #endif
48 | #define SIGNED signed
49 | #endif
50 |
51 | #if defined(_WIN32) || defined(__CYGWIN__)
52 | #ifndef M_PI
53 | #define M_PI 3.14159265358979323846
54 | #endif
55 | #endif
56 |
57 | #if defined(_WIN32) || defined(__CYGWIN__)
58 | #if defined(TESS_EXPORTS)
59 | #define TESS_API __declspec(dllexport)
60 | #elif defined(TESS_IMPORTS)
61 | #define TESS_API __declspec(dllimport)
62 | #else
63 | #define TESS_API
64 | #endif
65 | #define TESS_LOCAL
66 | #else
67 | #if __GNUC__ >= 4
68 | #if defined(TESS_EXPORTS) || defined(TESS_IMPORTS)
69 | #define TESS_API __attribute__ ((visibility ("default")))
70 | #define TESS_LOCAL __attribute__ ((visibility ("hidden")))
71 | #else
72 | #define TESS_API
73 | #define TESS_LOCAL
74 | #endif
75 | #else
76 | #define TESS_API
77 | #define TESS_LOCAL
78 | #endif
79 | #endif
80 |
81 | #endif // TESSERACT_CCUTIL_PLATFORM_H_
82 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/renderer.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: renderer.h
3 | // Description: Rendering interface to inject into TessBaseAPI
4 | //
5 | // (C) Copyright 2011, Google Inc.
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | ///////////////////////////////////////////////////////////////////////
17 |
18 | #ifndef TESSERACT_API_RENDERER_H_
19 | #define TESSERACT_API_RENDERER_H_
20 |
21 | // To avoid collision with other typenames include the ABSOLUTE MINIMUM
22 | // complexity of includes here. Use forward declarations wherever possible
23 | // and hide includes of complex types in baseapi.cpp.
24 | #include "genericvector.h"
25 | #include "platform.h"
26 | #include "publictypes.h"
27 |
28 | namespace tesseract {
29 |
30 | class TessBaseAPI;
31 |
32 | /**
33 | * Interface for rendering tesseract results into a document, such as text,
34 | * HOCR or pdf. This class is abstract. Specific classes handle individual
35 | * formats. This interface is then used to inject the renderer class into
36 | * tesseract when processing images.
37 | *
38 | * For simplicity implementing this with tesesract version 3.01,
39 | * the renderer contains document state that is cleared from document
40 | * to document just as the TessBaseAPI is. This way the base API can just
41 | * delegate its rendering functionality to injected renderers, and the
42 | * renderers can manage the associated state needed for the specific formats
43 | * in addition to the heuristics for producing it.
44 | */
45 | class TESS_API TessResultRenderer {
46 | public:
47 | virtual ~TessResultRenderer();
48 |
49 | // Takes ownership of pointer so must be new'd instance.
50 | // Renderers aren't ordered, but appends the sequences of next parameter
51 | // and existing next(). The renderers should be unique across both lists.
52 | void insert(TessResultRenderer* next);
53 |
54 | // Returns the next renderer or nullptr.
55 | TessResultRenderer* next() { return next_; }
56 |
57 | /**
58 | * Starts a new document with the given title.
59 | * This clears the contents of the output data.
60 | * Title should use UTF-8 encoding.
61 | */
62 | bool BeginDocument(const char* title);
63 |
64 | /**
65 | * Adds the recognized text from the source image to the current document.
66 | * Invalid if BeginDocument not yet called.
67 | *
68 | * Note that this API is a bit weird but is designed to fit into the
69 | * current TessBaseAPI implementation where the api has lots of state
70 | * information that we might want to add in.
71 | */
72 | bool AddImage(TessBaseAPI* api);
73 |
74 | /**
75 | * Finishes the document and finalizes the output data
76 | * Invalid if BeginDocument not yet called.
77 | */
78 | bool EndDocument();
79 |
80 | const char* file_extension() const { return file_extension_; }
81 | const char* title() const { return title_.c_str(); }
82 |
83 | /**
84 | * Returns the index of the last image given to AddImage
85 | * (i.e. images are incremented whether the image succeeded or not)
86 | *
87 | * This is always defined. It means either the number of the
88 | * current image, the last image ended, or in the completed document
89 | * depending on when in the document lifecycle you are looking at it.
90 | * Will return -1 if a document was never started.
91 | */
92 | int imagenum() const { return imagenum_; }
93 |
94 | protected:
95 | /**
96 | * Called by concrete classes.
97 | *
98 | * outputbase is the name of the output file excluding
99 | * extension. For example, "/path/to/chocolate-chip-cookie-recipe"
100 | *
101 | * extension indicates the file extension to be used for output
102 | * files. For example "pdf" will produce a .pdf file, and "hocr"
103 | * will produce .hocr files.
104 | */
105 | TessResultRenderer(const char *outputbase,
106 | const char* extension);
107 |
108 | // Hook for specialized handling in BeginDocument()
109 | virtual bool BeginDocumentHandler();
110 |
111 | // This must be overridden to render the OCR'd results
112 | virtual bool AddImageHandler(TessBaseAPI* api) = 0;
113 |
114 | // Hook for specialized handling in EndDocument()
115 | virtual bool EndDocumentHandler();
116 |
117 | // Renderers can call this to append '\0' terminated strings into
118 | // the output string returned by GetOutput.
119 | // This method will grow the output buffer if needed.
120 | void AppendString(const char* s);
121 |
122 | // Renderers can call this to append binary byte sequences into
123 | // the output string returned by GetOutput. Note that s is not necessarily
124 | // '\0' terminated (and can contain '\0' within it).
125 | // This method will grow the output buffer if needed.
126 | void AppendData(const char* s, int len);
127 |
128 | private:
129 | const char* file_extension_; // standard extension for generated output
130 | STRING title_; // title of document being renderered
131 | int imagenum_; // index of last image added
132 |
133 | FILE* fout_; // output file pointer
134 | TessResultRenderer* next_; // Can link multiple renderers together
135 | bool happy_; // I get grumpy when the disk fills up, etc.
136 | };
137 |
138 | /**
139 | * Renders tesseract output into a plain UTF-8 text string
140 | */
141 | class TESS_API TessTextRenderer : public TessResultRenderer {
142 | public:
143 | explicit TessTextRenderer(const char *outputbase);
144 |
145 | protected:
146 | virtual bool AddImageHandler(TessBaseAPI* api);
147 | };
148 |
149 | /**
150 | * Renders tesseract output into an hocr text string
151 | */
152 | class TESS_API TessHOcrRenderer : public TessResultRenderer {
153 | public:
154 | explicit TessHOcrRenderer(const char *outputbase, bool font_info);
155 | explicit TessHOcrRenderer(const char *outputbase);
156 |
157 | protected:
158 | virtual bool BeginDocumentHandler();
159 | virtual bool AddImageHandler(TessBaseAPI* api);
160 | virtual bool EndDocumentHandler();
161 |
162 | private:
163 | bool font_info_; // whether to print font information
164 | };
165 |
166 | /**
167 | * Renders Tesseract output into a TSV string
168 | */
169 | class TESS_API TessTsvRenderer : public TessResultRenderer {
170 | public:
171 | explicit TessTsvRenderer(const char* outputbase, bool font_info);
172 | explicit TessTsvRenderer(const char* outputbase);
173 |
174 | protected:
175 | virtual bool BeginDocumentHandler();
176 | virtual bool AddImageHandler(TessBaseAPI* api);
177 | virtual bool EndDocumentHandler();
178 |
179 | private:
180 | bool font_info_; // whether to print font information
181 | };
182 |
183 | /**
184 | * Renders tesseract output into searchable PDF
185 | */
186 | class TESS_API TessPDFRenderer : public TessResultRenderer {
187 | public:
188 | // datadir is the location of the TESSDATA. We need it because
189 | // we load a custom PDF font from this location.
190 | TessPDFRenderer(const char* outputbase, const char* datadir, bool textonly = false);
191 |
192 | protected:
193 | virtual bool BeginDocumentHandler();
194 | virtual bool AddImageHandler(TessBaseAPI* api);
195 | virtual bool EndDocumentHandler();
196 |
197 | private:
198 | // We don't want to have every image in memory at once,
199 | // so we store some metadata as we go along producing
200 | // PDFs one page at a time. At the end, that metadata is
201 | // used to make everything that isn't easily handled in a
202 | // streaming fashion.
203 | long int obj_; // counter for PDF objects
204 | GenericVector offsets_; // offset of every PDF object in bytes
205 | GenericVector pages_; // object number for every /Page object
206 | const char *datadir_; // where to find the custom font
207 | bool textonly_; // skip images if set
208 | // Bookkeeping only. DIY = Do It Yourself.
209 | void AppendPDFObjectDIY(size_t objectsize);
210 | // Bookkeeping + emit data.
211 | void AppendPDFObject(const char *data);
212 | // Create the /Contents object for an entire page.
213 | char* GetPDFTextObjects(TessBaseAPI* api, double width, double height);
214 | // Turn an image into a PDF object. Only transcode if we have to.
215 | static bool imageToPDFObj(Pix *pix, char *filename, long int objnum,
216 | char **pdf_object, long int *pdf_object_size);
217 | };
218 |
219 |
220 | /**
221 | * Renders tesseract output into a plain UTF-8 text string
222 | */
223 | class TESS_API TessUnlvRenderer : public TessResultRenderer {
224 | public:
225 | explicit TessUnlvRenderer(const char *outputbase);
226 |
227 | protected:
228 | virtual bool AddImageHandler(TessBaseAPI* api);
229 | };
230 |
231 | /**
232 | * Renders tesseract output into a plain UTF-8 text string
233 | */
234 | class TESS_API TessBoxTextRenderer : public TessResultRenderer {
235 | public:
236 | explicit TessBoxTextRenderer(const char *outputbase);
237 |
238 | protected:
239 | virtual bool AddImageHandler(TessBaseAPI* api);
240 | };
241 |
242 | /**
243 | * Renders tesseract output into an osd text string
244 | */
245 | class TESS_API TessOsdRenderer : public TessResultRenderer {
246 | public:
247 | explicit TessOsdRenderer(const char* outputbase);
248 |
249 | protected:
250 | virtual bool AddImageHandler(TessBaseAPI* api);
251 | };
252 |
253 | } // namespace tesseract.
254 |
255 | #endif // TESSERACT_API_RENDERER_H_
256 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/serialis.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | * File: serialis.h (Formerly serialmac.h)
3 | * Description: Inline routines and macros for serialisation functions
4 | * Author: Phil Cheatle
5 | * Created: Tue Oct 08 08:33:12 BST 1991
6 | *
7 | * (C) Copyright 1990, Hewlett-Packard Ltd.
8 | ** Licensed under the Apache License, Version 2.0 (the "License");
9 | ** you may not use this file except in compliance with the License.
10 | ** You may obtain a copy of the License at
11 | ** http://www.apache.org/licenses/LICENSE-2.0
12 | ** Unless required by applicable law or agreed to in writing, software
13 | ** distributed under the License is distributed on an "AS IS" BASIS,
14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | ** See the License for the specific language governing permissions and
16 | ** limitations under the License.
17 | *
18 | **********************************************************************/
19 |
20 | #ifndef SERIALIS_H
21 | #define SERIALIS_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include "host.h"
27 |
28 | template class GenericVector;
29 | class STRING;
30 |
31 | /***********************************************************************
32 | QUOTE_IT MACRO DEFINITION
33 | ===========================
34 | Replace with "". may be an arbitrary number of tokens
35 | ***********************************************************************/
36 |
37 | #define QUOTE_IT( parm ) #parm
38 |
39 | namespace tesseract {
40 |
41 | // Function to read a GenericVector from a whole file.
42 | // Returns false on failure.
43 | typedef bool (*FileReader)(const STRING& filename, GenericVector* data);
44 | // Function to write a GenericVector to a whole file.
45 | // Returns false on failure.
46 | typedef bool (*FileWriter)(const GenericVector& data,
47 | const STRING& filename);
48 |
49 | // Simple file class.
50 | // Allows for portable file input from memory and from foreign file systems.
51 | class TFile {
52 | public:
53 | TFile();
54 | ~TFile();
55 |
56 | // All the Open methods load the whole file into memory for reading.
57 | // Opens a file with a supplied reader, or nullptr to use the default.
58 | // Note that mixed read/write is not supported.
59 | bool Open(const STRING& filename, FileReader reader);
60 | // From an existing memory buffer.
61 | bool Open(const char* data, int size);
62 | // From an open file and an end offset.
63 | bool Open(FILE* fp, int64_t end_offset);
64 | // Sets the value of the swap flag, so that FReadEndian does the right thing.
65 | void set_swap(bool value) { swap_ = value; }
66 |
67 | // Reads a line like fgets. Returns nullptr on EOF, otherwise buffer.
68 | // Reads at most buffer_size bytes, including '\0' terminator, even if
69 | // the line is longer. Does nothing if buffer_size <= 0.
70 | // To use fscanf use FGets and sscanf.
71 | char* FGets(char* buffer, int buffer_size);
72 | // Replicates fread, followed by a swap of the bytes if needed, returning the
73 | // number of items read. If swap_ is true then the count items will each have
74 | // size bytes reversed.
75 | int FReadEndian(void* buffer, size_t size, int count);
76 | // Replicates fread, returning the number of items read.
77 | int FRead(void* buffer, size_t size, int count);
78 | // Resets the TFile as if it has been Opened, but nothing read.
79 | // Only allowed while reading!
80 | void Rewind();
81 |
82 | // Open for writing. Either supply a non-nullptr data with OpenWrite before
83 | // calling FWrite, (no close required), or supply a nullptr data to OpenWrite
84 | // and call CloseWrite to write to a file after the FWrites.
85 | void OpenWrite(GenericVector* data);
86 | bool CloseWrite(const STRING& filename, FileWriter writer);
87 |
88 | // Replicates fwrite, returning the number of items written.
89 | // To use fprintf, use snprintf and FWrite.
90 | int FWrite(const void* buffer, size_t size, int count);
91 |
92 | private:
93 | // The number of bytes used so far.
94 | int offset_;
95 | // The buffered data from the file.
96 | GenericVector* data_;
97 | // True if the data_ pointer is owned by *this.
98 | bool data_is_owned_;
99 | // True if the TFile is open for writing.
100 | bool is_writing_;
101 | // True if bytes need to be swapped in FReadEndian.
102 | bool swap_;
103 | };
104 |
105 | } // namespace tesseract.
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/strngs.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | * File: strngs.h (Formerly strings.h)
3 | * Description: STRING class definition.
4 | * Author: Ray Smith
5 | * Created: Fri Feb 15 09:15:01 GMT 1991
6 | *
7 | * (C) Copyright 1991, Hewlett-Packard Ltd.
8 | ** Licensed under the Apache License, Version 2.0 (the "License");
9 | ** you may not use this file except in compliance with the License.
10 | ** You may obtain a copy of the License at
11 | ** http://www.apache.org/licenses/LICENSE-2.0
12 | ** Unless required by applicable law or agreed to in writing, software
13 | ** distributed under the License is distributed on an "AS IS" BASIS,
14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | ** See the License for the specific language governing permissions and
16 | ** limitations under the License.
17 | *
18 | **********************************************************************/
19 |
20 | #ifndef STRNGS_H
21 | #define STRNGS_H
22 |
23 | #include // for assert
24 | #include // for uint32_t
25 | #include // for FILE
26 | #include // for strncpy
27 | #include "platform.h" // for TESS_API
28 |
29 | namespace tesseract {
30 | class TFile;
31 | } // namespace tesseract.
32 |
33 | // STRING_IS_PROTECTED means that string[index] = X is invalid
34 | // because you have to go through strings interface to modify it.
35 | // This allows the string to ensure internal integrity and maintain
36 | // its own string length. Unfortunately this is not possible because
37 | // STRINGS are used as direct-manipulation data buffers for things
38 | // like length arrays and many places cast away the const on string()
39 | // to mutate the string. Turning this off means that internally we
40 | // cannot assume we know the strlen.
41 | #define STRING_IS_PROTECTED 0
42 |
43 | template class GenericVector;
44 |
45 | class TESS_API STRING
46 | {
47 | public:
48 | STRING();
49 | STRING(const STRING &string);
50 | STRING(const char *string);
51 | STRING(const char *data, int length);
52 | ~STRING();
53 |
54 | // Writes to the given file. Returns false in case of error.
55 | bool Serialize(FILE* fp) const;
56 | // Reads from the given file. Returns false in case of error.
57 | // If swap is true, assumes a big/little-endian swap is needed.
58 | bool DeSerialize(bool swap, FILE* fp);
59 | // Writes to the given file. Returns false in case of error.
60 | bool Serialize(tesseract::TFile* fp) const;
61 | // Reads from the given file. Returns false in case of error.
62 | // If swap is true, assumes a big/little-endian swap is needed.
63 | bool DeSerialize(tesseract::TFile* fp);
64 | // As DeSerialize, but only seeks past the data - hence a static method.
65 | static bool SkipDeSerialize(tesseract::TFile* fp);
66 |
67 | bool contains(const char c) const;
68 | int32_t length() const;
69 | int32_t size() const { return length(); }
70 | // Workaround to avoid g++ -Wsign-compare warnings.
71 | uint32_t unsigned_size() const {
72 | const int32_t len = length();
73 | assert(0 <= len);
74 | return static_cast(len);
75 | }
76 | const char *string() const;
77 | const char *c_str() const;
78 |
79 | inline char* strdup() const {
80 | int32_t len = length() + 1;
81 | return strncpy(new char[len], GetCStr(), len);
82 | }
83 |
84 | #if STRING_IS_PROTECTED
85 | const char &operator[] (int32_t index) const;
86 | // len is number of chars in s to insert starting at index in this string
87 | void insert_range(int32_t index, const char*s, int len);
88 | void erase_range(int32_t index, int len);
89 | #else
90 | char &operator[] (int32_t index) const;
91 | #endif
92 | void split(const char c, GenericVector *splited);
93 | void truncate_at(int32_t index);
94 |
95 | bool operator== (const STRING & string) const;
96 | bool operator!= (const STRING & string) const;
97 | bool operator!= (const char *string) const;
98 |
99 | STRING & operator= (const char *string);
100 | STRING & operator= (const STRING & string);
101 |
102 | STRING operator+ (const STRING & string) const;
103 | STRING operator+ (const char ch) const;
104 |
105 | STRING & operator+= (const char *string);
106 | STRING & operator+= (const STRING & string);
107 | STRING & operator+= (const char ch);
108 |
109 | // Assignment for strings which are not null-terminated.
110 | void assign(const char *cstr, int len);
111 |
112 | // Appends the given string and int (as a %d) to this.
113 | // += cannot be used for ints as there as a char += operator that would
114 | // be ambiguous, and ints usually need a string before or between them
115 | // anyway.
116 | void add_str_int(const char* str, int number);
117 | // Appends the given string and double (as a %.8g) to this.
118 | void add_str_double(const char* str, double number);
119 |
120 | // ensure capacity but keep pointer encapsulated
121 | inline void ensure(int32_t min_capacity) { ensure_cstr(min_capacity); }
122 |
123 | private:
124 | typedef struct STRING_HEADER {
125 | // How much space was allocated in the string buffer for char data.
126 | int capacity_;
127 |
128 | // used_ is how much of the capacity is currently being used,
129 | // including a '\0' terminator.
130 | //
131 | // If used_ is 0 then string is nullptr (not even the '\0')
132 | // else if used_ > 0 then it is strlen() + 1 (because it includes '\0')
133 | // else strlen is >= 0 (not nullptr) but needs to be computed.
134 | // this condition is set when encapsulation is violated because
135 | // an API returned a mutable string.
136 | //
137 | // capacity_ - used_ = excess capacity that the string can grow
138 | // without reallocating
139 | mutable int used_;
140 | } STRING_HEADER;
141 |
142 | // To preserve the behavior of the old serialization, we only have space
143 | // for one pointer in this structure. So we are embedding a data structure
144 | // at the start of the storage that will hold additional state variables,
145 | // then storing the actual string contents immediately after.
146 | STRING_HEADER* data_;
147 |
148 | // returns the header part of the storage
149 | inline STRING_HEADER* GetHeader() {
150 | return data_;
151 | }
152 | inline const STRING_HEADER* GetHeader() const {
153 | return data_;
154 | }
155 |
156 | // returns the string data part of storage
157 | inline char* GetCStr() { return ((char*)data_) + sizeof(STRING_HEADER); }
158 |
159 | inline const char* GetCStr() const {
160 | return ((const char *)data_) + sizeof(STRING_HEADER);
161 | }
162 | inline bool InvariantOk() const {
163 | #if STRING_IS_PROTECTED
164 | return (GetHeader()->used_ == 0) ?
165 | (string() == nullptr) : (GetHeader()->used_ == (strlen(string()) + 1));
166 | #else
167 | return true;
168 | #endif
169 | }
170 |
171 | // Ensure string has requested capacity as optimization
172 | // to avoid unnecessary reallocations.
173 | // The return value is a cstr buffer with at least requested capacity
174 | char* ensure_cstr(int32_t min_capacity);
175 |
176 | void FixHeader() const; // make used_ non-negative, even if const
177 |
178 | char* AllocData(int used, int capacity);
179 | void DiscardData();
180 | };
181 | #endif
182 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/tess_version.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: version.h
3 | // Description: Version information
4 | //
5 | // (C) Copyright 2018, Google Inc.
6 | // Licensed under the Apache License, Version 2.0 (the "License");
7 | // you may not use this file except in compliance with the License.
8 | // You may obtain a copy of the License at
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | ///////////////////////////////////////////////////////////////////////
17 |
18 | #ifndef TESSERACT_API_VERSION_H_
19 | #define TESSERACT_API_VERSION_H_
20 |
21 | #define TESSERACT_MAJOR_VERSION 4
22 | #define TESSERACT_MINOR_VERSION 0
23 | #define TESSERACT_MICRO_VERSION 0
24 | #define TESSERACT_VERSION \
25 | (TESSERACT_MAJOR_VERSION << 16 | \
26 | TESSERACT_MINOR_VERSION << 8 | \
27 | TESSERACT_MICRO_VERSION)
28 | #define TESSERACT_VERSION_STR "4.0.0-beta.1"
29 |
30 | #endif // TESSERACT_API_VERSION_H_
31 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/thresholder.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: thresholder.h
3 | // Description: Base API for thresolding images in tesseract.
4 | // Author: Ray Smith
5 | // Created: Mon May 12 11:00:15 PDT 2008
6 | //
7 | // (C) Copyright 2008, Google Inc.
8 | // Licensed under the Apache License, Version 2.0 (the "License");
9 | // you may not use this file except in compliance with the License.
10 | // You may obtain a copy of the License at
11 | // http://www.apache.org/licenses/LICENSE-2.0
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 | //
18 | ///////////////////////////////////////////////////////////////////////
19 |
20 | #ifndef TESSERACT_CCMAIN_THRESHOLDER_H_
21 | #define TESSERACT_CCMAIN_THRESHOLDER_H_
22 |
23 | #include "platform.h"
24 | #include "publictypes.h"
25 |
26 | struct Pix;
27 |
28 | namespace tesseract {
29 |
30 | /// Base class for all tesseract image thresholding classes.
31 | /// Specific classes can add new thresholding methods by
32 | /// overriding ThresholdToPix.
33 | /// Each instance deals with a single image, but the design is intended to
34 | /// be useful for multiple calls to SetRectangle and ThresholdTo* if
35 | /// desired.
36 | class TESS_API ImageThresholder {
37 | public:
38 | ImageThresholder();
39 | virtual ~ImageThresholder();
40 |
41 | /// Destroy the Pix if there is one, freeing memory.
42 | virtual void Clear();
43 |
44 | /// Return true if no image has been set.
45 | bool IsEmpty() const;
46 |
47 | /// SetImage makes a copy of all the image data, so it may be deleted
48 | /// immediately after this call.
49 | /// Greyscale of 8 and color of 24 or 32 bits per pixel may be given.
50 | /// Palette color images will not work properly and must be converted to
51 | /// 24 bit.
52 | /// Binary images of 1 bit per pixel may also be given but they must be
53 | /// byte packed with the MSB of the first byte being the first pixel, and a
54 | /// one pixel is WHITE. For binary images set bytes_per_pixel=0.
55 | void SetImage(const unsigned char* imagedata, int width, int height,
56 | int bytes_per_pixel, int bytes_per_line);
57 |
58 | /// Store the coordinates of the rectangle to process for later use.
59 | /// Doesn't actually do any thresholding.
60 | void SetRectangle(int left, int top, int width, int height);
61 |
62 | /// Get enough parameters to be able to rebuild bounding boxes in the
63 | /// original image (not just within the rectangle).
64 | /// Left and top are enough with top-down coordinates, but
65 | /// the height of the rectangle and the image are needed for bottom-up.
66 | virtual void GetImageSizes(int* left, int* top, int* width, int* height,
67 | int* imagewidth, int* imageheight);
68 |
69 | /// Return true if the source image is color.
70 | bool IsColor() const {
71 | return pix_channels_ >= 3;
72 | }
73 |
74 | /// Returns true if the source image is binary.
75 | bool IsBinary() const {
76 | return pix_channels_ == 0;
77 | }
78 |
79 | int GetScaleFactor() const {
80 | return scale_;
81 | }
82 |
83 | // Set the resolution of the source image in pixels per inch.
84 | // This should be called right after SetImage(), and will let us return
85 | // appropriate font sizes for the text.
86 | void SetSourceYResolution(int ppi) {
87 | yres_ = ppi;
88 | estimated_res_ = ppi;
89 | }
90 | int GetSourceYResolution() const {
91 | return yres_;
92 | }
93 | int GetScaledYResolution() const {
94 | return scale_ * yres_;
95 | }
96 | // Set the resolution of the source image in pixels per inch, as estimated
97 | // by the thresholder from the text size found during thresholding.
98 | // This value will be used to set internal size thresholds during recognition
99 | // and will not influence the output "point size." The default value is
100 | // the same as the source resolution. (yres_)
101 | void SetEstimatedResolution(int ppi) {
102 | estimated_res_ = ppi;
103 | }
104 | // Returns the estimated resolution, including any active scaling.
105 | // This value will be used to set internal size thresholds during recognition.
106 | int GetScaledEstimatedResolution() const {
107 | return scale_ * estimated_res_;
108 | }
109 |
110 | /// Pix vs raw, which to use? Pix is the preferred input for efficiency,
111 | /// since raw buffers are copied.
112 | /// SetImage for Pix clones its input, so the source pix may be pixDestroyed
113 | /// immediately after, but may not go away until after the Thresholder has
114 | /// finished with it.
115 | void SetImage(const Pix* pix);
116 |
117 | /// Threshold the source image as efficiently as possible to the output Pix.
118 | /// Creates a Pix and sets pix to point to the resulting pointer.
119 | /// Caller must use pixDestroy to free the created Pix.
120 | /// Returns false on error.
121 | virtual bool ThresholdToPix(PageSegMode pageseg_mode, Pix** pix);
122 |
123 | // Gets a pix that contains an 8 bit threshold value at each pixel. The
124 | // returned pix may be an integer reduction of the binary image such that
125 | // the scale factor may be inferred from the ratio of the sizes, even down
126 | // to the extreme of a 1x1 pixel thresholds image.
127 | // Ideally the 8 bit threshold should be the exact threshold used to generate
128 | // the binary image in ThresholdToPix, but this is not a hard constraint.
129 | // Returns nullptr if the input is binary. PixDestroy after use.
130 | virtual Pix* GetPixRectThresholds();
131 |
132 | /// Get a clone/copy of the source image rectangle.
133 | /// The returned Pix must be pixDestroyed.
134 | /// This function will be used in the future by the page layout analysis, and
135 | /// the layout analysis that uses it will only be available with Leptonica,
136 | /// so there is no raw equivalent.
137 | Pix* GetPixRect();
138 |
139 | // Get a clone/copy of the source image rectangle, reduced to greyscale,
140 | // and at the same resolution as the output binary.
141 | // The returned Pix must be pixDestroyed.
142 | // Provided to the classifier to extract features from the greyscale image.
143 | virtual Pix* GetPixRectGrey();
144 |
145 | protected:
146 | // ----------------------------------------------------------------------
147 | // Utility functions that may be useful components for other thresholders.
148 |
149 | /// Common initialization shared between SetImage methods.
150 | virtual void Init();
151 |
152 | /// Return true if we are processing the full image.
153 | bool IsFullImage() const {
154 | return rect_left_ == 0 && rect_top_ == 0 &&
155 | rect_width_ == image_width_ && rect_height_ == image_height_;
156 | }
157 |
158 | // Otsu thresholds the rectangle, taking the rectangle from *this.
159 | void OtsuThresholdRectToPix(Pix* src_pix, Pix** out_pix) const;
160 |
161 | /// Threshold the rectangle, taking everything except the src_pix
162 | /// from the class, using thresholds/hi_values to the output pix.
163 | /// NOTE that num_channels is the size of the thresholds and hi_values
164 | // arrays and also the bytes per pixel in src_pix.
165 | void ThresholdRectToPix(Pix* src_pix, int num_channels,
166 | const int* thresholds, const int* hi_values,
167 | Pix** pix) const;
168 |
169 | protected:
170 | /// Clone or other copy of the source Pix.
171 | /// The pix will always be PixDestroy()ed on destruction of the class.
172 | Pix* pix_;
173 |
174 | int image_width_; //< Width of source pix_.
175 | int image_height_; //< Height of source pix_.
176 | int pix_channels_; //< Number of 8-bit channels in pix_.
177 | int pix_wpl_; //< Words per line of pix_.
178 | // Limits of image rectangle to be processed.
179 | int scale_; //< Scale factor from original image.
180 | int yres_; //< y pixels/inch in source image.
181 | int estimated_res_; //< Resolution estimate from text size.
182 | int rect_left_;
183 | int rect_top_;
184 | int rect_width_;
185 | int rect_height_;
186 | };
187 |
188 | } // namespace tesseract.
189 |
190 | #endif // TESSERACT_CCMAIN_THRESHOLDER_H_
191 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tesseract/unichar.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////
2 | // File: unichar.h
3 | // Description: Unicode character/ligature class.
4 | // Author: Ray Smith
5 | // Created: Wed Jun 28 17:05:01 PDT 2006
6 | //
7 | // (C) Copyright 2006, Google Inc.
8 | // Licensed under the Apache License, Version 2.0 (the "License");
9 | // you may not use this file except in compliance with the License.
10 | // You may obtain a copy of the License at
11 | // http://www.apache.org/licenses/LICENSE-2.0
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS,
14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | // See the License for the specific language governing permissions and
16 | // limitations under the License.
17 | //
18 | ///////////////////////////////////////////////////////////////////////
19 |
20 | #ifndef TESSERACT_CCUTIL_UNICHAR_H_
21 | #define TESSERACT_CCUTIL_UNICHAR_H_
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include "platform.h"
28 |
29 | // Maximum number of characters that can be stored in a UNICHAR. Must be
30 | // at least 4. Must not exceed 31 without changing the coding of length.
31 | #define UNICHAR_LEN 30
32 |
33 | // TODO(rays) Move these to the tesseract namespace.
34 | // A UNICHAR_ID is the unique id of a unichar.
35 | using UNICHAR_ID = int;
36 |
37 | // A variable to indicate an invalid or uninitialized unichar id.
38 | static const int INVALID_UNICHAR_ID = -1;
39 | // A special unichar that corresponds to INVALID_UNICHAR_ID.
40 | static const char INVALID_UNICHAR[] = "__INVALID_UNICHAR__";
41 |
42 | enum StrongScriptDirection {
43 | DIR_NEUTRAL = 0, // Text contains only neutral characters.
44 | DIR_LEFT_TO_RIGHT = 1, // Text contains no Right-to-Left characters.
45 | DIR_RIGHT_TO_LEFT = 2, // Text contains no Left-to-Right characters.
46 | DIR_MIX = 3, // Text contains a mixture of left-to-right
47 | // and right-to-left characters.
48 | };
49 |
50 | namespace tesseract {
51 |
52 | using char32 = signed int;
53 |
54 | // The UNICHAR class holds a single classification result. This may be
55 | // a single Unicode character (stored as between 1 and 4 utf8 bytes) or
56 | // multiple Unicode characters representing the NFKC expansion of a ligature
57 | // such as fi, ffl etc. These are also stored as utf8.
58 | class UNICHAR {
59 | public:
60 | UNICHAR() {
61 | memset(chars, 0, UNICHAR_LEN);
62 | }
63 |
64 | // Construct from a utf8 string. If len<0 then the string is null terminated.
65 | // If the string is too long to fit in the UNICHAR then it takes only what
66 | // will fit.
67 | UNICHAR(const char* utf8_str, int len);
68 |
69 | // Construct from a single UCS4 character.
70 | explicit UNICHAR(int unicode);
71 |
72 | // Default copy constructor and operator= are OK.
73 |
74 | // Get the first character as UCS-4.
75 | int first_uni() const;
76 |
77 | // Get the length of the UTF8 string.
78 | int utf8_len() const {
79 | int len = chars[UNICHAR_LEN - 1];
80 | return len >=0 && len < UNICHAR_LEN ? len : UNICHAR_LEN;
81 | }
82 |
83 | // Get a UTF8 string, but NOT nullptr terminated.
84 | const char* utf8() const {
85 | return chars;
86 | }
87 |
88 | // Get a terminated UTF8 string: Must delete[] it after use.
89 | char* utf8_str() const;
90 |
91 | // Get the number of bytes in the first character of the given utf8 string.
92 | static int utf8_step(const char* utf8_str);
93 |
94 | // A class to simplify iterating over and accessing elements of a UTF8
95 | // string. Note that unlike the UNICHAR class, const_iterator does NOT COPY or
96 | // take ownership of the underlying byte array. It also does not permit
97 | // modification of the array (as the name suggests).
98 | //
99 | // Example:
100 | // for (UNICHAR::const_iterator it = UNICHAR::begin(str, str_len);
101 | // it != UNICHAR::end(str, len);
102 | // ++it) {
103 | // tprintf("UCS-4 symbol code = %d\n", *it);
104 | // char buf[5];
105 | // int char_len = it.get_utf8(buf); buf[char_len] = '\0';
106 | // tprintf("Char = %s\n", buf);
107 | // }
108 | class const_iterator {
109 | using CI = const_iterator ;
110 |
111 | public:
112 | // Step to the next UTF8 character.
113 | // If the current position is at an illegal UTF8 character, then print an
114 | // error message and step by one byte. If the current position is at a nullptr
115 | // value, don't step past it.
116 | const_iterator& operator++();
117 |
118 | // Return the UCS-4 value at the current position.
119 | // If the current position is at an illegal UTF8 value, return a single
120 | // space character.
121 | int operator*() const;
122 |
123 | // Store the UTF-8 encoding of the current codepoint into buf, which must be
124 | // at least 4 bytes long. Return the number of bytes written.
125 | // If the current position is at an illegal UTF8 value, writes a single
126 | // space character and returns 1.
127 | // Note that this method does not null-terminate the buffer.
128 | int get_utf8(char* buf) const;
129 | // Returns the number of bytes of the current codepoint. Returns 1 if the
130 | // current position is at an illegal UTF8 value.
131 | int utf8_len() const;
132 | // Returns true if the UTF-8 encoding at the current position is legal.
133 | bool is_legal() const;
134 |
135 | // Return the pointer into the string at the current position.
136 | const char* utf8_data() const { return it_; }
137 |
138 | // Iterator equality operators.
139 | friend bool operator==(const CI& lhs, const CI& rhs) {
140 | return lhs.it_ == rhs.it_;
141 | }
142 | friend bool operator!=(const CI& lhs, const CI& rhs) {
143 | return !(lhs == rhs);
144 | }
145 |
146 | private:
147 | friend class UNICHAR;
148 | explicit const_iterator(const char* it) : it_(it) {}
149 |
150 | const char* it_; // Pointer into the string.
151 | };
152 |
153 | // Create a start/end iterator pointing to a string. Note that these methods
154 | // are static and do NOT create a copy or take ownership of the underlying
155 | // array.
156 | static const_iterator begin(const char* utf8_str, const int byte_length);
157 | static const_iterator end(const char* utf8_str, const int byte_length);
158 |
159 | // Converts a utf-8 string to a vector of unicodes.
160 | // Returns an empty vector if the input contains invalid UTF-8.
161 | static std::vector UTF8ToUTF32(const char* utf8_str);
162 | // Converts a vector of unicodes to a utf8 string.
163 | // Returns an empty string if the input contains an invalid unicode.
164 | static std::string UTF32ToUTF8(const std::vector& str32);
165 |
166 | private:
167 | // A UTF-8 representation of 1 or more Unicode characters.
168 | // The last element (chars[UNICHAR_LEN - 1]) is a length if
169 | // its value < UNICHAR_LEN, otherwise it is a genuine character.
170 | char chars[UNICHAR_LEN];
171 | };
172 |
173 | } // namespace tesseract
174 |
175 | #endif // TESSERACT_CCUTIL_UNICHAR_H_
176 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tiffconf.h:
--------------------------------------------------------------------------------
1 | /* libtiff/tiffconf.h. Generated from tiffconf.h.in by configure. */
2 | /*
3 | Configuration defines for installed libtiff.
4 | This file maintained for backward compatibility. Do not use definitions
5 | from this file in your programs.
6 | */
7 |
8 | #ifndef _TIFFCONF_
9 | #define _TIFFCONF_
10 |
11 | /* Signed 16-bit type */
12 | #define TIFF_INT16_T signed short
13 |
14 | /* Signed 32-bit type */
15 | #define TIFF_INT32_T signed int
16 |
17 | /* Signed 64-bit type */
18 | #define TIFF_INT64_T signed long long
19 |
20 | /* Signed 8-bit type */
21 | #define TIFF_INT8_T signed char
22 |
23 | /* Unsigned 16-bit type */
24 | #define TIFF_UINT16_T unsigned short
25 |
26 | /* Unsigned 32-bit type */
27 | #define TIFF_UINT32_T unsigned int
28 |
29 | /* Unsigned 64-bit type */
30 | #define TIFF_UINT64_T unsigned long long
31 |
32 | /* Unsigned 8-bit type */
33 | #define TIFF_UINT8_T unsigned char
34 |
35 | /* Signed size type */
36 | #define TIFF_SSIZE_T signed int
37 |
38 | /* Pointer difference type */
39 | #define TIFF_PTRDIFF_T ptrdiff_t
40 |
41 | /* Define to 1 if the system has the type `int16'. */
42 | /* #undef HAVE_INT16 */
43 |
44 | /* Define to 1 if the system has the type `int32'. */
45 | /* #undef HAVE_INT32 */
46 |
47 | /* Define to 1 if the system has the type `int8'. */
48 | /* #undef HAVE_INT8 */
49 |
50 | /* Compatibility stuff. */
51 |
52 | /* Define as 0 or 1 according to the floating point format suported by the
53 | machine */
54 | #define HAVE_IEEEFP 1
55 |
56 | /* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
57 | #define HOST_FILLORDER FILLORDER_MSB2LSB
58 |
59 | /* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian
60 | (Intel) */
61 | #define HOST_BIGENDIAN 0
62 |
63 | /* Support CCITT Group 3 & 4 algorithms */
64 | #define CCITT_SUPPORT 1
65 |
66 | /* Support JPEG compression (requires IJG JPEG library) */
67 | #define JPEG_SUPPORT 1
68 |
69 | /* Support JBIG compression (requires JBIG-KIT library) */
70 | /* #undef JBIG_SUPPORT */
71 |
72 | /* Support LogLuv high dynamic range encoding */
73 | #define LOGLUV_SUPPORT 1
74 |
75 | /* Support LZW algorithm */
76 | #define LZW_SUPPORT 1
77 |
78 | /* Support NeXT 2-bit RLE algorithm */
79 | #define NEXT_SUPPORT 1
80 |
81 | /* Support Old JPEG compresson (read contrib/ojpeg/README first! Compilation
82 | fails with unpatched IJG JPEG library) */
83 | #define OJPEG_SUPPORT 1
84 |
85 | /* Support Macintosh PackBits algorithm */
86 | #define PACKBITS_SUPPORT 1
87 |
88 | /* Support Pixar log-format algorithm (requires Zlib) */
89 | #define PIXARLOG_SUPPORT 1
90 |
91 | /* Support ThunderScan 4-bit RLE algorithm */
92 | #define THUNDER_SUPPORT 1
93 |
94 | /* Support Deflate compression */
95 | #define ZIP_SUPPORT 1
96 |
97 | /* Support strip chopping (whether or not to convert single-strip uncompressed
98 | images to mutiple strips of ~8Kb to reduce memory usage) */
99 | #define STRIPCHOP_DEFAULT TIFF_STRIPCHOP
100 |
101 | /* Enable SubIFD tag (330) support */
102 | #define SUBIFD_SUPPORT 1
103 |
104 | /* Treat extra sample as alpha (default enabled). The RGBA interface will
105 | treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many
106 | packages produce RGBA files but don't mark the alpha properly. */
107 | #define DEFAULT_EXTRASAMPLE_AS_ALPHA 1
108 |
109 | /* Pick up YCbCr subsampling info from the JPEG data stream to support files
110 | lacking the tag (default enabled). */
111 | #define CHECK_JPEG_YCBCR_SUBSAMPLING 1
112 |
113 | /* Support MS MDI magic number files as TIFF */
114 | #define MDI_SUPPORT 1
115 |
116 | /*
117 | * Feature support definitions.
118 | * XXX: These macros are obsoleted. Don't use them in your apps!
119 | * Macros stays here for backward compatibility and should be always defined.
120 | */
121 | #define COLORIMETRY_SUPPORT
122 | #define YCBCR_SUPPORT
123 | #define CMYK_SUPPORT
124 | #define ICC_SUPPORT
125 | #define PHOTOSHOP_SUPPORT
126 | #define IPTC_SUPPORT
127 |
128 | #endif /* _TIFFCONF_ */
129 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/include/tiffvers.h:
--------------------------------------------------------------------------------
1 | #define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.4\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
2 | /*
3 | * This define can be used in code that requires
4 | * compilation-related definitions specific to a
5 | * version or versions of the library. Runtime
6 | * version checking should be done based on the
7 | * string returned by TIFFGetVersion.
8 | */
9 | #define TIFFLIB_VERSION 20150621
10 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libjpeg.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libjpeg.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/liblept.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/liblept.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libpng.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libpng.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libtesseract.4.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libtesseract.4.dylib
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libtesseract.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libtesseract.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libtesseract.dylib:
--------------------------------------------------------------------------------
1 | libtesseract.4.dylib
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libtiff.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libtiff.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/External/Tesseract/lib/libz.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/External/Tesseract/lib/libz.a
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Handwriting Input Recognition-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Use this file to import your target's public headers that you would like to expose to Swift.
3 | //
4 |
5 | #import "SLTesseract.h"
6 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Handwriting_Input_Recognition.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.files.user-selected.read-only
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleVersion
22 | 1
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | Copyright © 2018 chargeflux. All rights reserved.
27 | NSMainStoryboardFile
28 | Main
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/MainViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MainViewController.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 11/10/18.
6 | // Copyright © 2018 chargeflux. All rights reserved.
7 | //
8 |
9 | import Cocoa
10 | import Carbon.HIToolbox
11 |
12 | class MainViewController: NSViewController {
13 | @IBOutlet var CharacterOutput: NSTextField!
14 |
15 | /// Represents a custom NSView class that enables drawing for user
16 | @IBOutlet var DrawCanvasView: DrawCanvasView!
17 |
18 | /// Holds instance of "CharacterChoices" class that holds all possible interpretations by Tesseract
19 | var choices: CharacterChoices!
20 |
21 | /// Collection View showing all possible interpretations by Tesseract
22 | @IBOutlet var CharacterOptionCollection: NSCollectionView!
23 |
24 | /// Best interpretation of user's character drawing given by Tesseract
25 | var result: String!
26 |
27 | /// Stores keyboard shortcut monitor (KeyDown events)
28 | var keyboardShortcutMonitor: Any?
29 |
30 | override func viewDidLoad() {
31 | super.viewDidLoad()
32 |
33 | // Start monitor for keyboard shortcuts via keyDown NSEvents
34 | startKeyboardShortcutMonitor()
35 | }
36 |
37 | /// Reset application state
38 | func resetState() {
39 | DrawCanvasView?.clearCanvas()
40 | self.CharacterOutput.stringValue = ""
41 | self.choices = nil
42 | CharacterOptionCollection.reloadData()
43 | }
44 |
45 | /// Copy the contents of text field `CharacterOutput` to pasteboard
46 | func copyCharacterOutputToClipboard() {
47 | let stringToCopy = self.CharacterOutput.stringValue
48 | let pasteboard = NSPasteboard.general
49 | pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil)
50 | pasteboard.setString(stringToCopy, forType: NSPasteboard.PasteboardType.string)
51 | }
52 |
53 | /// Initializes monitor for keyboard shortcuts, i.e., when user presses a key
54 | func startKeyboardShortcutMonitor() {
55 | self.keyboardShortcutMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: keyboardShortcut)
56 | }
57 |
58 | func keyboardShortcut(_ event: NSEvent) -> NSEvent? {
59 | // If particular shortcut is pressed, certain functions are executed and returns the
60 | // the event as `nil` to prevent triggering the "Basso"/default alert sound because the
61 | // system won't recognize the key press as a valid input/shortcut. Otherwise the event
62 | // is returned as is to the system input manager to be processed.
63 | switch Int(event.keyCode) {
64 | /// Check if Escape key is pressed: Clear application state
65 | case kVK_Escape:
66 | if event.isARepeat {
67 | // Hold Escape key to reset application state
68 | resetState()
69 | return nil
70 | }
71 | DrawCanvasView?.clearCanvas()
72 | self.choices = nil
73 | return nil
74 | /// Check if Return key is pressed: Initiate OCR and parse results
75 | case kVK_Return:
76 | guard let (result, rawChoiceArray) = DrawCanvasView?.ocr() else{
77 | return nil
78 | }
79 | self.result = result
80 | // Parse Tesseract's alternative choices
81 | let choicesArray = rawChoiceArray as! Array>
82 | self.choices = CharacterChoices(choicesArray: choicesArray)
83 | CharacterOptionCollection.reloadData()
84 | return nil
85 | /// Check if "C" key is pressed: Copy field to clipboard and clear
86 | case kVK_ANSI_C:
87 | // Prevent overwriting of clipboard with empty string
88 | if CharacterOutput.stringValue.isEmpty {
89 | return nil
90 | }
91 | if event.isARepeat {
92 | // Prevents overwriting of clipboard if "C" is held down too long
93 | if choices != nil {
94 | copyCharacterOutputToClipboard()
95 | resetState()
96 | }
97 | return nil
98 | }
99 | copyCharacterOutputToClipboard()
100 | resetState()
101 | return nil
102 | default:
103 | return event
104 | }
105 | }
106 | }
107 |
108 | extension MainViewController: NSCollectionViewDataSource {
109 | static let characterOptionItem = "CharacterOptionItem"
110 |
111 | func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
112 | guard let numberItems = self.choices?.totalChoices else {
113 | return 0
114 | }
115 | return numberItems
116 | }
117 |
118 | func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
119 | let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: MainViewController.characterOptionItem), for: indexPath)
120 |
121 | if self.choices?.totalChoices == nil {
122 | return item
123 | }
124 | else {
125 | // Populate `CharacterOptionCollection` items with all of Tesseract's possible choices
126 | item.textField?.stringValue = self.choices.possibleChoicesArray[indexPath[1]].character
127 | }
128 | return item
129 | }
130 |
131 | }
132 |
133 | extension MainViewController: NSCollectionViewDelegate {
134 | func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set) {
135 |
136 | // Append selection to `CharacterOutput` text field
137 | self.CharacterOutput.stringValue += (collectionView.item(at: indexPaths.first!)?.textField?.stringValue)!
138 |
139 | // Allows user to select symbol multiple times
140 | collectionView.deselectItems(at: indexPaths)
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Models/TesseractData.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TesseractData.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 5/16/19.
6 | // Copyright © 2019 chargeflux. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | /// Holds all possible choices as interpreted by Tesseract for given canvas image
12 | /// `possibleChoice`: struct
13 | /// - character = a possible character as interpreted by Tesseract
14 | /// - confidenceInterval = associated CI to possible character
15 | class CharacterChoices {
16 | struct possibleChoice {
17 | var character: String
18 | var confidenceInterval: Double
19 | }
20 |
21 | let totalChoices: Int?
22 |
23 | /// Array containing all `possibleChoice` instances
24 | var possibleChoicesArray: Array = []
25 |
26 | /// Initialize class `CharacterChoices`
27 | init?(choicesArray: Array>) {
28 | guard choicesArray.count == 1 else {
29 | return nil
30 | }
31 | self.totalChoices = choicesArray[0].count
32 | for choiceArray in choicesArray{
33 | for choice:NSArray in choiceArray{
34 | let tempChoice = possibleChoice(character: choice[0] as! String, confidenceInterval: choice[1] as! Double)
35 | possibleChoicesArray.append(tempChoice)
36 | }
37 | }
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Views/CharacterOptionCollectionView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CharacterOptionCollectionView.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 5/16/19.
6 | // Copyright © 2019 chargeflux. All rights reserved.
7 | //
8 |
9 | import Cocoa
10 |
11 | class CharacterOptionCollectionView: NSCollectionView {
12 |
13 | override func draw(_ dirtyRect: NSRect) {
14 | super.draw(dirtyRect)
15 |
16 | let topBorder: CALayer = CALayer()
17 | let borderWidth: CGFloat = 2.0
18 | topBorder.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: borderWidth) // note flipped coordinate system
19 | topBorder.backgroundColor = .black
20 | self.layer?.addSublayer(topBorder)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Views/CharacterOptionItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // CharacterOptionItem.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 11/11/18.
6 | // Copyright © 2018 chargeflux. All rights reserved.
7 | //
8 |
9 | import Cocoa
10 |
11 | class CharacterOptionItem: NSCollectionViewItem {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | let rightBorder: CALayer = CALayer()
16 | let borderWidth: CGFloat = 1.0
17 | rightBorder.frame = CGRect(x: self.view.frame.width - borderWidth, y: 0, width: borderWidth, height: self.view.frame.height)
18 | rightBorder.backgroundColor = .black
19 | self.view.wantsLayer = true
20 | self.view.layer?.addSublayer(rightBorder)
21 |
22 |
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Views/CharacterOptionItem.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/Views/DrawCanvasView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DrawCanvasView.swift
3 | // Handwriting Input Recognition
4 | //
5 | // Created by chargeflux on 5/16/19.
6 | // Copyright © 2019 chargeflux. All rights reserved.
7 | //
8 |
9 | import Cocoa
10 |
11 | /// Custom NSView class for drawing capabilities
12 | class DrawCanvasView: NSView {
13 | // Initiate class variables for initiating path and Tesseract
14 | // Path is not contiguous and will only be cleared upon user action (escape key)
15 | var startingPoint:CGPoint!
16 | var path: NSBezierPath = NSBezierPath()
17 |
18 | /// Get starting point and tells `path` the starting point
19 | /// Will be called every time user clicks left button (allowing for new paths)
20 | override func mouseDown(with event: NSEvent) {
21 | let mouseButton = event.buttonNumber
22 |
23 | // Debugging purposes
24 | if mouseButton == 0{
25 | startingPoint = event.locationInWindow //480,320 top right, 0,0 bottom left
26 | }
27 |
28 | path.move(to: convert(event.locationInWindow, from: nil))
29 | needsDisplay = true
30 | }
31 |
32 | /// Tells the new destination point from starting point to `path` and makes it draw
33 | override func mouseDragged(with event: NSEvent) {
34 | path.line(to: convert(event.locationInWindow, from: nil))
35 | needsDisplay = true
36 | }
37 |
38 | /// Drawing function of path with properties
39 | override func draw(_ dirtyRect: NSRect) {
40 | super.draw(dirtyRect)
41 |
42 | self.layer?.backgroundColor = .white
43 |
44 | let topBorder: CALayer = CALayer()
45 | let borderWidth: CGFloat = 2.0
46 | topBorder.frame = CGRect(x: 0, y: self.frame.height - borderWidth, width: self.frame.width, height: borderWidth)
47 | topBorder.backgroundColor = .black
48 | self.layer?.addSublayer(topBorder)
49 |
50 | path.lineWidth = 3.0
51 | path.lineCapStyle = .round
52 | path.lineJoinStyle = .round
53 | NSColor.black.set()
54 | path.stroke()
55 | }
56 |
57 | /// Clears canvas
58 | func clearCanvas() {
59 | path.removeAllPoints() // .removeAllPoints & reinstantiating `path`
60 | path = NSBezierPath() // with NSBezierPath() are required to remove `path` completely
61 | needsDisplay = true
62 | }
63 |
64 | /// Initiates OCR of canvas via Tesseract
65 | /// - Returns:
66 | /// - String: Tesseract's result with highest confidence interval
67 | /// - NSArray: A nested array of all possible character choices interpreted by Tesseract with CI
68 | func ocr() -> (String, NSArray) {
69 | let Tesseract = SLTesseract()
70 | Tesseract.language = "jpn"
71 | let viewSize: NSSize = self.bounds.size;
72 | let canvasRect = NSRect(x: 0, y: 0, width: viewSize.width, height: viewSize.height)
73 | let canvasBIR: NSBitmapImageRep = self.bitmapImageRepForCachingDisplay(in: canvasRect)!
74 | self.cacheDisplay(in: canvasRect, to: canvasBIR)
75 | let textImage = NSImage(size: viewSize)
76 | textImage.addRepresentation(canvasBIR)
77 | let rawChoiceArray: NSArray = Tesseract.getClassiferChoicesPerSymbol(textImage)! as NSArray
78 | return (Tesseract.recognize(textImage), rawChoiceArray)
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Handwriting Input Recognition/tessdata/eng.traineddata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/tessdata/eng.traineddata
--------------------------------------------------------------------------------
/Handwriting Input Recognition/tessdata/jpn.traineddata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/tessdata/jpn.traineddata
--------------------------------------------------------------------------------
/Handwriting Input Recognition/tessdata/jpn_vert.traineddata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chargeflux/Handwriting-Input-Recognition/8b76bed4f19cf4c30a54954cacb12338c616a652/Handwriting Input Recognition/tessdata/jpn_vert.traineddata
--------------------------------------------------------------------------------
/Handwriting Input RecognitionTests/Handwriting_Input_RecognitionTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Handwriting_Input_RecognitionTests.swift
3 | // Handwriting Input RecognitionTests
4 | //
5 | // Created by chargeflux on 11/10/18.
6 | // Copyright © 2018 chargeflux. All rights reserved.
7 | //
8 |
9 | import XCTest
10 | @testable import Handwriting_Input_Recognition
11 |
12 | class Handwriting_Input_RecognitionTests: XCTestCase {
13 |
14 | override func setUp() {
15 | // Put setup code here. This method is called before the invocation of each test method in the class.
16 | }
17 |
18 | override func tearDown() {
19 | // Put teardown code here. This method is called after the invocation of each test method in the class.
20 | }
21 |
22 | func testCharacterChoices() {
23 | let choicesArrayOneSymbol: Array> = [[NSArray(array: ["陜",0.5351977]), NSArray(array: ["豚",0.5284442]), NSArray(array: ["秘",0.5279514]), NSArray(array: ["擲",0.51511]), NSArray(array: ["夙",0.5126926])]]
24 |
25 | let choicesArrayTwoSymbol: Array> = [[NSArray(array: ["陜",0.5351977]), NSArray(array:["豚",0.5284442]), NSArray(array:["秘",0.5279514]), NSArray(array:["擲",0.51511]), NSArray(array:["夙",0.5126926])],[NSArray(array:["赫",0.9108368]), NSArray(array:["柳", 0.8045998]),NSArray(array:["國", 0.4923432])]]
26 |
27 | guard let CharacterChoicesOneSymbol = Handwriting_Input_Recognition.CharacterChoices(choicesArray: choicesArrayOneSymbol) else {
28 | XCTFail("CharacterChoices() failed with OneSymbol")
29 | return
30 | }
31 |
32 | XCTAssertTrue(Handwriting_Input_Recognition.CharacterChoices(choicesArray: choicesArrayTwoSymbol) == nil, "CharacterChoices initialization did not fail with two symbols")
33 |
34 | XCTAssertTrue(CharacterChoicesOneSymbol.totalChoices == 5, "CharacterChoices did not calculate total number of choices for one symbol")
35 |
36 | for (index, choiceNSArray) in choicesArrayOneSymbol[0].enumerated() {
37 | XCTAssertTrue(CharacterChoicesOneSymbol.possibleChoicesArray[index].character == choiceNSArray[0] as! String)
38 | XCTAssertTrue(CharacterChoicesOneSymbol.possibleChoicesArray[index].confidenceInterval == choiceNSArray[1] as! Double)
39 | }
40 | }
41 |
42 | func testPerformanceExample() {
43 | // This is an example of a performance test case.
44 | self.measure {
45 | // Put the code you want to measure the time of here.
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Handwriting Input RecognitionTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 chargeflux
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Handwriting Input Recognition
2 | Handwriting Input Recognition is a Swift app that allows the user to draw characters from a specified language and present the character in a text field. Character recognition is based on Tesseract OCR.
3 |
4 | ## Compilation
5 | 1) Launch `Handwriting Input Recognition.xcodeproj`
6 | 2) Add your signing certificate under the Target **Handwriting Input Recognition** → **General** → **Signing**
7 | 3) Build
8 |
9 | ## Usage
10 | 1) Draw character in bottom canvas
11 | 2) Press `Enter` to start OCR or `Escape` to clear canvas
12 | 3) Choose the character that best matches your intended input above the canvas
13 | 4) Continue to draw if results don't match and press `Enter` to perform OCR again
14 | 5) Hold down `C` to copy the results in the text field to clipboard
15 | 6) Hold down `Escape` to reset the app
16 |
17 | ## TODO
18 | 1) Dynamically update possible character options as user draws
19 | 2) Multiple character input + recognition
20 | 3) Overlays for function running (Copied, Cleared etc)
21 | 4) Add more languages
22 | 5) Specify language (Currently recognition language is set to Japanese)
23 | 6) Improve UI
24 |
25 | ## Contributing
26 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
27 |
28 | ## Libraries Used
29 | - Tesseract (v3.05.01)
30 | - [Tesseract macOS](https://github.com/scott0123/Tesseract-macOS) by [scott0123](https://github.com/scott0123)
31 | - Leptonica (v1.75.3)
32 | - LibPNG (v1.6.34)
33 | - LibTIFF (v4.0.9)
34 | - LibJPEG (v9c)
35 | - LibZ (v1.2.11)
36 |
37 | ## License
38 | [MIT](./LICENSE.txt)
--------------------------------------------------------------------------------