Configure CodeBlock With OpenCV

CONFIGURE CODEBLOCK WITH OPENCV
ref:http://jonniedub.blogspot.co.id/2013/01/setting-up-codeblocks-ide-for-use-with.html?showComment=1454444260714#c506464558721086998
http://blog.csdn.net/mummyding/article/details/49804921
1. Create new project:
File -> New -> Project…-> Find ‘OpenCV Project’ -> click ‘Go’ -> Next -> Write Project Title and the Path ->
Compiler: GNU GCC Compiler -> Finish

2. Default opencv template (main.cpp in /Sources/ directory) is created. Here is main.cpp:

3. Its time to configure this project so it’d be linked to opencv library.
From eclipse configuration above, we get the libraries path by using:
pkg-config –cflags opencv
pkg-config –libs opencv
We’ll do the same here:
a. Right click the Project Name ‘OpenCV’ -> Build Options -> Click the Project name (OpenCV) DO NOT the ‘Debug’ ->
Search directories tab -> Compiler tab -> click Add -> fill with: /usr/local/include/opencv
b. then click Linker tab -> click Add -> fill with: /usr/local/lib
c. Then at Linker settings tab -> In Link Libraries, Add this (one by one):
opencv_core
opencv_imgcodecs
opencv_highgui

In Others linker options:, add:
opencv-config --ldstaticflags

d. click OK

4. Test it!
Right click the Project name ‘OpenCV’ -> Build
make sure everything okay
Then click ‘Run’ (the green arrow) or from Build -> Run
SHORTCUT: F9 (Build and Run at ONCE!)

Configure Netbeans C++ With OpenCV

CONFIGURE NETBEANS C++ WITH OPENCV
ref: http://www.technical-recipes.com/2015/configure-netbeans-to-use-opencv-in-linux-environments/
1. Create C++ Application Project
File->New Project->C/C++ ->C/C++ Application->Next->’Give it the Project name and the location’ AND CHOOSE C++11->Finish

2. Configure the compiler:
Right Click The project->Properties->Build->C++ Compiler->’Include Directories’: /usr/local/include/opencv ->Apply

3. Add the opencv libraries:
Right Click The project->Properties->Build->Linker->’Additional Library Directories’: /usr/local/lib ->Apply
Right Click The project->Properties->Build->Linker->’Libraries’: Add -> Click Add Library THEN GO TO /usr/local/lib ->CLICK (SIMULTANEOUSLY) libopencv_core.so, libopencv_highgui.so, libopencv_imgproc.so, libopencv_imgcodecs.so
OK

NOTE: TO SHOW VIDEO CAPTURE, ADD libopencv_videoio.so
4. Test
in main.cpp:

BUILD & RUN:
OPENCV VERSION: 3.1.0

RUN FINISHED;

exit value 0;

real time: 0ms; user: 0ms; system: 0ms
SHOW IMAGE main.cpp:

 

VIDEO CAPTURE main.cpp (add linker libopencv_videoio.so) :

 

Configure Eclipse With C++ And OpenCV

CONFIGURE ECLIPSE WITH C++ AND OPENCV
ref:http://rodrigoberriel.com/2014/10/using-opencv-3-0-0-with-eclipse/
1. Assumed eclipse and cdt (C++ Development tools) already installed. if not, pls follow this:

a. Install C++ Development (CDT):
ref:https://eclipse.org/cdt/downloads.php
Help -> Install New Software -> Add… ->
Add Repository form:
Name: C++ Development Tools
Location: http://download.eclipse.org/tools/cdt/releases/8.8.1 (CDT 8.8.1 FOR ECLIPSE MARS)

b. Check All and Install

2. Creating a New C++ Project on Eclipse
a. File » New » C++ Project;
b. Give a name to your project in Project Name; for example: TestOpenCV
c. Choose Executable » Empty Project in Project Type;
d. Check Linux GCC in Toolchains and press Next;
e. Click on Finish;

3. Linking OpenCV to the newly created project
a. Select the project and go to the menu Project » Properties (or press Alt+ENTER);
b. We’re going to modify somethings on Tool Settings tab of C/C++ Build » Settings;
c. In GCC C++ Compiler » Includes, add “/usr/local/include/opencv” in Include paths (-l). Discover the correct path by typing the following on the terminal: pkg-config –cflags opencv;

d. Go to GCC C++ Linker » Libraries and add “/usr/local/lib” in Library search paths (-L). Discover the correct path by typing the following on the terminal:: pkg-config –libs opencv;

e. Still in GCC C++ Linker » Libraries, add the libraries you’ll need in your project in Libraries (-l). We’re going to need 3 to our project (don’t forget to link opencv_imgcodecs, since imread() has moved to it in OpenCV 3):
opencv_core
opencv_imgcodecs
opencv_highgui

Done!

