Nexus 6 Front Camera Upside Down

I know this question has been asked before, however I cannot find any solutions that work.

The front camera of the Nexus 6 always displayed upside down in my application. Some of the solutions are to use " setDisplayOrientation ", which flips the camera on the screen. However, we encode a video with frames derived from onPreviewFrame .

According to the Android SDK Documentation , setDisplayOrientation does not actually modify byte[] in onPreviewFrame .

This does not affect the order of the byte array transferred to the onPreviewFrame (byte [], camera), JPEG images, or recorded video. This method cannot be called during preview.

If it is not possible to get the Nexus 6 frames of the onPreviewFrame front cameras in the correct orientation , what is the fastest way to flip each frame without losing a drop in fps.

Thanks!

+5
source share
3 answers

I managed to resolve this and keep fps high by opening cv to flip frames.

 yuvimage = opencv_core.IplImage.create(frame.getWith / 2, frame.getHeight / 2 * 3 / 2, IPL_DEPTH_8U, 1); yuvimage.getByteBuffer().clear(); yuvimage.getByteBuffer().put(halveYUV420(frame.getData(), frame.getWidth(), frame.getHeight())); rgbimage = opencv_core.IplImage.create(frame.getWidth / 2, frame.getHeight / 2, IPL_DEPTH_8U, 3); rgbimage.getByteBuffer().clear(); opencv_imgproc.cvCvtColor(yuvimage, rgbimage, opencv_imgproc.CV_YUV2BGR_NV21); opencv_core.cvFlip(rgbimage, rgbimage, 0); 
+2
source

The code snippet under Camera.setDisplayOrientation () resolved this issue for me. You need to try it.

+3
source

The fastest way is to click inside the GPU itself. Preview the camera on GLSurfaceView and use vertex shaders to flip the image upside down. Then use glReadPixels to get the bytes of the current frame. I'm not sure about glReadPixels performance on other phones, but on Nexus 6/5 this should be pretty fast.

0
source

All Articles