OpenCV multi-threading frames on Android

荒凉一梦 提交于 2019-12-23 03:32:41

问题


I am doing some work with OpenCV on Android. My code was all on the Java interface and its performance was very bad, so I implemented almost all the image processing with JNI. So on Java I have:

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
{
    _imgBgrTemp = inputFrame.rgba();
    jniFrame(_imgBgrTemp.nativeObj);
    return _imgBgrTemp;
}

So jniFrame() function takes care of all the image processing in C++, and with this there was a good improvement in performance. But it is still around 8fps and my camera can do 30fps without any processing on the image.

Looking more close I saw that even while processing the code, it uses only 25% CPU of my Android, witch is a Zenfone 2 with a quad-core processor.

I am thinking about having it running in 4 threads so I would have o FIFO pool to receive frames, process, and display it in the received order.

I am thinking in use this: Creating a Manager for Multiple Threads

So my questions are:

I am going the right way ?

Do you have any tips ?

What should I consider (As I am working with JNI) ?

I didn't post the jniFrame() here because I don't think it is very relevant as it is a Work in progress code, very big. But it is about recognizing a rubik cube and getting its colors. if you also can give me any tips on that... but I may create another question only about this part later.

An update: I as just searching about using OpenCL, but it seeams even more complicated then multi-threading and I am not sure if the improvement would be good. would it be better then multi-threading ?

来源:https://stackoverflow.com/questions/38657849/opencv-multi-threading-frames-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!