• 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Android Camera2 frame horizontal inversion

I want to horizontally invert frames coming to Surface object made from TextureView. What I can do is to set transformation matrix to this TextureView instance, whereas I postScale by -1 for x and 1 for y (leave unchanged), and than postTranslate dx on the full width of the view and leave dy unchanged (0F).

But the problem appears when I rotate my device by 90 degrees (horizontally) with screen rotation off: the image is rotated by 180 degrees, and it, of course, makes perfect sense, because x and y axises did not change.

How it can be solved? Is it possible to play with the translation matrix in such a way to resolve this problem? Or may be with OpenGL ES tools?

P.S.: strangely, but rotation is done two times two times more comparing to the device rotation itself, e.g. when I rotate the device by 90 degrees - preview is rotated by 180.

P.S.S.: I tried to invert the preview using Matrix's setPolyToPoly method... and have got exactly the same result.

P.S.S.S.: Also, played with open gl to achieve the goal using simple scale and rotation transformations for the model and projection matricies, and have got exact the same result!

Update:

These are screenshots that describe default behavior of the front camera - frame inversion is applied by HAL by default and I can't read the text; still, whether I rotate the device or not - "frame orientation" does not change:

Default behavior in portrait orientation

Default behavior in landscape orientation

And these are screenshots when I apply, e.g., Matrix.scaleM(modelMatrix, 0, -1F, 1F, 1F); and then apply this matrix to every coordinate that comes into vertex shader, so I can now read the text because I applied the inversion myself so HAL's inversion with my custom inversion will result into inversion absence, but when I rotate my device (with device orientation change on rotation disabled, of course, and that's the point) - I'll see myself flipped upside down, and that's, of course, make perfect sense, because device's coordinate system won't change. Still, I want to be able to avoid image rotation somehow on device rotation itself (like in the default mode - whether the device is rotated or not - the preview image just "does not care"), and to still be able to read the text (I mean, like in portrait mode).

Customized behavior in portrait mode - works as needed Customized behavior when device is rotated (but configuration is portrait anyway) - flipped upside down instead of horizontally

Do you run your tests on front or back camera? Usually only the front camera frame needs to be flipped horizontally, not the back camera.

Anyway if you need different transformations based on device orientation, you need to detect orientation changes in your Activity. Camera doesn't do anything by itself when device is rotated, you will get the same results whatever transformation method you choose.

Update #2

I just realised that this problem can be solved if transformation is applied at the right moment in the pipeline. I will show a working example, it uses OpenGL extensively but I hope you can find something of use. See this code fragment, it uses a vertex shader to transform the coordinates. In drawFrame() there's a call to getTransformMatrix(). Instead of performing this call, get a matrix from this method I wrote when performing a similar task.

  • 1
Reply Report
    • Yes, it is all about front camera. The activity is portrait mode only in this case (android:screenOrientation="portrait"), so the goal is to make it work in such a configuration. And, of course, camera doesn't do anything, but still something does, because in the default mode the camera image is not flipped if the device is rotated. I suppose it is abstracted by HAL and uses gyroscope to perform needed computations, but the question is either we can control it in a way to resolve the problem...
      • 1
    • Does the problem occurs with preview or with resulting photo/video? Also I think you should elaborate on your problem: what's wrong with the default mode? Maybe attach some pictures.
    • "because in the default mode the camera image is not flipped if the device is rotated" - it's not flipped since you haven't flipped it. You either flip the image on X axis or not and if you do, you will always get the frame upside down in landscape. The question is if this transform is needed. If we are talking about the preview frame I assure you nothing is hidden and no transform is applied by default.
    • Transformation matrix replacement on configuration change detection isn't smooth enough to satisfy the requirements, but thank you for your response anyway
      • 1
    • Thanks for the upvote! You now what, I think I might be wrong here, please disregard my earlier message. It should be possible, you just need to flip the image earlier in the pipeline. I will think about it.