Skip to content

android: JavaCamera2View use calculateCameraFrameSize() method#14981

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:android_camera_use_calc_frame_size_method
Jul 6, 2019
Merged

android: JavaCamera2View use calculateCameraFrameSize() method#14981
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:android_camera_use_calc_frame_size_method

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Jul 4, 2019

from CameraBridgeViewBase (common base with JavaCameraView)

Both interfaces (JavaCameraView/JavaCamera2View) using the same method and the same approach.
If user want to tune calculation then it should override "View" class and override this method (calculateCameraFrameSize())

resolves #14915

from CameraBridgeViewBase (common base with JavaCameraView)
@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jul 4, 2019

/cc @floe @DorJoogl

@JoogsWasTaken
Copy link
Copy Markdown

JoogsWasTaken commented Jul 5, 2019

Great effort. However it's missing the aspect ratio check from the old JavaCamera2View. Therefore this line would have to look more like this.

if (width >= calcWidth && height >= calcHeight && Math.abs(aspect - (float) width / height) <= 0.02) {
    calcWidth = (int) width;
    calcHeight = (int) height;
}

aspect is defined as float aspect = (float) maxAllowedWidth / maxAllowedHeight prior to the outer loop. Tested it on my end and using JavaCamera2View now selects the correct preview size. It also doesn't break JavaCameraView for the sake of supporting the deprecated camera API.

This doesn't fix the broken previews on certain preview sizes I mentioned yet. If developers should override calculateCameraFrameSize() to adjust the preview size to their needs, then they might encounter the same issue with the faulty camera output.

I'm positive however that this change is very necessary and should be merged asap. As a first-time user of OpenCV4Android just a couple months ago I was a bit frustrated to see it not work out of the box. So I'm very glad this issue is getting resolved.

@floe
Copy link
Copy Markdown
Contributor

floe commented Jul 5, 2019

Can't test right now unfortunately, but looks good. Should this also be in 4.1.1?

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jul 6, 2019

Purpose of this patch is to reuse existed code from both JavaCameraView/JavaCamera2View and provide the same selection for apps.

Next step is to refine frame selection itself:

  • user callback instead of method overload
  • aspect ratio (current approach is not reliable in some cases)
  • try approach with "scoring" of each frame size and select the best one (will eliminate "select the first" workaround)

Suggestions are welcome!

(to merge this - 👍 )

@opencv-pushbot opencv-pushbot merged commit 3998b41 into opencv:3.4 Jul 6, 2019
opencv-pushbot pushed a commit that referenced this pull request Jul 6, 2019
@JoogsWasTaken
Copy link
Copy Markdown

aspect ratio (current approach is not reliable in some cases)

Just curious. What's unreliable with the current approach? I get the part about reusing old code but what's stopping us from adding the aspect ratio check to CameraBridgeViewBase? That'd somewhat fix the behavior in #14915 and in the recent comments of #11261.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jul 8, 2019

Example:

2019-07-08 20:33:16.083 15844-15844/org.opencv.samples.puzzle15 I/JavaCamera2View: calcPreviewSize: 1184x576
2019-07-08 20:33:23.070 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 1600x1200  aspect: 1.3333333333333333  e_aspect:2.0555555555555554
2019-07-08 20:33:24.506 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 1280x720  aspect: 1.7777777777777777  e_aspect:2.0555555555555554
2019-07-08 20:33:28.580 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 960x720  aspect: 1.3333333333333333  e_aspect:2.0555555555555554
2019-07-08 20:33:30.887 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 864x480  aspect: 1.8  e_aspect:2.0555555555555554
2019-07-08 20:33:35.285 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 720x480  aspect: 1.5  e_aspect:2.0555555555555554
2019-07-08 20:33:35.290 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 640x480  aspect: 1.3333333333333333  e_aspect:2.0555555555555554
2019-07-08 20:33:35.293 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 480x320  aspect: 1.5  e_aspect:2.0555555555555554
2019-07-08 20:33:35.298 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 320x240  aspect: 1.3333333333333333  e_aspect:2.0555555555555554
2019-07-08 20:33:35.303 15844-15844/org.opencv.samples.puzzle15 D/CameraBridge: trying size: 176x144  aspect: 1.2222222222222223  e_aspect:2.0555555555555554
2019-07-08 20:33:35.309 15844-15844/org.opencv.samples.puzzle15 I/JavaCamera2View: Selected preview size to 864x480

0.02 aspect threshold is not reliable here.

BTW, device screen size is 1280x720, but application area is much smaller (status bar, title bar, "home" button area)

@alalek alalek mentioned this pull request Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants