Android的位图致命信号11(SIGSEGV) [英] Android Bitmap Fatal signal 11 (SIGSEGV)

查看:550
本文介绍了Android的位图致命信号11(SIGSEGV)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发和Android的应用程序,拍照,并进行OCR它。结果
我有时和某个没有得到这个错误没有改变我的code,

该错误: 20 01-08:41:59.940:A / libc的(10967):致命信号11(SIGSEGV)为00000000(code = 1)

我有裁剪图像,让用户突出显示文本的方法:

 私人无效performCrop(){    档案文件=新的文件(_path);
    乌里outputFileUri = Uri.fromFile(文件);    尝试{        //调用标准作物动作意图(用户设备可能不支持它)
        意图cropIntent =新意图(com.android.camera.action.CROP);
        cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);
        //显示图像类型和URI
        cropIntent.setDataAndType(picUri,图像/ *);
        //设置裁剪性能
        cropIntent.putExtra(裁剪,真);
        //注明所需作物方面
        cropIntent.putExtra(aspectX,5);
        cropIntent.putExtra(aspectY,1);
        //指示输出X和Y
        cropIntent.putExtra(outputX,500);
        cropIntent.putExtra(outputY,100);
        //检索返回数据
        cropIntent.putExtra(回归数据,真正的);
        //启动活动 - 我们处理返回的的onActivityResult
        startActivityForResult(cropIntent,2);    }赶上(ActivityNotFoundException anfe){
         //显示错误信息
         字符串的errorMessage =哎呦 - 你的设备不支持作物的行动!
         吐司面包= Toast.makeText(这一点,的errorMessage,Toast.LENGTH_SHORT);
         toast.show();
    }赶上(例外前){
        Log.v(TAG,ex.toString());
    }
}

在这里是做OCR方法:

 保护无效onPhotoTaken(){
    _taken = TRUE;    BitmapFactory.Options选项=新BitmapFactory.Options();
    options.inSampleSize = 2;    位图位图= BitmapFactory.de codeFILE(_path,期权);    尝试{
        ExifInterface EXIF​​ =新ExifInterface(_path);
        INT exifOrientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);        Log.v(TAG,东方+ exifOrientation);        INT旋转= 0;        开关(exifOrientation){
        案例ExifInterface.ORIENTATION_ROTATE_90:
            旋转= 90;
            打破;
        案例ExifInterface.ORIENTATION_ROTATE_180:
            旋转= 180;
            打破;
        案例ExifInterface.ORIENTATION_ROTATE_270:
            旋转= 270;
            打破;
        }        Log.v(TAG,旋转+旋转);        如果(旋转!= 0){            //获取宽度放大器;给定图像的高度。
            INT W = bitmap.getWidth();
            INT H = bitmap.getHeight();            //设置pre旋转
            矩阵MTX =新的Matrix();
            。MTX preRotate(旋转);            //旋转位图
            位图= Bitmap.createBitmap(位图,0,0,W,H,MTX,假);
        }        //转换为ARGB_8888,苔丝要求
        位= bitmap.copy(Bitmap.Config.ARGB_8888,真);    }赶上(IOException异常五){
        Log.e(TAG,无法正确的方向:+ e.toString());
    }    // _image.setImageBitmap(位图);    Log.v(TAGbaseApi之前);    TessBaseAPI baseApi =新TessBaseAPI();
    baseApi.setDebug(真);
    baseApi.init(DATA_PATH,郎);
    baseApi.setImage(位图);    串recognizedText = baseApi.getUTF8Text();    baseApi.end();    //现在,您有recognizedText VAR的文字,你可以用它做任何事情。
    //我们将显示它剥离出来修剪字母数字版本(如果lang是ENG)
    //使垃圾不会使它的显示。    Log.v(TAG,进行OCR文字:+ recognizedText);    如果(lang.equalsIgnoreCase(工程)){
        recognizedText = recognizedText.replaceAll([^ A-ZA-Z0-9] +,);
    }    recognizedText = recognizedText.trim();    如果(recognizedText.length()!= 0){
        _field.setText(_field.getText()的toString()长()== 0 recognizedText:?_field.getText()++ recognizedText);
        _field.setSelection(。_field.getText()的toString()长());
    }    //循环完成。
}


