Why does the default camera preview for Android look smoother than my own camera preview?

I just set up a very simple camera preview that displays the full screen mode of the camera. I compared the smoothness of both my application and the Android camera and realized that the camera for Android looks a lot smoother.

Why is this so? Are there any special tricks to improve camera preview performance?

+6
source share
2 answers

I ran into the same problem a while ago, and it turned out to be related to camera resolution. Most likely, your Camera initialized with the highest resolution available, which can slow down performance during preview. Try setting a picture size below with something like this .-

 Camera.Parameters params = camera.getParameters(); params.setPictureSize(1280, 960); camera.setParameters(params); 

Please note that you need to set the available image size. You can check the available sizes with

 camera.getParameters().getSupportedPictureSizes(); 

Hope this helps.

EDIT

It seems that the image size is used with a different aspect ratio than the standard, and slows down. This is how I choose pictureSize .

First, I get the default aspect ratio of the camera pictureSize

 Camera.Parameters params = camera.getParameters(); defaultCameraRatio = (float) params.getPictureSize().width / (float) params.getPictureSize().height; 

And then I get a lower pictureSize that matches the same ratio.

 private Size getPreferredPictureSize() { Size res = null; List<Size> sizes = camera.getParameters().getSupportedPictureSizes(); for (Size s : sizes) { float ratio = (float) s.width / (float) s.height; if (ratio == defaultCameraRatio && s.height <= PHOTO_HEIGHT_THRESHOLD) { res = s; break; } } return res; } 

Where PHOTO_HEIGHT_THRESHOLD is the maximum height you want to allow.

+5
source

This answer was a little late, but after struggling with the same problem, I decided that I shared what I found.

Not only could I not compare the β€œsmoothness” of the camera in the warehouse, but I was not able to match the size of the camera. My live preview was much darker compared to the camera, especially in low light conditions.

My solution was ultimately the FPS issue, as Robin originally suggested in an early comment.

The default FPS preview on the Nexus 5 is a static 15 FPS. The android android application detects and sets the FPS preview, which uses the dynamic range (if this range includes 30 frames per second). On node 5, this range is 7 frames per second β†’ 30 frames per second. In low light, the camera drops to a lower FPS to keep the preview vibrant, while in bright conditions it jumps to 30 frames per second.

Corresponding code from android android application:

Here are the api camera calls to install FPS using hard-coded values ​​(for simplicity) specific to Nexus 5.

 public void setFps(Camera camera) { Camera.Parameters params = camera.getParameters(); params.setPreviewFpsRange(7000, 30000); Camera.setParameters(params); } 
+1
source

Source: https://habr.com/ru/post/954109/


All Articles