如何在镜像中显示 OpenCV JavaCameraView 前置摄像头 (Android)?
How to display OpenCV JavaCameraView front camera in mirror image (Android)?
我目前正在 android 中试验 openCV 的 java 人脸检测示例。但是,相机创建的视图不在镜像中 imaging.I 尝试将 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) 返回黑色显示。
制作镜像的最小改动是将以下代码添加到您的 CvCameraViewListener2:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
Core.flip(rgba, rgba, 1);
return rgba;
}
这不是最有效的方法,但可能是可以接受的。在我相当弱的测试设备上,这将 FPS 从 7.17 降低到 7.15.
水平反转:
Core.flip(rgba, rgba, 1);
垂直反转:
Core.flip(rgba, rgba, -1);
我目前正在 android 中试验 openCV 的 java 人脸检测示例。但是,相机创建的视图不在镜像中 imaging.I 尝试将 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) 返回黑色显示。
制作镜像的最小改动是将以下代码添加到您的 CvCameraViewListener2:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
Core.flip(rgba, rgba, 1);
return rgba;
}
这不是最有效的方法,但可能是可以接受的。在我相当弱的测试设备上,这将 FPS 从 7.17 降低到 7.15.
水平反转:
Core.flip(rgba, rgba, 1);
垂直反转:
Core.flip(rgba, rgba, -1);