解决方案

建议之一是ExifInterface初始化的问题。

ExifInterface的构造函数有一个严重的错误。
它不会检查参数文件名字符串是否为空或不是,也没有会抛出异常,所以拍击JNI结果SIGSEGV。

下面的文章将帮助你(对不起,这个职位是日本...)
http://alpha.mixi.co.jp/2013/11572/
http://alpha.mixi.co.jp/images /android-compat-jni-crash-exif.png

所以,你应该在初始化ExifInterface对象之前检查_path值。

I'm developing and android app that take a picture and OCRed it.
I'm getting this error sometime and sometime not without changing my code,

THE ERROR : 01-08 20:41:59.940: A/libc(10967): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)

I have a method that crop the image to let the user highlight the text :

private void performCrop(){

    File file = new File(_path);
    Uri outputFileUri = Uri.fromFile(file);

    try{

        //call the standard crop action intent (the user device may not support it)
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        //indicate image type and Uri
        cropIntent.setDataAndType(picUri, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        //indicate aspect of desired crop
        cropIntent.putExtra("aspectX", 5);
        cropIntent.putExtra("aspectY", 1);
        //indicate output X and Y
        cropIntent.putExtra("outputX", 500);
        cropIntent.putExtra("outputY", 100);
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        startActivityForResult(cropIntent, 2);

    }catch(ActivityNotFoundException anfe){
         //display an error message
         String errorMessage = "Whoops - your device doesn't support the crop action!";
         Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
         toast.show();
    } catch (Exception ex) {
        Log.v(TAG, ex.toString());
    }
}

and here is the method that do the OCR :

protected void onPhotoTaken() {
    _taken = true;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 2;

    Bitmap bitmap = BitmapFactory.decodeFile(_path, options);

    try {
        ExifInterface exif = new ExifInterface(_path);
        int exifOrientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        Log.v(TAG, "Orient: " + exifOrientation);

        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;
        }

        Log.v(TAG, "Rotation: " + rotate);

        if (rotate != 0) {

            // Getting width & height of the given image.
            int w = bitmap.getWidth();
            int h = bitmap.getHeight();

            // Setting pre rotate
            Matrix mtx = new Matrix();
            mtx.preRotate(rotate);

            // Rotating Bitmap
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
        }

        // Convert to ARGB_8888, required by tess
        bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

    } catch (IOException e) {
        Log.e(TAG, "Couldn't correct orientation: " + e.toString());
    }

    // _image.setImageBitmap( bitmap );

    Log.v(TAG, "Before baseApi");

    TessBaseAPI baseApi = new TessBaseAPI();
    baseApi.setDebug(true);
    baseApi.init(DATA_PATH, lang);
    baseApi.setImage(bitmap);

    String recognizedText = baseApi.getUTF8Text();

    baseApi.end();

    // You now have the text in recognizedText var, you can do anything with it.
    // We will display a stripped out trimmed alpha-numeric version of it (if lang is eng)
    // so that garbage doesn't make it to the display.

    Log.v(TAG, "OCRED TEXT: " + recognizedText);

    if ( lang.equalsIgnoreCase("eng") ) {
        recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " ");
    }

    recognizedText = recognizedText.trim();

    if ( recognizedText.length() != 0 ) {
        _field.setText(_field.getText().toString().length() == 0 ? recognizedText : _field.getText() + " " + recognizedText);
        _field.setSelection(_field.getText().toString().length());
    }

    // Cycle done.
}

解决方案

One suggestion is a ExifInterface initialization problem.

ExifInterface's constructor has a serious bug. It won't check whether the argument filename string is null or not, and no exception will be thrown, so crashing on JNI results to SIGSEGV.

The following post will help you(sorry, this post is in japanese...) http://alpha.mixi.co.jp/2013/11572/ http://alpha.mixi.co.jp/images/android-compat-jni-crash-exif.png

So you should check the _path value before initializing ExifInterface object.

这篇关于Android的位图致命信号11(SIGSEGV)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