4. Lets test it!
a. Right-click on the project in Project Explorer and go to New » Folder;
b. Give a name to the folder, for instance: src.
c. Right-click on the src folder and go to New » File;
b. Give a name to the file, for instance: DisplayImage.cpp and type (or copy and paste) the code snippet below. Don’t forget to save the file.

Project » Build All (or Ctrl+B) to build;

5. Run the program
a. Right-click on the project in Project Explorer and go to Run As » Local C/C++ Application
b. The image should be appeared!!!

Installing Tesseract OCR on Ubuntu 14.04

Reference: https://github.com/tesseract-ocr/tesseract/wiki/Compiling
http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html

Compilation:

  1. clone the package from github
  2. Go to the new dir
  3. autogen
  4. configure

    Here i can’t configure it correctly because it always complained about leptonica 1.74

    I already did

    But the error still persist!
    SOLUTION: I HAVE TO COMPILE AND INSTALL LEPTONICA 1.74 MANUALLY (READ: http://myprojects.advchaweb.com/index.php/2017/02/02/installing-leptonica-1-74-1-on-ubuntu-14-04/)
    NOW IT SUCCESS!

     
  5. Since we have to compile leptonica to use version 1.74, we should use LDFLAGS=”-L/usr/local/lib” CFLAGS=”-I/usr/local/include” make instead of make for Tesseract.

     
  6. make install

     
  7. sudo ldconfig

     
  8. Make training

     
  9. Install the training

    For the training tutorial, pls read: https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00 (OR https://github.com/tesseract-ocr/tesseract/wiki/Training-Tesseract for older tesseract version). It says it use neural network-based recognition engine. ALSO “Tesseract 4.00 takes a few days to a couple of weeks. Even with all this new training data, you might find it inadequate for your particular problem, and therefore you are here wanting to retrain it.”. IT’D TAKE A FEW DAYS – WEEKS??? IT SEEMS SAME WITH TRAINING OPENCV. IF I HAVE PLENTY OF TIME I CAN DO THAT. ACTUALLY IT’S INTERESTING!
  10. For visual debugging, build ScrollView.jar

    Export ‘SCROLLVIEW_PATH’:

     

     

  11. Install Language
    For example to install english and many other files, pls see https://github.com/tesseract-ocr/tesseract/wiki/Data-Files. I downloaded english language https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-3.02.eng.tar.gz/download.
    <OLD>Then extract the zip file ‘tesseract-ocr-3.02.eng.tar.gz’. then move all files in /tesseract-ocr/tessdata/ to /tesseract/tessdata/
    DONT FORGET TO POINT OUT ‘TESSDATA_PREFIX’!

    </OLD>
    <NEW>It’d be much better to copy/move the ‘tessdata’ directory into /usr/local/share/tessdata/ than copy/move them into /cpp/tesseract/tessdata/ above (the OLD> because we dont have to type ‘export TESSDATA_PREFIX…’ everytime we need to scan an image. I did this after did the old one

    </NEW>
    AT FIRST I FORGOT ABOUT THIS. WHEN I DID A TEST, HERE IS THE MESSAGE
  12. Check tesseract version (with -v or –version)

     
  13. Test!

    Here is the image source (‘phototest.tif’) And here is the result in /tesseract/output.txt

    NOTE : IT BETTER TO NOT USE FILENAME WITH HAS SPACE BECAUSE TESSERACT CAN’T FIND IT!
    ALSO USE IMAGE WITH HIGH RESOLUTION! OR WE CAN DO THE TRAINING STUFF (IF WE HAVE PLENTY OF TIME!!!)
    OTHER TESTS

    BUT I FOUND THE RESULT STILL NOT GOOD!!! MANY WEIRD CHARS, SPELLING MISTAKES,ETC
    ANOTHER TEST WITH COMMAND TERMINAL:

    Display the result in the terminal:

    open the original image so we can compare it

     
  14. Question: Can we use tesseract to read/scan pdf file?
    pls read: http://kiirani.com/2013/03/22/tesseract-pdf.html
    http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/
    http://stackoverflow.com/questions/30925218/converting-a-pdf-to-text-using-tesseract-ocr
    TESSERACT CAN’T DO THIS DIRECTLY. IT SAID TO CONVERT THE PDF TO TIFF IMAGE FIRST! ALSO THE MULTI PAGE PDF NEED TO BE CONVERTED TO MULTI TIFF FILES! READ http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/ TO SEE THE SCRIPT TO DO THAT!

Installing Leptonica 1.74.1 on Ubuntu 14.04

Reference: http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html
http://www.leptonica.org/download.html

  1. Download the newest leptonica version (1.74.1) here : http://www.leptonica.org/source/leptonica-1.74.1.tar.gz
    I use wget:


     
  2. Extract the zip file
  3. Go to the new created directory (leptonica-1.74.1) then configure

     
  4. make

     
  5. Because my machine didn’t have ‘checkinstall’, install it first

     
  6. Create the package with ‘checkinstall’

     
  7. Then execute ‘sudo ldconfig’