简体   繁体   中英

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. When using the app in portrait mode the image is still in landscape mode though (it's rotated by 90 degrees and stretched). 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. 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).

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?

在此输入图像描述

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

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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