Git Product home page Git Product logo

camera2-yuv2rgb's Introduction

Camera2-Yuv2Rgb in NDK

Android5.0 Camera2 ImageReader 读取YUV格式转为RGB格式的方法

本工程提取于tzutalin/dlib-android

高效:

在双Cortex-A72大核+四Cortex-A53小核(RK3399)下处理640x480图片平均耗时22ms

不同方法性能比较见 http://blog.mclover.cn/archives/206.html

使用方法:

1.将so库放到jniLibs文件夹下

2.将src中代码放入工程

3.在Application或入口Activity中加入

    static{
        System.loadLibrary("ImageConvert");
    }

示例方法:

    static{
        System.loadLibrary("ImageConvert");
    }
    public void onImageAvailable(ImageReader reader) {
        Image image = reader.acquireLatestImage();
        Image.Plane[] plane = image.getPlanes();
        byte[][] mYUVBytes = new byte[plane.length][];
        for (int i = 0; i < plane.length; ++i) {
            mYUVBytes[i] = new byte[plane[i].getBuffer().capacity()];
        }
        int[] mRGBBytes = new int[640 * 480];

        for (int i = 0; i < plane.length; ++i) {
            plane[i].getBuffer().get(mYUVBytes[i]);
        }

        final int yRowStride = plane[0].getRowStride();
        final int uvRowStride = plane[1].getRowStride();
        final int uvPixelStride = plane[1].getPixelStride();

        ImageConvert.convertYUV420ToARGB8888(
                mYUVBytes[0],
                mYUVBytes[1],
                mYUVBytes[2],
                mRGBBytes,
                image.getWidth(),
                image.getHeight(),
                yRowStride,
                uvRowStride,
                uvPixelStride,
                false);

        Bitmap mRGBframeBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
        mRGBframeBitmap.setPixels(mRGBBytes, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
        image.close();
    }

camera2-yuv2rgb's People

Contributors

xvolica avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

camera2-yuv2rgb's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.