Back to project page android-opencv-template.
The source code is released under:
MIT License
If you think the Android project android-opencv-template listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.floatlearning.android_opencv_template; /*from w ww . jav a 2 s. com*/ import android.app.Activity; import android.os.Bundle; import android.util.Log; import org.opencv.android.BaseLoaderCallback; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.JavaCameraView; import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 { private static final String TAG = "MainActivity"; private CameraBridgeViewBase mOpenCVCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV load success"); mOpenCVCameraView.enableView(); } break; default: { super.onManagerConnected(status); } break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mOpenCVCameraView = new JavaCameraView(this, -1); setContentView(mOpenCVCameraView); mOpenCVCameraView.setCvCameraViewListener(this); } @Override public void onPause() { super.onPause(); if (mOpenCVCameraView != null) { mOpenCVCameraView.disableView(); } } @Override public void onResume() { super.onResume(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback); } @Override public void onDestroy() { super.onDestroy(); if (mOpenCVCameraView != null) { mOpenCVCameraView.disableView(); } } public void onCameraViewStarted(int width, int height) { } public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { return inputFrame.rgba(); } public void onCameraViewStopped() { } }