http://action713.tistory.com/entry/Making-a-Simple-OCR-Android-App-using-Tesseract 와 비슷한 내용.
http://gaut.am/making-an-ocr-android-app-using-tesseract/#more-1219
이 블로그에 가면 tesseract(테서렉트) 을 쉽게 사용할 수 있도록 도와준다.
* 필요한 것 : android SDK , AndroidNDK , ant ..?
* 실행 환경 : 이클립스 케플러( 안드로이드 , c/c++ 사용가능.) , win8 64bit
물론 블로그에도 설명이 잘 되어 있지만.. 한글로 적어두자.ㅜㅠ
1.
https://github.com/rmtheis/tess-two 이 곳에서 파일을 다운받자. 이 프로젝트는 안드로이드에서 사용하기 위한 tesseract , leptonica ,jpeg lib를 컴파일하기 위한 도구가 포함되어 있다고 한다.
나는 tess-two만 실행해봤다.
2.
tess-two를 ant로 빌드시킨다.
* ant 빌드 방법 - 이 프로젝트를 실행 시키는데 필요한지는 모르겠으나 일단 따라했다.
더보기 접기
*ant 빌드
1. http://ant.apache.org/bindownload.cgi 이 곳에 가서 zip파일 다운 로드.
2. 압축을 푼다.
3.환경변수를 설정한다.
- 사용자 변수에서 새로 만들기
-> 변수이름 : ANT_HOME / 변수값 : C:\setup\apache-ant-1.9.4-bin\apache-ant-1.9.4
- 시스템 변수에서 path 편집
-> 변수값에 추가 - %ANT_HOME%\bin;
- 시스템 변수에서 path 새로 만들기
-> 변수이름 : ANT_HOME / 변수값 : C:\setup\apache-ant-1.9.4-bin\apache-ant-1.9.4;
4. cmd 창을 열고
> ant
라고 치면
buildfile : build.xml does not exist!
build failed 라고 떴다.
5. 안드로이드 adk 설치 폴더로 가서 - tools - ant - build.xml에
<!-- compilation options -->
<property name="java.encoding" value="UTF-8" />
<property name="java.target" value="1.5" />
<property name="java.source" value="1.5" />
이런 부분이 있는데 현재 작업 프로젝트랑 값이 같아야 한다. 나는 1.6으로 수정
6. 실행한 프로젝트안에 build.xml에서
project name = " 프로젝트명 입력 " 후 저장
properties 파일에
sdk.dir=안드로이드 sdk경로
추가 후 저장
ex) sdk.dir=D:\\dev\\sdk\\android-sdk_r10-windows\\android-sdk-windows
접기 cmd 창을 열고
> cd 프로젝트 경로 / tess-two
ex ) cd C:\Users\Desktop\tess-two
그러면 이렇게
cd 프로젝트 경로 / tess-two > 프로젝트 경로로 이동한다.
> ndk-build
입력 후 엔터. 이제 부터는 오래 기다려야 한다.
ndk는 환경변수에 등록되어 있어야 한다.
> ant release
입력.끝.
3.
이클립스를 켜서
file - import - existing projects into workspace - tess-two를 추가
4.
tess-two프로젝트 우클릭 - properties - android - 하단에 library에서 is library 체크박스 선택
5.
내 안드로이드 프로젝트에서 (만들어야 한다. 지금은 있다고 가정.)
프로젝트 우클릭 - properties - android - ribrary - add -> teww-two선택.
* 자신의 프로젝트에 포함되어야 하는 부분
더보기 접기
1. 이미지 캡쳐 코드
( http://labs.makemachine.net/2010/03/simple-android-photo-capture/ )
// _path = path to the image to be OCRed
ExifInterface exif = new ExifInterface(_path);
int exifOrientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotate = 0;
switch (exifOrientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
}
if (rotate != 0) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
// Setting pre rotate
Matrix mtx = new Matrix();
mtx.preRotate(rotate);
// Rotating Bitmap & convert to ARGB_8888, required by tess
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
}
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
2. TessBaseAPI사용
TessBaseAPI baseApi = new TessBaseAPI();
// DATA_PATH = Path to the storage
// lang = for which the language data exists, usually "eng"
baseApi.init(DATA_PATH, lang);
// Eg. baseApi.init("/mnt/sdcard/tesseract/tessdata/eng.traineddata", "eng");
baseApi.setImage(bitmap);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
( * 언어 파일을 얻을 수 있는 곳. https://code.google.com/p/tesseract-ocr/downloads/list )
접기
내 프로젝트에 tess-two를 함께 쓰는 것인데.
만들어야 할 안드로이드 프로젝트 예제도 찾았다.
1.
https://github.com/GautamGupta/Simple-Android-OCR
여기서 다운 받은 후
이클립스에서 안드로이드 프로젝트 import시켜서
프로젝트 우클릭 - properties - android - ribrary - add -> teww-two 선택 후 실행시키면 된다.
2.
예제가 하나 더 있었는데 그냥 꺼버렸는지.. 안보인다.
일단 apk를 올리려는데 용량커서 안된다네..ㅜ
https://github.com/rmtheis/android-ocr 이 곳에서 다운받지는 않았는데 같은 소스인듯?
이게 맞다면 이클립스에서 import하면 2개 소스파일에서 에러가 날 것이다.
DecodeHandler.java
CaptureActivity.java
에러가 나는 부분을 드래그하고
ctrl + 1을 누른 후 convert 'switch' to 'if-else'클릭하면 에러가 사라진다.
* if-else로 바꿔야 하는 이유
http://www.androidpub.com/1808135
더보기 접기
ADT 14 update 이후, 라이브러리 프로젝트에서 case 문에 대해 아래와 같은 에러가 발생합니다.
"case expressions must be constant expressions"
이유는 라이브러리 프로젝트에서 ADT 14 이후, final 로 설정하지 않기 때문이라고 하네요.
http://stackoverflow.com/questions/7840914/android-resource-ids-suddenly-not-final-switches-broken
해결방법은 의외로 간단한데요.
switch 문 대신 if-else 로 바꿔주시면 됩니다.
이클립스에서 Ctrl+1 혹은 Cmd+1(Mac) 을 눌러주시면, 자동 변환해줍니다.
http://tools.android.com/recent/switchstatementconversion
접기 http://tools.android.com/recent/switchstatementconversion
더보기 접기
posted Sep 29, 2011, 2:35 PM by Tor Norbye As of ADT 14, resource constants in
library projects are no longer final. This is explained in greater detail in
this document .
However, one consequence of this is that some existing projects no longer compile when you use ADT 14. And the reason may be hard to understand. To help with this, there's a new quickfix detector which looks for a specific compiler error and when present adds a "quickfix". This means that when you hover over the error it offers more help:
If you select this quickfix you get this dialog:
And if you select this option, you get the following dialog:
Hopefully this will make it much more obvious what's going on, and make it a lot less painful to update any code which depended on constants in library project resources.
접기