Camerainfo.orientation gives the wrong answer

Android provides this code to preview the camera face up for all camera and screen settings:

public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } 

In the simplest case, when the screen is in portrait orientation ( rotation is 0) with a reverse camera, this reduces to result = info.orientation . According to documents, information. Orientation

angle of rotation of the camera image clockwise, so that it is displayed correctly on the display in a natural orientation. It must be 0, 90, 180 or 270.

This means that info.orientation should be the sum that the raw camera images rotate counterclockwise.

On the back of the camera, the Samsung Galaxy S II info.orientation is 90, as expected for reverse cameras. However, the preview of the original camera rotates 90 degrees clockwise, not counterclockwise. This means that after applying the above code, the preview is displayed upside down (180 degrees).

Why is there a 180 degree difference between the information reported by the camera and the actual orientation of its raw images?

This exact problem - the camera images are 90 degrees clockwise, when info.orientation reports 90 - this question is also reported.

Also see this possibly related question .

+8
android android camera
source share

No one has answered this question yet.

See similar questions:

23
Is CameraInfo.orientation registered correctly? Incorrectly implemented?
17
Is the setDisplayOrientation sample code correct?
3
Orientation of the camera on Android, the phone gives false data?

or similar:

23
Is CameraInfo.orientation registered correctly? Incorrectly implemented?
22
Should the Android camera image be rotated after capture?
8
setOrientationHint rotates the video counterclockwise on some front-facing cameras of phones (HTC)
3
Detect camera sensor in reverse terrain (Nexus 5 rear camera)
2
Android Image / Video rotated 90 degrees counterclockwise
one
How can I implement an Android camera to take photos in any orientation of the screen?
0
onPreviewFrame reverse image rotated 180 degrees on some devices
0
Get camera interior orientation in API <9
0
Does photographing in portrait mode remain counterclockwise?
0
Camera control and user rotation

All Articles