简体   繁体   English

Android应用中的相机定位

[英]Camera Orientation in Android App

I have created an Android app that opens a video stream, extending the class JavaCameraView. 我创建了一个Android应用程序,用于打开视频流,扩展JavaCameraView类。 The application should capture frames to process them. 应用程序应捕获帧以处理它们。 I have used, to realize this app, the tutorials contained in the OpenCV4Android package (version 2.4.5). 我已经使用OpenCV4Android包(版本2.4.5)中包含的教程来实现这个应用程序。 I use Eclipse Juno, and my phone is a samsung s4, and surfing the web I realize that my problem is very common on many devices, including galaxy s,s2,s3,s4. 我使用Eclipse Juno,我的手机是三星s4,在网上冲浪我意识到我的问题在很多设备上很常见,包括galaxy s,s2,s3,s4。

My problem is that my camera, when is opened, in portrait mode results rotated of 90 degrees. 我的问题是我的相机在打开时,在纵向模式下会旋转90度。 It seems to be always in landscape orientation. 它似乎总是在横向方向。 I have read somewhere that it is possible to flip camera on the fly, but I have not understood how. 我在某处读过可以动态翻转相机,但我还不知道怎么做。 Could someone help me? 有人能帮助我吗?

Default camera orientation is in landscape mode only. 默认摄像机方向仅在横向模式下。 You need to set the parameters on the camera to set the rotation 您需要在摄像机上设置参数以设置旋转

Camera.Parameters parameters = camera.getParameters();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            parameters .set("orientation", "portrait");
            parameters .set("rotation",90);
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {                               
            parameters .set("orientation", "landscape");          
            parameters .set("rotation", 90);
        }

camera.setParameters(parameters);

or

camera.setDisplayOrientation(90);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM