Android OpenCV在应用程序中显示两个(正面+背面)摄像头

uinbv5nw  于 2023-01-09  发布在  Android
关注(0)|答案(1)|浏览(201)

我正在尝试将前置摄像头预览叠加到后置摄像头预览上。我可以访问前置摄像头或后置摄像头,但不能同时访问两者。
下面是我的代码:
活动_主要. 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);
        

    }

问题:我只看到屏幕上的后摄像头视图。我想要的是一个小窗口,前摄像头视图覆盖在这个上面,这样我就可以看到两者。
我该怎么做呢?

von4xj4u

von4xj4u1#

不能这么做。
“Android的cv::VideoCapture类实现不支持同时使用多个摄像头。”“Android Camera API不支持并发使用摄像头”
http://answers.opencv.org/question/8328/can-i-open-2-android-cameras-concurrently/

相关问题