GithubHelp home page GithubHelp logo

openglcamera's Introduction

OpenGLCamera

Android camera using SurfaceTexture

This is a minimalistic example of custom camera preview app that uses SurfaceTexture and uses a matrix transform to change the way it is displayed.

Here, we show front camera image not as a mirror.

Many details like error checking have been skipped for brevity. In the real world, you will open the camera on a separate EventThread, so that the camera callbacks would not interfere with UI thread.

Depends on android-support-v4.jar

openglcamera's People

Contributors

alexcohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

openglcamera's Issues

performance issues to capture frames fps to bitmap processing NDK in apk mode release

Hi, Alex. nice to meet you.

thanks for attention, I am Android developer, I am working in project where it capture frames fps from camera of mobile phone. after each frame is processed to get bitmap using a native library with opencv SDK and after this bitmap is showed in an ImageView. this process to consume heap memory and to affect the performance the app. I add the next tag in the manifest.xml to increase the heap memory:

    <application
    android:name="app"
    android:largeHeap="true" />

With this, the app work fine when to generate an apk version in debug modem but when to generate an apk version in release mode, the app is very slow and doesn't fine, there is issues in the performance.

I worked with a logic using a SurfaceView component to get frames from camera, I use a SurfaceView because I need to use in background inside of the app, I want to ask you, how do I solve this problem, counting on your help.

I am using this logic to get frames:

    public synchronized void onPreviewFrame(final byte[] data, final Camera camera) {
        executorService.execute(new Runnable() {
            public void run() {

                            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

                    Camera.Parameters parameters = camera.getParameters();
                    orientation = OrientationDevice.getOrientationDevice().getOrientation();
                    orientation = normalize(orientation);

                   //converter yuv to bitmap
                   int width = parameters.getPreviewSize().width;
                   int height = parameters.getPreviewSize().height;
                   YuvImage yuv = new YuvImage(data, parameters.getPreviewFormat(), width, height, null);
                   ByteArrayOutputStream out = new ByteArrayOutputStream();
                  yuv.compressToJpeg(new Rect(0, 0, width, height), 80, out);
                 byte[] bytes = out.toByteArray();
                 Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

               // rotate image 
               if (cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                    matrix.setScale(-1, 1);
                    matrix.postTranslate(bitmap.getWidth(), 0);
                    matrix.postRotate(rotation + 90);
                } else {
                    matrix.postRotate(rotation + 90);
                }                        

               // process bitmap from method jni
                ....

            if (bitmap != null && !bitmap.isRecycled()) {
                bitmap.recycle();
                bitmap = null;
            }


               camera.addCallbackBuffer(data);

                return;

        });

    }

};

Thanks for your attention, can you help me, please. I review your work, it is very good and you have experience in this topic and a big participation in the developer community.

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.