Android開発初心者です。
以下のコードの中では、fun bindCameraUseCases() の imageAnalyzer でCameraXからRGBA8888フォーマットのimageを受け取ったあと、fun detectObjects(image: ImageProxy)で bitmapBufferにRGBのビットだけ渡しているようです。
よく分からない点は、imageAnalyzerから受け取ったのは"RGBA"、bitmapBufferは”ARGB”なので、planes[0]ではimageのAlphaではなく、Redが切り落とされるのではないのでしょうか。
またplaneを実行した場合、bitmapBufferはRGB888になるということでしょうか。
解答よろしくお願いいたします。
Main_Activity.kt
1private fun bindCameraUseCases() { 2 3 // CameraProvider 4 val cameraProvider = 5 cameraProvider ?: throw IllegalStateException("Camera initialization failed.") 6 7 // CameraSelector - makes assumption that we're only using the back camera 8 val cameraSelector = 9 CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build() 10 11 // Preview. Only using the 4:3 ratio because this is the closest to our models 12 preview = 13 Preview.Builder() 14 .setTargetAspectRatio(AspectRatio.RATIO_4_3) 15 .setTargetRotation(fragmentCameraBinding.viewFinder.display.rotation) 16 .build() 17 18 // ImageAnalysis. Using RGBA 8888 to match how our models work 19 imageAnalyzer = 20 ImageAnalysis.Builder() 21 .setTargetAspectRatio(AspectRatio.RATIO_4_3) 22 .setTargetRotation(fragmentCameraBinding.viewFinder.display.rotation) 23 .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) 24 .setOutputImageFormat(OUTPUT_IMAGE_FORMAT_RGBA_8888) 25 .build() 26 // The analyzer can then be assigned to the instance 27 .also { 28 it.setAnalyzer(cameraExecutor) { image -> 29 if (!::bitmapBuffer.isInitialized) { 30 // The image rotation and RGB image buffer are initialized only once 31 // the analyzer has started running 32 bitmapBuffer = Bitmap.createBitmap( 33 image.width, 34 image.height, 35 Bitmap.Config.ARGB_8888 36 ) 37 } 38 detectObjects(image) 39 } 40 } 41 42 // Must unbind the use-cases before rebinding them 43 cameraProvider.unbindAll() 44 try { 45 // A variable number of use-cases can be passed here - 46 // camera provides access to CameraControl & CameraInfo 47 camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalyzer) 48 49 // Attach the viewfinder's surface provider to preview use case 50 preview?.setSurfaceProvider(fragmentCameraBinding.viewFinder.surfaceProvider) 51 } catch (exc: Exception) { 52 Log.e(TAG, "Use case binding failed", exc) 53 } 54 } 55 56 private fun detectObjects(image: ImageProxy) { 57 // Copy out RGB bits to the shared bitmap buffer 58 image.use { bitmapBuffer.copyPixelsFromBuffer(image.planes[0].buffer) } 59 60 val imageRotation = image.imageInfo.rotationDegrees 61 // Pass Bitmap and rotation to the object detector helper for processing and detection 62 objectDetectorHelper.detect(bitmapBuffer, imageRotation) 63 }
あなたの回答
tips
プレビュー