dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38

Thread: Using Tesseract in MFC

  1. #16
    Join Date
    Jan 2009
    Posts
    263

    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 ?

  2. #17
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,464

    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?
    Last edited by 2kaud; September 25th, 2018 at 08:19 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

  3. #18
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by 2kaud View Post
    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

    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.

  4. #19
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,252

    Re: Using Tesseract in MFC

    Quote Originally Posted by mesajflaviu View Post
    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?
    Victor Nijegorodov

  5. #20
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,774

    Re: Using Tesseract in MFC

    Quote Originally Posted by mesajflaviu View Post
    After all, I have installed VS2017, and I like it.
    That's great news.

  6. #21
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by Arjay View Post
    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 !

  7. #22
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by VictorN View Post
    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.

  8. #23
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    I wonder if someone used tesseract in MFC ... could point me what I am doing wrong ?

  9. #24
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,774

    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?

  10. #25
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by Arjay View Post
    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 ....

  11. #26
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,464

    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);
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

  12. #27
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by 2kaud View Post
    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 ...

  13. #28
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,464

    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.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

  14. #29
    Join Date
    Jan 2009
    Posts
    263

    Re: Using Tesseract in MFC

    Quote Originally Posted by 2kaud View Post
    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 ....
    Last edited by mesajflaviu; October 3rd, 2018 at 06:46 AM.

  15. #30
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,464

    Re: Using Tesseract in MFC

    You are redefining the symbol DLLSYM.
    Try just

    Code:
    debug_file = "C:\\Flaviu\\test.txt";
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)