I'm developing an application in Eclipse with OpenCV. The application consists of detecting and recognizing objects (predefined in the database) in real time. Initially there is a menu where the user can view the objects that the database has and then the "go" button that launches the camera of the mobile device and tries to recognize those same objects in video. I use a SurfaceTexture
as support but when I run the crash application after a few seconds and in logcat
queueBuffer: SurfaceTexture has been abandoned!
Code to create Surface
and setup of the camera:
public void setupCamera(int width, int height)
{
//Log.i(TAG, "setupCamera");
synchronized (this) {
if (mCamera != null) {
Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> sizes = params.getSupportedPreviewSizes();
mFrameWidth = width;
mFrameHeight = height;
// selecting optimal camera preview size
{
int minDiff = Integer.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - height) < minDiff) {
mFrameWidth = size.width;
mFrameHeight = size.height;
minDiff = Math.abs(size.height - height);
}
}
}
params.setPreviewSize(getFrameWidth(), getFrameHeight());
//Log.i(TAG, Integer.valueOf(mFrameWidth).toString());
//Log.i(TAG, Integer.valueOf(mFrameHeight).toString());
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
// List<String> FocusModes = params.getSupportedFocusModes();
// if (FocusModes
// .contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
// params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
// }
mCamera.setParameters(params);
/* Now allocate the buffer */
params = mCamera.getParameters();
int size = params.getPreviewSize().width
* params.getPreviewSize().height;
size = size
* ImageFormat
.getBitsPerPixel(params.getPreviewFormat()) / 8;
mBuffer = new byte[size];
/* The buffer where the current frame will be copied */
mFrame = new byte[size];
mCamera.addCallbackBuffer(mBuffer);
onPreviewStarted(params.getPreviewSize().width,
params.getPreviewSize().height);
try {
setPreview();
} catch (IOException e) {
//Log.e(TAG,
//"mCamera.setPreviewDisplay/setPreviewTexture fails: "
//+ e);
}
/*
* Notify that the preview is about to be started and deliver
* preview size
*/
//onPreviewStarted(params.getPreviewSize().width,
//params.getPreviewSize().height);
/* Now we can start a preview */
mCamera.startPreview();
}
}
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width,
int height) {
//Log.i(TAG, "surfaceChanged");
setupCamera(width, height);
}
public void surfaceCreated(SurfaceHolder holder) {
//Log.i(TAG, "surfaceCreated");
(new Thread(this)).start();
}
public void surfaceDestroyed(SurfaceHolder holder) {
//Log.i(TAG, "surfaceDestroyed");
releaseCamera();
}
I have already researched this problem in several forums but none have solved my problem. I've tried the solution for this post but changing the order of functions did not come to anything. Can someone help me?