如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头? [英] How to display OpenCV JavaCameraView front camera in mirror image (Android)?

查看:1529
本文介绍了如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试验openCV的android中面部检测的java示例。但是,相机创建的视图不是镜像。我尝试将 android:screenOrientation 设置为 reverseLandscape 但是那没起效。我想尝试实现这个,有什么建议吗?

I am currently experimenting with the openCV's java example on face detection in android. However, the view created by the camera is not in mirror imaging.I tried setting the android:screenOrientation to reverseLandscape but it did not work. I would like to try to achieve this, any suggestions?

布局代码:

<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;

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

onCreate()方法

onCreate() method

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

mOpenCvCameraView不包含setDisplayOrientation()方法,setRotation(180)返回黑色显示。

mOpenCvCameraView did not contain a setDisplayOrientation() method and setRotation(180) returned me with a black display.

推荐答案

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

The minimal change to make the mirror is to add the following code to your CvCameraViewListener2:

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

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

This is not the most efficient way, but probably acceptable. On my rather weak test device, this reduces FPS from 7.17 to 7.15.

这篇关于如何在镜像(Android)中显示OpenCV JavaCameraView前置摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