Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CameraX Image take picture slow

I am using CameraX

Here is my image capture :

 mImageCapture = ImageCapture.Builder()
            .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
            .setTargetAspectRatio(screenAspectRatio)
            .build()

ImageCaptureListener :

mImageCapture.takePicture(
                executor!!,
                object : ImageCapture.OnImageCapturedCallback() {


                    override fun onCaptureSuccess(image: ImageProxy) {
                        Log.d("AAAA", "Success")

                            val rotatedBitmap = bitmapHelper.rotateImage(
                                bitmapHelper.imageToBitmap(image = image.image!!),
                                image.imageInfo.rotationDegrees.toFloat()
                            )

                            runOnUiThread {
                                mImageView.setImageBitmap(rotatedBitmap)
                            }

                    }

                    override fun onError(
                        imageCaptureError: Int,
                        message: String,
                        cause: Throwable?
                    ) {
                        2
                        super.onError(imageCaptureError, message, cause)
                    }
                })

When i call takePicture app freezes, and only after 3-4 seconds onCaptureSuccess called

How can I make this process faster?

like image 858
Rasul Avatar asked Feb 22 '20 11:02

Rasul


1 Answers

CameraX take photo slow because of compressing into JPEG.

The difference between MINIMIZE_LATENCY_MODE and MAXIMIZE_QUALITY_MODE is the JPEG image compression quality.

  private static final byte JPEG_QUALITY_MAXIMIZE_QUALITY_MODE = 100;
  private static final byte JPEG_QUALITY_MINIMIZE_LATENCY_MODE = 95;

Therefore, even if the MINIMIZE_LATENCY_MODE mode is set, the image quality will only decrease from 100 to 95. Not much difference.

From the Version 1.1.0-alpha11, the API provides an additional function setJpegQuality that allows to customize the compression quality. Can improve the delay when taking pictures.

If you don't care about the best image quality, you can use this method.

 imageCapture = ImageCapture.Builder()
            .setJpegQuality(QUALITY_JPEG_75)
            .build()
like image 144
tr4n Avatar answered Sep 18 '22 05:09

tr4n