TensorfFlowLight(Android)をつかったオブジェクト検知のデモプログラムの内容です。
https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android_play_services
このプログラムではCameraXのImageAnalysisから検出器に画像を渡す際に、4_3比率で渡しており、それに合わせてPreviewの比率も4_3になっているようです。
実際には画面いっぱいにPreviewが表示されているのですが、どうしてなのか理解できません。
scaleType "fillStart"で調べてもあまり情報が出てこなかったので、ご存じの方がいれば教えていただけないでしょうか。
宜しくお願いいたします。
fragment_camera.xml
1<?xml version="1.0" encoding="utf-8"?> 2 3<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:id="@+id/camera_container" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent"> 9 10 <androidx.camera.view.PreviewView 11 android:id="@+id/view_finder" 12 android:layout_width="match_parent" 13 android:layout_height="match_parent" 14 app:scaleType="fillStart"/> 15 16 <org.tensorflow.lite.examples.objectdetection.OverlayView 17 android:id="@+id/overlay" 18 android:layout_height="match_parent" 19 android:layout_width="match_parent" /> 20 21 <androidx.core.widget.ContentLoadingProgressBar 22 android:id="@+id/progress_circular" 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:indeterminate="true" 26 android:visibility="visible" 27 android:layout_gravity="center" 28 style="?android:attr/progressBarStyleLarge" /> 29 30 <include 31 android:id="@+id/bottom_sheet_layout" 32 layout="@layout/info_bottom_sheet" /> 33</androidx.coordinatorlayout.widget.CoordinatorLayout>
MainActivity.kt
1..... 2// Preview. Only using the 4:3 ratio because this is the closest to our models 3 preview = 4 Preview.Builder() 5 .setTargetAspectRatio(AspectRatio.RATIO_4_3) 6 .setTargetRotation(fragmentCameraBinding.viewFinder.display.rotation) 7 .build() 8 9 // ImageAnalysis. Using RGBA 8888 to match how our models work 10 imageAnalyzer = 11 ImageAnalysis.Builder() 12 .setTargetAspectRatio(AspectRatio.RATIO_4_3) 13 .setTargetRotation(fragmentCameraBinding.viewFinder.display.rotation) 14 .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) 15 .setOutputImageFormat(OUTPUT_IMAGE_FORMAT_RGBA_8888) 16 .build() 17 // The analyzer can then be assigned to the instance 18 .also { 19 it.setAnalyzer(cameraExecutor) { image -> 20 if (!::bitmapBuffer.isInitialized) { 21 // The image rotation and RGB image buffer are initialized only once 22 // the analyzer has started running 23 bitmapBuffer = Bitmap.createBitmap( 24 image.width, 25 image.height, 26 Bitmap.Config.ARGB_8888 27 ) 28 } 29 detectObjects(image) 30 } 31 } 32 33 // Must unbind the use-cases before rebinding them 34 cameraProvider.unbindAll() 35 try { 36 // A variable number of use-cases can be passed here - 37 // camera provides access to CameraControl & CameraInfo 38 camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalyzer) 39 40 // Attach the viewfinder's surface provider to preview use case 41 preview?.setSurfaceProvider(fragmentCameraBinding.viewFinder.surfaceProvider) 42 } catch (exc: Exception) { 43 Log.e(TAG, "Use case binding failed", exc) 44 } 45 } 46.....
回答2件
あなたの回答
tips
プレビュー