我正在做一个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 ms。哪个是启动这些任务的最佳和最快的方式?在其他线程?在主线程中?
由于
答案 0 :(得分:1)
您应该记住以下事项
效率最高的是
number of threads == number of processors
但是线程越多,RAM就越多。
因此,您应根据可用的RAM和CPU来决定。
顺便说一下,Camera.open是一个阻塞调用,所以把它放在一个线程中,效率更高,但我希望你不要在Camera.open下处理图像,因为在这种情况下,线程或没有线程不会物质