Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Issues with Nexus 5x - Camera is upside down #91

Closed
vhuynh opened this issue Nov 3, 2015 · 16 comments
Closed

Issues with Nexus 5x - Camera is upside down #91

vhuynh opened this issue Nov 3, 2015 · 16 comments

Comments

@vhuynh
Copy link

vhuynh commented Nov 3, 2015

There's an issue specifically with the Nexus 5x - images are upside down. It seems to be related to the way the camera orientation is being set.

Supposedly the correct way to set it is here:
http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

For reference:
https://code.google.com/p/android/issues/detail?id=191210 (See comment #4)

Any chance you guys are working on a solution? Thanks in advance.

@braebot
Copy link
Member

braebot commented Nov 4, 2015

We have not done any work on this issue, as this is the first report we've had. We do handle rotation in much the same way as specified in your references, but not exactly. Please see the rotation-related code here. Are you able to tell if any of the logic is different that the references you posted?

@vhuynh
Copy link
Author

vhuynh commented Nov 4, 2015

Hi. I had to navigate through the source code a bit to understand - I don't think you guys use the rotation code to apply to the "Camera.setDisplayOrientation", but rather to do something else with your display

The only place in the code that utilizes the method mentioned in the first comment is in CardScanner.java in the prepareScanner() method:

mCamera.setDisplayOrientation(90);

It is hardcoded to 90.

@ktchernov
Copy link

Confirmed on a 5X in our app as well.

@maevelander
Copy link

Confirmed on Nexus 5X in our app as well

Here's a good clear description of the issue and solution: http://9to5google.com/2015/11/07/why-are-images-nexus-5x-upside-down/

@jcady
Copy link

jcady commented Nov 17, 2015

Can confirm, happens on Nexus 5X with our app.

@MitekDev-ASingal
Copy link

We have noticed this issue on Nexus 5x as well.

@Cardio Team: Could you please let us know when will you release a patch for it?

@pocketwod
Copy link

Hey Guys, experiencing same problem, any news on a fix?

@MitekDev-ASingal
Copy link

I resolved this issue by calling below function in startPreview() function defined in CameraManager.java file in the Manatee SDK.

public void setCameraDisplayOrientation(Context context, Camera mCamera) {
    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(0, info); // Use the first rear-facing camera
    int rotation = getDeviceCurrentOrientation(context);

    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;
    }
    mCamera.setDisplayOrientation(result);
}

So the startPreview looks like this:

public void startPreview() {
    if (camera != null && !previewing) {
        setCameraDisplayOrientation(context,camera);
        camera.startPreview();
        previewing = true;
    }
}

With these changes, Camera preview is not upside down while scanning the documents. Hope this helps.

@MitekDev-ASingal
Copy link

Sorry. Forgot to provide the function below:

public static int getDeviceCurrentOrientation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int rotation = windowManager.getDefaultDisplay().getRotation();
    Log.d("Utils", "Current orientation = " + rotation);
    return rotation;
}

@braebot
Copy link
Member

braebot commented Nov 18, 2015

Sorry for the delay. @MitekDev-ASingal, any chance you could submit a PR with your change? We'd be happy to release an update if it works.

@MitekDev-ASingal
Copy link

@braebot Thanks for your comment. What is the procedure to submit a PR? Could you please share a link for that?

@braebot
Copy link
Member

braebot commented Nov 18, 2015

@apMadden
Copy link

apMadden commented Dec 2, 2015

Any update on this issue?

@braebot
Copy link
Member

braebot commented Dec 2, 2015

Sorry, no update.

@Chrisplus
Copy link

May I inquire the update on this issue?
@MitekDev-ASingal it seems no pull requests have been seen.

@braebot
Copy link
Member

braebot commented Dec 14, 2015

Please see card-io/card.io-Android-source#49.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants