Android + Opencv: Surfacetexture has been abandoned

Asked

Viewed 114 times

3

I’m developing an Eclipse application with Opencv. The application consists of detecting and recognizing objects (predefined in the database) in real time. Initially has a menu where the user can view the objects that the database has and then the "go" button that launches the camera from the mobile device and tries to recognize these same objects in video. I used a SurfaceTexture as support but when I run "go" the application crash after a few seconds and in logcat in addition to other information has this:

queueBuffer: Surfacetexture has been abandoned!

Code to create Surface and setup 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();
}

Already research this problem in several forums but none solved my problem. I have tried the solution of this post but changing the order of the functions came to nothing. Someone can give me a help?

  • 1

    Peter, could you check if there’s some other error appearing, maybe if you can extract one stacktrace relative to Exception that occurred. This SurfaceTexture has been abandoned it seems to me a lot that there was a Leak of some resource.

  • Yeah, I’ve checked the program more than once, and there’s only one mistake. The strange thing is that the application on a wiko smartphone works perfectly, however the same application on mobile phones like LG, Sony and Samsung does not work

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.