Not able to compile tesseract with opencv and qt

1,346 views
Skip to first unread message

Giseli Ramos

unread,
Mar 14, 2014, 7:22:41 AM3/14/14
to tesser...@googlegroups.com
I'm trying to compile my project in Qt that uses tesseract and opencv. In the .pro file:
INCLUDEPATH += /usr/local/include/tesseract
INCLUDEPATH += /usr/local/include/leptonica
LIBS += -ltesseract -llept

The errors (I only past the first lines, because is a big list, all from tesscallback.h):

In file included from /usr/local/include/tesseract/baseapi.h:31:0,

from src/utils/ocrReader.cpp:6:

/usr/local/include/tesseract/tesscallback.h:278:29: error: 'remove_reference' is not a template

/usr/local/include/tesseract/tesscallback.h:278:29: error: redefinition of 'struct remove_reference<T>'

/usr/local/include/tesseract/tesscallback.h:277:29: error: previous definition of 'struct remove_reference<T>'

/usr/local/include/tesseract/tesscallback.h:296:12: error: expected nested-name-specifier before 'remove_reference'

/usr/local/include/tesseract/tesscallback.h:296:12: error: expected ';' at end of member declaration

/usr/local/include/tesseract/tesscallback.h:296:28: error: expected unqualified-id before '<' token


What is strange is that I have compiled with sucess with another simple qt project to test tesseract funcionality, with the same config in the .pro file. I don't know why this project in particular is having issues. 

zdenko podobny

unread,
Mar 14, 2014, 8:31:19 AM3/14/14
to tesser...@googlegroups.com
You will need to provide more information (e.g. tesseract version, compiler and its version, basic OS info) and maybe full test case (you was able to install/compile tesseract on your system, so there must be problem in your project why you are not able to use tesseract library). If your project is online available, please send link to it.

Zdenko


--
--
You received this message because you are subscribed to the Google
Groups "tesseract-ocr" group.
To post to this group, send email to tesser...@googlegroups.com
To unsubscribe from this group, send email to
tesseract-oc...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/tesseract-ocr?hl=en

---
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giseli Ramos

unread,
Mar 14, 2014, 1:43:42 PM3/14/14
to tesser...@googlegroups.com
Ok, I'm using Linux Mint 14 (cinnamon)
Tesseract from svn code revision 1054 (last fetched 13 Mar)
Leptonica 1.70
g++ 4.7.2
Qt 4.8.4 (Qt Creator 2.8.0) 
Using OpenCV 2.4.8, c++11 and boost lib.

At the moment, I can't paste the project here. Later, I will try to create a simple test case, but I suspect that it will compile because is simple...

The redefinition problem with templates could be a problem with using the boost and c++11?

Giseli Ramos

unread,
Mar 14, 2014, 2:11:38 PM3/14/14
to tesser...@googlegroups.com
I'm sending a test case that reproduce the problem. 
testCase.tar.gz

zdenko podobny

unread,
Mar 14, 2014, 5:58:57 PM3/14/14
to tesser...@googlegroups.com
It looks like "#include <opencv2/core/core.hpp>" cause problem for tesseract in case of c++11... 

As quick fix it looks like putting "#include <tesseract/baseapi.h>" above that line should be sufficient.

Maybe somebody with more time/experiences in c++11 should do deeper investigation of this.

Zdenko

Giseli Ramos

unread,
Mar 17, 2014, 6:00:28 AM3/17/14
to tesser...@googlegroups.com
That is weird... well, I have tried to put the include before anything, not resolved the problem.

I will try to compile the project without c++11 and see what happens. 

zdenko podobny

unread,
Mar 17, 2014, 1:51:46 PM3/17/14
to tesser...@googlegroups.com
It looks like I was too quick with my findings... :-(

First of all - to make clear my previous post: I removed tesseract include from ocrRead.cpp to ocrRead.h (see attached file) and I was able to compile your test case. If I did not change your test case - it fails as you described. 

Next: I tried to dig in the problem and I found out problem is not in opencv... There is easy fix - just do not use "using namespace std;"[1] or use it after including tesseract header files...


Zdenko
ocrReader.h

Giseli Ramos

unread,
Mar 20, 2014, 6:59:31 AM3/20/14
to tesser...@googlegroups.com
I have tried what you suggested, but it still not working. Maybe because of the lots of dependencies of the project (many includes in various files). 
I think that clearing everything of the namespace it will compile. I will take some time to clean all.

Anyway, thanks a lot for the help! 

Deepak Kumar

unread,
Aug 22, 2014, 7:53:47 AM8/22/14
to tesser...@googlegroups.com
Tesseract header tesscallback.h file reports error due to redefinition of remove_reference. This remove_reference is a template and defined in std. 

To overcome this problem, I have commented out definition lines in tesscallback.h file and replaced remove_reference string with std::remove_reference in other places of the file. There are six occurrences of remove_reference string after definition.

After making these in changes tesscallback.h file, the compilation is normal.

zdenko podobny

unread,
Aug 22, 2014, 3:24:51 PM8/22/14
to tesser...@googlegroups.com
Did you get this error with "using namespace std;"?

Zdenko


--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.

Deepak Kumar

unread,
Aug 25, 2014, 10:35:56 AM8/25/14
to tesser...@googlegroups.com
I got this error when I tried to include threading in my project. I came here to get solution for the similar problem. I had used "using namespace std;"  I commented "using namespace std;" and then also the problem was not resolved. While compiling, I had included the two flags -std=c++0x and -pthread. I think, the threading related problem may have resolved with pthread flag.

Here is a link which says the inclusion of remove_reference in std since c++11: http://en.cppreference.com/w/cpp/types/remove_reference 
I thought that the problem is due to the updated version of c++ standard, which has predefined remove_reference in std, used during compilation. When compiler has definition for remove_reference in std, then the redefinition in tesseract_callback.h was causing the error. I commented the redefinition in tesseract_callback.h file and made reference to std wherever remove_reference was called in the file. The compilation was normal. The result was same when executed. The problem was resolved.

I uncommented the line "using namespace std;" and removed the modifications made to call the std functions. I could compile and run the program.
Reply all
Reply to author
Forward
0 new messages