CameraX相机加载速度慢 [英] CameraX slow camera load speed

查看:790
本文介绍了CameraX相机加载速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我从使用旧版相机api迁移到了CameraX,尽管设置非常简单,但我注意到了一个问题。现在,开始显示预览的时间似乎比以前快了将近两倍。
我正在测试galaxy s7。
我的代码如下:

So I migrated from using legacy camera api to CameraX and even though it was quite simple to setup, I've noticed one issue. Now camera seems to take almost twice if not longer to start showing preview than it had before. I'm testing on galaxy s7. My code looks like this:

val previewConfig = PreviewConfig.Builder().apply {
    setTargetAspectRatio(Rational(1, 1))
    setTargetResolution(Size(binding.codeScannerView.width, binding.codeScannerView.height))
}.build()

val preview = Preview(previewConfig)

preview.setOnPreviewOutputUpdateListener { preview ->
    val parent = binding.codeScannerView.parent as ViewGroup
    parent.removeView(binding.codeScannerView)
    parent.addView(binding.codeScannerView, 0)
    binding.codeScannerView.surfaceTexture = preview.surfaceTexture
}

val analyzerConfig = ImageAnalysisConfig.Builder().apply {
    val analyzerThread = HandlerThread(
            "QrCodeReader").apply { start() }
    setCallbackHandler(Handler(analyzerThread.looper))
    setImageReaderMode(
            ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
}.build()

val analyzerUseCase = ImageAnalysis(analyzerConfig).apply {
    analyzer = QrCodeAnalyzer(requireContext(), Handler(), { qrCode ->
        if (activity == null) {
            return@QrCodeAnalyzer
        }
        presenter.disableCameraPreview()
        presenter.updateTable(qrCode.toLowerCase().parseTableId(), isFromOrder, Screens.MENU_SCREEN)
    })
}

CameraX.bindToLifecycle(this, preview, analyzerUseCase)

任何想法

P。 S.我也偶尔会看到预览中的撕裂

推荐答案

所以我花了很多时间试图找到解决方案,无济于事。
我甚至遇到过多个问题(使用alpha04),

So I've spent quite some time trying to find the solution, to no avail. I have even encountered multiple issues (with alpha04) like:


  • 打开/关闭相机时,随机SIGSEGV崩溃

  • 我尝试了来自google的示例项目和代码实验室,这些示例项目和代码实验室在测试的设备上也无法100%地工作

  • 在某个时候,我收到了有关
    摄影机在后台使用,即使它绑定到
    生命周期并且关闭了窗口,这也是我希望用户
    看到的最后一件事。

  • 相机确实载入速度较慢,即使关闭分析仪,我的FPS也很糟糕。

  • 分辨率会降到最低,并且在某些设备上预览会像素化

  • 每隔一段时间预览会开始垂直撕裂

  • 分析器框架的尺寸与预览不同,并且存在一些长宽比问题,需要花费相当长的时间才能解决。

  • 要正常工作还需要很多样板

  • Documen边缘情况的处理几乎不存在,因此大多数内容都是反复试验。

  • Random SIGSEGV crashes when turning camera on/off
  • I tried sample projects and codelabs from google which also were not working 100% of the time on tested devices
  • At some point I got notification that camera was being used in background, even though It was bound to lifecycle and window closed, which is the last thing I want my users to see.
  • Camera was indeed loading slower and I was getting horrible FPS even with analyzer off.
  • Resolution would drop down to lowest possible and preview would be pixelated on some devices
  • Every once in a while preview would start tearing vertically
  • Analyzer frame was different size than preview and there were some aspect ratio issues which took quite some time to resolve.
  • There's still quite some boilerplate required for it to work
  • Documentation for edge cases is pretty much non existent, so most of the stuff is trial and error.

最后,我才开始寻找其他库,并出现 https://github.com/natario1/CameraView 最简单的相机库,我见过。即使在后台运行分析仪步骤的情况下,它也比camerax简单得多,似乎可以正常工作,加载速度更快,以2到3倍的FPS渲染预览。到目前为止,我还没有遇到任何问题。

In the end I just started looking for other libraries and came upon https://github.com/natario1/CameraView This is by far the easiest to use library I have ever seen for camera. Way simplier than camerax, it seems to just work, loads way faster, renders preview at 2x-3x higher FPS even with analyzer step running in the background. So far I had no issues with it.

即使我坚信,在使用CameraX时我会丢失某些东西,并且可能有一种使其工作的方法,最后,它似乎暂时不值得,我可能会等到有生产就绪版本,然后再试一次。

Even though I strongly believe, that I was missing something, when using CameraX and there's probably a way to make it work, in the end it just doesn't seem worth it for now and I'll probably wait till there's a production ready version until I try again.

这篇关于CameraX相机加载速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