Skip to content

JavaCamera2View incorrect camera output caused by wrong preview size #14915

@JoogsWasTaken

Description

@JoogsWasTaken
System information (version)
  • OpenCV => 4.1.0
  • Operating System / Platform => Android API Level 28 (Patch: June 1st, 2019)
  • Compiler => clang++ 7.0
Detailed description

Using JavaCamera2View will output a faulty camera image as shown below if the aspect ratio of the preview size, calculated by calcPreviewSize, does not match up with the actual screen aspect ratio.

Details

device-2019-06-27-122401

For reference, the device I tested this on is a Xiaomi Mi A1 with the latest patches installed. It has a device screen size of 1920x1080. The calculated preview size, which is also being used in the image above, is 1440x1080. This results in an aspect ratio of 4:3 as opposed to the screen aspect ratio of 16:9. The highest preview size with the same aspect ratio as provided by the device is 1280x720. Here's a small snippet of the device's reported available preview sizes:

  • 1440x1080 (automatically picked as "best")
  • 1280x960
  • 1280x720 (should be picked as "best")
  • 1280x640
  • 864x480
  • ...

This behavior is due to calcPreviewSize assuming that the first output size provided by getOutputSizes can be assumed as the "best" preview size from the start. Deleting the two lines before looping over all available preview sizes fixes this behavior. Just for reference, the image below is the same scene as above but with the two lines deleted.

Details

device-2019-06-27-122256

I'm willing to submit a PR since this fix is just deleting two lines of code. However I'd like to see if someone is able to confirm this behavior.

Steps to reproduce

Haven't found a way to reproduce it yet because it seems to be an issue that heavily depends on the device (and I only have one device to test it on). However overriding the call to calcPreviewSize in connectCamera with dimensions smaller than the device's screen dimensions should evoke this behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions