--- lang: ja-jp breaks: true --- # Android 内蔵カメラを使ったバーコードの読込 `CameraX` `ML Kit` 2021-08-05 > googlesamples/android-vision > https://github.com/googlesamples/android-vision > CameraXとML KitでQRコード・バーコードリーダーを作る > https://qiita.com/ryo_mm2d/items/982809ab940dc9549fba > Scan Barcodes with ML Kit on Android > https://developers.google.com/ml-kit/vision/barcode-scanning/android > mlkit/android/material-showcase/ > https://github.com/googlesamples/mlkit/tree/master/android/material-showcase > mlkit/android/vision-quickstart/ > https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart > CameraX の概要 > https://developer.android.com/training/camerax?hl=ja > android/camera-samples > https://github.com/android/camera-samples/tree/main/CameraXBasic ## /app/build.gradle モデルをアプリにバンドルする設定 ```json= dependencies { // ... // Use this dependency to bundle the model with your app // Barcode model implementation 'com.google.mlkit:barcode-scanning:16.2.0' // Or comment the dependency above and uncomment the dependency below to // use unbundled model that depends on Google Play Services // implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:16.2.0' // Object detection feature with bundled default classifier implementation 'com.google.mlkit:object-detection:16.2.6' // Object detection feature with custom classifier support implementation 'com.google.mlkit:object-detection-custom:16.3.3' // Face features implementation 'com.google.mlkit:face-detection:16.1.2' // Or comment the dependency above and uncomment the dependency below to // use unbundled model that depends on Google Play Services // implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.2.0' // Text features implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.3.0' // Image labeling implementation 'com.google.mlkit:image-labeling:17.0.5' // Or comment the dependency above and uncomment the dependency below to // use unbundled model that depends on Google Play Services // implementation 'com.google.android.gms:play-services-mlkit-image-labeling:16.0.5' // Image labeling custom implementation 'com.google.mlkit:image-labeling-custom:16.3.1' // Pose detection with default models implementation 'com.google.mlkit:pose-detection:17.0.1-beta4' // Pose detection with accurate models implementation 'com.google.mlkit:pose-detection-accurate:17.0.1-beta4' // Selfie segmentation implementation 'com.google.mlkit:segmentation-selfie:16.0.0-beta2' implementation 'com.google.mlkit:camera:16.0.0-beta1' } ``` ## gradle.properties ```json= ``` ## src/main/AndroidManifest.xml ```xml= <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" ・・・ android:installLocation="auto"> <!-- CameraX libraries require minSdkVersion 21, while this quickstart app supports low to 16. Needs to use overrideLibrary to make the merger tool ignore this conflict and import the libraries while keeping the app's lower minSdkVersion value. In code, will check SDK version, before calling CameraX APIs. --> <uses-sdk tools:overrideLibrary=" androidx.camera.camera2, androidx.camera.core, androidx.camera.view, androidx.camera.lifecycle" /> <uses-feature android:name="android.hardware.camera"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.CAMERA"/> <application ・・・ > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <!-- Optional: Add it to automatically download ML model to device after your app is installed.--> <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode,face,ocr,ica"/> ・・・ <activity ・・・ </activity> </application> <queries> <intent> <action android:name="android.media.action.IMAGE_CAPTURE" /> </intent> </queries> </manifest> ``` ## gradle.properties ```jsonld= # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # Uses one worker to build. This helps resolve build OOM issue. org.gradle.workers.max=1 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app's APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true ``` ###### tags: `Android` `内蔵カメラ` `バーコード` `CameraX` `ML Kit`