Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Camera Slowly on Android. #3700

Closed
NguyenTrongThinh opened this issue Sep 16, 2022 · 4 comments
Closed

Open Camera Slowly on Android. #3700

NguyenTrongThinh opened this issue Sep 16, 2022 · 4 comments
Assignees
Labels
legacy:face detection Issues related to Face Detection platform:android Issues with Android as Platform type:others issues not falling in bug, perfromance, support, build and install or feature

Comments

@NguyenTrongThinh
Copy link

NguyenTrongThinh commented Sep 16, 2022

Symptoms
Camera opens slowly in android studio project. Please see attached image below
Alt Text

Environment

  • Android 12
  • Oppo Reno 4 ( 8GB/128GB)
  • Mediapipe latest version.

Time measurement
The screen is black for about 2 seconds before showing camera frames.
This is logcat of measurement while running application

2022-09-16 10:29:40.555 19250-19250/com.thinhnguyen.xface D/ObjectRecordsViewModel: setupStreamingPipeline takse: 1791671822 ns

The function setupStreamingPipeline in code snip below.

Code snip

Full class: https://pastebin.com/pE1QdjbR

Some of code related to setup stream pipeline:

private val faceDetectionPreview by lazy {
        FaceDetection(
            activity, FaceDetectionOptions
                .builder()
                .setStaticImageMode(false)
                .setModelSelection(0) //short range model
                .build()
        )
    }

override fun onResume() {
        super.onResume()
        // objectRecordsViewModel.fetchObjectRecords() and objectRecordsViewModel.runTestFace() do background job in coroutine. 
        objectRecordsViewModel.fetchObjectRecords()
        objectRecordsViewModel.runTestFace()
        if (allPermissionsGranted()) {
            getAvailableLensFacing()
            val elaspe = measureNanoTime {
                setupStreamingPipeline()
            }
            Timber.d("setupStreamingPipeline takse: $elaspe ns")
        } else {
            requestPermissionLauncher.launch(REQUIRED_PERMISSIONS)
        }
    }

private fun setupStreamingPipeline() {

        faceDetectionPreview.setErrorListener { message, e ->
            Timber.e(TAG,"setupStreamingPipeline: $message -- ${e.message}"
            )
        }
        cameraInput = CameraInput(activity)
        cameraInput?.setNewFrameListener { textureFrame ->
            faceDetectionPreview.send(textureFrame)
        }
        glSurfaceView = SolutionGlSurfaceView(
            activity, faceDetectionPreview.glContext,
            faceDetectionPreview.glMajorVersion
        )
        glSurfaceView?.setSolutionResultRenderer(FaceDetectionResultGlRenderer())
        glSurfaceView?.setRenderInputImage(true)
        faceDetectionPreview.setResultListener { faceDetectionResult ->
            setupFaceDetectionResults(faceDetectionResult)
        }
        glSurfaceView?.post { starCamera() }
        binding.glSurface.removeAllViews()
        binding.glSurface.addView(glSurfaceView)
        glSurfaceView?.visibility = View.VISIBLE
        binding.glSurface.requestLayout()
    }

    private fun starCamera() {
        cameraInput?.start(activity,
        faceDetectionPreview.glContext,
        if (viewModel.getCurrentCameraId() == CameraSelector.LENS_FACING_FRONT) CameraInput.CameraFacing.FRONT else CameraInput.CameraFacing.BACK,
        glSurfaceView!!.width,
        glSurfaceView!!.height)
    }

Is it possible to make it faster? Please correct me if any wrong usage?

@NguyenTrongThinh NguyenTrongThinh added the type:others issues not falling in bug, perfromance, support, build and install or feature label Sep 16, 2022
@kuaashish kuaashish added android::camera legacy:face detection Issues related to Face Detection platform:android Issues with Android as Platform labels Sep 16, 2022
@kuaashish kuaashish assigned eknight7 and unassigned kuaashish Sep 16, 2022
@kuaashish kuaashish added the stat:awaiting googler Waiting for Google Engineer's Response label Sep 16, 2022
@kuaashish
Copy link
Collaborator

kuaashish commented Sep 21, 2022

Hi @NguyenTrongThinh,
We have similar closed issue #3384 and comment(3384), which will give you the better understanding for you query. Thank you!

@NguyenTrongThinh
Copy link
Author

Hi @kuaashish, thank you for your answer.

@kuaashish
Copy link
Collaborator

Hi @NguyenTrongThinh, Currently MediaPipe has limited resources for new features and needs improvement in the model performance. We will update if there is any specific update on this issue. Thank you!

@kuaashish kuaashish removed the stat:awaiting googler Waiting for Google Engineer's Response label Sep 21, 2022
@kuaashish kuaashish assigned kuaashish and unassigned eknight7 Sep 21, 2022
@NguyenTrongThinh
Copy link
Author

Hi @kuaashish, sure! Thanks and hope for a new release with some improvement in model performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy:face detection Issues related to Face Detection platform:android Issues with Android as Platform type:others issues not falling in bug, perfromance, support, build and install or feature
Projects
None yet
Development

No branches or pull requests

4 participants