0

I am using CameraX ImageAnalysis.Analyzer to do face detection. However, the Image object size is too large to use FirebaseVisionImage.fromMediaImage, therefore I tried converting the image to bitmap and recale and rotate based on camera rotation. The perfomance is still huge lag, this is becuase of Bitmap scaling operation.

FirebaseVisionImage.fromMediaImage takes 120ms to convert 640x480 image. FirebaseVisionImage.fromBitmap takes 30ms to convert 640x480 image (but wrong rotation) so no face detaction. FirebaseVisionImage.fromBitmap with scaling 90ms to convert 480x360 image.

My question is how to optize this process so that I can get a 480x360 bitmap and improve perfromnce.

I have used this following implementation to convert Image to bitmap.

https://github.com/xizhang/camerax-gpuimage/blob/master/app/src/main/java/com/appinmotion/gpuimage/YuvToRgbConverter.kt

My code.

        Bitmap bitmapImage2 = Bitmap.createBitmap(
                imageX.getWidth(), imageX.getHeight(), Bitmap.Config.ARGB_8888);
        ByteBuffer byteBuffer = converter.yuvToRgb(imageX, bitmapImage2);

        bitmapImage2 = BitmapUtils.rotateScaleBitmap(bitmapImage2, rotation, 1, 480);
        FirebaseVisionImage image =
                FirebaseVisionImage.fromBitmap(bitmapImage2);
        Log.d("myApp", "" + (System.currentTimeMillis() - start));
Patola
  • 515
  • 8
  • 30
  • Can you provide the code surrounding the creation of your ImageAnalysis object? I'm not sure if it is more efficient or not, but you could try using the [ImageAnalysis.Builder().setTargetResolution()](https://developer.android.com/reference/androidx/camera/core/ImageAnalysis.Builder#setTargetResolution(android.util.Size)) You can see this in context [here](https://developer.android.com/training/camerax/analyze#implementation) – topher217 Aug 06 '20 at 01:07
  • Thanks, if setTargetResolution() worked properly I dont have to do any of this. I always get 640x480, even when I set 480x320. I can go higher than defualt size but I cant go lower. I need a small image to keep up with the frame rate of face detection. Is there a way to overrride traget resoultion ? – Patola Aug 06 '20 at 01:10
  • Yep, just saw your other question and added an answer [there](https://stackoverflow.com/a/63275585/2760299). Follow up with me there before moving on to answering this question. – topher217 Aug 06 '20 at 01:26

0 Answers0