android-Camera2Basic icon indicating copy to clipboard operation
android-Camera2Basic copied to clipboard

Nexus 5x captured image is inverted

Open gbero opened this issue 10 years ago • 20 comments

When taking a picture using a Nexus 5x the picture is inverted (upside down) I was looking for a fix regarding this issue here since it's Google sample :)

gbero avatar Dec 08 '15 12:12 gbero

Are you using this sample's source code to take the picture?

keyboardsurfer avatar Dec 08 '15 13:12 keyboardsurfer

Yes I am.

It looks like doing :

CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics("" + mCameraDevice.getId());
int rotation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, rotation);

instead of :

int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

fixes the issue (at least on Nexus 5 and Nexus 5x)

gbero avatar Dec 08 '15 13:12 gbero

Do you want me to submit a PR with this ?

gbero avatar Dec 09 '15 08:12 gbero

@keyboardsurfer @yaraki any progress on this ? I can't figure out how to do this right. I'm getting problem on Galaxy S6 which has inverted (upside down) Front facing camera picture... :(

gbero avatar Jan 07 '16 13:01 gbero

Hi, @gbero . Please use the formula below instead of ORIENTATIONS.get(rotation).

private int getOrientation(int rotation) {
    return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}

I'm applying this change to the sample soon.

EDIT: mSensorOrientation is a field assigned from characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) in setUpCameraOutputs.

yaraki avatar Jan 12 '16 08:01 yaraki

Hi @yaraki,

I've tested your

private int getOrientation(int rotation) { return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; }

method and its not working on Nexus 5x on Back camera. Image is still rotated in final output. If you take portrait image it will save it rotated for 90 degrees. On the other side @gbero 's solution works perfectly on Nexus 5X.

UMFsimke avatar Apr 07 '16 14:04 UMFsimke

@yaraki @keyboardsurfer I'm getting complaints from users with Nexus 6 that FFC picture is inverted and can't figure out how to handle it. Could Google come up with a sample tested on at least devices like N5, N5x, N6 and N6p both front and rear camera ?

gbero avatar May 09 '16 08:05 gbero

Any update here?

mariobat88 avatar Jun 16 '16 18:06 mariobat88

Any news on this front? Having the same issue.

alistairsykes avatar Jun 21 '16 11:06 alistairsykes

I think I fixed this issue but I'm not 100% sure if this is the best fix. I got the sensor orientation from the camera characteristics and then I just added an ExifInterface with the desired fixed orientation for the image file. Like this:

Integer sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); if (sensorOrientation != null) { switch (sensorOrientation) { case 90: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90)); break; case 180: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_180)); break; case 270: exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_270)); break; } exif.saveAttributes();

mariobat88 avatar Jun 22 '16 17:06 mariobat88

How to rotate for video capture?

ajayld avatar Nov 14 '16 10:11 ajayld

Is there a solution for video preview? Cant find anything to solve it.

HenningL avatar Mar 30 '17 13:03 HenningL

Still with this fix. I have an issues with it. On the Phone the Images looks fine. But when I send them with email to my PC. (In preview they still look fine.) Once it's on my pc , it's rotated -90. From 3 phones that I have LGG4, Samsung J7 and Sony Experia (something). Only works on the LGG4 ( and it takes 16:9 images , others take 4:3).

I don't think its Windows fault, because when I capture the image and save it. Then load it on a ImageView , its rotated.

paakjis avatar Apr 13 '17 09:04 paakjis

The pictures are not being saved ?

talalz94 avatar Jun 18 '17 04:06 talalz94

Same for me, it is working fine on Pixel, Oppo, Micromax, Gionee but is rotated -90 degree on Samsung, can any one suggest a fix .. please

shashwattt-Pretlist avatar Sep 28 '17 07:09 shashwattt-Pretlist

I have the same problem. The picture in preview mode is rotated -90. I could not find how to fix this except for checking if it's Samsung phone and then rotating the picture my self. I thought that this Camera 2 api's should be much easier to use, but they introduce so many problems that you did not had with Camera 1. And what is worse, there is no real feedback or solution for this problem, in like one year now, with so many people complaining.

aleksamarkoni avatar Dec 12 '17 22:12 aleksamarkoni

Can somebody tell, How to calculate JPEG_ORIENTATION for front camera? I used (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; for back camera. which is working just fine.

NagoorBabu avatar Jul 16 '18 07:07 NagoorBabu

Not Working for Front Camera.Tested on S5(Samsung).

sohambannerjee8 avatar Sep 05 '18 07:09 sohambannerjee8

This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!

codingjeremy avatar Sep 19 '19 22:09 codingjeremy

This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!

codingjeremy avatar Sep 19 '19 22:09 codingjeremy