我目前正在android中尝试openCV的java示例进行人脸检测。但是,相机创建的 View 不是镜像成像。我尝试将 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。
关于java - 如何镜像显示OpenCV JavaCameraView前置摄像头(Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47497345/