-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_dummy.cpp
More file actions
165 lines (141 loc) · 3.47 KB
/
Copy pathmain_dummy.cpp
File metadata and controls
165 lines (141 loc) · 3.47 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "mfcpch.h"
// #define USE_VLD //Uncomment for Visual Leak Detector.
#if (defined _MSC_VER && defined USE_VLD)
#include <vld.h>
#endif
// Include automatically generated configuration file if running autoconf
#include "config.h"
#ifdef USING_GETTEXT
#include <libintl.h>
#include <locale.h>
#define _(x) gettext(x)
#else
#define _(x) (x)
#endif
#include "allheaders.h"
#include "baseapi.h"
#include "strngs.h"
#include "tprintf.h"
#include "tesseractmain.h"
#ifdef __darwin__
#include "fmemopen.h"
#endif
bool isLibLept() {
#if defined(HAVE_LIBLEPT)
return true;
#else
return false;
#endif
}
bool isLibTiff() {
#if defined(HAVE_LIBLEPT)
return true;
#else
return false;
#endif
}
// useless <<<<<<<<
int readBuf(const char *fname,l_uint8 *buf) {
FILE *fp;
long len;
fp=fopen(fname,"rb");
fseek(fp,0,SEEK_END); //go to end
len=ftell(fp); //get position at end (length)
fseek(fp,0,SEEK_SET); //go to beg.
buf=(l_uint8 *)malloc(len); //malloc buffer
fread(buf,len,1,fp); //read into buffer
fclose(fp);
return len;
}
char* ProcessPagesWrapper(const char* image,tesseract::TessBaseAPI* api) {
//printf("ok->%s",text_out);
STRING mstr;
api->ProcessPages(image, NULL, 0, &mstr);
const char *tmpStr=mstr.string();
char *retStr = new char[strlen(tmpStr) + 1];
strcpy (retStr,tmpStr);
return retStr;
}
char* ProcessPagesPix(const char* image,tesseract::TessBaseAPI* api) {
STRING mstr;
int page=0;
Pix *pix;
pix = pixRead(image);
//l_uint8 buf[10000];
//int len=readBuf(image,buf);
//if (len < 0)
// puts("Cannot Read Buffer");
api->ProcessPage(pix, page, NULL, NULL, 0, &mstr);
const char *tmpStr=mstr.string();
char *retStr = new char[strlen(tmpStr) + 1];
strcpy (retStr,tmpStr);
//printf("ok->%s",retStr);
return retStr;
}
char* ProcessPagesFileStream(const char* image,tesseract::TessBaseAPI* api) {
Pix *pix;
STRING mstr;
int page=0;
FILE *fp=fopen(image,"rb");
pix=pixReadStream(fp,0);
api->ProcessPage(pix, page, NULL, NULL, 0, &mstr);
const char *tmpStr=mstr.string();
char *retStr = new char[strlen(tmpStr) + 1];
strcpy (retStr,tmpStr);
//printf("ok->%s",retStr);
fclose(fp);
return retStr;
}
void dump_buffer(void *buffer, int buffer_size)
{
int i;
for(i = 0;i < buffer_size;++i)
printf("%c", ((char *)buffer)[i]);
}
char* ProcessPagesBuffer(char* buffer, int fileLen, tesseract::TessBaseAPI* api) {
FILE *stream;
//int ch;
stream=fmemopen((void*)buffer,fileLen,"rb");
//int count;
//while ((ch = fgetc (stream)) != EOF)
// printf ("Got %d:%c\n", count++,ch);
//fclose (stream);
//puts("''''''''''''''''''");
Pix *pix;
int page=0;
STRING mstr;
pix=pixReadStream(stream,0);
api->ProcessPage(pix, page, NULL, NULL, 0, &mstr);
const char *tmpStr=mstr.string();
char *retStr = new char[strlen(tmpStr) + 1];
strcpy (retStr,tmpStr);
//printf("ok->%s",retStr);
return retStr;
}
char* ProcessPagesRaw(const char* image,tesseract::TessBaseAPI* api) {
FILE *fp=fopen(image,"rb");
//Get file length
fseek(fp, 0, SEEK_END);
int fileLen=ftell(fp);
fseek(fp, 0, SEEK_SET);
printf("fileLen=%d\n",fileLen);
char *buffer;
//Allocate memory
buffer=(char *)malloc(fileLen+1);
if (!buffer)
{
fprintf(stderr, "Memory error!");
fclose(fp);
return NULL ;
}
int n;
n = fread(buffer,fileLen, 1, fp);
fclose(fp);
printf("n=%d\n",n);
//dump_buffer(buffer,fileLen);
char* retStr;
retStr=ProcessPagesBuffer(buffer,fileLen, api);
//Free memory
free(buffer);
return retStr;
}