如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头?
我目前正在用openCV的java示例在android中进行人脸检测实验。但是,相机创建的视图不是镜像成像。我尝试将如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头?,java,android,opencv,android-camera,Java,Android,Opencv,Android Camera,我目前正在用openCV的java示例在android中进行人脸检测实验。但是,相机创建的视图不是镜像成像。我尝试将android:screenOrientation设置为reverseLandscape,但不起作用。我想尝试做到这一点,有什么建议吗 布局中的代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" an
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"
/>
在OpenCV上加载
mOpenCvCameraView.setCameraIndex(1);
mOpenCvCameraView.enableView();
onCreate()方法
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);
对于垂直反转:
Core.flip(rgba, rgba, 1);
Core.flip(rgba, rgba, -1);
您需要将相机索引设置为。@AlexCohn,它仍然不会生成镜像。请尝试mOpenCvCameraView.setScaleX(-1)@AlexCohn,设置scaleX会返回我一个黑屏:(@AlexCohn:谢谢它工作了!!!