5

I have written an optic flow detection application which based on OpenCV for Android tutorials and source code of Barry Thomas's application OpenCV Demo 2. Now I want to make this application a background task so I can pass the detection result to my main activity via listener interface.

All the application samples in OpenCV totorials extends Activity and implements CvCameraViewListener and shows camera input on the scrren. I want to able to capture camera frames and do optic flow detection on frames in background without showing them on the screen.

How can I get frames from camera in background witout showing camera input?

Mukaddes
  • 307
  • 2
  • 12

2 Answers2

1

There are two ways, but you have to keep a Mat in the memory in the method onCameraFrame:

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();      
    return mRgba;
}

1) make the cameraview invisible 2) make onCameraFrame return null

Both ways you should do your additional work in another view.

xMKx
  • 121
  • 4
0

The only way I found to get camera frames in background is by using a SurfaceTexture instead of a SurfaceView, and therefore set it using Camera.setPreviewTexture instead of Camera.setPreviewDisplay.

This answer as well as this one helped.

Community
  • 1
  • 1
JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
  • 2
    You're talking about the Android Camera library, while the question is about OpenCV's library, which uses `org.opencv.android.CameraBridgeViewBase` – Mohamed Khamis Jun 26 '15 at 11:29