Compile error while setting imageAnalysis.setAnalyzer()

前端 未结 2 517
梦如初夏
梦如初夏 2021-01-18 07:18

I\'m creating a tool to capture every frame from preview using cameraX (for face recognition purpose)

I found that using ImageAnalysis was the way to go.

Unt

2条回答
  •  生来不讨喜
    2021-01-18 08:14

    You can also find the implementation in the official CameraX sample app: CameraFragment.kt.

    The part which you need is this:

    // Executor field
    private lateinit var analysisExecutor: Executor
    
    // in onCreate()
    analysisExecutor = Executors.newSingleThreadExecutor()
    
    // after initializing imageAnalysis
    imageAnalysis.setAnalyzer(analysisExecutor, ImageAnalysis.Analyzer {
        // TODO analyze
    })
    

    If you're wondering whether to use Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(n) or something else, take a look at the Executors documentation.

提交回复
热议问题