Camera preview freezed after switching camera
I am developing an Android application, and I use opencv libraries, in 2.4.5 version, for this purpose. I am basing my application on this tutorial, taken from the set of tutorials contained in the OpenCV4Android package.
In onCameraFrame, I take a mat obtained from a background processing, and I copy it on mRgba, before it is send to deliverAndDrawFrame, in this way:
if(pointsArrived==true){
myobjectMain.getMatOfFeatures().copyTo(mRgba);
}
return mRgba;
I have also implemented a method (called if a button is pressed) to switch camera. The method simply does:
mOpenCvCameraView.disableView();
mOpenCvCameraView.set_mCameraIndex_front();
openedcam=CameraInfo.CAMERA_FACING_FRONT;
mOpenCvCameraView.enableView();
The application works properly if I don't switch camera. Instead, if I press button to switch it, sometimes (not always) preview blocks, and it seems as freezed. This effect stops, if I remove the instruction of copy on mRgba from onCameraFrame.
It's really important for me that copy, so I cannot remove it.
How can I solve this problem, to switch every time camera without problems?
Any help would be really appreciated.