EzequielAdrianM / Camera2Vision

Android Face Detector
Apache License 2.0
117 stars 52 forks source link

Size returned as null on Sony Xperia z5 7.1.1 #4

Closed eliayakoumi closed 7 years ago

eliayakoumi commented 7 years ago

i am trying to run the app on a sony Xperia z5. once the camera is launched i get the following exception

E/Camera2Source: Camera Error: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.common.images.Size.getWidth()' on a null object reference

at com.orbis.bioselfielib.others.Camera2Source.setUpCameraOutputs(Camera2Source.java:857) at com.orbis.bioselfielib.others.Camera2Source.openCamera(Camera2Source.java:791) at com.orbis.bioselfielib.others.Camera2Source.start(Camera2Source.java:613) at com.orbis.bioselfielib.others.CameraSourcePreview.startIfReady(CameraSourcePreview.java:139) at com.orbis.bioselfielib.others.CameraSourcePreview.access$200(CameraSourcePreview.java:21) at com.orbis.bioselfielib.others.CameraSourcePreview$2.onSurfaceTextureAvailable(CameraSourcePreview.java:179)

this is happening after

Size largest = getBestAspectPictureSize(map.getOutputSizes(ImageFormat.JPEG));

largest is happening to be null

i tried adding the following

       if (largest == null)
       {
           DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
            largest =  new Size (metrics.heightPixels , metrics.widthPixels);
      }

but the preview is not smooth as on other devices. any solution i can work with

eliayakoumi commented 7 years ago

i have increased tolerance to 0.15 and it worked but again with the preview not being smooth (its like displaying frames one by one) . but the question is if i want to develop an app that works on different type of mobiles what average tolerance should be used?

EzequielAdrianM commented 7 years ago

The Aspect Ratio tolerance used in this Camera app is the best and I do not recommend to modify it at all. Because if you make tolerance lower, it will be difficult or impossible to find a Preview resolution that fits exactly the Screen resolution and your Camera app will fail to show a camera preview. Secondly, if you make tolerance higher, almost any resolution will be eligible for the camera preview. Resulting in a high probability for the preview to be stretched.

Finally, keep in mind that changing the preview tolerance might not interfere on the frames sampling rate. It is the preview resolution itself the one that MUST ALWAYS BE lower or equal than the screen resolution.