简体   繁体   中英

OpenCV Android: Get camera frames in background without showing on the screen

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM