如何解决Mediapipe Objectron Kotlin
我想为 kotlin 制作 Objectron 但出现此错误 -> Logcat img
- 启动我的应用
- 获取消息框以访问我的相机
- 点击确定
- 在黑屏上跳转
- 黑屏 2-3 秒后应用崩溃
这就是我运行相机的方式:
override fun onResume() {
super.onResume()
converter = ExternalTextureConverter(eglManager!!.context)
converter!!.setFlipY(FLIP_FRAMES_VERTICALLY)
converter!!.setConsumer(processor)
if (PermissionHelper.cameraPermissionsGranted(this)) {
startCamera()
}
}
private fun startCamera() {
cameraHelper = CameraXPreviewHelper()
cameraHelper!!.setOnCameraStartedListener { surfaceTexture: SurfaceTexture? ->
previewFrameTexture = surfaceTexture
// Make the display view visible to start showing the preview. This triggers the
// SurfaceHolder.Callback added to (the holder of) previewDisplayView.
previewDisplayView!!.visibility = View.VISIBLE
}
cameraHelper!!.startCamera(this,CAMERA_FACING,/*surfaceTexture=*/null)
}
这是用于查看相机:
private fun setupPreviewDisplayView() {
previewDisplayView!!.visibility = View.GONE
val viewGroup = findViewById<ViewGroup>(R.id.preview_display_layout)
viewGroup.addView(previewDisplayView)
previewDisplayView!!
.holder
.addCallback(
object : SurfaceHolder.Callback {
override fun surfaceCreated(holder: SurfaceHolder) {
processor!!.videoSurfaceOutput.setSurface(holder.surface)
}
override fun surfaceChanged(
holder: SurfaceHolder,format: Int,width: Int,height: Int
) {
val viewSize = Size(width,height)
val displaySize =
cameraHelper!!.computeDisplaySizeFromViewSize(viewSize)
converter!!.setSurfaceTextureAndAttachToGLContext(
previewFrameTexture,displaySize.width,displaySize.height
)
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
processor!!.videoSurfaceOutput.setSurface(null)
}
})
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。