4

I need to be able to detect the reverse landscape sensor on a device.

This is the code I was using to detect reverse landscape, however doesn't seem to be working for Nexus 5X:

public boolean isSensorInReverseLandscape() {
    return ((getCameraPosition().equals(Position.FRONT) && mCameraInfo.orientation == 90) ||
            (getCameraPosition().equals(Position.BACK) && mCameraInfo.orientation == 270));
}

Seems to be working fine for my Nexus 6P which has the front camera sensor in reverse landscape and therefore orientation is returned as 90 for both back and front cameras (when normal front camera returns 270). However Nexus 5X CameraInfo.orientation seems to be returning 90, which is the same as your normal back camera orientation.

Is there any other reliable way of detecting that the camera sensor is positioned in reverse landscape? Unfortunately I don't have a device to play around with.

EDIT:

Looking at the CameraInfo docs:

public int orientation

Added in API level 9 The orientation of the camera image. The value is the angle that the camera image needs to be rotated clockwise so it shows correctly on the display in its natural orientation. It should be 0, 90, 180, or 270.

For example, suppose a device has a naturally tall screen. The back-facing camera sensor is mounted in landscape. You are looking at the screen. If the top side of the camera sensor is aligned with the right edge of the screen in natural orientation, the value should be 90. If the top side of a front-facing camera sensor is aligned with the right of the screen, the value should be 270.

So why does the back facing camera sensor mounted in reverse landscape orientation also reports 90? That is just strange..

EDIT 2:

My code for getting the camera info:

 for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        int cameraId = i;
        CameraInfo cameraInfo = new CameraInfo();
        Camera.getCameraInfo(i, cameraInfo);

        CameraLegacy camera = new CameraLegacy(cameraId, cameraInfo, mContext, mMode);
        cameras.add(camera);
    }

Where CameraLegacy saves the info into mCamraInfo.

EDIT 3:

This is how the camera constructor outputs orientation:

02-19 18:48:01.832: D/CameraController(8093): .findAvailableCameraDevices() - entered
02-19 18:48:01.833: D/CameraController(8093): .findAvailableCameraDevices() - camera id is 0
02-19 18:48:01.833: D/CameraController(8093): .findAvailableCameraDevices() - camera orientation is 90
02-19 18:48:01.994: D/CameraLegacy(8093): CameraLegacy() - camera orientation in constructor is 90
02-19 18:48:01.994: D/CameraController(8093): .findAvailableCameraDevices() - camera id is 1
02-19 18:48:01.995: D/CameraController(8093): .findAvailableCameraDevices() - camera orientation is 270
02-19 18:48:01.995: D/CameraLegacy(8093): CameraLegacy() - camera orientation in constructor is 270
vkislicins
  • 3,331
  • 3
  • 32
  • 62
  • My Nexus 5X does return 270; maybe your code to get **mCameraInfo** is wrong? – Alex Cohn Feb 18 '16 at 14:01
  • Interesting. I've updated the question with my code for getting the info but surely if there was a problem there, I'd notice it on other devices... – vkislicins Feb 18 '16 at 14:18
  • Just out of curiosity, can I ask your Nexus 5X version / build number? That's probably farfetched but maybe something to do with versions as I'm sure I've tested my code for detecting reverse landscape before and it worked fine... – vkislicins Feb 18 '16 at 14:23
  • Sorry, the Nexus is not on me at this moment. Just out of curiosity, did you try to log `cameraInfo.orientation` from inside this loop? Before you initialize **CameraLegacy**? – Alex Cohn Feb 18 '16 at 14:29
  • 1
    No but might be worth a try. Turnaround will be pretty slow as our testers are remote but I don't have any better ideas :) – vkislicins Feb 18 '16 at 14:46
  • Please see my comment here: http://stackoverflow.com/questions/35490789/picture-taken-from-camera-displayed-in-imageview-is-always-horizontal-android/35491306?noredirect=1#comment58677128_35491306 – Endre Börcsök Feb 18 '16 at 21:04
  • I don't have a problem rotating the image - I have code for that. It's just suddenly Nexus 5X started reporting orientation 90 instead of 270 for the back camera.. – vkislicins Feb 19 '16 at 10:32
  • 1
    @AlexCohn I think you're correct and the problem is in setting/getting camera orientation. Not sure how and why on that specific device, but will investigate. Thank you for the suggestion! – vkislicins Feb 22 '16 at 10:13
  • So it looks like the during the construction phase the back camera reports orientation 90... Back to square one – vkislicins Feb 22 '16 at 14:26
  • Is this one specific device? Or some "class" of Nexus 5X's? Googling shows that camera2 API is expected to resolve this problem. My Nexus 5X has Marshmello 6.01 build MMB29Q – Alex Cohn Feb 22 '16 at 15:13
  • All of the Nexus 5Xs my testers test on seem to be failing, including google/bullhead/bullhead:6.0.1/MMB29Q/2480792. camera2 does resolve this issue but introduces a trunkload of new ones. I've implemented camera2 API but so far I'm not confident enough to switch the production app to it. – vkislicins Feb 22 '16 at 17:49

0 Answers0