I am using OpenCV to attempt real-time video processing. Since the processing is quite heavy, it significantly slows down the output frames, which makes the real-time stream look choppy.
I would like to offload part of the processing in AsyncTask. I tried this and it actually makes the video a lot smoother. However, he finishes launching a large number of Tasks at the same time, and then they will slowly return with some results.
Is there a way to slow this down and wait for the result, either using the Synchronize statements, or in some other way?
On each frame of the camera, I run one of these tasks. DoImGProcessing performs long processing and returns the result of the string.
private class LongOperation extends AsyncTask<Mat, Void, String> { @Override protected String doInBackground(Mat... params) { Mat inputFrame = params[0]; cropToCenter(inputFrame); return doImgProcessing(inputFrame); } @Override protected void onPostExecute(String result) { Log.d(TAG, "on post execute: "+result); } @Override protected void onPreExecute() { Log.d(TAG, "on pre execute"); } } public Mat onCameraFrame(Mat inputFrame) { inputFrame.copyTo(mRgba);
Jameo source share