• ImageConverter引起的 invalid address or address of corrupt block 0xb7feab58 passed to dlfree


    虹软人脸识别,其方法要传NV21格式的byte[], github上有一个虹软的Demo,是不是虹软工作人员写的不清楚,这个Demo里bitmap转NV21格式byte[]用的是一个第三方库https://github.com/gqjjqg/android-extend,
    用法如下:

    ImageConverter convert = new ImageConverter();
    convert.initial(mBitmap.getWidth(), mBitmap.getHeight(), ImageConverter.CP_PAF_NV21);
    if (convert.convert(mBitmap, data)) {
    Log.d(TAG, "convert ok!");
    }
    convert.destroy();
    !
    

      


    本来是没有问题,但是我这边需求是大量检测照片,所以会频繁多次调用这个方法,以900次为例,在某些平板上是没有问题的,但是个别平板在100次左右时会报错:

    07-18 21:44:53.719 6365-6609/cn.gxh.face A/libc: invalid address or address of corrupt block 0xb80402f8 passed to dlfree
    Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdeadbaad in tid 6609 (pool-2-thread-2)
    07-18 21:44:53.820 175-175/? E/DEBUG: Failed to find a valid tombstone, default to using tombstone 0.
    failed to open tombstone file '/data/tombstones/tombstone_00': No such file or directory
    

      

    解决方法:可以换一个转换方法。

    public byte[] getNV21(int inputWidth, int inputHeight, Bitmap scaled) {
    
    int[] argb = new int[inputWidth * inputHeight];
    
    scaled.getPixels(argb, 0, inputWidth, 0, 0, inputWidth, inputHeight);
    byte[] yuv = new byte[inputWidth * inputHeight * 3 / 2];
    
    encodeYUV420SP(yuv, argb, inputWidth, inputHeight);
    
    return yuv;
    }
    
    private void encodeYUV420SP(byte[] yuv420sp, int[] argb, int width, int height) {
    int frameSize = width * height;
    
    int yIndex = 0;
    int uvIndex = frameSize;
    
    int R, G, B, Y, U, V;
    int index = 0;
    
    for (int j = 0; j < height; j++) {
    for (int i = 0; i < width; i++) {
    R = (argb[index] & 0xff0000) >> 16;
    G = (argb[index] & 0xff00) >> 8;
    B = (argb[index] & 0xff);
    
    // well known RGB to YUV algorithm
    Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
    U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
    V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
    
    yuv420sp[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
    
    if (j % 2 == 0 && index % 2 == 0 && uvIndex < yuv420sp.length - 2) {
    yuv420sp[uvIndex++] = (byte) ((V < 0) ? 0 : ((V > 255) ? 255 : V));
    yuv420sp[uvIndex++] = (byte) ((U < 0) ? 0 : ((U > 255) ? 255 : U));
    }
    index++;
    }
    }
    }
    

      

    经测试,可用。

  • 相关阅读:
    移动MM首届手机软件设计及创意大赛决赛取得圆满成功
    Windows Phone 7 EKB系列文章发布
    EVC3/4项目升级到Visual Studio项目的一些建议
    Windows Phone SDK 7.1 RTM 发布
    Howto: 创建Windows Phone 7自定义控件
    风云再起,7迹由你WP7技术沙龙上海站第二次活动
    Windows Phone Dev Notes如何使用ConnectionSettingsTask 来启动连接设置页面
    【OneNote Mobile】 如何处理便签内容的格式?
    《101 Windows Phone 7 Apps》读书笔记PASSWORDS & SECRETS
    3年MVP路,一颗感恩的心
  • 原文地址:https://www.cnblogs.com/Zzz-/p/10683412.html
Copyright © 2020-2023  润新知