Android OCR Application Using Tesseract - android

I am currently developping an android application based on OCR (Optical Character Recognition). I've downloaded the "tesseract- android" project that contains tools for compiling the Tesseract, Leptonica, and JPEG libraries for use on Android. I am developping via Eclipse on Windows Vista OS.
I've also downloaded the necessary tools (android-ndk;apache ant..), and I've done carefully all the steps to build this project and add it as a library to my basic application.
My app consists of opening the camera for taking a picture and then processing this picture via tesseract API in order to transform it into text.
My question is:
1. Is it true that this procedure doesn't work under Windows OS?
2. When compiling, I am having the following error:
"java.lang.IllegalArgumentException: Data path must contain subfolder tessdata!"
What could be the potential error? The concerned portion of the java code is:
File myDir = getExternalFilesDir(Environment.MEDIA_MOUNTED);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(myDir, "eng");
I've also tried to use "/tess-two/external/tesseract-3.01/tessdata/tessconfigs" instead of "myDir", but the error remains the same.
I would highly appreciate any help.
Thanks in advance.

Q1. It should work on any operating system, I've been able to ndk-build on Win7, Mac OS Lion, and Ubuntu without any issues.
Q2. Make sure that you have permissions to write to the external storage, and have sufficient space to do so.
If that still fails, have a look at the DDMS and see the file explorer and double check your application is setting up the directory structure and copying over the traineddata.
I had an odd issue where it was creating the eng.traineddata file, but it was 0 bytes which led to all sorts of odd issues.
You could also create the directory structure manually to get you progressing, and fix this initialisation issue later on (but don't forget it!)

I was facing the same problem. Worked for me when I removed "tessdata" from the path.
Before (fail): path = "/mnt/sdcard/tesseract/tessdata";
After (success): path = "/mnt/sdcard/tesseract/";
Then, baseApi.init(path, "eng") worked with no exceptions.
Of course, tessdata folder should be in the path with the desired.traineddata file.

Path errors while compiling native stuff usually is not related with your java code. Your java code would be responsible for runtime problems. Check your build scripts and post more log messages.

Related

How to download a file from FTP and store it locally with Cordova?

I'm struggling for some days to do that. Without success.
I've found two ways that I think reasonably to follow:
1: Plugin cordova-sftp-plugin.
I see that it is writted to deal with 'secure ftp', but why wouldn't work in an ordinary non secure ftp? Nothing was metioned about it.
I've tried so, applying the 'Use Example' from the official page, the code fells in the success callback function, but when I list the local directory, nothing was changed! It gives me no clue about what goes wrong! In true, the software does not detect nothing wrong.
Before the previous steps, I did not forget to precautionally install and enable the 'cordova-plugin-file', 'cordova-plugin-file-transfer' and 'cordova-plugin-network-information' and to add the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in the AndroidManifest.xml. Tryied to save files in cordova.file.externalRootDirectory and cordova.file.externalRootDirectory + "/Downloads/. Nothing worked.
2. The macdonst FtpClient plugin.
Searching for my issue, one of the first pages that appears is How to ftp a file over to a server from PhoneGap/webapp?, and beyond some further search I've found another one in a relatively old post mentioned the successful use this plugin in a Cordova application. So I can consider this plugin as a stable choice.
The problem with this method comes earlier: I coundn't even build the application after a manual installation proccess. May it is a problem in the manual installation proccess.
The official plugin documentation teachs to install it in a PhoneGap application, and not a Cordova. The steps was not replicable to Cordova, due to some differences in paths and configuration, and some others links also supports the plugin installation solely in Phonegap, not Cordova.
I also tryied follow the steps in the http://antonylees.blogspot.com.br/2015/01/how-to-manually-add-cordova-plugins-to.html and Manually install Device plugin (and others) into cordova 3.0 to manually add the plugin. The steps in the first link also was not well replicable, and although the second one are more straitfoward, also does not solved the issue.
Building it gives me a java error compilation. The first error output (what uses to cause all the following errors are):
E:\danilo\Documentos\projetos_cordova\ftpDownload3\platforms\android\src\com\phonegap\plugins\ftpclient\FtpClient.java:27:
error: package org.apache.cordova.api does not exist
import org.apache.cordova.api.CallbackContext;
Very strange. May I have to search for the org.apache.cordova.api jar file and put in the lib folder? Also, I did not forget to put the commons-net-2.2.jar in the project libs folder.
Can anyone have some suggestion to succeed this? I just want to download a file through ftp protocol and save locally and so, if there's an alternative method to succeed, it will be appreciated too.
Thanks in advance.

Error: File path too long on windows, keep below 240 characters

So, I made some changes to my build.gradle(app) file and android studio gives me this error (open the image in new tab for better viewing):
My build.gradle(app) file (this is not the edited file, I deleted new lines of code and still no luck/solution.):
Everything was quite working well until I made some changes in the build.gradle(app) file, but then I deleted those new lines of code and android studio is still keep giving me the error.
The error relates to the compile 'com.google.android.gms:play-services:8.3.0'.
I have tried deleting/renaming those png images inside the stated folder,but then when I rebuild the project, the png images are automatically downloaded.
My build.gradle(project) file contains classpath 'com.android.tools.build:gradle:1.5.0'. I want to know what causes this error, and how to fix it? Many thanks.
You could also try changing your build directory for your project since that is where most of the path issues will arise. In your root build.gradle file
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
...
}
}
Android Studio will pick up on the change and still show your new build location in the Project view. It's a lot easier than moving your entire project.
EDIT
While Windows 10 Insider Preview now offers the ability for allowing for longer file path limits these limits currently are only actually accessible to apps which have specifically enabled support for longer file paths.
At the current time, it appears that these applications with the extended path enabled seem to be only apps that are installed via the Windows Store.
At the current time, Gradle does not and potentially cannot have this option enabled to utilize the enhanced NTFS file path length.
I just ran into the same issue. I don't know a fix for your exact problem, but I found a work around; I see your project has a deep file path hierarchy. Why not just move your project up from a lower level?
Ex: C:\Projects\YourProject
That fixed the problem for me.
Cause of problem : 'C:\users...\commom_google_signin_btn_text_dark_normal.9.png' icon path length is greater than 240 character which exceeds Maximum File Path Length Limitation of Windows OS.
Solution is : Move your project into top directory like 'C:\your_project' or reduce length of your project name.
Here is windows path limit chart
As a very solid alternative to actually moving the project I'd suggest using a hard link. The syntax of that would be like this
mklink /J C:\AndroidProjects\ProjectName C:\MyVeryVeryVeryVery…VeryVeryVeryLongPath\ProjectName
Now you can work on your project in C:\AndroidProjects\ProjectName, and have the changes right where your project is supposed to be.
I agree with Vladimir Dimov answer.
You must choose the short path for your project as it is mentioned that the file path should be below 240 characters on Windows.
This link helps me out : http://www.feelzdroid.com/2016/01/android-studio-error-file-path-too-long-windows.html
As an addition on lodock's answer, you can use a hash on the project path if you have lots of projects with the same name:
import java.security.MessageDigest
def hashString(String s){
MessageDigest.getInstance("SHA1").digest(s.bytes).encodeHex().toString()
}
allprojects {
buildDir = "C:/AB/${hashString(projectDir.getAbsolutePath())}"
}
Shortening project paths is really a bit of a hack, Ivan Neeson's response seems the way forward.
If you are lucky enough to be using Android Studio then you will see a useful error message about file length.
If however you hit the same issue doing a command line ionic build all you will see if some kind of crunch error for a png file and it's not so obvious.
The real issue is Google Play Services having such extravagant filenames such as common_google_signin_btn_text_light_normal_background.9.png which is simply not Windows friendly. Dump that inside an Android build and the path explodes outside our control to platforms\android\build\intermediates\exploded-aar\com.google.android.gms\play-services-base\10.2.1\res\drawable-xhdpi-v4\common_google_signin_btn_text_light_normal_background.9.png
Have look at this http://feelzdroid.com/2016/01/android-studio-error-file-path-too-long-windows.html. Solution is too simple keep path of folder less then 240 characters.
Make sure you will have less then 240 charters in the path
I found this issue when I have two repeated folder in same like,
E:\project-one\project-one
and when it has a large length of folder name like,
E:\project-one-with-very-big-name
To avoid this problem make a folder of project simple and short.
You Should Have To Keep Your Project Directory As Less Deep As Possible
For Example:-
D:/AndroidWorkSpace/ProjectName
Because Gradle Support Only 240 Character length of Project Path
Thanks
You can use NTFS junction point to create shorter path to your project.
To read more about Junctions read this :
Hard Links and Junctions
A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories, and a junction can link directories located on different local volumes on the same computer. Otherwise, junctions operate identically to hard links
For Windows users:
You might be tempted to create a network share to the project root folder and then map to it. This technique will shorten the overall path length but will cause problems for Android Studio due to the difficulty in detecting modified files. A better solution is to use the windows subst command. Here is an example script to circumvent the problem. Tweak names as necessary and modify to point to your project and install directories.
File: launchAS.cmd
subst P: "C:\private\java42\ide\42g\workspaces\AndroidStudioProjects"
cd "C:\private\java42\programs\android-studio-base\bin"
start studio64.exe
The above commands will create a P: drive and map it to the project root folder. This will reduce the overall path length to project files and might give you some relief for the too long path name problem. Use P:\ as you would have used the long root name when opening projects.
To remove the mapping use command: subst P: /d
I was facing the same issue , my project is in C drive and it is in deeper path location, What i did I just moved my project to other lower deep path location and it works, you just change the project location and project should not be in deep location hierarchy.
I had a different experience with this problem. First I has this error but then i noticed that my previous projects in the same directory were opening. This is the path:
C:\Users\koralis\Documents\extraction\Ex_Files_Android_App_Dev_LDS_Upd\Exercise Files\Ch01\01_06\ImageAssets
Surprisingly, I updated that gradle version to
'com.android.tools.build:gradle:3.2.1' from 'com.android.tools.build:gradle:2.0.0'
This solved my problem.

