我正在尝试将前置摄像头预览叠加在后置摄像头预览之上。我可以使用前置或后置摄像头,但不能同时使用它们。

这是我的代码:

activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:opencv="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:id="@+id/CameraViewBack"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        opencv:camera_id="back"
        opencv:show_fps="true" />
    <!-- camera_id: "any", "back", "front" or by number value -->

    <org.opencv.android.JavaCameraView
        android:id="@+id/CameraViewFront"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:visibility="gone"
        opencv:camera_id="front"
        opencv:show_fps="true" />

</FrameLayout>

MainActivity.java:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);

        mFrameLayout = (FrameLayout) findViewById(R.id.main_framelayout);

        mOpenCvCameraViewBack = (CameraBridgeViewBase) findViewById(R.id.CameraViewBack);
        mOpenCvCameraViewBack.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraViewBack.setCvCameraViewListener(this);

        mOpenCvCameraViewFront = (CameraBridgeViewBase) findViewById(R.id.CameraViewFront);
        mOpenCvCameraViewFront.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraViewFront.setCvCameraViewListener(this);


    }

问题:我只能在屏幕上看到后置摄像头 View 。我想要的是一个小窗口,前摄像头 View 叠加在此窗口之上,这样我就可以看到两者。

我怎样才能做到这一点?谢谢。

最佳答案

无法做到这一点。



http://answers.opencv.org/question/8328/can-i-open-2-android-cameras-concurrently/

10-06 12:15