多线程Android摄像头帧处理 [英] Android Camera Frame processing with MultiThreading

查看:590
本文介绍了多线程Android摄像头帧处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的OpenCV,Vuforia和的tesseract(苔丝二)我的应用程序。我的系统是这样工作的:

I am using OpenCV,Vuforia and Tesseract(tess-two) for my app. My system works like this:

  1. Vuforia检测目标,并将完整的帧的OpenCV(JNI)
  2. OpenCV中得到帧做了一些图像处理,使之可读的的tesseract(JNI)
  3. 的tesseract(苔丝二)主罚字节数组从OpenCV中,并不会在图像上的OCR处理(字节数组)

我的问题开始的第三部分。由于我的目标是做实时摄像头帧的OCR,我想使用多线程使用户界面良好,没有造成现场摄像机的视觉走缓。

My problem starts with the 3rd part. Since my aim is to do the ocr on real time camera frames, i am trying to use multi-threading to make UI smooth and not to cause live camera visual to go slow.

我决定使用AsyncTask的该是这样的:

I decided to use AsyncTask for that like this :

public void getFromNative(final byte[] imagedata, final int width,final int height,final byte [] typeData, final int typeWidth,final int typeHeight) {

        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                ocr(imagedata, width, height,typeData,typeWidth,typeHeight);                    
                return null;
            }

        }.execute();                
}

这让现场摄像机流比正常的,单个线程的方式平滑。但问题是,因为它开始的,因为直播相机帧那么多的AsyncTask,甚至当我打开相机远离目标,它不断在$ P $做OCR pviously创建AsycnTask并返回结果他们一个接一个。除了AsyncTask的,我想IntenService,但结果是一样的。

It makes the live camera stream smoother than normal, single thread way. But the problem is since its starting so many AsyncTask because of the live camera frames, even when i turn the camera away from the target, it keeps on doing OCR on the previously created AsycnTask and returns results for them one after another. In addition to AsyncTask, i tried IntenService, but the result was the same.

我要问,如果有一种方法可以解决这个问题,使这一过程更加高效。

I want to ask if there is a way to solve this issue and make the process more efficient.

感谢

推荐答案

我的建议,你不要试图识别每一个帧相机peview提取。我们采用了类似下面的内容在previewFrame法:

I'm suggesting, that you don't try to recognize every single frame your camera peview fetches. We used something similar to the following onPreviewFrame-method:

public final void onPreviewFrame(final byte[] data, final Camera camera) {
    this.data = data;
    now = Calendar.getInstance().getTimeInMillis();

    if (now - lastRecognitionTime > TIME_BETWEEN_RECOGNITION_STARTS_IN_MILLIS) {
        lastRecognitionTime = now;
        startRecognition(); // here you can start your async task
    }
}

这意味着识别过程只启动每隔数preVIEW帧,这取决于你如何配置TIME_BETWEEN_RECOGNITION_STARTS_IN_MILLIS。

That means the recognition process starts only every few preview frames, depending how you configure TIME_BETWEEN_RECOGNITION_STARTS_IN_MILLIS.

这篇关于多线程Android摄像头帧处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