Image processing in AsyncTask
Evening,
I`m trying to create an Augmented Reality application by detecting markers in a scene. In order to do that, I need to do heavy processing on an image. I do that in onCameraFrame() method at every frame, but the image processing holds up the thread and camera feels laggy with low fps. So I try to put image processing part to the background by using AsyncTask. I have found an example of AsyncTask in CameraCalibrationActivity and by following it I try to replicate the code, but after launching the application it crashes and the error is Fatal signal 11 (SIGSEGV) at 0x00000028 (code=1), thread 16291 (AsyncTask #5). Also, if I try to implement AsyncTask in other way, the app is ran successfully, but the FPS is still low (the FPS increase is like 2 FPS). I will post both of the implementations. If anyone has any suggestions, experiences - please post.
Implementation like in CameraCalibrationActivity():
public Mat onCameraFrame(CvCameraViewFrame inputFrame)
{
mRgba = inputFrame.rgba();
new AsyncTask<Void, Void, Void>()
{
@Override
protected Void doInBackground(Void... arg0) {
MarkerDetector.detect(mRgba, detectedMarkers, CameraParameters, (float) 0.14, mRgba);
return null;
}
}.execute();
return mRgba;
}
My own implementation with seter methods on child class:
public class MarkerDetector extends AsyncTask<Void, Void, Void>
{
private Mat inGlobal;
private Vector<Marker> detectedMarkersGlobal;
private CameraParameters cameraParametersGlobal;
public void detect(Mat in, Vector<Marker> detectedMarkers, CameraParameters cp,float markerSizeMeters, Mat frameDebug)
{
// image processing code here
}
public void setInputFrameMatrix(Mat _in)
{
inGlobal = _in;
}
public void setDetectedMarkers(Vector<Marker> _detectedMarkers)
{
detectedMarkersGlobal = _detectedMarkers;
}
public void setCameraParameters(CameraParameters _cameraParameters)
{
cameraParametersGlobal = _cameraParameters;
}
@Override
protected Void doInBackground(Void... params)
{
this.detect(inGlobal, detectedMarkersGlobal, cameraParametersGlobal, (float) 0.14, inGlobal);
return null;
}
}
public class Tutorial3Activity extends Activity implements CvCameraViewListener2, OnTouchListener
{
public Mat onCameraFrame(CvCameraViewFrame inputFrame)
{
mRgba = inputFrame.rgba();
MarkerDetector.setCameraParameters(CameraParameters);
MarkerDetector.setDetectedMarkers(detectedMarkers);
MarkerDetector.setInputFrameMatrix(mRgba);
MarkerDetector.execute();
return mRgba;
}
}