简体   繁体   English

使用CameraGLSurfaceView以纵向模式显示camera2预览

[英]Displaying camera2 preview in portrait mode using CameraGLSurfaceView

I'm trying to use OpenCV in an Android AR application with the Camera2 API and OpenCV's CameraGLSurfaceView. 我正在尝试使用Camera2 API和OpenCV的CameraGLSurfaceView在Android AR应用程序中使用OpenCV。 When using the app in portrait mode the image is still in landscape mode though (it's rotated by 90 degrees and stretched). 在纵向模式下使用应用程序时,图像仍处于横向模式(旋转90度并拉伸)。 When using it in Landscape mode everything works fine. 在横向模式下使用它时一切正常。

As far as I understand the problem originates in the camera always delivering frames in landscape mode and the OpenGL part interfering with the view adjusting to the portrait mode. 据我所知,问题源于相机始终以横向模式提供帧,而OpenGL部分干扰视图调整为纵向模式。 I therefore tried transposing and flipping the image in the c++ part of the code as well as adjusting the preview size to portrait but it ends up being half black and squished (see image). 因此,我尝试在代码的c ++部分中移植和翻转图像,以及将预览大小调整为纵向,但最终变为半黑色并压扁(见图像)。

Is there another way of solving this problem? 还有另一种解决这个问题的方法吗?

Does anyone have any experience in using the CameraGLSurfaceView in portrait mode with camera2 and can help me out on this? 有没有人有使用CameraGLSurfaceView在肖像模式下使用CameraGLSurfaceView的经验,可以帮我解决这个问题吗?

在此输入图像描述

I actually found a solution that works for me after at least a day of trying, probably I should have looked more into openGL before trying... 我实际上找到了一个在尝试至少一天之后对我有用的解决方案,可能在尝试之前我应该​​更多地考虑openGL ...

For anyone else struggling with the same problem, you can change the texCoord2D in OpenCV's CameraGLRenderBase (you can extend it by listening for rotation changes and adapting the coords accordingly). 对于其他遇到同样问题的人,可以在OpenCV的CameraGLRenderBase中更改texCoord2D(您可以通过监听旋转变化并相应地调整坐标来扩展它)。 For portrait mode it worked for me to set 对于肖像模式,我可以设置它

private final float texCoord2D[] = { 1, 0, 0, 0, 1, 1, 0, 1 }; The advantage of this approach is that you don't need any flipping in the OpenCV code and it doesn't seem to affect the frame rate at all. 这种方法的优点是您不需要在OpenCV代码中进行任何翻转,它似乎根本不会影响帧速率。

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

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