Re: Using Tesseract in MFC
Soon as I included
Code:
#include <tesseract/baseapi.h>
in my VS2010 project, I got
Code:
1>c:\flaviu\imagetext\tesseract\include\tesseract\publictypes.h(33): error C2144: syntax error : 'int' should be preceded by ';'
to
/** Number of printers' points in an inch. The unit of the pointsize return. */
constexpr int kPointsPerInch = 72;
...
...
fatal error C1083: Cannot open include file: 'cinttypes': No such file or directory
I have no chance to use tesseract library into VS2010 project ... would I ?
Re: Using Tesseract in MFC
You cannot use the code of tesseract in VS2010, but if tesseract is compiled into a .dll or an .obj, then potentially these could be used by VS2010 c++ code. When you referred to using the tesseraft library within VS2010 previously, this is what I thought you meant. When you compile a c++ program, this produces .obj file(s) which are then linked to produce the .exe (or .dll) file. These .obj files need not all have been compiled at the same time by the same compiler. Indeed, this is how say a program composed of Fortran and c++ sources is compiled and linked. The c++ compiler produces a.obj file, the Fortran compiler produces a .obj file and then the linker combines these to produce the .exe. If you use VS2017 to produce a .dll from the tesseract source, then the exported functions can be used by another c++ program by referencing the appropriate .lib file at link time and including an appropriate header for the function definitions. However if this header for tesseract requires <cinttypes> then this avenue is closed off (if you can't get around it) and you're left with linking multiple .obj files.
However, why are you trying to persist with using VS2010? This is 8 years old and doesn't even support c++11 - never mind the latest c++17 standard. Why not just move to the current VS2017?
Re: Using Tesseract in MFC
Quote:
Originally Posted by
2kaud
You cannot use the code of tesseract in VS2010, but if tesseract is compiled into a .dll or an .obj, then potentially these could be used by VS2010 c++ code. When you referred to using the tesseraft library within VS2010 previously, this is what I thought you meant. When you compile a c++ program, this produces .obj file(s) which are then linked to produce the .exe (or .dll) file. These .obj files need not all have been compiled at the same time by the same compiler. Indeed, this is how say a program composed of Fortran and c++ sources is compiled and linked. The c++ compiler produces a.obj file, the Fortran compiler produces a .obj file and then the linker combines these to produce the .exe. If you use VS2017 to produce a .dll from the tesseract source, then the exported functions can be used by another c++ program by referencing the appropriate .lib file at link time and including an appropriate header for the function definitions. However if this header for tesseract requires <cinttypes> then this avenue is closed off (if you can't get around it) and you're left with linking multiple .obj files.
However, why are you trying to persist with using VS2010? This is 8 years old and doesn't even support c++11 - never mind the latest c++17 standard. Why not just move to the current VS2017?
After all, I have installed VS2017, and I like it. I needed VS2010 compiled tesseract library because the project where I am intend to use this library is VS2010 project ... now I should convert this parent project, built in VS2010 into VS2017 ... I hope I will succeed.
I have successfully compiled leptonica and tesseract libraries, but only with VS2017 ... now is follow the next step: to see why these libraries is not working in my project :D
All these libs are compiled as Debug Win32, and my MFC project is compiled as Debug x86, all of them as Multi-threaded Debug DLL (/MDd) ...
When I tested their sample code:
Code:
tesseract::TessBaseAPI api;
if (0 != api.Init(NULL, _T("eng"), tesseract::OEM_DEFAULT))
{
m_sState.Format(_T("tesseract initialize error"));
return FALSE;
}
always the app is pass by error branch ... but this is other issue. Anyway, I really thank you for your time and patience.
Re: Using Tesseract in MFC
Quote:
Originally Posted by
mesajflaviu
When I tested their sample code:
Code:
tesseract::TessBaseAPI api;
if (0 != api.Init(NULL, _T("eng"), tesseract::OEM_DEFAULT))
{
m_sState.Format(_T("tesseract initialize error"));
return FALSE;
}
always the app is pass by error branch ... but this is other issue. Anyway, I really thank you for your time and patience.
Are you sure Init failed if it returns any non-zero value?
Re: Using Tesseract in MFC
Quote:
Originally Posted by
mesajflaviu
After all, I have installed VS2017, and I like it.
That's great news.
Re: Using Tesseract in MFC
Quote:
Originally Posted by
Arjay
That's great news.
It surprise me few things: it not consume a tone of RAM (or HDD space), (I admit, it consume more than VS2010), and I can open VS2010 project, work in VS2017 (with his great IDE), and when is done, I can open the project in VS2010 and compile it there ... fantastic !
Re: Using Tesseract in MFC
Quote:
Originally Posted by
VictorN
Are you sure Init failed if it returns any non-zero value?
Yes, I am sure: I have tried:
Code:
int n = api.Init(NULL, _T("eng"), tesseract::OEM_DEFAULT);
and n is -1. And here is the comments from Init method:
Code:
* Start tesseract. Returns zero on success and -1 on failure.
* NOTE that the only members that may be called before Init are those
* listed above here in the class definition.
Re: Using Tesseract in MFC
I wonder if someone used tesseract in MFC ... could point me what I am doing wrong ?
Re: Using Tesseract in MFC
Have you tried to call GetLastError after the failed Init call? Btw, if folks here knew what the problem was, they would be posting?
Re: Using Tesseract in MFC
Quote:
Originally Posted by
Arjay
Have you tried to call GetLastError after the failed Init call? Btw, if folks here knew what the problem was, they would be posting?
I have tried:
Code:
tesseract::TessBaseAPI api;
int n = api.Init(NULL, _T("eng"), tesseract::OEM_DEFAULT);
DWORD nError = GetLastError();
n is -1, and nError is 3, which mean: The system cannot find the path specified. ... strange ....
Re: Using Tesseract in MFC
I haven't used tesseract - but the documentation at https://zdenop.github.io/tesseract-d...ab1cfc3bc09f3e
Are you compiling as ASCII or Unicode? From the documentation, the expected first 2 parameters are const char * - ie ASCII. You are using _T("..") which gives ASCII if compiled as ASCII or Unicode if compiled as Unicode. Have you tried setting parameter 2 to NULL which should default to eng?
There is no indication in the documentation that .init() sets LastError, so GetLastError() may or may not return a valid value if .init() returns -1.
As you are using OEM_DEFAULT, there is no need to use the 3 parameter version - just use the 2 param version which defaults to OEM_DEFAULT.
Have you tried
Code:
int n = api.init(NULL, NULL);
Re: Using Tesseract in MFC
Quote:
Originally Posted by
2kaud
I haven't used tesseract - but the documentation at
https://zdenop.github.io/tesseract-d...ab1cfc3bc09f3e
Are you compiling as ASCII or Unicode? From the documentation, the expected first 2 parameters are const char * - ie ASCII. You are using _T("..") which gives ASCII if compiled as ASCII or Unicode if compiled as Unicode. Have you tried setting parameter 2 to NULL which should default to eng?
There is no indication in the documentation that .init() sets LastError, so GetLastError() may or may not return a valid value if .init() returns -1.
As you are using OEM_DEFAULT, there is no need to use the 3 parameter version - just use the 2 param version which defaults to OEM_DEFAULT.
Have you tried
Code:
int n = api.init(NULL, NULL);
I have tried
Code:
tesseract::TessBaseAPI api;
int n = api.Init(NULL, NULL);
DWORD nError = GetLastError();
with the same results ... I have compiled the project as ASCII, same result, Unicode, same result ...
Re: Using Tesseract in MFC
According to the source, when a failure occurs, info is output via tprintf() to the file specified by the file name in the variable debug_file - or if non specified to stderr. As you are running a mfc program I guess there is no stderr - so the debug file name needs to be set. I think you just need to set it as debug_file is defined as
DLLSYM char* debug_file = "";
Failing that, as you have the source then a debug of the .init() function should indicate where is the problem.
Re: Using Tesseract in MFC
Quote:
Originally Posted by
2kaud
According to the source, when a failure occurs, info is output via tprintf() to the file specified by the file name in the variable debug_file - or if non specified to stderr. As you are running a mfc program I guess there is no stderr - so the debug file name needs to be set. I think you just need to set it as debug_file is defined as
DLLSYM char* debug_file = "";
Failing that, as you have the source then a debug of the .init() function should indicate where is the problem.
I have put the following line in MyProjectApp.h
Code:
#define DLLSYM char* debug_file = "C:\\Flaviu\\test.txt";
and I collect no data (0 bytes) ... my guess is that I didn't put this file where should be ....
Re: Using Tesseract in MFC
You are redefining the symbol DLLSYM.
Try just
Code:
debug_file = "C:\\Flaviu\\test.txt";