Tesseract working with XCode - c++

I wish to use Tesseract with OpenCV on a C++ project (not iOS) I'm working, but I'm unable to get Tesseract to work with XCode. I've added the .dylib files for Leptonica and Tesseract and it works fine, but then I get the following error when I run the APIExample program
read_params_file: parameter not found: save_raw_choices
If I do not add the .dylib files and try adding the header files obtained through Homebrew, I get the following error
Undefined symbols for architecture x86_64:
"tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
tesseractTest() in main.o
"tesseract::TessBaseAPI::End()", referenced from:
tesseractTest() in main.o
I'm a little inexperienced with development in Mac OS X.

I encountered same problem and found only this remark on google groups:
http://code.google.com/p/tesseract-ocr/issues/detail?id=990
Basically, just use different tessdata - e.g. download spanish and set it as language. It would pass that step and show some results. Though they were not splendid in my case but at least you will see it working:).
Then I would recommend asking at the project google group for help...

I had the same problem when I didn't include the tesseract c flags and libraries when compiling.
if you add this to your cflags: pkg-config --cflags tesseract
and this to your libs: pkg-config --libs tesseract
then it should compile.

I know it is an old question but I didn't found anythink online and after hours I solved this issue by adding the line (-ltesseract) to the Build Settings -> Other Linker Flags in xCode

Related

How to compile OpenCV with extra modules on OS X?

I've previously compiled OpenCV 3.0 successfully following this guide, which essentially consists of the following steps:
Download all the prerequisites (XCode, Command Line Tools, CMake and OpenCV source)
Build static libs by configuring CMake (via gui) with:
Uncheck BUILD_SHARED_LIBS
Uncheck BUILD_TESTS
Add an SDK path to CMAKE_OSX_SYSROOT (if it matters, I used /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk).
Add x86_64 to CMAKE_OSX_ARCHITECTURES (emphasis mine, this seems to be the issue, I'm sure I've followed this step)
Uncheck WITH_1394
Uncheck WITH_FFMPEG
Configure and generate via CMake, then make and sudo make install from the CLI.
All of the above alone works fine.
I'm now looking to compile OpenCV with the extra modules. According to their read-me it should be as simple as filling out OPENCV_EXTRA_MODULES_PATH to <opencv_contrib>/modules in CMake and then building as usual.
I followed the steps outlined above with the added parameter and building OpenCV succeeds, however, when trying to use one of the extra modules in a program (namely cv::ximgproc::createStructuredEdgeDetection, if it matters), I'm getting the following error when compiling:
Undefined symbols for architecture x86_64:
"cv::ximgproc::createStructuredEdgeDetection(cv::String const&, cv::Ptr<cv::ximgproc::RFFeatureGetter const>)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've included the header which should include the above:
#include <opencv2/ximgproc.hpp>
I'm compiling via XCode, where I've set an additional header search path of /usr/local/include and a library search path of /usr/local/lib for the project, am I missing something here?
Standard OpenCV functionality works fine.
What could be the issue and how would I go about solving it?
OpenCV contrib modules are built correctly.
You just need to add the contrib libs to your dependencies, in this case adding: -lopencv_ximgproc.
All available libs can be found under <OPENCV_DIR>/install/ folder.
E.g. in my 32bit vc12 static build are in<OPENCV_DIR>/install/x86/vc12/staticlib folder.

MinGW "undefined reference to IMG_Load/IMG_Init/IMG_Quit" LazyFoo

