实时处理图像 Android

Process images in real time Android

我正在做一个 Android 实时处理图像的应用程序,但我不知道哪种处理这些帧的方法最有效。

我在这样的线程中启动采集过程:

/**
     * Thread to open camera acquisition process
     */
    private static class CameraHandlerThread extends HandlerThread {
        Handler mHandler = null;

        CameraHandlerThread() {
            super("CameraHandlerThread");
            start();
            mHandler = new Handler(getLooper());
        }

        synchronized void notifyCameraOpened() {
            notify();
        }

        void openCamera() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        mCamera = Camera.open(cameraUsed.ordinal());
                    } catch (RuntimeException e) {
                        Log.e(TAG, "failed to open front camera");
                    }
                    notifyCameraOpened();
                }
            });
            try {
                wait();
            } catch (InterruptedException e) {
                Log.w(TAG, "wait was interrupted");
            }
        }
    }

我达到了高帧率(25 fps 或多或少),我的处理任务约为 300 毫秒。启动这些任务的最佳和最快方法是什么?在其他线程?在主线程中?

谢谢

以下几点您应该牢记

  1. 您的 android 设备上的处理器数量
  2. 可用 RAM 量

最有效的时间是

number of threads == number of processors

但是线程越多,需要的 RAM 就越大。

所以您应该根据可用的 RAM 和 CPU 来决定。

顺便说一句,Camera.open是一个阻塞调用,所以放在一个线程中,效率更高,但我希望你不是在Camera.open下处理图像,因为那样的话,线程或没有线程都没有关系。