Sunday 25 March 2012

Android OCR tutorial - image to text

This tutorial will show how to use and implement OCR library (tesseract) in android application. Tesseract is open source library for OCR originally developed by HP.

1. Download tesseract library for android https://github.com/rmtheis/tess-two/downloads. Download as .zip for
    windows, as .tar.gz for linux user.

2. Software requirement
    - Eclipse
    - Java JDK
    - Android SDK
    - Android NDK
    - Cygwin ( for windows users)
    - Apache-ant
3. For windows user, make sure you already installed cygwin ( you can download it  and install it from http://www.cygwin.com/ make sure during the cygwin installation, install also these source and library gcc-core, gcc-g++, make, swig)

4. Download apache-ant from http://ant.apache.org/bindownload.cgi choose .zip for windows, .tar.bz for linux user.

5. Unzip the apache and set the environment variable (mine is C:\apache-ant-1.8.3\bin)


6. Run cygwin (for windows user only,for linux user,run terminal)
     a.cd <project-directory>/tess-two
     b.export TESSERACT_PATH=${PWD}/external/tesseract-3.01
     c.export  LEPTONICA_PATH=${PWD}/external/leptonica-1.68
     d.export LIBJPEG_PATH=${PWD}/external/libjpeg
     e.ndk-build(for windows user, /cygdrive/<ndk-directory>/ndk-build)
     f. android update project --path . (for windows user, sometime cygwin cannot execute this command, so
        use command prompt to execute this command).
        Note: The “.” after --path must be included in the command.
     g. ant release ( sometimes you will get error like java tools.jar not found, set environment variable
         JAVA_HOME to the jdk folder, mine is C:\Program Files\Java\jdk1.7.0)

7. Run Eclipse. Right click on package explorer, import>> General >> Existing Project into Workspace >> 
    Next >> Select Root Directory >> Browse the tess-two folder location >> Finish.
    You will see tess-two folder in your package explorer.
    
8. Right click on the project >> Android Tools >> Fix Project Properties. Right click >> Properties >> 
    Android >> Check Is Library. 
    Download the simple OCR android app from https://github.com/GautamGupta/Simple-Android-OCR.
    Right click on package explorer, import the simple OCR android app folder.

9. Right click on the project >> Android >> Add >> click tess-two >> OK
   
10. Run the app. Good luck



References
[1] http://gaut.am/making-an-ocr-android-app-using-tesseract/
[2] http://ant.apache.org/bindownload.cgi
[3] http://wolfpaulus.com/journal/android-and-ocr
[4] http://rmtheis.wordpress.com/2011/08/06/using-tesseract-tools-for-android-to-create-a-basic-ocr-app/
[5] https://github.com/rmtheis/tess-two


Android NDK tutorial (JNI)

JNI stands for Java native interface that enable Java to use Native application or library such as C/C++ or assembly in Java application.
1. Before following this tutorial, all those software should be installed and downloaded first :

a) Eclipse
b) Android SDK
c) Android NDK
d) Cygwin (for windows user)

2. Create new project. Then create ‘jni’ folder in project file
3. Edit .java file to integrate with JNI
4. Create “hello-jni.c” in “jni” folder (right click on “jni” folder>>new>>File
5. Paste source code as shown (make sure package name is correct: mine use “com.example.hellojni”) in 
    this .c file, jstring 
    - Java_com_example_hellojni_HelloJni_stringFromJNI (red:package,purple:java class that jump to
       .c file, blue: function name in java class)

6. Under “jni” folder, create “Android.mk” file. (same procedure as created .c file)
7. Native Compilation
    - Use cygwin to compile native part ( go to project folder using cygwin command line and type file path
      for ndk-build in android-ndk)
    - If the compilation with no error, it will generate .so file
8. Run (running on galaxy y)

XNA 4.0 installation tutorial

1. VS 2010 installation
    - Download and install visual studio 2010 (skip this step if you already install visual studio 2010)
    - For students, you can easily download vs 2010 from https://www.dreamspark.com/ - use your student
       email or hotmail email to create dreamspark’s student account. You will be able to download many
       windows software for free. You can download vs 2010 from this website

2. XNA installation
    - Download and install xna 4.0 from this site http://www.microsoft.com/download/en/details.aspx?id=23714
    - After the installation, start visual studio 2010
    - Make sure your XNA is linked with vs 2010 File>>New>>Project..>>Other Languages>> Visual
       C#>>XNA Game Studio 4.0.


3. Now you can start developing your own game... Good Luck~!

Thursday 22 March 2012

Android starter tutorial

1. Download and install java JDK
    http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3-download-1501626.html

2. Download Eclipse ( I prefer classic version)
    http://www.eclipse.org/downloads/

3. Download Android SDK (choose .zip file)
    http://developer.android.com/sdk/index.html

4. Run Eclipse and choose path for the workspace
5. Close the "welcome" window
6. To link with Android, click Help>> Install New Software..

7.  Click “Add” and for the name, type “ADT Plugin”, for the Location, type https://dl-ssl.google.com/android/eclipse/ then click “Ok”.

8. Choose work with : ADT Plugin that we already add before, and install the Developer Tools. Proceed the installation.

9. Unzip Android SDK
10. Go back to eclipse, Window>>Preferences>>choose the android sdk folder that had been unzipped before
11. After Android platform had been installed, the Android icon will be appeared at the top
12. Click Android SDK Manager button
13. Choose the Android version you want to install. (It will take more than an hour to install all versions)  
14. After the installation, Click AVD Manager button
15. Click New, put your virtual device name, target. Click create AVD.
16. Choose the virtual device that you’ve created and click start>>Launch.
17. Wait for the emulator to launch (depends on your processor, it will take a few minutes)
18. Simple App - HelloWorld Android
Do not close the emulator, File>> New >> Android Project(If Android Project does not appear, click   Project..>>Android>>Android Project)

19. Put Project Name, for the build target, it depends on your emulator. Mine is Android 2.2

20. Put the Package Name. (ex : com.hello.android, every project should have different package name) and click finish. The project will be in the package explorer.

21. Adding element on xml . Go to main.xml under res>>layout>>main.xml

22. Add button on the layout (drag the button and place it in the layout or you can put xml code to add button)
23. Give an id for TextView ( you can put your own suitable id, mine is “textview1”, also erase the android:text=“”)
24. Click to the .java code
25. Add click listener to perform activity when the button is clicked
26. Run the code(Click run button), run as Android Application

27. The result as shown, after you click the button, the words will come out.
28. Run on device. Make sure your Android device have been installed its driver on your computer. Connect your device to your computer. (Make sure your device in usb debugging mode: on your android device, go to settings>>Application>>Development>>tick to USB debugging)
29. Go to android sdk folder>>tools>>ddms. If it detect your device, you will see your device on the ddms. 

30. Close the emulator. Run the code once again.

That's all... Easy rite?..