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.
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));