I am going off of LazyFoo's SDL2 tutorials for C++ using the MinGW g++ compiler (using console). I have followed his page here, step-for-step. I have finally come across this error after having downloaded his example.
I have seen plenty of people online struggle with SDL_Image, but I've not yet seen this and I haven't found any solution to it yet.
I've loaded the include and lib folders with the proper assets
I've copied all necessary .dll's to my compile destination
The example LazyFoo provides includes for SDL_Image and SDL itself
(this question my sound redundant, but I've yet to come across a solution that applies to console-compilation)
Based on the comments above, the answer seems to be:
You need to install the development libraries for SDL_image.
You can download them here: https://www.libsdl.org/projects/SDL_image/
(look under the heading "Development libraries").
You need to ensure the path where the libSDL2_image.a file resides is in the linker search path. One way of doing this is to add an appropriate -L parameter to the link command. You could also drop the file in the default library search path.
I've had this problem in linux. the solution is simple.
add to linker:
-lSDL2_image -g `sdl2-config --cflags --libs`
I had the same problem, and the solution was to include the SDL2main library in linker parameters.
For Dev-C++ IDE you can follow the instructions below:
Get SDL or SDL2 working correctly with Dev-C++

install a C++ json library on xcode

I'm very new to xcode and c++ programming so please let me know if I'm going about this all wrong. Basically, I want to create a C++ project that requires a library to deal with making and receiving json calls. (this will eventually be integrating as the 'engine' of an iOs and android app.) I want to use xcode to create this and I tried installing libjson but couldn't get it to recognize. I then tried using JsonCpp and followed the instruction.
1) I downloaded the tar.gz
2) I downloaded the scons python program and in the jsoncpp folder and ran the appropriate command (something like 'python scons.py platform=linux-gcc check')
This created a .a and a .dylib file
Next, i tried to move the files into the project and link it in xcode from 'Link Binary With Libraries' portion of the Build Phases tab in the project settings.
I linked up the code to my file with an include statement:
#include "lib/jsoncpp/json.h"
This led to the following error:
Undefined symbols for architecture x86_64:
"Json::Reader::parse(std::__1::basic_string, std::__1::allocator > const&, Json::Value&, bool)", referenced from:
jsonParser::parseLogin(std::__1::basic_string, std::__1::allocator >&, std::__1::basic_string, std::__1::allocator >&) in jsonParser.o
ld: symbol(s) not found for architecture x86_64
(null): "Json::Reader::parse(std::__1::basic_string, std::__1::allocator > const&, Json::Value&, bool)", referenced from:
All I am trying to do is set up this library but It has been keeping me from working on my code for the past day looking for a solution.
For the libjson library, I tried following the directions here but with similar issues:
Cannot Install libjson in c++ Embedding in XCode 4 Project
Does anyone have any advice on steps I can take to set this up? Thank you for your time.
In the project navigator (left side of XCode), click above your project. Then:
Build Phases -> Link binary with libraries
Here is where you add all libraries and/or frameworks that will be linked to your application. Leave this page open, then drag and drop the libraries inside the libraries area... that's it! no secret!
If it doesn't work. You are probably with a wrong library. Try lipo -info library to check if the library architeture is the same you are trying to use (x86_64 in this case).
If it still doesn't work. You are probably with C++ incompatibility. Any mixing of libstdc++ and libc++ in builds will cause trouble. All C++11 code built with clang should set an environment variable: CXX=clang++ -std=c++11 -stdlib=libc++, or add CXX="clang++ -std=c++11 -stdlib=libc++" as an argument to configure.). If you compiled libjson via command line, check it again. But, for libJSON, it's much easier if you open a new XCode Project and add the files to the project instead of compile it via command line.
In the end, I tried just copying the entire source project into my xcode project and building it. it ended up solving the issue.
This is How I solved the issue:
download libjson from sourceforge
unzip it.
-
move the _internal folder, libjson.h, and JSONOptions.h into the
xcode project folder
add those files to your xcode project
remove the test suite files from this project as you don't need them
build your main to test it and you should be good to go.

openCV undefined symbols _cvCvtColor

I know similar questions has been posted but the solutions I found haven't worked at all for me.
I'm using XCode 4.5 and openCV 2.4.3. I built the library from source, I have the compiler set to LLVM GCC 4.2 and whenever I try to use cvCvtColor(), I get the following error message:
Undefined symbols for architecture x86_64:
"_cvCvtColor referenced from:
_main in main.o
Any insight would be greatly appreciated!
I found the problem and I'm kicking myself. It turns out I didn't import a particular library (libopencv_imgproc to be specific) that cvCvtColor() was on.
In Terminal, "cd" to the directory that contains your OpenCV library (or actually libraries, as I see a few of them are built when I look at this "how to build OpenCV tutorial") and then type in this command:
"nm -arch x86_64 _________.a" (fill in the name of the library where the underscores are)
This dumps out all the symbols of the library. You can egrep or search for "cvCvtColor".
My guess is that you've built OpenCV for 32-bit only (and this will be easy to see if you get absolutely no symbols when specifying "-arch x86_64" in the "nm" command) and that you need to also build your OpenCV libraries for 64-bit (x86_64).

Linking Libraries in Xcode

I'm using a powerbook (osx 10.5) and recently downloaded and installed FFTW 3.2 (link text). I've been able to compile and run some simple programs based on the online tutorial using the terminal:
g++ main.cpp -lfftw3 -lm
However, I can't get the same program to compile in Xcode. I get a linking error, "symbol(s) not found". There is a file called libfftw3.a in /usr/local/lib. How can this be linked? Furthermore, apparently the libraries have to be linked in a particular order, i.e. see: link text
thanks for any help
To link to a .a library like this in Xcode you need to:
Double-click on your target or application in Xcode to open the Info window
Switch to the "Build" tab
Add -lfftw3 to "Other Linker Flags" (under "Linking")
Add the path to your library to the "Library Search Paths" (under "Search Paths"). In your case this will be /usr/local/lib
We use FFTW (it's great by the way), this works for us!
Did you set these options for the target?
Under "Linking->Other Linker Flags" add: "-L/path/to/library -lfftw3 -lm"
warning in /Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libfftw3.a, file is not of required architecture
Maybe the binary format was different e.g. the library could be 32 bit while the application 64.
OK - I finally got this working. I also needed the the GNU Scientific Libraries and ran into similar issues with the architecture setting. For anyone interested, this tutorial goes through how to set up Xcode and link libraries:
https://web.archive.org/web/20101006023300/http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31