Git Product home page Git Product logo

android-yuv-utils's Introduction

android-yuv-utils

CAUTION! The version from master branch actually works but has some issues like a lot of memory consumption and some other issues, currently I'm working on it.

Compiled libyuv Google library and wrapper for it for easy and fast scale, rotate, mirror and convert frames from android Camera2 or CameraX.

Supported features:

  1. Scale horizontally and/or vertically.
  2. Rotating by 90, 180 or 270 degrees.
  3. Mirror horizontally or vertically.
  4. Convert android YUV_420_8888 frame to ARGB.

Supported ABIs:

armeabi-v7a, arm64-v8a, x86, x86_64

How to use

Init library:

val yuvUtils = YuvUtils()                                    // getting an instance of the library

Prepare a frame from Camera2 or CameraX for scaling, rotating etc.:

val image = ...                                              // getting an image from Camera2 or CameraX api
var yuvFrame = yuvUtils.convertToI420(image)                 // this step isn't mandatory but it may help you in case if the colors of the output frame (after scale, rotate etc.) are distorted  

Scale:

/* the first way */
val image = ...                                             // getting an image from Camera2 or CameraX api
val scaledWidth = image.width * 2                           // getting current width and height
val scaledHeight = image.height * 2                         // of a frame and for example double them
yuvFrame = yuvUtils.scale(image, scaledWidth, scaledHeight, Constants.FILTER_BOX)

/* the second way here yuvFrame was taken from the yuvUtils.convertToI420 method as showed above */ 
val scaledWidth = yuvFrame.width * 2                        // getting current width and height
val scaledHeight = yuvFrame.height * 2                      // of a frame and for example double them
yuvFrame = yuvUtils.scale(yuvFrame, scaledWidth, scaledHeight, Constants.FILTER_BOX)

Rotate:

val rotate = Constants.ROTATE_270                           // setting the rotation angle
yuvFrame = yuvUtils.rotate(image, rotate)
/* or */
yuvFrame = yuvUtils.rotate(yuvFrame, rotate)

Mirror:

/* for mirror horizontally */
yuvFrame = yuvUtils.mirrorH(image)
/* or */
yuvFrame =  yuvUtils.mirrorH(yuvFrame)

/* for mirror vertically */
yuvFrame = yuvUtils.mirrorV(image)
/* or */
yuvFrame = yuvUtils.mirrorV(yuvFrame)

Convert to ARGB:

val argbFrame = yuvUtils.yuv420ToArgb(image)
/* or */
val argbFrame = yuvUtils.yuv420ToArgb(yuvFrame)

Project structure

The project consists of two modules:

  • app - here you can find a sample app that demonsrates scaling, rotating, mirroring and converting procedures by capturing frames from device's camera.
  • yuv - here you can find a C++ class that interacts with libyuv 1759 and a JNI wrapper for interacting with it from Java/Kotlin layer.

Compiled library:

  • yuv.aar - it's a compiled library of yuv module that mentioned above, it placed in a root directory of the project, you can easily add it to your project using gradle dependencies. First you should place yuv.aar in the libs folder of your project and then add to your build.gradle:
dependencies {
    api fileTree(dir: 'libs', include: '*.jar')       // this line is necessary in order to gradle took yuv.aar from "libs" dir
    api files('libs/yuv.aar')                         // dependency for yuv.aar library
    ...                                               // other dependencies
}

android-yuv-utils's People

Contributors

theeasiestway avatar

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.