1

所以,我一直在尝试用 Tesseract 制作一个 OCR 应用程序。所以我下载了 tess-two,用 NDK 构建它并作为模块添加到 Android Studio。我的问题来了。我的代码:

 public class MainActivity extends ActionBarActivity implements View.OnClickListener {
    private static final int SELECT_PHOTO = 100;

    Button OCR_btn;

    ImageView iv_pic;

    Bitmap MyBitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OCR_btn=(Button) findViewById(R.id.OCR_button);
        OCR_btn.setOnClickListener(this);
        iv_pic=(ImageView) findViewById(R.id.iv_pic);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

        switch(requestCode) {
            case SELECT_PHOTO:
                if(resultCode == RESULT_OK){
                    Uri selectedImage = imageReturnedIntent.getData();
                    InputStream imageStream = null;
                    try {
                        imageStream = getContentResolver().openInputStream(selectedImage);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    Bitmap MyBitmap = BitmapFactory.decodeStream(imageStream);
                    iv_pic.setImageBitmap(MyBitmap);
                    TessBaseAPI baseApi = new TessBaseAPI();
// DATA_PATH = Path to the storage
// lang = for which the language data exists, usually "eng"
                    baseApi.init("mnt/sdcard/eng.traineddata", "eng");
// Eg. baseApi.init("/mnt/sdcard/tesseract/tessdata/eng.traineddata", "eng");
                    baseApi.setImage(MyBitmap);
                    String recognizedText = baseApi.getUTF8Text();
                    baseApi.end();
                }
        }
    }

    @Override
    public void onClick(View v) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, SELECT_PHOTO);

    }
}

这是错误日志:

  Error:Execution failed for task ':tesstwo:compileReleaseNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /home/michal089/Documents/Android/NDK/android-ndk-r10d/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/michal089/AndroidStudioProjects/OCR_app/tesstwo/build/intermediates/ndk/release/Android.mk APP_PLATFORM=android-8 NDK_OUT=/home/michal089/AndroidStudioProjects/OCR_app/tesstwo/build/intermediates/ndk/release/obj NDK_LIBS_OUT=/home/michal089/AndroidStudioProjects/OCR_app/tesstwo/build/intermediates/ndk/release/lib APP_ABI=all
  Error Code:
    2
  Output:
    In file included from /home/michal089/AndroidStudioProjects/OCR_app/tesstwo/src/main/jni/com_googlecode_leptonica_android/writefile.cpp:17:0:
    /home/michal089/AndroidStudioProjects/OCR_app/tesstwo/src/main/jni/com_googlecode_leptonica_android/common.h:22:24: fatal error: allheaders.h: No such file or directory
     #include <allheaders.h>
                            ^
    compilation terminated.
    make: *** [/home/michal089/AndroidStudioProjects/OCR_app/tesstwo/build/intermediates/ndk/release/obj/local/arm64-v8a/objs/tesstwo//home/michal089/AndroidStudioProjects/OCR_app/tesstwo/src/main/jni/com_googlecode_leptonica_android/writefile.o] Error 1

有什么问题?

4

0 回答 0