我从CameraBridgeViewBase
(OpenCV)扩展了一项活动。调用mOpenCvCameraView.enableView();
时,应显示摄像头。但现在不是。
我的活动如下
public class MainActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "OCVApplication::MainActivity";
public static final int VIEW_MODE_RGBA = 0;
private CameraBridgeViewBase mOpenCvCameraView;
public static int viewMode = VIEW_MODE_RGBA;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
public void onCameraViewStarted(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void onCameraViewStopped() {
// TODO Auto-generated method stub
}
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
}
xml是
<org.opencv.android.JavaCameraView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:visibility="gone"
android:layout_marginBottom="10dp"
android:layout_above="@+id/ImageCaptureButton"
android:id="@+id/image_manipulations_activity_surface_view"
opencv:show_fps="true"
opencv:camera_id="any"/>
答案 0 :(得分:3)
你错过了这个:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
return inputFrame.rgba();
}
希望这有帮助!