Tesseract-OCR 3.02 with libc++

∥☆過路亽.° 提交于 2019-12-03 10:17:30

问题


Xcode 4.6, iOS SDK 6.1, tesseract-ocr 3.02

Since the last OpenCV versions are built using libc++, and tesseract-ocr is built using libstdc++, they can't be used together in one xcode project.
So, I'm trying to build tesseract using libc++. Using the script here (updating the base sdk and deploy target to 6.1), tesseract is being built just fine, and works in my xcode project once the C++ standard library is set to the compiler default. Than, I tried altering the script to build it with libc++, according to the answer here. I changed CXX to point to clang++, and added -stdlib=libc++ to the CXXFLAGS.
The result is that the script succeeds, and the libraries are built, but when choosing libc++ as the C++ standard library in xcode, I'm getting a lot of linker errors and the project build fails. The new libraries still work when the standard library is set to the compiler default (just like when it was built regularly).

What am I missing?


回答1:


Ok, so my problem was that after adding and removing references to libraries a few times in my project, I had quite a mess in my Library Search Paths. Plus, I didn't add the new "include" folder (created when building tesseract) to the User Header Search Paths.

So, just a quick recap, in order to build tesseract-ocr using libc++, so it can work along with newer OpenCV versions:

  • Download leptonica-1.69
  • Download tesseract 3.02
  • Arrange them in the folder structure explained in the original tutorial here
  • Download this script to the same folder.
  • Edit the script for your relevant IOS_BASE_SDK and IOS_DEPLOY_TGT.
  • Edit CXX to use clang++: CXX="/usr/bin/clang++"
  • Edit CXXFLAGS to use libc++ as the standard library: CXXFLAGS="$CFLAGS -stdlib=libc++"
  • Use the script and build tesseract and leptonica.
  • Add these libraries to your xcode project, change the "C++ Standard Library" setting to libc++.
  • Make sure your "Library Search Paths" setting is not pointing to any old tesseract libs.
  • Make sure your "User Header Search Paths" setting is pointing to the new "include" folder created when you built the new libs.
  • Now, when you try building your project, you'll have a few missing header files. Just copy them from the old "include" folder from tesseract and leptonica.

That's it. At this point, you'll have a project capable of using both new OpenCV versions AND tesseract 3.02 together. If it's a new project, don't forget to edit your prefix file accordingly to include OpenCV and Tesseract in case of __cplusplus, and rename any .m file using them to .mm

Big thanks to to this answer, that got me well on my way.




回答2:


Tsseract-OCR-iOS has been updated to handle this issue (working in the same project as a libc++ compiled project e.g. OpenCV). Don't forget these steps when installing it:

If you are using iOS7 or greater, link libstdc++.6.0.9.dylib library (Your target => General => Linked Frameworks and Libraries => + => libstdc++.6.0.9)

Go to your project, click on the project and in the Build Settings tab add -lstdc++ to all the "Other Linker Flags" keys.

*Go to your project settings, and ensure that C++ Standard Library => Compiler Default. (thanks to https://github.com/trein)

Copy and import the tessdata folder from the Template Framework Project under the root of your project. It contains the "tessdata" files. You can add more tessdata files copyng them here.

*I had to set the C++ Standard Library to "libc++" in order for OpenCV to compile.



来源:https://stackoverflow.com/questions/16323316/tesseract-ocr-3-02-with-libc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!