Can't create a new Android project with PhoneGap 2.2

I have a problem when I try to create an android project with PhoneGap. (I have windows 8 64 bit).
I put the right paths in my PATH environment variables, but when I try to create a new project, this is what I get:
Cscript not found as an internal or external command... (bad translation from French but you get the point.)
This error is new to me, because before it always returned:
Missing one of the following ...
How can I fix this error?
Though you may have the right PATH variables, you might not have the latest version of ANT or missing the commons-codec. I answered this question in another thread, so you might want to take a look there and see if any of those apply.

Adobe air 3.0 ANE for Android, null ExtensionContext?

I've been working with the vibration example from Adobe for Air 3.0's native extensions on Android.
I have the ANE compiled and the .apk packaged.
The problem I'm having is the actionscript library is getting a null ExtensionContext.
I tried creating the .apk with adt -package -target apk-debug so that I can see the actionscript traces in logcat and that's where I'm finding the null error.
extContext = ExtensionContext.createExtensionContext("com.adobe.Vibration", null);
extContext is null and crashes on the following .call() method.
All of the source is stock from the examples, I haven't changed anything.
Does anyone have any experience with getting one of Adobe's ANE examples working on a windows machine? Most of the examples are for Mac.
Good lord. What a waste of a week.
I was using a tutorial from gotoandlearn.com that was telling me to, in by build script, use a jar command to put my native extension in to a jar.
I simply used the .jar that's automatically built in the NativeAndroid/bin/ folder and all is well.
It turns out, that tutorial is out dated and not really useful for the build anymore.
One additional comment. You need to set target platform and checkbox Is Library from Properties -> Android to get compiled jar in bin folder.
P.S. .sh from gotoandlearn can be executed in Powershell in Windows with minor changes for running bat files: ( cmd "/c adt.bat" )
I'm having the exact same problem on a Native Extension I'm writing, and have open sourced. I started this project with tutorial code from Adobe DevNet. I've found examples of this specific issue I've tried to follow exactly, and have had no luck with it yet. I've identified it to be a sandbox allow-domain problem.
Here's my line of code:
_aneContext = ExtensionContext.createExtensionContext("com.adobe.sampleasextension", "");
Here is a link to the code in my GitHub project:
https://github.com/interactivenyc/ANESampleProject/blob/master/TEST_AndroidAIR/src/ANESampleTest.as
Here is my compiler error:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
at flash.system::Security$/allowDomain()
at com.adobe.sampleasextension::SampleASExtension()[/Users/stevewarren/Clients/Speakaboos/git_repositories/ANESampleProject/ANESampleSWC/src/com/adobe/sampleasextension/SampleASExtension.as:14]
at ANESampleTest/initializeANE()[/Users/stevewarren/Clients/Speakaboos/git_repositories/ANESampleProject/TEST_AndroidAIR/src/ANESampleTest.as:198]
at ANESampleTest/onAddedToStage()[/Users/stevewarren/Clients/Speakaboos/git_repositories/ANESampleProject/TEST_AndroidAIR/src/ANESampleTest.as:131]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at AppEntryCommon/run()
at global/runtime::AndroidMobileDeviceAppEntry()

How to build Android NDK sample: "bitmap-plasma"

I am trying to build the bitmap-plasma sample that is included with the ndk, but getting an error. I run ndk-build from the samples/bitmap-plasma directory, and the error it displays is that it cannnot locate android/bitmap.h file.
How do i direct the ndk-build script to the file it needs?
Using android-ndk-r4 on Ubuntu Lucid 10.04
Well it's working now, so in case anyone was having my same problem:
There as an android-ndk-r4b bugfix release today, which it seems no longer has this problem.
Available to download here.
http://developer.android.com/sdk/ndk/index.html
With Ubuntu 10.04 and NDK r5b, I have just posted a bug report (with the fix included) for build_platforms.sh. See http://code.google.com/p/android/issues/detail?id=15180 for details. Essentially, the local declarations in the symlink routine must be amended. Otherwise, it only links the first file (alphabetically) from each directory, and truncates the remainder from the list.
Correcting this allowed the symbolic links to be fully populated, thereby filling in the missing header files and libraries and allowing the samples to build successfully.

Categories

Resources