如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头?

时间:2017-11-26 14:46:35

标签: java android opencv android-camera

我目前正在尝试使用openCV的android实例中的人脸检测示例。但是,相机创建的视图不是镜像。我尝试将android:screenOrientation设置为reverseLandscape,但它不起作用。我想尝试实现这个,有什么建议吗?

布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<org.opencv.android.JavaCameraView
    android:id="@+id/fd_activity_surface_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:screenOrientation="reverseLandscape"
    />

实例

private CameraBridgeViewBase mOpenCvCameraView;
装载OpenCV时

mOpenCvCameraView.setCameraIndex(1);
mOpenCvCameraView.enableView();

onCreate()方法

mOpenCvCameraView = findViewById(R.id.fd_activity_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);

mOpenCvCameraView没有包含setDisplayOrientation()方法,而setRotation(180)则返回黑色显示。

2 个答案:

答案 0 :(得分:1)

制作镜像的最小变化是将以下代码添加到 CvCameraViewListener2

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat rgba = inputFrame.rgba();
    Core.flip(rgba, rgba, 1);
    return rgba;
}

这不是最有效的方式,但可能是可以接受的。在我相当弱的测试设备上,这会将FPS从 7.17 降低到 7.15

答案 1 :(得分:0)

对于水平反转:

Core.flip(rgba, rgba, 1);

垂直反转:

Core.flip(rgba, rgba, -1);