commit 8b5230917449786155809ae40ddbcb893d4a53c7 Author: sitiseptiyahagustin Date: Tue Jun 9 10:30:24 2026 +0700 Upload folder pertama kali diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3820a95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.build/ +.buildlog/ +.history +.svn/ +.swiftpm/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins-dependencies +.pub-cache/ +.pub/ +/build/ +/coverage/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..83b34eb --- /dev/null +++ b/.metadata @@ -0,0 +1,45 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "f6ff1529fd6d8af5f706051d9251ac9231c83407" + channel: "stable" + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: android + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: ios + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: linux + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: macos + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: web + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + - platform: windows + create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/README.md b/README.md new file mode 100644 index 0000000..9631abf --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# fungid3_new + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..0d29021 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,28 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at https://dart.dev/lints. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..be3943c --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,14 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java +.cxx/ + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 0000000..2ef4344 --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + id("com.android.application") + id("kotlin-android") + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "com.example.fungid3_new" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "com.example.fungid3_new" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig = signingConfigs.getByName("debug") + } + } +} + +flutter { + source = "../.." +} \ No newline at end of file diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..036368b --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/kotlin/com/example/fungid3_new/MainActivity.kt b/android/app/src/main/kotlin/com/example/fungid3_new/MainActivity.kt new file mode 100644 index 0000000..bbfb9f6 --- /dev/null +++ b/android/app/src/main/kotlin/com/example/fungid3_new/MainActivity.kt @@ -0,0 +1,5 @@ +package com.example.fungid3_new + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity : FlutterActivity() diff --git a/android/app/src/main/res/drawable-v21/launch_background.xml b/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..f74085f --- /dev/null +++ b/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/android/app/src/main/res/drawable/launch_background.xml b/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000..304732f --- /dev/null +++ b/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..db77bb4 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..17987b7 Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..09d4391 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..d5f1c8d Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..4d6372e Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/values-night/styles.xml b/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..06952be --- /dev/null +++ b/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..cb1ef88 --- /dev/null +++ b/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/android/app/src/profile/AndroidManifest.xml b/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 0000000..d33c83d --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,27 @@ +import com.android.build.gradle.LibraryExtension + +allprojects { + repositories { + google() + mavenCentral() + } +} + +val newBuildDir: Directory = + rootProject.layout.buildDirectory + .dir("../../build") + .get() +rootProject.layout.buildDirectory.value(newBuildDir) + +subprojects { + val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) + project.layout.buildDirectory.value(newSubprojectBuildDir) +} +subprojects { + project.evaluationDependsOn(":app") +} + +tasks.register("clean") { + delete(rootProject.layout.buildDirectory) +} + diff --git a/android/build/reports/problems/problems-report.html b/android/build/reports/problems/problems-report.html new file mode 100644 index 0000000..95b98a5 --- /dev/null +++ b/android/build/reports/problems/problems-report.html @@ -0,0 +1,663 @@ + + + + + + + + + + + + + Gradle Configuration Cache + + + +
+ +
+ Loading... +
+ + + + + + diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 0000000..fbee1d8 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError +android.useAndroidX=true diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e4ef43f --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts new file mode 100644 index 0000000..ca7fe06 --- /dev/null +++ b/android/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + val flutterSdkPath = + run { + val properties = java.util.Properties() + file("local.properties").inputStream().use { properties.load(it) } + val flutterSdkPath = properties.getProperty("flutter.sdk") + require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" } + flutterSdkPath + } + + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") + + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("dev.flutter.flutter-plugin-loader") version "1.0.0" + id("com.android.application") version "8.11.1" apply false + id("org.jetbrains.kotlin.android") version "2.2.20" apply false +} + +include(":app") diff --git a/assets/1.jpg b/assets/1.jpg new file mode 100644 index 0000000..a9bb527 Binary files /dev/null and b/assets/1.jpg differ diff --git a/assets/10.jpeg b/assets/10.jpeg new file mode 100644 index 0000000..981a5b8 Binary files /dev/null and b/assets/10.jpeg differ diff --git a/assets/11.jpg b/assets/11.jpg new file mode 100644 index 0000000..88a77d6 Binary files /dev/null and b/assets/11.jpg differ diff --git a/assets/12.jpg b/assets/12.jpg new file mode 100644 index 0000000..239ea46 Binary files /dev/null and b/assets/12.jpg differ diff --git a/assets/13.jpeg b/assets/13.jpeg new file mode 100644 index 0000000..b01c383 Binary files /dev/null and b/assets/13.jpeg differ diff --git a/assets/14.jpeg b/assets/14.jpeg new file mode 100644 index 0000000..7327e1f Binary files /dev/null and b/assets/14.jpeg differ diff --git a/assets/15.jpeg b/assets/15.jpeg new file mode 100644 index 0000000..1ead67e Binary files /dev/null and b/assets/15.jpeg differ diff --git a/assets/2.jpeg b/assets/2.jpeg new file mode 100644 index 0000000..86b166e Binary files /dev/null and b/assets/2.jpeg differ diff --git a/assets/3.jpg b/assets/3.jpg new file mode 100644 index 0000000..ce0c438 Binary files /dev/null and b/assets/3.jpg differ diff --git a/assets/4.jpeg b/assets/4.jpeg new file mode 100644 index 0000000..a888f3c Binary files /dev/null and b/assets/4.jpeg differ diff --git a/assets/5.jpeg b/assets/5.jpeg new file mode 100644 index 0000000..8b7f46a Binary files /dev/null and b/assets/5.jpeg differ diff --git a/assets/6.jpeg b/assets/6.jpeg new file mode 100644 index 0000000..ad06ac6 Binary files /dev/null and b/assets/6.jpeg differ diff --git a/assets/7.jpg b/assets/7.jpg new file mode 100644 index 0000000..a98114c Binary files /dev/null and b/assets/7.jpg differ diff --git a/assets/8.jpg b/assets/8.jpg new file mode 100644 index 0000000..dbfbff1 Binary files /dev/null and b/assets/8.jpg differ diff --git a/assets/9.jpeg b/assets/9.jpeg new file mode 100644 index 0000000..a683eda Binary files /dev/null and b/assets/9.jpeg differ diff --git a/assets/bau_menyenga.jpeg b/assets/bau_menyenga.jpeg new file mode 100644 index 0000000..a6964a2 Binary files /dev/null and b/assets/bau_menyenga.jpeg differ diff --git a/assets/labels.txt b/assets/labels.txt new file mode 100644 index 0000000..b668460 --- /dev/null +++ b/assets/labels.txt @@ -0,0 +1,4 @@ +Auricularia auricula judae +Fly Agaric +Termitomyces +amanita_patherina \ No newline at end of file diff --git a/assets/licin_berlendir.jpeg b/assets/licin_berlendir.jpeg new file mode 100644 index 0000000..14aa2d9 Binary files /dev/null and b/assets/licin_berlendir.jpeg differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..d0d1399 Binary files /dev/null and b/assets/logo.png differ diff --git a/assets/model_cnn.tflite b/assets/model_cnn.tflite new file mode 100644 index 0000000..a4c178a Binary files /dev/null and b/assets/model_cnn.tflite differ diff --git a/assets/models/model cnn.tflite b/assets/models/model cnn.tflite new file mode 100644 index 0000000..a4c178a Binary files /dev/null and b/assets/models/model cnn.tflite differ diff --git a/assets/scanjamur.png b/assets/scanjamur.png new file mode 100644 index 0000000..e693a9a Binary files /dev/null and b/assets/scanjamur.png differ diff --git a/assets/tempat_lembap.jpeg b/assets/tempat_lembap.jpeg new file mode 100644 index 0000000..63aa0a0 Binary files /dev/null and b/assets/tempat_lembap.jpeg differ diff --git a/assets/warna_mencolok.jpeg b/assets/warna_mencolok.jpeg new file mode 100644 index 0000000..3cf9db8 Binary files /dev/null and b/assets/warna_mencolok.jpeg differ diff --git a/ios/.gitignore b/ios/.gitignore new file mode 100644 index 0000000..7a7f987 --- /dev/null +++ b/ios/.gitignore @@ -0,0 +1,34 @@ +**/dgph +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/ios/Flutter/AppFrameworkInfo.plist b/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000..1dc6cf7 --- /dev/null +++ b/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 13.0 + + diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000..592ceee --- /dev/null +++ b/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000..592ceee --- /dev/null +++ b/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..836c708 --- /dev/null +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,616 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..e3773d4 --- /dev/null +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/Runner.xcworkspace/contents.xcworkspacedata b/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000..6266644 --- /dev/null +++ b/ios/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import Flutter +import UIKit + +@main +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d36b1fa --- /dev/null +++ b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000..dc9ada4 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png new file mode 100644 index 0000000..7353c41 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000..797d452 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000..6ed2d93 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000..4cd7b00 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000..fe73094 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000..321773c Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000..797d452 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000..502f463 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000..0ec3034 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000..0ec3034 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000..e9f5fea Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000..84ac32a Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000..8953cba Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000..0467bf1 Binary files /dev/null and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000..0bedcf2 --- /dev/null +++ b/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 0000000..89c2725 --- /dev/null +++ b/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file diff --git a/ios/Runner/Base.lproj/LaunchScreen.storyboard b/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f2e259c --- /dev/null +++ b/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/Runner/Base.lproj/Main.storyboard b/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f3c2851 --- /dev/null +++ b/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist new file mode 100644 index 0000000..287089f --- /dev/null +++ b/ios/Runner/Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Fungid3 New + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + fungid3_new + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/ios/Runner/Runner-Bridging-Header.h b/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000..308a2a5 --- /dev/null +++ b/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/ios/RunnerTests/RunnerTests.swift b/ios/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..86a7c3b --- /dev/null +++ b/ios/RunnerTests/RunnerTests.swift @@ -0,0 +1,12 @@ +import Flutter +import UIKit +import XCTest + +class RunnerTests: XCTestCase { + + func testExample() { + // If you add code to the Runner application, consider adding tests here. + // See https://developer.apple.com/documentation/xctest for more information about using XCTest. + } + +} diff --git a/lib/main.dart b/lib/main.dart new file mode 100644 index 0000000..f9765e7 --- /dev/null +++ b/lib/main.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:fungid3/screens/home_screen.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'screens/ai_screen.dart'; +import 'screens/splash_screen.dart'; +import 'screens/output_screen.dart'; + +void main() { + runApp(const MyApp()); +} + + + + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + title: 'FungiGuard', + theme: ThemeData( + primaryColor: const Color(0xFF4CAF50), + textTheme: GoogleFonts.poppinsTextTheme(), // font global + scaffoldBackgroundColor: const Color(0xFFF5F5F5), + ), + home: const SplashScreen(), // Halaman pertama yang dijalankan + ); + } +} diff --git a/lib/screens/ai_screen.dart b/lib/screens/ai_screen.dart new file mode 100644 index 0000000..793e653 --- /dev/null +++ b/lib/screens/ai_screen.dart @@ -0,0 +1,112 @@ +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:image_picker/image_picker.dart'; +import 'package:fungid3/widgets/bottom_navbar.dart'; +import 'output_screen.dart'; // Sesuaikan path import Anda + +class AIScanScreen extends StatefulWidget { + const AIScanScreen({super.key}); + + @override + State createState() => _AIScanScreenState(); +} + +class _AIScanScreenState extends State { + final ImagePicker _picker = ImagePicker(); + final Color primaryColor = const Color(0xFF4CAF50); + final Color backgroundColor = const Color(0xFFF9F9F9); + + Future _takePhoto() async { + final XFile? image = await _picker.pickImage(source: ImageSource.camera); + if (image != null) { + if (!mounted) return; + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => OutputScreen(imagePath: image.path), + ), + ); + } + } + + Future _pickFromGallery() async { + final XFile? image = await _picker.pickImage(source: ImageSource.gallery); + if (image != null) { + if (!mounted) return; + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => OutputScreen(imagePath: image.path), + ), + ); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: backgroundColor, + extendBody: true, + appBar: AppBar( + backgroundColor: Colors.white, + elevation: 0, + title: Text( + "Deteksi Jamur", + style: GoogleFonts.poppins(color: Colors.black87, fontWeight: FontWeight.w600), + ), + centerTitle: true, + ), + body: Padding( + padding: const EdgeInsets.all(20), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.cloud_upload_outlined, size: 100, color: Colors.green), + const SizedBox(height: 20), + Text( + "Ambil atau unggah foto jamur untuk dianalisis AI.", + textAlign: TextAlign.center, + style: GoogleFonts.poppins(color: Colors.black54, fontSize: 16), + ), + const SizedBox(height: 40), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _buildActionButton( + onPressed: _takePhoto, + icon: Icons.camera_alt, + label: "Kamera", + isPrimary: true, + ), + const SizedBox(width: 20), + _buildActionButton( + onPressed: _pickFromGallery, + icon: Icons.photo_library, + label: "Galeri", + isPrimary: false, + ), + ], + ), + ], + ), + ), + bottomNavigationBar: const BottomNavBar(selectedIndex: 1), + ); + } + + Widget _buildActionButton({required VoidCallback onPressed, required IconData icon, required String label, required bool isPrimary}) { + return ElevatedButton.icon( + style: ElevatedButton.styleFrom( + backgroundColor: isPrimary ? primaryColor : Colors.white, + foregroundColor: isPrimary ? Colors.white : primaryColor, + side: isPrimary ? BorderSide.none : BorderSide(color: primaryColor), + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + ), + onPressed: onPressed, + icon: Icon(icon), + label: Text(label, style: GoogleFonts.poppins(fontWeight: FontWeight.w500)), + ); + } +} \ No newline at end of file diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart new file mode 100644 index 0000000..ecefae1 --- /dev/null +++ b/lib/screens/home_screen.dart @@ -0,0 +1,202 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:fungid3/widgets/bottom_navbar.dart'; + +class HomeScreen extends StatefulWidget { + const HomeScreen({super.key}); + + @override + State createState() => _HomeScreenState(); +} + +class _HomeScreenState extends State { + final List> ciriJamur = [ + { + "title": "Warna Mencolok", + "desc": "Hindari jamur dengan warna merah, kuning, atau jingga terang.", + "img": "assets/warna_mencolok.jpeg" + }, + { + "title": "Tempat Lembap", + "desc": "Sering ditemukan di area dengan kelembapan ekstrem dan kotor.", + "img": "assets/tempat_lembap.jpeg" + }, + { + "title": "Bau Menyengat", + "desc": "Memiliki aroma busuk atau tajam seperti amonia.", + "img": "assets/bau_menyenga.jpeg" + }, + { + "title": "Cincin di Batang", + "desc": "Memiliki struktur seperti cincin atau cawan pada pangkal batang.", + "img": "assets/licin_berlendir.jpeg" + }, + ]; + + int _currentPage = 0; + + @override + Widget build(BuildContext context) { + const Color backgroundColor = Color(0xFFF9F9F9); + + return Scaffold( + backgroundColor: backgroundColor, + extendBody: true, + body: SafeArea( + child: SingleChildScrollView( + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 🔹 HEADER LOGO (Ganti teks dengan gambar langsung) + Image.asset( + 'assets/logo.png', // Pastikan path logo benar + height: 40, // Sesuaikan tinggi logo Anda + fit: BoxFit.contain, + ), + const SizedBox(height: 16), + Text( + "Dengan sekali foto, Anda dapat mengenali jamur liar yang aman dan berbahaya dikonsumsi. Ayo coba sekarang!", + style: GoogleFonts.poppins( + fontSize: 15, + color: Colors.black87, + height: 1.4, + ), + ), + const SizedBox(height: 20), + + // 🔹 BANNER GAMBAR + Container( + height: 160, + width: double.infinity, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + image: const DecorationImage( + image: AssetImage('assets/scanjamur.png'), + fit: BoxFit.cover, + ), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.15), + blurRadius: 12, + offset: const Offset(0, 5), + ), + ], + ), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + color: Colors.black.withOpacity(0.3), + ), + ), + ), + + const SizedBox(height: 30), + + // 🔹 TITLE SECTION + Text( + "Ciri Jamur Beracun", + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w600, + color: Colors.black87, + ), + ), + const SizedBox(height: 16), + + // 🔹 SLIDER BOX + Container( + height: 320, + width: double.infinity, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.05), + blurRadius: 20, + offset: const Offset(0, 10), + ) + ], + ), + child: Column( + children: [ + Expanded( + flex: 3, + child: ClipRRect( + borderRadius: const BorderRadius.vertical(top: Radius.circular(25)), + child: PageView.builder( + onPageChanged: (index) => setState(() => _currentPage = index), + itemCount: ciriJamur.length, + itemBuilder: (context, index) { + return Image.asset( + ciriJamur[index]['img']!, + fit: BoxFit.cover, + width: double.infinity, + ); + }, + ), + ), + ), + Expanded( + flex: 2, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + ciriJamur[_currentPage]['title']!, + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.redAccent, + ), + ), + const SizedBox(height: 4), + Text( + ciriJamur[_currentPage]['desc']!, + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: 13, + color: Colors.grey[600], + height: 1.3, + ), + ), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate( + ciriJamur.length, + (index) => _buildIndicator(index == _currentPage), + ), + ), + ], + ), + ), + ), + ], + ), + ), + const SizedBox(height: 100), + ], + ), + ), + ), + bottomNavigationBar: const BottomNavBar(selectedIndex: 0), + ); + } + + Widget _buildIndicator(bool isActive) { + return AnimatedContainer( + duration: const Duration(milliseconds: 300), + margin: const EdgeInsets.symmetric(horizontal: 4), + height: 8, + width: isActive ? 24 : 8, + decoration: BoxDecoration( + color: isActive ? Colors.green : Colors.grey[300], + borderRadius: BorderRadius.circular(10), + ), + ); + } +} \ No newline at end of file diff --git a/lib/screens/info_screen.dart b/lib/screens/info_screen.dart new file mode 100644 index 0000000..2aa2cd5 --- /dev/null +++ b/lib/screens/info_screen.dart @@ -0,0 +1,226 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import '../widgets/bottom_navbar.dart'; + +class InfoScreen extends StatefulWidget { + const InfoScreen({super.key}); + + @override + State createState() => _InfoScreenState(); +} + +class _InfoScreenState extends State { + final Color primaryColor = const Color(0xFF2E7D32); + final Color accentPoison = const Color(0xFFE53935); + final Color accentSafe = const Color(0xFF43A047); + + // Data Jamur yang diperluas + final List> mushrooms = [ + { + 'name': 'Fly Agaric', + 'latin': 'Amanita Muscaria', + 'status': 'Beracun ⚠️', + 'images': ['assets/1.jpg', 'assets/2.jpeg', 'assets/3.jpg', 'assets/4.jpeg'], + 'summary': 'Ikon jamur beracun dengan tudung merah bintik putih yang sangat mencolok.', + 'habitat': 'Tumbuh di wilayah beriklim dingin hingga sedang di Eropa, Asia Utara, dan Amerika Utara. Umumnya ditemukan di hutan konifer dan hutan campuran yang didominasi pohon pinus, spruce, fir, dan birch. Jamur ini bersimbiosis mikoriza dengan akar pohon dan biasanya muncul di tanah berlumut, tanah berpasir, atau area hutan lembap pada akhir musim panas hingga musim gugur.', + 'characteristics': 'Tudung berdiameter 8–20 cm berwarna merah cerah hingga merah-oranye dengan bintik putih sisa selubung universal. Insang putih krem dan rapat, batang putih kokoh setinggi 10–20 cm dengan cincin jelas serta pangkal batang memiliki volva berbentuk kantung. Warna tudung dapat memudar saat jamur menua.', + 'danger': 'Mengandung Muscimol. Gejala berupa mual, kejang, hingga halusinasi berat yang tidak menyenangkan.', + }, + { + 'name': 'Panther Cap', + 'latin': 'Amanita Pantherina', + 'status': 'Beracun ⚠️', + 'images': ['assets/5.jpeg', 'assets/6.jpeg', 'assets/7.jpg', 'assets/8.jpg'], + 'summary': 'Kerabat dekat Fly Agaric namun dengan konsentrasi toksin yang jauh lebih kuat.', + 'habitat': 'Ditemukan di hutan gugur dan konifer pada daerah beriklim sedang. Biasanya tumbuh di tanah hutan kaya bahan organik di sekitar pohon oak, beech, pinus, dan cemara. Muncul pada akhir musim panas hingga musim gugur, sering tersembunyi di antara daun kering atau rumput hutan.', + 'characteristics': 'Tudung berdiameter 5–12 cm berwarna cokelat kekuningan hingga cokelat zaitun dengan bintik putih kecil tersusun rapi. Pinggiran tudung beralur halus, insang putih rapat, batang ramping dengan cincin tipis, serta pangkal batang membulat dengan volva berbentuk cincin konsentris.', + 'danger': 'Sangat berbahaya. Toksinnya menyerang sistem saraf pusat, menyebabkan kebingungan dan koma.', + }, + { + 'name': 'Jamur Kuping', + 'latin': 'Auricularia Auricula', + 'status': 'Aman Dikonsumsi ✅', + 'images': ['assets/9.jpeg', 'assets/10.jpeg', 'assets/11.jpg', 'assets/12.jpg'], + 'summary': 'Jamur konsumsi populer yang kaya akan serat dan baik untuk sirkulasi darah.', + 'habitat': 'Tumbuh di daerah tropis dan subtropis pada kayu mati, batang pohon lapuk, atau ranting lembap. Sering muncul setelah hujan di lingkungan dengan kelembapan tinggi seperti hutan tropis, kebun, dan area teduh. Biasanya tumbuh berkelompok sepanjang tahun di daerah lembap.', + 'characteristics': 'Bentuk menyerupai telinga manusia dengan warna cokelat kemerahan hingga cokelat kehitaman. Permukaan luar sedikit berbulu halus, bagian dalam licin mengilap, bertekstur kenyal seperti gel, tidak memiliki batang jelas, dan berukuran sekitar 3–10 cm.', + 'benefits': 'Rendah kalori, tinggi serat, dan mengandung antioksidan yang baik untuk kesehatan jantung.', + }, + { + 'name': 'Jamur Rayap', + 'latin': 'Termitomyces sp.', + 'status': 'Aman Dikonsumsi ✅', + 'images': ['assets/13.jpeg', 'assets/14.jpeg', 'assets/15.jpeg', 'assets/13.jpeg'], + 'summary': 'Jamur liar musiman yang memiliki cita rasa paling gurih di antara jamur lainnya.', + 'habitat': 'Tumbuh di daerah tropis di sekitar sarang rayap tanah. Muncul secara musiman setelah hujan lebat pada tanah lembap di padang rumput, ladang, atau pinggir hutan yang memiliki koloni rayap aktif.', + 'characteristics': 'Memiliki tudung berbentuk payung dengan puncak meruncing (umbo) berwarna putih krem hingga cokelat muda. Batang panjang ramping terhubung ke akar semu (pseudorhiza) yang menembus tanah menuju sarang rayap. Insang putih rapat, ukuran tudung dapat mencapai 5–20 cm dengan daging tebal dan aroma gurih khas.', + 'benefits': 'Sumber protein yang sangat tinggi dan sering dianggap sebagai pengganti rasa daging alami.', + }, + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: const Color(0xFFF8FBF8), + appBar: AppBar( + title: Text("Ensiklopedia Jamur", style: GoogleFonts.poppins(fontWeight: FontWeight.bold, color: Colors.white)), + centerTitle: true, + backgroundColor: primaryColor, + elevation: 0, + ), + body: ListView.builder( + padding: const EdgeInsets.fromLTRB(20, 20, 20, 100), + itemCount: mushrooms.length, + itemBuilder: (context, index) => _buildEnhancedCard(context, mushrooms[index]), + ), + bottomNavigationBar: const BottomNavBar(selectedIndex: 2), + ); + } + + Widget _buildEnhancedCard(BuildContext context, Map item) { + final bool isPoisonous = item['status'].toString().contains("Beracun"); + + return Container( + margin: const EdgeInsets.only(bottom: 20), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(24), + boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 20, offset: const Offset(0, 10))], + ), + child: InkWell( + borderRadius: BorderRadius.circular(24), + onTap: () => _showDetailModal(context, item), + child: Column( + children: [ + ClipRRect( + borderRadius: const BorderRadius.vertical(top: Radius.circular(24)), + child: Image.asset(item['images'][0], height: 180, width: double.infinity, fit: BoxFit.cover), + ), + Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(item['name'], style: GoogleFonts.poppins(fontSize: 18, fontWeight: FontWeight.bold)), + Icon(isPoisonous ? Icons.report_problem : Icons.check_circle, color: isPoisonous ? accentPoison : accentSafe), + ], + ), + Text(item['summary'], style: GoogleFonts.poppins(fontSize: 13, color: Colors.black54)), + ], + ), + ), + ], + ), + ), + ); + } + + void _showDetailModal(BuildContext context, Map item) { + final bool isPoisonous = item['status'].toString().contains("Beracun"); + int currentSlide = 0; + + showModalBottomSheet( + context: context, + isScrollControlled: true, + backgroundColor: Colors.transparent, + builder: (context) => StatefulBuilder( + builder: (context, setModalState) => DraggableScrollableSheet( + initialChildSize: 0.9, + builder: (_, controller) => Container( + decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(32))), + child: ListView( + controller: controller, + padding: const EdgeInsets.all(24), + children: [ + _buildModalHeader(), + _buildImageSlider(item['images'], (index) => setModalState(() => currentSlide = index), currentSlide), + const SizedBox(height: 20), + + // Judul & Nama Latin + Text(item['name'], style: GoogleFonts.poppins(fontSize: 26, fontWeight: FontWeight.bold)), + Text(item['latin'], style: GoogleFonts.poppins(fontSize: 16, fontStyle: FontStyle.italic, color: primaryColor)), + const Divider(height: 30), + + // Section Detail + _infoSection("📍 Habitat", item['habitat']), + _infoSection("🔍 Karakteristik", item['characteristics']), + isPoisonous + ? _infoSection("⚠️ Bahaya Toksin", item['danger'], color: accentPoison) + : _infoSection("🥗 Manfaat", item['benefits'], color: accentSafe), + + const SizedBox(height: 30), + ElevatedButton( + onPressed: () => Navigator.pop(context), + style: ElevatedButton.styleFrom( + backgroundColor: primaryColor, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + padding: const EdgeInsets.symmetric(vertical: 16) + ), + child: const Text("Tutup Informasi", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), + ), + const SizedBox(height: 30), + ], + ), + ), + ), + ), + ); + } + + Widget _buildModalHeader() { + return Center( + child: Container( + margin: const EdgeInsets.only(bottom: 20), + width: 50, height: 5, + decoration: BoxDecoration(color: Colors.grey[300], borderRadius: BorderRadius.circular(10)), + ), + ); + } + + Widget _buildImageSlider(List images, Function(int) onPageChanged, int currentSlide) { + return SizedBox( + height: 250, + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + PageView.builder( + itemCount: images.length, + onPageChanged: onPageChanged, + itemBuilder: (context, index) => ClipRRect( + borderRadius: BorderRadius.circular(20), + child: Image.asset(images[index], fit: BoxFit.cover), + ), + ), + Positioned( + bottom: 10, + child: Row( + children: List.generate(images.length, (index) => AnimatedContainer( + duration: const Duration(milliseconds: 300), + margin: const EdgeInsets.symmetric(horizontal: 4), + height: 8, width: currentSlide == index ? 24 : 8, + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)), + )), + ), + ) + ], + ), + ); + } + + Widget _infoSection(String title, String content, {Color color = Colors.black87}) { + return Padding( + padding: const EdgeInsets.only(bottom: 18), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title, style: GoogleFonts.poppins(fontWeight: FontWeight.bold, fontSize: 16, color: primaryColor)), + const SizedBox(height: 6), + Text(content, style: GoogleFonts.poppins(fontSize: 14, color: color, height: 1.5), textAlign: TextAlign.justify), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/screens/output_screen.dart b/lib/screens/output_screen.dart new file mode 100644 index 0000000..7870a87 --- /dev/null +++ b/lib/screens/output_screen.dart @@ -0,0 +1,360 @@ +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:tflite_v2/tflite_v2.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class OutputScreen extends StatefulWidget { + final String imagePath; + + const OutputScreen({super.key, required this.imagePath}); + + @override + State createState() => _OutputScreenState(); +} + +// Database Mapping Hasil Prediksi +final Map> dataJamur = { + + "Auricularia auricula judae": { + "kategori": "Aman Dikonsumsi ✅", + "habitat": + "Tumbuh di daerah tropis dan subtropis pada kayu mati, batang pohon lapuk, atau ranting lembap. " + "Sering muncul setelah hujan di lingkungan dengan kelembapan tinggi seperti hutan tropis, kebun, " + "dan area teduh serta biasanya tumbuh berkelompok sepanjang tahun.", + "karakteristik": + "Bentuk menyerupai telinga manusia dengan warna cokelat kemerahan hingga kehitaman. " + "Permukaan luar sedikit berbulu halus, bagian dalam licin mengilap, bertekstur kenyal seperti gel, " + "tidak memiliki batang jelas, dan berukuran sekitar 3–10 cm." + }, + + "Fly Agaric": { + "kategori": "Beracun ⚠️", + "habitat": + "Tumbuh di wilayah beriklim dingin hingga sedang di hutan konifer dan campuran. " + "Sering ditemukan di bawah pohon pinus, spruce, fir, dan birch pada tanah berlumut " + "atau lembap di akhir musim panas hingga musim gugur.", + "karakteristik": + "Tudung merah cerah berdiameter 8–20 cm dengan bintik putih. Insang putih rapat, " + "batang putih kokoh dengan cincin serta pangkal batang memiliki volva berbentuk kantung." + }, + + "amanita_patherina": { + "kategori": "Beracun ⚠️", + "habitat": + "Ditemukan di hutan gugur dan konifer pada daerah beriklim sedang. " + "Biasanya tumbuh di tanah kaya bahan organik di sekitar pohon oak, beech, pinus, dan cemara.", + "karakteristik": + "Tudung cokelat kekuningan 5–12 cm dengan bintik putih kecil rapi. " + "Memiliki insang putih, batang ramping bercincin, dan pangkal batang " + "membulat dengan volva berbentuk cincin konsentris." + }, + + "Termitomyces": { + "kategori": "Aman Dikonsumsi ✅", + "habitat": + "Tumbuh di daerah tropis di sekitar sarang rayap tanah dan muncul setelah hujan lebat " + "di padang rumput, ladang, atau pinggir hutan yang memiliki koloni rayap aktif.", + "karakteristik": + "Tudung berbentuk payung dengan puncak meruncing berwarna putih krem hingga cokelat muda. " + "Batang panjang terhubung ke akar semu (pseudorhiza) menuju sarang rayap, insang putih rapat " + "dan daging jamur tebal beraroma gurih." + }, +}; +class _OutputScreenState extends State { + bool _modelLoaded = false; + String label = "Mengidentifikasi..."; + String kategori = "-"; + String deskripsi = "Sedang menganalisis data..."; + double confidence = 0.0; + bool isLoading = true; + + @override + void initState() { + super.initState(); + _runModel(); + } + + @override + void dispose() { + Tflite.close(); + super.dispose(); + } + + Color _getAccuracyColor(double conf) { + double percent = conf * 100; + if (percent < 60) return Colors.red; + if (percent < 80) return Colors.orange; + return Colors.green; + } + + String _getAccuracyLabel(double conf) { + double percent = conf * 100; + if (percent < 60) return "Akurasi Rendah (Objek tidak dikenali)"; + if (percent < 80) return "Akurasi Cukup"; + return "Akurasi Sangat Tinggi"; + } + + Future _runModel() async { + try { + if (!_modelLoaded) { + await Tflite.loadModel( + model: "assets/model_cnn.tflite", + labels: "assets/labels.txt", + ); + _modelLoaded = true; + } + + var recognitions = await Tflite.runModelOnImage( + path: widget.imagePath, + imageMean: 0, + imageStd: 255, + numResults: 1, + threshold: 0.1, + ); + + if (recognitions != null && recognitions.isNotEmpty) { + final result = recognitions[0]; + String resultLabel = result['label']?.toString() ?? "-"; + + setState(() { + confidence = (result['confidence'] as double); + + // ===== CONFIDENCE THRESHOLD ===== + if (confidence < 0.6) { + label = "Tidak Dikenali"; + kategori = "Bukan Jamur"; + deskripsi = + "Gambar tidak dapat diidentifikasi sebagai jamur. " + "Silakan ambil gambar jamur dengan jelas."; + } else { + label = resultLabel; + var info = dataJamur[resultLabel]; + if (info != null) { + kategori = info["kategori"]!; + + String habitat = info["habitat"]!; + String karakteristik = info["karakteristik"]!; + + deskripsi = + "Habitat:\n$habitat\n\n" + "Karakteristik:\n$karakteristik"; + } else { + kategori = "Tidak Diketahui"; + deskripsi = "Data penjelasan untuk jenis ini belum tersedia."; + } + } + // =============================== + + isLoading = false; + }); + } + } catch (e) { + debugPrint("Error: $e"); + } + } + + @override + Widget build(BuildContext context) { + bool isPoisonous = kategori.contains("Beracun"); + Color accuracyColor = _getAccuracyColor(confidence); + + return Scaffold( + backgroundColor: const Color(0xFFF5F7F5), + appBar: AppBar( + backgroundColor: Colors.transparent, + elevation: 0, + leading: IconButton( + icon: const Icon(Icons.arrow_back_ios_new, color: Colors.black), + onPressed: () => Navigator.pop(context), + ), + title: Text( + 'HASIL IDENTIFIKASI', + style: GoogleFonts.poppins( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + centerTitle: true, + ), + body: isLoading + ? const Center( + child: CircularProgressIndicator(color: Color(0xFF2E7D32))) + : SingleChildScrollView( + padding: const EdgeInsets.all(24), + child: Column( + children: [ + Container( + width: double.infinity, + height: 320, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(28), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.1), + blurRadius: 20, + offset: const Offset(0, 10), + ) + ], + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(28), + child: Image.file( + File(widget.imagePath), + fit: BoxFit.cover, + ), + ), + ), + const SizedBox(height: 25), + + Container( + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.05), + blurRadius: 10, + ) + ], + ), + child: Column( + children: [ + _buildResultRow( + Icons.eco_outlined, "Nama Jamur", label, Colors.blue), + const Divider(height: 30), + _buildResultRow( + isPoisonous + ? Icons.warning_amber_rounded + : Icons.check_circle_outline, + "Kategori", + kategori, + isPoisonous ? Colors.red : Colors.green, + ), + const Divider(height: 30), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text("Akurasi Prediksi", + style: GoogleFonts.poppins( + fontSize: 13, + color: Colors.grey[600])), + Text( + "${(confidence * 100).toStringAsFixed(1)}%", + style: GoogleFonts.poppins( + fontWeight: FontWeight.bold, + color: accuracyColor), + ), + ], + ), + const SizedBox(height: 10), + ClipRRect( + borderRadius: BorderRadius.circular(10), + child: LinearProgressIndicator( + value: confidence, + backgroundColor: Colors.grey[200], + valueColor: + AlwaysStoppedAnimation( + accuracyColor), + minHeight: 10, + ), + ), + const SizedBox(height: 8), + Text( + _getAccuracyLabel(confidence), + style: GoogleFonts.poppins( + fontSize: 11, + color: accuracyColor, + fontWeight: FontWeight.w500), + ), + ], + ), + ], + ), + ), + const SizedBox(height: 20), + + Container( + width: double.infinity, + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: isPoisonous + ? const Color(0xFFFFEBEE) + : const Color(0xFFE8F5E9), + borderRadius: BorderRadius.circular(25), + border: Border.all( + color: isPoisonous + ? Colors.red.shade100 + : Colors.green.shade100), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Icon(Icons.info_outline, + color: + isPoisonous ? Colors.red : Colors.green, + size: 20), + const SizedBox(width: 8), + Text("Penjelasan Detail", + style: GoogleFonts.poppins( + fontWeight: FontWeight.bold, + color: isPoisonous + ? Colors.red[900] + : Colors.green[900])), + ], + ), + const SizedBox(height: 12), + Text( + deskripsi, + style: GoogleFonts.poppins( + fontSize: 14, + color: Colors.black87, + height: 1.6), + textAlign: TextAlign.justify, + ), + ], + ), + ), + ], + ), + ), + ); + } + + Widget _buildResultRow( + IconData icon, String title, String value, Color color) { + return Row( + children: [ + Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: color.withOpacity(0.1), + borderRadius: BorderRadius.circular(12)), + child: Icon(icon, color: color, size: 26), + ), + const SizedBox(width: 15), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title, + style: GoogleFonts.poppins( + fontSize: 12, color: Colors.grey[600])), + Text(value, + style: GoogleFonts.poppins( + fontSize: 16, fontWeight: FontWeight.bold)), + ], + ), + ), + ], + ); + } + +} diff --git a/lib/screens/splash_screen.dart b/lib/screens/splash_screen.dart new file mode 100644 index 0000000..06f71bc --- /dev/null +++ b/lib/screens/splash_screen.dart @@ -0,0 +1,36 @@ +import 'dart:async'; +import 'package:flutter/material.dart'; +import 'home_screen.dart'; + +class SplashScreen extends StatefulWidget { + const SplashScreen({Key? key}) : super(key: key); + + @override + State createState() => _SplashScreenState(); +} + +class _SplashScreenState extends State { + @override + void initState() { + super.initState(); + Timer(const Duration(seconds: 3), () { + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (context) => const HomeScreen()), + ); + }); + } + + @override + Widget build(BuildContext context) { + return const Scaffold( + backgroundColor: Colors.white, + body: Center( + child: Image( + image: AssetImage('assets/logo.png'), + width: 200, // sesuaikan ukuran logo + ), + ), + ); + } +} diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/widgets/bottom_navbar.dart b/lib/widgets/bottom_navbar.dart new file mode 100644 index 0000000..b43e36e --- /dev/null +++ b/lib/widgets/bottom_navbar.dart @@ -0,0 +1,152 @@ +import 'package:flutter/material.dart'; +import '../screens/home_screen.dart'; +import '../screens/ai_screen.dart'; // Pastikan nama file sesuai, di kode awal Anda memakai ai_screen.dart +import '../screens/info_screen.dart'; + +class BottomNavBar extends StatelessWidget { + final int selectedIndex; + + const BottomNavBar({super.key, required this.selectedIndex}); + + @override + Widget build(BuildContext context) { + const Color activeColor = Color(0xFF4CAF50); + const Color inactiveColor = Colors.grey; + + return Stack( + alignment: Alignment.bottomCenter, + clipBehavior: Clip.none, // Agar label di bawah FAB tidak terpotong + children: [ + // 1. Navbar Background (Container Putih) + Container( + height: 70, + margin: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.95), + borderRadius: BorderRadius.circular(24), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.08), + blurRadius: 10, + offset: const Offset(0, 4), + ), + ], + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 40), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _BottomNavItem( + icon: Icons.home_rounded, + label: "Beranda", + isActive: selectedIndex == 0, + onTap: () { + if (selectedIndex != 0) { + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (_) => const HomeScreen()), + ); + } + }, + ), + const SizedBox(width: 60), // Space untuk area tombol tengah + _BottomNavItem( + icon: Icons.info_outline_rounded, + label: "Info", + isActive: selectedIndex == 2, + onTap: () { + if (selectedIndex != 2) { + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (_) => const InfoScreen()), + ); + } + }, + ), + ], + ), + ), + ), + + // 2. Tombol Utama: Klasifikasi AI + Positioned( + bottom: 35, // Ditinggikan sedikit agar pas + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FloatingActionButton( + backgroundColor: activeColor, + elevation: 6, + shape: const CircleBorder(), + onPressed: () { + if (selectedIndex != 1) { + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (_) => const AIScanScreen()), + ); + } + }, + // MENGGUNAKAN IKON PSIKOLOGI/AI + child: const Icon( + Icons.psychology_rounded, + size: 32, + color: Colors.white + ), + ), + const SizedBox(height: 4), + Text( + "AI Scan", + style: TextStyle( + color: selectedIndex == 1 ? activeColor : inactiveColor, + fontSize: 12, + fontWeight: selectedIndex == 1 ? FontWeight.w600 : FontWeight.normal, + ), + ), + ], + ), + ), + ], + ); + } +} + +class _BottomNavItem extends StatelessWidget { + final IconData icon; + final String label; + final bool isActive; + final VoidCallback onTap; + + const _BottomNavItem({ + required this.icon, + required this.label, + required this.isActive, + required this.onTap, + }); + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + borderRadius: BorderRadius.circular(16), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + icon, + color: isActive ? const Color(0xFF4CAF50) : Colors.grey + ), + const SizedBox(height: 4), + Text( + label, + style: TextStyle( + color: isActive ? const Color(0xFF4CAF50) : Colors.grey, + fontSize: 12, + fontWeight: isActive ? FontWeight.w600 : FontWeight.normal, + ), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/widgets/custom_button.dart b/lib/widgets/custom_button.dart new file mode 100644 index 0000000..e69de29 diff --git a/linux/.gitignore b/linux/.gitignore new file mode 100644 index 0000000..d3896c9 --- /dev/null +++ b/linux/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt new file mode 100644 index 0000000..2ff4806 --- /dev/null +++ b/linux/CMakeLists.txt @@ -0,0 +1,128 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.13) +project(runner LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "fungid3_new") +# The unique GTK application identifier for this application. See: +# https://wiki.gnome.org/HowDoI/ChooseApplicationID +set(APPLICATION_ID "com.example.fungid3_new") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(SET CMP0063 NEW) + +# Load bundled libraries from the lib/ directory relative to the binary. +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Define build configuration options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) + install(FILES "${bundled_library}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endforeach(bundled_library) + +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/linux/flutter/CMakeLists.txt b/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000..d5bd016 --- /dev/null +++ b/linux/flutter/CMakeLists.txt @@ -0,0 +1,88 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000..64a0ece --- /dev/null +++ b/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + +#include + +void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); + file_selector_plugin_register_with_registrar(file_selector_linux_registrar); +} diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000..e0f0a47 --- /dev/null +++ b/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake new file mode 100644 index 0000000..2db3c22 --- /dev/null +++ b/linux/flutter/generated_plugins.cmake @@ -0,0 +1,24 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + file_selector_linux +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/linux/runner/CMakeLists.txt b/linux/runner/CMakeLists.txt new file mode 100644 index 0000000..e97dabc --- /dev/null +++ b/linux/runner/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.13) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the application ID. +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Add dependency libraries. Add any application-specific dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) + +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") diff --git a/linux/runner/main.cc b/linux/runner/main.cc new file mode 100644 index 0000000..e7c5c54 --- /dev/null +++ b/linux/runner/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/linux/runner/my_application.cc b/linux/runner/my_application.cc new file mode 100644 index 0000000..57a0309 --- /dev/null +++ b/linux/runner/my_application.cc @@ -0,0 +1,148 @@ +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Called when first Flutter frame received. +static void first_frame_cb(MyApplication* self, FlView* view) { + gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view))); +} + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "fungid3_new"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "fungid3_new"); + } + + gtk_window_set_default_size(window, 1280, 720); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments( + project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + GdkRGBA background_color; + // Background defaults to black, override it here if necessary, e.g. #00000000 + // for transparent. + gdk_rgba_parse(&background_color, "#000000"); + fl_view_set_background_color(view, &background_color); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + // Show the window when Flutter renders. + // Requires the view to be realized so we can start rendering. + g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), + self); + gtk_widget_realize(GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, + gchar*** arguments, + int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GApplication::startup. +static void my_application_startup(GApplication* application) { + // MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application startup. + + G_APPLICATION_CLASS(my_application_parent_class)->startup(application); +} + +// Implements GApplication::shutdown. +static void my_application_shutdown(GApplication* application) { + // MyApplication* self = MY_APPLICATION(object); + + // Perform any actions required at application shutdown. + + G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = + my_application_local_command_line; + G_APPLICATION_CLASS(klass)->startup = my_application_startup; + G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + // Set the program name to the application ID, which helps various systems + // like GTK and desktop environments map this running application to its + // corresponding .desktop file. This ensures better integration by allowing + // the application to be recognized beyond its binary name. + g_set_prgname(APPLICATION_ID); + + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, "flags", + G_APPLICATION_NON_UNIQUE, nullptr)); +} diff --git a/linux/runner/my_application.h b/linux/runner/my_application.h new file mode 100644 index 0000000..db16367 --- /dev/null +++ b/linux/runner/my_application.h @@ -0,0 +1,21 @@ +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, + my_application, + MY, + APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/macos/.gitignore b/macos/.gitignore new file mode 100644 index 0000000..746adbb --- /dev/null +++ b/macos/.gitignore @@ -0,0 +1,7 @@ +# Flutter-related +**/Flutter/ephemeral/ +**/Pods/ + +# Xcode-related +**/dgph +**/xcuserdata/ diff --git a/macos/Flutter/Flutter-Debug.xcconfig b/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000..c2efd0b --- /dev/null +++ b/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/Flutter-Release.xcconfig b/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000..c2efd0b --- /dev/null +++ b/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift new file mode 100644 index 0000000..b878e03 --- /dev/null +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -0,0 +1,14 @@ +// +// Generated file. Do not edit. +// + +import FlutterMacOS +import Foundation + +import file_selector_macos +import path_provider_foundation + +func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) +} diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..75df36c --- /dev/null +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,705 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 331C80D8294CF71000263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C80D7294CF71000263BE5 /* RunnerTests.swift */; }; + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C80D9294CF71000263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC10EC2044A3C60003C045; + remoteInfo = Runner; + }; + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 331C80D5294CF71000263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 331C80D7294CF71000263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* fungid3_new.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "fungid3_new.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 331C80D2294CF70F00263BE5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 331C80D6294CF71000263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C80D7294CF71000263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 331C80D6294CF71000263BE5 /* RunnerTests */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* fungid3_new.app */, + 331C80D5294CF71000263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C80D4294CF70F00263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C80D1294CF70F00263BE5 /* Sources */, + 331C80D2294CF70F00263BE5 /* Frameworks */, + 331C80D3294CF70F00263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C80DA294CF71000263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C80D5294CF71000263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* fungid3_new.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C80D4294CF70F00263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 33CC10EC2044A3C60003C045; + }; + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 331C80D4294CF70F00263BE5 /* RunnerTests */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C80D3294CF70F00263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C80D1294CF70F00263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C80D8294CF71000263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C80DA294CF71000263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC10EC2044A3C60003C045 /* Runner */; + targetProxy = 331C80D9294CF71000263BE5 /* PBXContainerItemProxy */; + }; + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 331C80DB294CF71000263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/fungid3_new.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/fungid3_new"; + }; + name = Debug; + }; + 331C80DC294CF71000263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/fungid3_new.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/fungid3_new"; + }; + name = Release; + }; + 331C80DD294CF71000263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/fungid3_new.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/fungid3_new"; + }; + name = Profile; + }; + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C80DB294CF71000263BE5 /* Debug */, + 331C80DC294CF71000263BE5 /* Release */, + 331C80DD294CF71000263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..a53cc5c --- /dev/null +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macos/Runner.xcworkspace/contents.xcworkspacedata b/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000..b3c1761 --- /dev/null +++ b/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import Cocoa +import FlutterMacOS + +@main +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } +} diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..a2ec33f --- /dev/null +++ b/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png new file mode 100644 index 0000000..82b6f9d Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png new file mode 100644 index 0000000..13b35eb Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png new file mode 100644 index 0000000..0a3f5fa Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png new file mode 100644 index 0000000..bdb5722 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png new file mode 100644 index 0000000..f083318 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png new file mode 100644 index 0000000..326c0e7 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png new file mode 100644 index 0000000..2f1632c Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png differ diff --git a/macos/Runner/Base.lproj/MainMenu.xib b/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..80e867a --- /dev/null +++ b/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macos/Runner/Configs/AppInfo.xcconfig b/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000..f9e673e --- /dev/null +++ b/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = fungid3_new + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = com.example.fungid3New + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2025 com.example. All rights reserved. diff --git a/macos/Runner/Configs/Debug.xcconfig b/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000..36b0fd9 --- /dev/null +++ b/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/macos/Runner/Configs/Release.xcconfig b/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000..dff4f49 --- /dev/null +++ b/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/macos/Runner/Configs/Warnings.xcconfig b/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000..42bcbf4 --- /dev/null +++ b/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000..dddb8a3 --- /dev/null +++ b/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/macos/Runner/Info.plist b/macos/Runner/Info.plist new file mode 100644 index 0000000..4789daa --- /dev/null +++ b/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/macos/Runner/MainFlutterWindow.swift b/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000..3cc05eb --- /dev/null +++ b/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,15 @@ +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements new file mode 100644 index 0000000..852fa1a --- /dev/null +++ b/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/macos/RunnerTests/RunnerTests.swift b/macos/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..61f3bd1 --- /dev/null +++ b/macos/RunnerTests/RunnerTests.swift @@ -0,0 +1,12 @@ +import Cocoa +import FlutterMacOS +import XCTest + +class RunnerTests: XCTestCase { + + func testExample() { + // If you add code to the Runner application, consider adding tests here. + // See https://developer.apple.com/documentation/xctest for more information about using XCTest. + } + +} diff --git a/plugins/tflite_v2-1.0.0/CHANGELOG.md b/plugins/tflite_v2-1.0.0/CHANGELOG.md new file mode 100644 index 0000000..3c5c4d2 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/CHANGELOG.md @@ -0,0 +1,74 @@ +## 1.1.2 + +- Add null safety support for Android + +## 1.1.1 + +- Fix error: ';' expected on Android + +## 1.1.0 + +- Upgrade to TensorFlowLiteObjC 2.2. +- Add support for GPU delegate. +- Fix label size for YOLO. + +## 1.0.6 + +* Add support for resources outside packaged assets. +* Upgrade version of Flutter SDK and Android Studio. +* Set mininum SDK version to 2.1.0 + +## 1.0.5 + +* Set compileSdkVersion to 28, fixing build error "Execution failed for task ':tflite:verifyReleaseResources'." +* Add notes about CONTRIB_PATH. +* Update pubspec.yaml for Flutter 1.10.0 and later. +* Update example app to use image plugin 2.1.4. + +## 1.0.4 + +* Add PoseNet support + +## 1.0.3 + +* Add an asynch option to offload the TfLite run from the UI thread +* Add Deeplab support + +## 1.0.2 + +* Add pix2pix support +* Make number of detections dynamic in Android + +## 1.0.1 + +* Add detectObjectOnBinary +* Add runModelOnFrame +* Add detectObjectOnFrame + +## 1.0.0 + +* Support Object Detection with SSD MobileNet and Tiny Yolov2. +* Updated to TensorFlow Lite API v1.12.0. +* No longer accepts parameter `inputSize` and `numChannels`. They will be retrieved from input tensor. +* `numThreads` is moved to `Tflite.loadModel`. + +## 0.0.5 + +* Support byte list: runModelOnBinary + +## 0.0.4 + +* Support Swift based project + +## 0.0.3 + +* Pass error message in channel in Android. +* Use non hard coded label size in iOS. + +## 0.0.2 + +* Fixed link. + +## 0.0.1 + +* Initial release. diff --git a/plugins/tflite_v2-1.0.0/LICENSE b/plugins/tflite_v2-1.0.0/LICENSE new file mode 100644 index 0000000..59c6ea2 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 Qian Sha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/README.md b/plugins/tflite_v2-1.0.0/README.md new file mode 100644 index 0000000..216b457 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/README.md @@ -0,0 +1,513 @@ +# tflite + +A Flutter plugin for accessing TensorFlow Lite API. Supports image classification, object detection ([SSD](https://github.com/tensorflow/models/tree/master/research/object_detection) and [YOLO](https://pjreddie.com/darknet/yolov2/)), [Pix2Pix](https://phillipi.github.io/pix2pix/) and [Deeplab](https://github.com/tensorflow/models/tree/master/research/deeplab) and [PoseNet](https://www.tensorflow.org/lite/models/pose_estimation/overview) on both iOS and Android. + +### Table of Contents + +- [Installation](#Installation) +- [Usage](#Usage) + - [Image Classification](#Image-Classification) + - [Object Detection](#Object-Detection) + - [SSD MobileNet](#SSD-MobileNet) + - [YOLO](#Tiny-YOLOv2) + - [Pix2Pix](#Pix2Pix) + - [Deeplab](#Deeplab) + - [PoseNet](#PoseNet) +- [Example](#Example) + - [Prediction in Static Images](#Prediction-in-Static-Images) + - [Real-time Detection](#Real-time-Detection) + +### Breaking changes + +#### Since 1.1.0: + +1. iOS TensorFlow Lite library is upgraded from TensorFlowLite 1.x to TensorFlowLiteObjC 2.x. Changes to native code are denoted with `TFLITE2`. + +#### Since 1.0.0: + +1. Updated to TensorFlow Lite API v1.12.0. +2. No longer accepts parameter `inputSize` and `numChannels`. They will be retrieved from input tensor. +3. `numThreads` is moved to `Tflite.loadModel`. + +## Installation + +Add `tflite` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/). + +### Android + +In `android/app/build.gradle`, add the following setting in `android` block. + +``` + aaptOptions { + noCompress 'tflite' + noCompress 'lite' + } +``` + +### iOS + +Solutions to build errors on iOS: + +* 'vector' file not found" + + Open `ios/Runner.xcworkspace` in Xcode, click Runner > Tagets > Runner > Build Settings, search `Compile Sources As`, change the value to `Objective-C++` + +* 'tensorflow/lite/kernels/register.h' file not found + + The plugin assumes the tensorflow header files are located in path "tensorflow/lite/kernels". + + However, for early versions of tensorflow the header path is "tensorflow/contrib/lite/kernels". + + Use `CONTRIB_PATH` to toggle the path. Uncomment `//#define CONTRIB_PATH` from here: + https://github.com/shaqian/flutter_tflite/blob/master/ios/Classes/TflitePlugin.mm#L1 + +## Usage + +1. Create a `assets` folder and place your label file and model file in it. In `pubspec.yaml` add: + +``` + assets: + - assets/labels.txt + - assets/mobilenet_v1_1.0_224.tflite +``` + +2. Import the library: + +```dart +import 'package:tflite/tflite.dart'; +``` + +3. Load the model and labels: + +```dart +String res = await Tflite.loadModel( + model: "assets/mobilenet_v1_1.0_224.tflite", + labels: "assets/labels.txt", + numThreads: 1, // defaults to 1 + isAsset: true, // defaults to true, set to false to load resources outside assets + useGpuDelegate: false // defaults to false, set to true to use GPU delegate +); +``` + +4. See the section for the respective model below. + +5. Release resources: + +``` +await Tflite.close(); +``` + +### GPU Delegate + +When using GPU delegate, refer to [this step](https://www.tensorflow.org/lite/performance/gpu#step_5_release_mode) for release mode setting to get better performance. + +### Image Classification + +- Output format: +``` +{ + index: 0, + label: "person", + confidence: 0.629 +} +``` + +- Run on image: + +```dart +var recognitions = await Tflite.runModelOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 117.0 + imageStd: 255.0, // defaults to 1.0 + numResults: 2, // defaults to 5 + threshold: 0.2, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.runModelOnBinary( + binary: imageToByteListFloat32(image, 224, 127.5, 127.5),// required + numResults: 6, // defaults to 5 + threshold: 0.05, // defaults to 0.1 + asynch: true // defaults to true +); + +Uint8List imageToByteListFloat32( + img.Image image, int inputSize, double mean, double std) { + var convertedBytes = Float32List(1 * inputSize * inputSize * 3); + var buffer = Float32List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; + } + } + return convertedBytes.buffer.asUint8List(); +} + +Uint8List imageToByteListUint8(img.Image image, int inputSize) { + var convertedBytes = Uint8List(1 * inputSize * inputSize * 3); + var buffer = Uint8List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = img.getRed(pixel); + buffer[pixelIndex++] = img.getGreen(pixel); + buffer[pixelIndex++] = img.getBlue(pixel); + } + } + return convertedBytes.buffer.asUint8List(); +} +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.runModelOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, + imageWidth: img.width, + imageMean: 127.5, // defaults to 127.5 + imageStd: 127.5, // defaults to 127.5 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +### Object Detection + +- Output format: + +`x, y, w, h` are between [0, 1]. You can scale `x, w` by the width and `y, h` by the height of the image. + +``` +{ + detectedClass: "hot dog", + confidenceInClass: 0.123, + rect: { + x: 0.15, + y: 0.33, + w: 0.80, + h: 0.27 + } +} +``` + +#### SSD MobileNet: + +- Run on image: + +```dart +var recognitions = await Tflite.detectObjectOnImage( + path: filepath, // required + model: "SSDMobileNet", + imageMean: 127.5, + imageStd: 127.5, + threshold: 0.4, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.detectObjectOnBinary( + binary: imageToByteListUint8(resizedImage, 300), // required + model: "SSDMobileNet", + threshold: 0.4, // defaults to 0.1 + numResultsPerClass: 2, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.detectObjectOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + model: "SSDMobileNet", + imageHeight: img.height, + imageWidth: img.width, + imageMean: 127.5, // defaults to 127.5 + imageStd: 127.5, // defaults to 127.5 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +#### Tiny YOLOv2: + +- Run on image: + +```dart +var recognitions = await Tflite.detectObjectOnImage( + path: filepath, // required + model: "YOLO", + imageMean: 0.0, + imageStd: 255.0, + threshold: 0.3, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.detectObjectOnBinary( + binary: imageToByteListFloat32(resizedImage, 416, 0.0, 255.0), // required + model: "YOLO", + threshold: 0.3, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.detectObjectOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + model: "YOLO", + imageHeight: img.height, + imageWidth: img.width, + imageMean: 0, // defaults to 127.5 + imageStd: 255.0, // defaults to 127.5 + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +### Pix2Pix + +> Thanks to [RP](https://github.com/shaqian/flutter_tflite/pull/18) from [Green Appers](https://github.com/GreenAppers) + +- Output format: + + The output of Pix2Pix inference is Uint8List type. Depending on the `outputType` used, the output is: + + - (if outputType is png) byte array of a png image + + - (otherwise) byte array of the raw output + +- Run on image: + +```dart +var result = await runPix2PixOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 0.0 + imageStd: 255.0, // defaults to 255.0 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runPix2PixOnBinary( + binary: binary, // required + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runPix2PixOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 127.5, // defaults to 0.0 + imageStd: 127.5, // defaults to 255.0 + rotation: 90, // defaults to 90, Android only + asynch: true // defaults to true +); +``` + +### Deeplab + +> Thanks to [RP](https://github.com/shaqian/flutter_tflite/pull/22) from [see--](https://github.com/see--) for Android implementation. + +- Output format: + + The output of Deeplab inference is Uint8List type. Depending on the `outputType` used, the output is: + + - (if outputType is png) byte array of a png image + + - (otherwise) byte array of r, g, b, a values of the pixels + +- Run on image: + +```dart +var result = await runSegmentationOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 0.0 + imageStd: 255.0, // defaults to 255.0 + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runSegmentationOnBinary( + binary: binary, // required + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runSegmentationOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 127.5, // defaults to 0.0 + imageStd: 127.5, // defaults to 255.0 + rotation: 90, // defaults to 90, Android only + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +### PoseNet + +> Model is from [StackOverflow thread](https://stackoverflow.com/a/55288616). + +- Output format: + +`x, y` are between [0, 1]. You can scale `x` by the width and `y` by the height of the image. + +``` +[ // array of poses/persons + { // pose #1 + score: 0.6324902, + keypoints: { + 0: { + x: 0.250, + y: 0.125, + part: nose, + score: 0.9971070 + }, + 1: { + x: 0.230, + y: 0.105, + part: leftEye, + score: 0.9978438 + } + ...... + } + }, + { // pose #2 + score: 0.32534285, + keypoints: { + 0: { + x: 0.402, + y: 0.538, + part: nose, + score: 0.8798978 + }, + 1: { + x: 0.380, + y: 0.513, + part: leftEye, + score: 0.7090239 + } + ...... + } + }, + ...... +] +``` + +- Run on image: + +```dart +var result = await runPoseNetOnImage( + path: filepath, // required + imageMean: 125.0, // defaults to 125.0 + imageStd: 125.0, // defaults to 125.0 + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runPoseNetOnBinary( + binary: binary, // required + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runPoseNetOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 125.0, // defaults to 125.0 + imageStd: 125.0, // defaults to 125.0 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +## Example + +### Prediction in Static Images + + Refer to the [example](https://github.com/shaqian/flutter_tflite/tree/master/example). + +### Real-time detection + + Refer to [flutter_realtime_Detection](https://github.com/shaqian/flutter_realtime_detection). + +## Run test cases + +`flutter test test/tflite_test.dart` \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build.gradle b/plugins/tflite_v2-1.0.0/android/build.gradle new file mode 100644 index 0000000..77f5690 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build.gradle @@ -0,0 +1,40 @@ +group 'sq.flutter.tflite' +version '1.0-SNAPSHOT' + +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.6.3' + } +} + +rootProject.allprojects { + repositories { + google() + jcenter() + } +} + +apply plugin: 'com.android.library' + +android { + namespace "org.tensorflow.lite.flutter" + compileSdkVersion 33 + + defaultConfig { + minSdkVersion 19 + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + lintOptions { + disable 'InvalidPackage' + } + + dependencies { + implementation 'org.tensorflow:tensorflow-lite:+' + implementation 'org.tensorflow:tensorflow-lite-gpu:+' + } +} diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml b/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml new file mode 100644 index 0000000..958d677 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json b/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json new file mode 100644 index 0000000..1c292f0 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json @@ -0,0 +1,18 @@ +{ + "version": 3, + "artifactType": { + "type": "AAPT_FRIENDLY_MERGED_MANIFESTS", + "kind": "Directory" + }, + "applicationId": "sq.flutter.tflite", + "variantName": "debug", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "attributes": [], + "outputFile": "AndroidManifest.xml" + } + ], + "elementType": "File" +} \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/aar_metadata/debug/aar-metadata.properties b/plugins/tflite_v2-1.0.0/android/build/intermediates/aar_metadata/debug/aar-metadata.properties new file mode 100644 index 0000000..776557e --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/aar_metadata/debug/aar-metadata.properties @@ -0,0 +1,5 @@ +aarFormatVersion=1.0 +aarMetadataVersion=1.0 +minCompileSdk=1 +minCompileSdkExtension=0 +minAndroidGradlePluginVersion=1.0.0 diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/compile_r_class_jar/debug/R.jar b/plugins/tflite_v2-1.0.0/android/build/intermediates/compile_r_class_jar/debug/R.jar new file mode 100644 index 0000000..0a26c8f Binary files /dev/null and b/plugins/tflite_v2-1.0.0/android/build/intermediates/compile_r_class_jar/debug/R.jar differ diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/compile_symbol_list/debug/R.txt b/plugins/tflite_v2-1.0.0/android/build/intermediates/compile_symbol_list/debug/R.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties new file mode 100644 index 0000000..494802b --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties @@ -0,0 +1 @@ +#Wed Dec 31 13:31:17 WIB 2025 diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml new file mode 100644 index 0000000..e3a941d --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/mergeDebugShaders/merger.xml b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/mergeDebugShaders/merger.xml new file mode 100644 index 0000000..edf9849 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/mergeDebugShaders/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/packageDebugAssets/merger.xml b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/packageDebugAssets/merger.xml new file mode 100644 index 0000000..857dc88 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/incremental/packageDebugAssets/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/local_only_symbol_list/debug/R-def.txt b/plugins/tflite_v2-1.0.0/android/build/intermediates/local_only_symbol_list/debug/R-def.txt new file mode 100644 index 0000000..78ac5b8 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/local_only_symbol_list/debug/R-def.txt @@ -0,0 +1,2 @@ +R_DEF: Internal format may change without notice +local diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt b/plugins/tflite_v2-1.0.0/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt new file mode 100644 index 0000000..a354e08 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt @@ -0,0 +1,7 @@ +1 +2 +4 +5 +6 +7 diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml b/plugins/tflite_v2-1.0.0/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml new file mode 100644 index 0000000..958d677 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/navigation_json/debug/navigation.json b/plugins/tflite_v2-1.0.0/android/build/intermediates/navigation_json/debug/navigation.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/navigation_json/debug/navigation.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt b/plugins/tflite_v2-1.0.0/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt new file mode 100644 index 0000000..3388a3e --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt @@ -0,0 +1 @@ +sq.flutter.tflite diff --git a/plugins/tflite_v2-1.0.0/android/build/outputs/logs/manifest-merger-debug-report.txt b/plugins/tflite_v2-1.0.0/android/build/outputs/logs/manifest-merger-debug-report.txt new file mode 100644 index 0000000..44c0191 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/build/outputs/logs/manifest-merger-debug-report.txt @@ -0,0 +1,17 @@ +-- Merging decision tree log --- +manifest +ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:1-3:12 +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:1-3:12 + package + ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:2:3-30 + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + xmlns:android + ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:11-69 +uses-sdk +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml reason: use-sdk injection requested +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + android:targetSdkVersion + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + android:minSdkVersion + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml diff --git a/plugins/tflite_v2-1.0.0/android/gradle.properties b/plugins/tflite_v2-1.0.0/android/gradle.properties new file mode 100644 index 0000000..4167249 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true +android.enableR8=true \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/android/settings.gradle b/plugins/tflite_v2-1.0.0/android/settings.gradle new file mode 100644 index 0000000..cf4f116 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'tflite' diff --git a/plugins/tflite_v2-1.0.0/android/src/main/AndroidManifest.xml b/plugins/tflite_v2-1.0.0/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..332c149 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/plugins/tflite_v2-1.0.0/android/src/main/java/sq/flutter/tflite/TflitePlugin.java b/plugins/tflite_v2-1.0.0/android/src/main/java/sq/flutter/tflite/TflitePlugin.java new file mode 100644 index 0000000..54582c1 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/android/src/main/java/sq/flutter/tflite/TflitePlugin.java @@ -0,0 +1,1622 @@ +package sq.flutter.tflite; + +import android.app.Activity; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.os.SystemClock; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.ScriptIntrinsicYuvToRGB; +import android.renderscript.Type; +import android.util.Log; + +import androidx.annotation.NonNull; + +import io.flutter.FlutterInjector; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.loader.FlutterLoader; +import io.flutter.embedding.engine.plugins.activity.ActivityAware; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.PluginRegistry; + +import org.tensorflow.lite.DataType; +import org.tensorflow.lite.Interpreter; +import org.tensorflow.lite.Tensor; + +import org.tensorflow.lite.gpu.GpuDelegate; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Vector; + + +public class TflitePlugin implements FlutterPlugin, MethodCallHandler, ActivityAware { + private Activity activity; + private Interpreter tfLite; + private boolean tfLiteBusy = false; + private int inputSize = 0; + private Vector labels; + float[][] labelProb; + private static final int BYTES_PER_CHANNEL = 4; + + String[] partNames = { + "nose", "leftEye", "rightEye", "leftEar", "rightEar", "leftShoulder", + "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", + "leftHip", "rightHip", "leftKnee", "rightKnee", "leftAnkle", "rightAnkle" + }; + + String[][] poseChain = { + {"nose", "leftEye"}, {"leftEye", "leftEar"}, {"nose", "rightEye"}, + {"rightEye", "rightEar"}, {"nose", "leftShoulder"}, + {"leftShoulder", "leftElbow"}, {"leftElbow", "leftWrist"}, + {"leftShoulder", "leftHip"}, {"leftHip", "leftKnee"}, + {"leftKnee", "leftAnkle"}, {"nose", "rightShoulder"}, + {"rightShoulder", "rightElbow"}, {"rightElbow", "rightWrist"}, + {"rightShoulder", "rightHip"}, {"rightHip", "rightKnee"}, + {"rightKnee", "rightAnkle"} + }; + + Map partsIds = new HashMap<>(); + List parentToChildEdges = new ArrayList<>(); + List childToParentEdges = new ArrayList<>(); + + private MethodChannel channel; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "tflite"); + channel.setMethodCallHandler(this); + } + + @Override + public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) { + activity = binding.getActivity(); + } + + @Override + public void onDetachedFromActivity() { + activity = null; + } + + @Override + public void onDetachedFromActivityForConfigChanges() { + this.onDetachedFromActivity(); + } + + @Override + public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { + this.onAttachedToActivity(binding); + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + if (call.method.equals("loadModel")) { + try { + String res = loadModel((HashMap) call.arguments); + result.success(res); + } catch (Exception e) { + result.error("Failed to load model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnImage")) { + try { + new RunModelOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnBinary")) { + try { + new RunModelOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnFrame")) { + try { + new RunModelOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnImage")) { + try { + detectObjectOnImage((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnBinary")) { + try { + detectObjectOnBinary((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnFrame")) { + try { + detectObjectOnFrame((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("close")) { + close(); + } else if (call.method.equals("runPix2PixOnImage")) { + try { + new RunPix2PixOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPix2PixOnBinary")) { + try { + new RunPix2PixOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPix2PixOnFrame")) { + try { + new RunPix2PixOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnImage")) { + try { + new RunSegmentationOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnBinary")) { + try { + new RunSegmentationOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnFrame")) { + try { + new RunSegmentationOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnImage")) { + try { + runPoseNetOnImage((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnBinary")) { + try { + runPoseNetOnBinary((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnFrame")) { + try { + runPoseNetOnFrame((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else { + result.error("Invalid method", call.method.toString(), ""); + } + } + + private String loadModel(HashMap args) throws IOException { + String model = args.get("model").toString(); + Object isAssetObj = args.get("isAsset"); + boolean isAsset = isAssetObj == null ? false : (boolean) isAssetObj; + MappedByteBuffer buffer = null; + String key = null; + AssetManager assetManager = null; + if (isAsset) { + assetManager = activity.getApplicationContext().getAssets(); + FlutterLoader loader = FlutterInjector.instance().flutterLoader(); + key = loader.getLookupKeyForAsset(model); + AssetFileDescriptor fileDescriptor = assetManager.openFd(key); + FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); + FileChannel fileChannel = inputStream.getChannel(); + long startOffset = fileDescriptor.getStartOffset(); + long declaredLength = fileDescriptor.getDeclaredLength(); + buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); + } else { + FileInputStream inputStream = new FileInputStream(new File(model)); + FileChannel fileChannel = inputStream.getChannel(); + long declaredLength = fileChannel.size(); + buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, declaredLength); + } + + int numThreads = (int) args.get("numThreads"); + Boolean useGpuDelegate = (Boolean) args.get("useGpuDelegate"); + if (useGpuDelegate == null) { + useGpuDelegate = false; + } + + final Interpreter.Options tfliteOptions = new Interpreter.Options(); + tfliteOptions.setNumThreads(numThreads); + if (useGpuDelegate){ + GpuDelegate delegate = new GpuDelegate(); + tfliteOptions.addDelegate(delegate); + } + tfLite = new Interpreter(buffer, tfliteOptions); + + String labels = args.get("labels").toString(); + + if (labels.length() > 0) { + if (isAsset) { + FlutterLoader loader = FlutterInjector.instance().flutterLoader(); + key = loader.getLookupKeyForAsset(labels); + loadLabels(assetManager, key); + } else { + loadLabels(null, labels); + } + } + + return "success"; + } + + private void loadLabels(AssetManager assetManager, String path) { + BufferedReader br; + try { + if (assetManager != null) { + br = new BufferedReader(new InputStreamReader(assetManager.open(path))); + } else { + br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path)))); + } + String line; + labels = new Vector<>(); + while ((line = br.readLine()) != null) { + labels.add(line); + } + labelProb = new float[1][labels.size()]; + br.close(); + } catch (IOException e) { + throw new RuntimeException("Failed to read label file", e); + } + } + + private List> GetTopN(int numResults, float threshold) { + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("confidence"), (float) lhs.get("confidence")); + } + }); + + for (int i = 0; i < labels.size(); ++i) { + float confidence = labelProb[0][i]; + if (confidence > threshold) { + Map res = new HashMap<>(); + res.put("index", i); + res.put("label", labels.size() > i ? labels.get(i) : "unknown"); + res.put("confidence", confidence); + pq.add(res); + } + } + + final ArrayList> recognitions = new ArrayList<>(); + int recognitionsSize = Math.min(pq.size(), numResults); + for (int i = 0; i < recognitionsSize; ++i) { + recognitions.add(pq.poll()); + } + + return recognitions; + } + + Bitmap feedOutput(ByteBuffer imgData, float mean, float std) { + Tensor tensor = tfLite.getOutputTensor(0); + int outputSize = tensor.shape()[1]; + Bitmap bitmapRaw = Bitmap.createBitmap(outputSize, outputSize, Bitmap.Config.ARGB_8888); + + if (tensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < outputSize; ++i) { + for (int j = 0; j < outputSize; ++j) { + int pixelValue = 0xFF << 24; + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF) << 16); + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF) << 8); + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF)); + bitmapRaw.setPixel(j, i, pixelValue); + } + } + } else { + for (int i = 0; i < outputSize; ++i) { + for (int j = 0; j < outputSize; ++j) { + int pixelValue = 0xFF << 24; + pixelValue |= ((imgData.get() & 0xFF) << 16); + pixelValue |= ((imgData.get() & 0xFF) << 8); + pixelValue |= ((imgData.get() & 0xFF)); + bitmapRaw.setPixel(j, i, pixelValue); + } + } + } + return bitmapRaw; + } + + ByteBuffer feedInputTensor(Bitmap bitmapRaw, float mean, float std) throws IOException { + Tensor tensor = tfLite.getInputTensor(0); + int[] shape = tensor.shape(); + inputSize = shape[1]; + int inputChannels = shape[3]; + + int bytePerChannel = tensor.dataType() == DataType.UINT8 ? 1 : BYTES_PER_CHANNEL; + ByteBuffer imgData = ByteBuffer.allocateDirect(1 * inputSize * inputSize * inputChannels * bytePerChannel); + imgData.order(ByteOrder.nativeOrder()); + + Bitmap bitmap = bitmapRaw; + if (bitmapRaw.getWidth() != inputSize || bitmapRaw.getHeight() != inputSize) { + Matrix matrix = getTransformationMatrix(bitmapRaw.getWidth(), bitmapRaw.getHeight(), + inputSize, inputSize, false); + bitmap = Bitmap.createBitmap(inputSize, inputSize, Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(bitmap); + if (inputChannels == 1){ + Paint paint = new Paint(); + ColorMatrix cm = new ColorMatrix(); + cm.setSaturation(0); + ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); + paint.setColorFilter(f); + canvas.drawBitmap(bitmapRaw, matrix, paint); + } else { + canvas.drawBitmap(bitmapRaw, matrix, null); + } + } + + if (tensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < inputSize; ++i) { + for (int j = 0; j < inputSize; ++j) { + int pixelValue = bitmap.getPixel(j, i); + if (inputChannels > 1){ + imgData.putFloat((((pixelValue >> 16) & 0xFF) - mean) / std); + imgData.putFloat((((pixelValue >> 8) & 0xFF) - mean) / std); + imgData.putFloat(((pixelValue & 0xFF) - mean) / std); + } else { + imgData.putFloat((((pixelValue >> 16 | pixelValue >> 8 | pixelValue) & 0xFF) - mean) / std); + } + } + } + } else { + for (int i = 0; i < inputSize; ++i) { + for (int j = 0; j < inputSize; ++j) { + int pixelValue = bitmap.getPixel(j, i); + if (inputChannels > 1){ + imgData.put((byte) ((pixelValue >> 16) & 0xFF)); + imgData.put((byte) ((pixelValue >> 8) & 0xFF)); + imgData.put((byte) (pixelValue & 0xFF)); + } else { + imgData.put((byte) ((pixelValue >> 16 | pixelValue >> 8 | pixelValue) & 0xFF)); + } + } + } + } + + return imgData; + } + + ByteBuffer feedInputTensorImage(String path, float mean, float std) throws IOException { + InputStream inputStream = new FileInputStream(path.replace("file://", "")); + Bitmap bitmapRaw = BitmapFactory.decodeStream(inputStream); + + return feedInputTensor(bitmapRaw, mean, std); + } + + ByteBuffer feedInputTensorFrame(List bytesList, int imageHeight, int imageWidth, float mean, float std, int rotation) throws IOException { + ByteBuffer Y = ByteBuffer.wrap(bytesList.get(0)); + ByteBuffer U = ByteBuffer.wrap(bytesList.get(1)); + ByteBuffer V = ByteBuffer.wrap(bytesList.get(2)); + + int Yb = Y.remaining(); + int Ub = U.remaining(); + int Vb = V.remaining(); + + byte[] data = new byte[Yb + Ub + Vb]; + + Y.get(data, 0, Yb); + V.get(data, Yb, Vb); + U.get(data, Yb + Vb, Ub); + + Bitmap bitmapRaw = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888); + Allocation bmData = renderScriptNV21ToRGBA888( + activity.getApplicationContext(), + imageWidth, + imageHeight, + data); + bmData.copyTo(bitmapRaw); + + Matrix matrix = new Matrix(); + matrix.postRotate(rotation); + bitmapRaw = Bitmap.createBitmap(bitmapRaw, 0, 0, bitmapRaw.getWidth(), bitmapRaw.getHeight(), matrix, true); + + return feedInputTensor(bitmapRaw, mean, std); + } + + public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) { + // https://stackoverflow.com/a/36409748 + RenderScript rs = RenderScript.create(context); + ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs)); + + Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length); + Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT); + + Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height); + Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT); + + in.copyFrom(nv21); + + yuvToRgbIntrinsic.setInput(in); + yuvToRgbIntrinsic.forEach(out); + return out; + } + + private abstract class TfliteTask extends AsyncTask { + Result result; + boolean asynch; + + TfliteTask(HashMap args, Result result) { + if (tfLiteBusy) throw new RuntimeException("Interpreter busy"); + else tfLiteBusy = true; + Object asynch = args.get("asynch"); + this.asynch = asynch == null ? false : (boolean) asynch; + this.result = result; + } + + abstract void runTflite(); + + abstract void onRunTfliteDone(); + + public void executeTfliteTask() { + if (asynch) execute(); + else { + runTflite(); + tfLiteBusy = false; + onRunTfliteDone(); + } + } + + protected Void doInBackground(Void... backgroundArguments) { + runTflite(); + return null; + } + + protected void onPostExecute(Void backgroundResult) { + tfLiteBusy = false; + onRunTfliteDone(); + } + } + + private class RunModelOnImage extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + ByteBuffer input; + long startTime; + + RunModelOnImage(HashMap args, Result result) throws IOException { + super(args, result); + + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + } + + protected void runTflite() { + tfLite.run(input, labelProb); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + private class RunModelOnBinary extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + ByteBuffer imgData; + + RunModelOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + + byte[] binary = (byte[]) args.get("binary"); + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + imgData = ByteBuffer.wrap(binary); + } + + protected void runTflite() { + tfLite.run(imgData, labelProb); + } + + protected void onRunTfliteDone() { + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + private class RunModelOnFrame extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + long startTime; + ByteBuffer imgData; + + RunModelOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + startTime = SystemClock.uptimeMillis(); + + imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + } + + protected void runTflite() { + tfLite.run(imgData, labelProb); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + void detectObjectOnImage(HashMap args, Result result) throws IOException { + String path = args.get("path").toString(); + String model = args.get("model").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + ByteBuffer imgData = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + void detectObjectOnBinary(HashMap args, Result result) throws IOException { + byte[] binary = (byte[]) args.get("binary"); + String model = args.get("model").toString(); + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + ByteBuffer imgData = ByteBuffer.wrap(binary); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + void detectObjectOnFrame(HashMap args, Result result) throws IOException { + List bytesList = (ArrayList) args.get("bytesList"); + String model = args.get("model").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + + ByteBuffer imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + private class RunSSDMobileNet extends TfliteTask { + int num; + int numResultsPerClass; + float threshold; + float[][][] outputLocations; + float[][] outputClasses; + float[][] outputScores; + float[] numDetections = new float[1]; + Object[] inputArray; + Map outputMap = new HashMap<>(); + long startTime; + + RunSSDMobileNet(HashMap args, ByteBuffer imgData, int numResultsPerClass, float threshold, Result result) { + super(args, result); + this.num = tfLite.getOutputTensor(0).shape()[1]; + this.numResultsPerClass = numResultsPerClass; + this.threshold = threshold; + this.outputLocations = new float[1][num][4]; + this.outputClasses = new float[1][num]; + this.outputScores = new float[1][num]; + this.inputArray = new Object[]{imgData}; + + outputMap.put(0, outputLocations); + outputMap.put(1, outputClasses); + outputMap.put(2, outputScores); + outputMap.put(3, numDetections); + + startTime = SystemClock.uptimeMillis(); + } + + protected void runTflite() { + tfLite.runForMultipleInputsOutputs(inputArray, outputMap); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + Map counters = new HashMap<>(); + final List> results = new ArrayList<>(); + + for (int i = 0; i < numDetections[0]; ++i) { + if (outputScores[0][i] < threshold) continue; + + String detectedClass = labels.get((int) outputClasses[0][i] + 1); + + if (counters.get(detectedClass) == null) { + counters.put(detectedClass, 1); + } else { + int count = counters.get(detectedClass); + if (count >= numResultsPerClass) { + continue; + } else { + counters.put(detectedClass, count + 1); + } + } + + Map rect = new HashMap<>(); + float ymin = Math.max(0, outputLocations[0][i][0]); + float xmin = Math.max(0, outputLocations[0][i][1]); + float ymax = outputLocations[0][i][2]; + float xmax = outputLocations[0][i][3]; + rect.put("x", xmin); + rect.put("y", ymin); + rect.put("w", Math.min(1 - xmin, xmax - xmin)); + rect.put("h", Math.min(1 - ymin, ymax - ymin)); + + Map ret = new HashMap<>(); + ret.put("rect", rect); + ret.put("confidenceInClass", outputScores[0][i]); + ret.put("detectedClass", detectedClass); + + results.add(ret); + } + + result.success(results); + } + } + + private class RunYOLO extends TfliteTask { + ByteBuffer imgData; + int blockSize; + int numBoxesPerBlock; + List anchors; + float threshold; + int numResultsPerClass; + long startTime; + int gridSize; + int numClasses; + final float[][][][] output; + + RunYOLO(HashMap args, + ByteBuffer imgData, + int blockSize, + int numBoxesPerBlock, + List anchors, + float threshold, + int numResultsPerClass, + Result result) { + super(args, result); + this.imgData = imgData; + this.blockSize = blockSize; + this.numBoxesPerBlock = numBoxesPerBlock; + this.anchors = anchors; + this.threshold = threshold; + this.numResultsPerClass = numResultsPerClass; + this.startTime = SystemClock.uptimeMillis(); + + Tensor tensor = tfLite.getInputTensor(0); + inputSize = tensor.shape()[1]; + + this.gridSize = inputSize / blockSize; + this.numClasses = labels.size(); + this.output = new float[1][gridSize][gridSize][(numClasses + 5) * numBoxesPerBlock]; + } + + protected void runTflite() { + tfLite.run(imgData, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("confidenceInClass"), (float) lhs.get("confidenceInClass")); + } + }); + + for (int y = 0; y < gridSize; ++y) { + for (int x = 0; x < gridSize; ++x) { + for (int b = 0; b < numBoxesPerBlock; ++b) { + final int offset = (numClasses + 5) * b; + + final float confidence = sigmoid(output[0][y][x][offset + 4]); + + final float[] classes = new float[numClasses]; + for (int c = 0; c < numClasses; ++c) { + classes[c] = output[0][y][x][offset + 5 + c]; + } + softmax(classes); + + int detectedClass = -1; + float maxClass = 0; + for (int c = 0; c < numClasses; ++c) { + if (classes[c] > maxClass) { + detectedClass = c; + maxClass = classes[c]; + } + } + + final float confidenceInClass = maxClass * confidence; + if (confidenceInClass > threshold) { + final float xPos = (x + sigmoid(output[0][y][x][offset + 0])) * blockSize; + final float yPos = (y + sigmoid(output[0][y][x][offset + 1])) * blockSize; + + final float w = (float) (Math.exp(output[0][y][x][offset + 2]) * anchors.get(2 * b + 0)) * blockSize; + final float h = (float) (Math.exp(output[0][y][x][offset + 3]) * anchors.get(2 * b + 1)) * blockSize; + + final float xmin = Math.max(0, (xPos - w / 2) / inputSize); + final float ymin = Math.max(0, (yPos - h / 2) / inputSize); + + Map rect = new HashMap<>(); + rect.put("x", xmin); + rect.put("y", ymin); + rect.put("w", Math.min(1 - xmin, w / inputSize)); + rect.put("h", Math.min(1 - ymin, h / inputSize)); + + Map ret = new HashMap<>(); + ret.put("rect", rect); + ret.put("confidenceInClass", confidenceInClass); + ret.put("detectedClass", labels.get(detectedClass)); + + pq.add(ret); + } + } + } + } + + Map counters = new HashMap<>(); + List> results = new ArrayList<>(); + + for (int i = 0; i < pq.size(); ++i) { + Map ret = pq.poll(); + String detectedClass = ret.get("detectedClass").toString(); + + if (counters.get(detectedClass) == null) { + counters.put(detectedClass, 1); + } else { + int count = counters.get(detectedClass); + if (count >= numResultsPerClass) { + continue; + } else { + counters.put(detectedClass, count + 1); + } + } + results.add(ret); + } + result.success(results); + } + } + + private class RunPix2PixOnImage extends TfliteTask { + String path, outputType; + float IMAGE_MEAN, IMAGE_STD; + long startTime; + ByteBuffer input, output; + + RunPix2PixOnImage(HashMap args, Result result) throws IOException { + super(args, result); + path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + IMAGE_STD = (float) std; + + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + Bitmap bitmapRaw = feedOutput(output, IMAGE_MEAN, IMAGE_STD); + + if (outputType.equals("png")) { + result.success(compressPNG(bitmapRaw)); + } else { + result.success(bitmapRaw); + } + } + } + + private class RunPix2PixOnBinary extends TfliteTask { + long startTime; + String outputType; + ByteBuffer input, output; + + RunPix2PixOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + byte[] binary = (byte[]) args.get("binary"); + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = ByteBuffer.wrap(binary); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + result.success(output.array()); + } + } + + private class RunPix2PixOnFrame extends TfliteTask { + long startTime; + String outputType; + float IMAGE_MEAN, IMAGE_STD; + ByteBuffer input, output; + + RunPix2PixOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + Bitmap bitmapRaw = feedOutput(output, IMAGE_MEAN, IMAGE_STD); + + if (outputType.equals("png")) { + result.success(compressPNG(bitmapRaw)); + } else { + result.success(bitmapRaw); + } + } + } + + private class RunSegmentationOnImage extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnImage(HashMap args, Result result) throws IOException { + super(args, result); + + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + private class RunSegmentationOnBinary extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + + byte[] binary = (byte[]) args.get("binary"); + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = ByteBuffer.wrap(binary); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + private class RunSegmentationOnFrame extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + + byte[] fetchArgmax(ByteBuffer output, List labelColors, String outputType) { + Tensor outputTensor = tfLite.getOutputTensor(0); + int outputBatchSize = outputTensor.shape()[0]; + assert outputBatchSize == 1; + int outputHeight = outputTensor.shape()[1]; + int outputWidth = outputTensor.shape()[2]; + int outputChannels = outputTensor.shape()[3]; + + Bitmap outputArgmax = null; + byte[] outputBytes = new byte[outputWidth * outputHeight * 4]; + if (outputType.equals("png")) { + outputArgmax = Bitmap.createBitmap(outputWidth, outputHeight, Bitmap.Config.ARGB_8888); + } + + if (outputTensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < outputHeight; ++i) { + for (int j = 0; j < outputWidth; ++j) { + int maxIndex = 0; + float maxValue = 0.0f; + for (int c = 0; c < outputChannels; ++c) { + float outputValue = output.getFloat(); + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + int labelColor = labelColors.get(maxIndex).intValue(); + if (outputType.equals("png")) { + outputArgmax.setPixel(j, i, labelColor); + } else { + setPixel(outputBytes, i * outputWidth + j, labelColor); + } + } + } + } else { + for (int i = 0; i < outputHeight; ++i) { + for (int j = 0; j < outputWidth; ++j) { + int maxIndex = 0; + int maxValue = 0; + for (int c = 0; c < outputChannels; ++c) { + int outputValue = output.get(); + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + int labelColor = labelColors.get(maxIndex).intValue(); + if (outputType.equals("png")) { + outputArgmax.setPixel(j, i, labelColor); + } else { + setPixel(outputBytes, i * outputWidth + j, labelColor); + } + } + } + } + if (outputType.equals("png")) { + return compressPNG(outputArgmax); + } else { + return outputBytes; + } + } + + void setPixel(byte[] rgba, int index, long color) { + rgba[index * 4] = (byte) ((color >> 16) & 0xFF); + rgba[index * 4 + 1] = (byte) ((color >> 8) & 0xFF); + rgba[index * 4 + 2] = (byte) (color & 0xFF); + rgba[index * 4 + 3] = (byte) ((color >> 24) & 0xFF); + } + + byte[] compressPNG(Bitmap bitmap) { + // https://stackoverflow.com/questions/4989182/converting-java-bitmap-to-byte-array#4989543 + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); + byte[] byteArray = stream.toByteArray(); + // bitmap.recycle(); + return byteArray; + } + + void runPoseNetOnImage(HashMap args, Result result) throws IOException { + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void runPoseNetOnBinary(HashMap args, Result result) throws IOException { + byte[] binary = (byte[]) args.get("binary"); + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = ByteBuffer.wrap(binary); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void runPoseNetOnFrame(HashMap args, Result result) throws IOException { + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void initPoseNet(Map outputMap) { + if (partsIds.size() == 0) { + for (int i = 0; i < partNames.length; ++i) + partsIds.put(partNames[i], i); + + for (int i = 0; i < poseChain.length; ++i) { + parentToChildEdges.add(partsIds.get(poseChain[i][1])); + childToParentEdges.add(partsIds.get(poseChain[i][0])); + } + } + + for (int i = 0; i < tfLite.getOutputTensorCount(); i++) { + int[] shape = tfLite.getOutputTensor(i).shape(); + float[][][][] output = new float[shape[0]][shape[1]][shape[2]][shape[3]]; + outputMap.put(i, output); + } + } + + private class RunPoseNet extends TfliteTask { + long startTime; + Object[] input; + Map outputMap = new HashMap<>(); + int numResults; + double threshold; + int nmsRadius; + + int localMaximumRadius = 1; + int outputStride = 16; + + RunPoseNet(HashMap args, + ByteBuffer imgData, + int numResults, + double threshold, + int nmsRadius, + Result result) throws IOException { + super(args, result); + this.numResults = numResults; + this.threshold = threshold; + this.nmsRadius = nmsRadius; + + input = new Object[]{imgData}; + initPoseNet(outputMap); + + startTime = SystemClock.uptimeMillis(); + } + + protected void runTflite() { + tfLite.runForMultipleInputsOutputs(input, outputMap); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + float[][][] scores = ((float[][][][]) outputMap.get(0))[0]; + float[][][] offsets = ((float[][][][]) outputMap.get(1))[0]; + float[][][] displacementsFwd = ((float[][][][]) outputMap.get(2))[0]; + float[][][] displacementsBwd = ((float[][][][]) outputMap.get(3))[0]; + + PriorityQueue> pq = buildPartWithScoreQueue(scores, threshold, localMaximumRadius); + + int numParts = scores[0][0].length; + int numEdges = parentToChildEdges.size(); + int sqaredNmsRadius = nmsRadius * nmsRadius; + + List> results = new ArrayList<>(); + + while (results.size() < numResults && pq.size() > 0) { + Map root = pq.poll(); + float[] rootPoint = getImageCoords(root, outputStride, numParts, offsets); + + if (withinNmsRadiusOfCorrespondingPoint( + results, sqaredNmsRadius, rootPoint[0], rootPoint[1], (int) root.get("partId"))) + continue; + + Map keypoint = new HashMap<>(); + keypoint.put("score", root.get("score")); + keypoint.put("part", partNames[(int) root.get("partId")]); + keypoint.put("y", rootPoint[0] / inputSize); + keypoint.put("x", rootPoint[1] / inputSize); + + Map> keypoints = new HashMap<>(); + keypoints.put((int) root.get("partId"), keypoint); + + for (int edge = numEdges - 1; edge >= 0; --edge) { + int sourceKeypointId = parentToChildEdges.get(edge); + int targetKeypointId = childToParentEdges.get(edge); + if (keypoints.containsKey(sourceKeypointId) && !keypoints.containsKey(targetKeypointId)) { + keypoint = traverseToTargetKeypoint(edge, keypoints.get(sourceKeypointId), + targetKeypointId, scores, offsets, outputStride, displacementsBwd); + keypoints.put(targetKeypointId, keypoint); + } + } + + for (int edge = 0; edge < numEdges; ++edge) { + int sourceKeypointId = childToParentEdges.get(edge); + int targetKeypointId = parentToChildEdges.get(edge); + if (keypoints.containsKey(sourceKeypointId) && !keypoints.containsKey(targetKeypointId)) { + keypoint = traverseToTargetKeypoint(edge, keypoints.get(sourceKeypointId), + targetKeypointId, scores, offsets, outputStride, displacementsFwd); + keypoints.put(targetKeypointId, keypoint); + } + } + + Map result = new HashMap<>(); + result.put("keypoints", keypoints); + result.put("score", getInstanceScore(keypoints, numParts)); + results.add(result); + } + + result.success(results); + } + } + + PriorityQueue> buildPartWithScoreQueue(float[][][] scores, + double threshold, + int localMaximumRadius) { + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("score"), (float) lhs.get("score")); + } + }); + + for (int heatmapY = 0; heatmapY < scores.length; ++heatmapY) { + for (int heatmapX = 0; heatmapX < scores[0].length; ++heatmapX) { + for (int keypointId = 0; keypointId < scores[0][0].length; ++keypointId) { + float score = sigmoid(scores[heatmapY][heatmapX][keypointId]); + if (score < threshold) continue; + + if (scoreIsMaximumInLocalWindow( + keypointId, score, heatmapY, heatmapX, localMaximumRadius, scores)) { + Map res = new HashMap<>(); + res.put("score", score); + res.put("y", heatmapY); + res.put("x", heatmapX); + res.put("partId", keypointId); + pq.add(res); + } + } + } + } + + return pq; + } + + boolean scoreIsMaximumInLocalWindow(int keypointId, + float score, + int heatmapY, + int heatmapX, + int localMaximumRadius, + float[][][] scores) { + boolean localMaximum = true; + int height = scores.length; + int width = scores[0].length; + + int yStart = Math.max(heatmapY - localMaximumRadius, 0); + int yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); + for (int yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { + int xStart = Math.max(heatmapX - localMaximumRadius, 0); + int xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); + for (int xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { + if (sigmoid(scores[yCurrent][xCurrent][keypointId]) > score) { + localMaximum = false; + break; + } + } + if (!localMaximum) { + break; + } + } + + return localMaximum; + } + + float[] getImageCoords(Map keypoint, + int outputStride, + int numParts, + float[][][] offsets) { + int heatmapY = (int) keypoint.get("y"); + int heatmapX = (int) keypoint.get("x"); + int keypointId = (int) keypoint.get("partId"); + float offsetY = offsets[heatmapY][heatmapX][keypointId]; + float offsetX = offsets[heatmapY][heatmapX][keypointId + numParts]; + + float y = heatmapY * outputStride + offsetY; + float x = heatmapX * outputStride + offsetX; + + return new float[]{y, x}; + } + + boolean withinNmsRadiusOfCorrespondingPoint(List> poses, + float squaredNmsRadius, + float y, + float x, + int keypointId) { + for (Map pose : poses) { + Map keypoints = (Map) pose.get("keypoints"); + Map correspondingKeypoint = (Map) keypoints.get(keypointId); + float _x = (float) correspondingKeypoint.get("x") * inputSize - x; + float _y = (float) correspondingKeypoint.get("y") * inputSize - y; + float squaredDistance = _x * _x + _y * _y; + if (squaredDistance <= squaredNmsRadius) + return true; + } + + return false; + } + + Map traverseToTargetKeypoint(int edgeId, + Map sourceKeypoint, + int targetKeypointId, + float[][][] scores, + float[][][] offsets, + int outputStride, + float[][][] displacements) { + int height = scores.length; + int width = scores[0].length; + int numKeypoints = scores[0][0].length; + float sourceKeypointY = (float) sourceKeypoint.get("y") * inputSize; + float sourceKeypointX = (float) sourceKeypoint.get("x") * inputSize; + + int[] sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypointY, sourceKeypointX, + outputStride, height, width); + + float[] displacement = getDisplacement(edgeId, sourceKeypointIndices, displacements); + + float[] displacedPoint = new float[]{ + sourceKeypointY + displacement[0], + sourceKeypointX + displacement[1] + }; + + float[] targetKeypoint = displacedPoint; + + final int offsetRefineStep = 2; + for (int i = 0; i < offsetRefineStep; i++) { + int[] targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint[0], targetKeypoint[1], + outputStride, height, width); + + int targetKeypointY = targetKeypointIndices[0]; + int targetKeypointX = targetKeypointIndices[1]; + + float offsetY = offsets[targetKeypointY][targetKeypointX][targetKeypointId]; + float offsetX = offsets[targetKeypointY][targetKeypointX][targetKeypointId + numKeypoints]; + + targetKeypoint = new float[]{ + targetKeypointY * outputStride + offsetY, + targetKeypointX * outputStride + offsetX + }; + } + + int[] targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint[0], targetKeypoint[1], + outputStride, height, width); + + float score = sigmoid(scores[targetKeypointIndices[0]][targetKeypointIndices[1]][targetKeypointId]); + + Map keypoint = new HashMap<>(); + keypoint.put("score", score); + keypoint.put("part", partNames[targetKeypointId]); + keypoint.put("y", targetKeypoint[0] / inputSize); + keypoint.put("x", targetKeypoint[1] / inputSize); + + return keypoint; + } + + int[] getStridedIndexNearPoint(float _y, float _x, int outputStride, int height, int width) { + int y_ = Math.round(_y / outputStride); + int x_ = Math.round(_x / outputStride); + int y = y_ < 0 ? 0 : y_ > height - 1 ? height - 1 : y_; + int x = x_ < 0 ? 0 : x_ > width - 1 ? width - 1 : x_; + return new int[]{y, x}; + } + + float[] getDisplacement(int edgeId, int[] keypoint, float[][][] displacements) { + int numEdges = displacements[0][0].length / 2; + int y = keypoint[0]; + int x = keypoint[1]; + return new float[]{displacements[y][x][edgeId], displacements[y][x][edgeId + numEdges]}; + } + + float getInstanceScore(Map> keypoints, int numKeypoints) { + float scores = 0; + for (Map.Entry> keypoint : keypoints.entrySet()) + scores += (float) keypoint.getValue().get("score"); + return scores / numKeypoints; + } + + private float sigmoid(final float x) { + return (float) (1. / (1. + Math.exp(-x))); + } + + private void softmax(final float[] vals) { + float max = Float.NEGATIVE_INFINITY; + for (final float val : vals) { + max = Math.max(max, val); + } + float sum = 0.0f; + for (int i = 0; i < vals.length; ++i) { + vals[i] = (float) Math.exp(vals[i] - max); + sum += vals[i]; + } + for (int i = 0; i < vals.length; ++i) { + vals[i] = vals[i] / sum; + } + } + + private static Matrix getTransformationMatrix(final int srcWidth, + final int srcHeight, + final int dstWidth, + final int dstHeight, + final boolean maintainAspectRatio) { + final Matrix matrix = new Matrix(); + + if (srcWidth != dstWidth || srcHeight != dstHeight) { + final float scaleFactorX = dstWidth / (float) srcWidth; + final float scaleFactorY = dstHeight / (float) srcHeight; + + if (maintainAspectRatio) { + final float scaleFactor = Math.max(scaleFactorX, scaleFactorY); + matrix.postScale(scaleFactor, scaleFactor); + } else { + matrix.postScale(scaleFactorX, scaleFactorY); + } + } + + matrix.invert(new Matrix()); + return matrix; + } + + private void close() { + if (tfLite != null) + tfLite.close(); + labels = null; + labelProb = null; + } +} diff --git a/plugins/tflite_v2-1.0.0/example/README.md b/plugins/tflite_v2-1.0.0/example/README.md new file mode 100644 index 0000000..849606f --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/README.md @@ -0,0 +1,35 @@ +# tflite_example + +Use tflite plugin to run model on images. The image is captured by camera or selected from gallery (with the help of [image_picker](https://pub.dartlang.org/packages/image_picker) plugin). + +![](yolo.jpg) + +## Prerequisites + +Create a `assets` folder. From https://github.com/shaqian/flutter_tflite/tree/master/example/assets +dowload the following files and place them in `assets` folder. + - mobilenet_v1_1.0_224.tflite + - mobilenet_v1_1.0_224.txt + - ssd_mobilenet.tflite + - ssd_mobilenet.txt + - yolov2_tiny.tflite + - yolov2_tiny.txt + - deeplabv3_257_mv_gpu.tflite + - deeplabv3_257_mv_gpu.txt + - posenet_mv1_075_float_from_checkpoints.tflite + +## Install + +``` +flutter packages get +``` + +## Run + +``` +flutter run +``` + +## Caveat + +```recognizeImageBinary(image)``` (sample code for ```runModelOnBinary```) is slow on iOS when decoding image due to a [known issue](https://github.com/brendan-duncan/image/issues/55) with image package. diff --git a/plugins/tflite_v2-1.0.0/example/android/app/build.gradle b/plugins/tflite_v2-1.0.0/example/android/app/build.gradle new file mode 100644 index 0000000..a627ccf --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/app/build.gradle @@ -0,0 +1,65 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion 28 + + lintOptions { + disable 'InvalidPackage' + } + + aaptOptions { + noCompress 'tflite' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "sq.flutter.tfliteexample" + minSdkVersion 19 + targetSdkVersion 28 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' +} diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/AndroidManifest.xml b/plugins/tflite_v2-1.0.0/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..aa3336f --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java b/plugins/tflite_v2-1.0.0/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java new file mode 100644 index 0000000..968a340 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java @@ -0,0 +1,13 @@ +package sq.flutter.tfliteexample; + +import android.os.Bundle; +import io.flutter.app.FlutterActivity; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class MainActivity extends FlutterActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } +} diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/drawable/launch_background.xml b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000..304732f --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..db77bb4 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..17987b7 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..09d4391 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..d5f1c8d Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..4d6372e Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/values/styles.xml b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..00fa441 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + diff --git a/plugins/tflite_v2-1.0.0/example/android/build.gradle b/plugins/tflite_v2-1.0.0/example/android/build.gradle new file mode 100644 index 0000000..83f114c --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/build.gradle @@ -0,0 +1,29 @@ +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.6.1' + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/plugins/tflite_v2-1.0.0/example/android/gradle.properties b/plugins/tflite_v2-1.0.0/example/android/gradle.properties new file mode 100644 index 0000000..29bf260 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.jvmargs=-Xmx1536M +target-platform=android-arm64 +android.useAndroidX=true +android.enableJetifier=true diff --git a/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.jar b/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.properties b/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..46510f3 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Mar 28 00:33:22 ICT 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/plugins/tflite_v2-1.0.0/example/android/gradlew b/plugins/tflite_v2-1.0.0/example/android/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/plugins/tflite_v2-1.0.0/example/android/gradlew.bat b/plugins/tflite_v2-1.0.0/example/android/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/plugins/tflite_v2-1.0.0/example/android/settings.gradle b/plugins/tflite_v2-1.0.0/example/android/settings.gradle new file mode 100644 index 0000000..5a2f14f --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/settings.gradle @@ -0,0 +1,15 @@ +include ':app' + +def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + +def plugins = new Properties() +def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') +if (pluginsFile.exists()) { + pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } +} + +plugins.each { name, path -> + def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() + include ":$name" + project(":$name").projectDir = pluginDirectory +} diff --git a/plugins/tflite_v2-1.0.0/example/android/settings_aar.gradle b/plugins/tflite_v2-1.0.0/example/android/settings_aar.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/android/settings_aar.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.tflite b/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.tflite new file mode 100644 index 0000000..d2d9a9b Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.tflite differ diff --git a/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.txt b/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.txt new file mode 100644 index 0000000..ecfffa3 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/assets/deeplabv3_257_mv_gpu.txt @@ -0,0 +1,21 @@ +background +aeroplane +biyclce +bird +boat +bottle +bus +car +cat +chair +cow +diningtable +dog +horse +motorbike +person +potted plant +sheep +sofa +train +tv-monitor diff --git a/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.tflite b/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.tflite new file mode 100644 index 0000000..d34691e Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.tflite differ diff --git a/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.txt b/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.txt new file mode 100644 index 0000000..fe81123 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/assets/mobilenet_v1_1.0_224.txt @@ -0,0 +1,1001 @@ +background +tench +goldfish +great white shark +tiger shark +hammerhead +electric ray +stingray +cock +hen +ostrich +brambling +goldfinch +house finch +junco +indigo bunting +robin +bulbul +jay +magpie +chickadee +water ouzel +kite +bald eagle +vulture +great grey owl +European fire salamander +common newt +eft +spotted salamander +axolotl +bullfrog +tree frog +tailed frog +loggerhead +leatherback turtle +mud turtle +terrapin +box turtle +banded gecko +common iguana +American chameleon +whiptail +agama +frilled lizard +alligator lizard +Gila monster +green lizard +African chameleon +Komodo dragon +African crocodile +American alligator +triceratops +thunder snake +ringneck snake +hognose snake +green snake +king snake +garter snake +water snake +vine snake +night snake +boa constrictor +rock python +Indian cobra +green mamba +sea snake +horned viper +diamondback +sidewinder +trilobite +harvestman +scorpion +black and gold garden spider +barn spider +garden spider +black widow +tarantula +wolf spider +tick +centipede +black grouse +ptarmigan +ruffed grouse +prairie chicken +peacock +quail +partridge +African grey +macaw +sulphur-crested cockatoo +lorikeet +coucal +bee eater +hornbill +hummingbird +jacamar +toucan +drake +red-breasted merganser +goose +black swan +tusker +echidna +platypus +wallaby +koala +wombat +jellyfish +sea anemone +brain coral +flatworm +nematode +conch +snail +slug +sea slug +chiton +chambered nautilus +Dungeness crab +rock crab +fiddler crab +king crab +American lobster +spiny lobster +crayfish +hermit crab +isopod +white stork +black stork +spoonbill +flamingo +little blue heron +American egret +bittern +crane +limpkin +European gallinule +American coot +bustard +ruddy turnstone +red-backed sandpiper +redshank +dowitcher +oystercatcher +pelican +king penguin +albatross +grey whale +killer whale +dugong +sea lion +Chihuahua +Japanese spaniel +Maltese dog +Pekinese +Shih-Tzu +Blenheim spaniel +papillon +toy terrier +Rhodesian ridgeback +Afghan hound +basset +beagle +bloodhound +bluetick +black-and-tan coonhound +Walker hound +English foxhound +redbone +borzoi +Irish wolfhound +Italian greyhound +whippet +Ibizan hound +Norwegian elkhound +otterhound +Saluki +Scottish deerhound +Weimaraner +Staffordshire bullterrier +American Staffordshire terrier +Bedlington terrier +Border terrier +Kerry blue terrier +Irish terrier +Norfolk terrier +Norwich terrier +Yorkshire terrier +wire-haired fox terrier +Lakeland terrier +Sealyham terrier +Airedale +cairn +Australian terrier +Dandie Dinmont +Boston bull +miniature schnauzer +giant schnauzer +standard schnauzer +Scotch terrier +Tibetan terrier +silky terrier +soft-coated wheaten terrier +West Highland white terrier +Lhasa +flat-coated retriever +curly-coated retriever +golden retriever +Labrador retriever +Chesapeake Bay retriever +German short-haired pointer +vizsla +English setter +Irish setter +Gordon setter +Brittany spaniel +clumber +English springer +Welsh springer spaniel +cocker spaniel +Sussex spaniel +Irish water spaniel +kuvasz +schipperke +groenendael +malinois +briard +kelpie +komondor +Old English sheepdog +Shetland sheepdog +collie +Border collie +Bouvier des Flandres +Rottweiler +German shepherd +Doberman +miniature pinscher +Greater Swiss Mountain dog +Bernese mountain dog +Appenzeller +EntleBucher +boxer +bull mastiff +Tibetan mastiff +French bulldog +Great Dane +Saint Bernard +Eskimo dog +malamute +Siberian husky +dalmatian +affenpinscher +basenji +pug +Leonberg +Newfoundland +Great Pyrenees +Samoyed +Pomeranian +chow +keeshond +Brabancon griffon +Pembroke +Cardigan +toy poodle +miniature poodle +standard poodle +Mexican hairless +timber wolf +white wolf +red wolf +coyote +dingo +dhole +African hunting dog +hyena +red fox +kit fox +Arctic fox +grey fox +tabby +tiger cat +Persian cat +Siamese cat +Egyptian cat +cougar +lynx +leopard +snow leopard +jaguar +lion +tiger +cheetah +brown bear +American black bear +ice bear +sloth bear +mongoose +meerkat +tiger beetle +ladybug +ground beetle +long-horned beetle +leaf beetle +dung beetle +rhinoceros beetle +weevil +fly +bee +ant +grasshopper +cricket +walking stick +cockroach +mantis +cicada +leafhopper +lacewing +dragonfly +damselfly +admiral +ringlet +monarch +cabbage butterfly +sulphur butterfly +lycaenid +starfish +sea urchin +sea cucumber +wood rabbit +hare +Angora +hamster +porcupine +fox squirrel +marmot +beaver +guinea pig +sorrel +zebra +hog +wild boar +warthog +hippopotamus +ox +water buffalo +bison +ram +bighorn +ibex +hartebeest +impala +gazelle +Arabian camel +llama +weasel +mink +polecat +black-footed ferret +otter +skunk +badger +armadillo +three-toed sloth +orangutan +gorilla +chimpanzee +gibbon +siamang +guenon +patas +baboon +macaque +langur +colobus +proboscis monkey +marmoset +capuchin +howler monkey +titi +spider monkey +squirrel monkey +Madagascar cat +indri +Indian elephant +African elephant +lesser panda +giant panda +barracouta +eel +coho +rock beauty +anemone fish +sturgeon +gar +lionfish +puffer +abacus +abaya +academic gown +accordion +acoustic guitar +aircraft carrier +airliner +airship +altar +ambulance +amphibian +analog clock +apiary +apron +ashcan +assault rifle +backpack +bakery +balance beam +balloon +ballpoint +Band Aid +banjo +bannister +barbell +barber chair +barbershop +barn +barometer +barrel +barrow +baseball +basketball +bassinet +bassoon +bathing cap +bath towel +bathtub +beach wagon +beacon +beaker +bearskin +beer bottle +beer glass +bell cote +bib +bicycle-built-for-two +bikini +binder +binoculars +birdhouse +boathouse +bobsled +bolo tie +bonnet +bookcase +bookshop +bottlecap +bow +bow tie +brass +brassiere +breakwater +breastplate +broom +bucket +buckle +bulletproof vest +bullet train +butcher shop +cab +caldron +candle +cannon +canoe +can opener +cardigan +car mirror +carousel +carpenter's kit +carton +car wheel +cash machine +cassette +cassette player +castle +catamaran +CD player +cello +cellular telephone +chain +chainlink fence +chain mail +chain saw +chest +chiffonier +chime +china cabinet +Christmas stocking +church +cinema +cleaver +cliff dwelling +cloak +clog +cocktail shaker +coffee mug +coffeepot +coil +combination lock +computer keyboard +confectionery +container ship +convertible +corkscrew +cornet +cowboy boot +cowboy hat +cradle +crane +crash helmet +crate +crib +Crock Pot +croquet ball +crutch +cuirass +dam +desk +desktop computer +dial telephone +diaper +digital clock +digital watch +dining table +dishrag +dishwasher +disk brake +dock +dogsled +dome +doormat +drilling platform +drum +drumstick +dumbbell +Dutch oven +electric fan +electric guitar +electric locomotive +entertainment center +envelope +espresso maker +face powder +feather boa +file +fireboat +fire engine +fire screen +flagpole +flute +folding chair +football helmet +forklift +fountain +fountain pen +four-poster +freight car +French horn +frying pan +fur coat +garbage truck +gasmask +gas pump +goblet +go-kart +golf ball +golfcart +gondola +gong +gown +grand piano +greenhouse +grille +grocery store +guillotine +hair slide +hair spray +half track +hammer +hamper +hand blower +hand-held computer +handkerchief +hard disc +harmonica +harp +harvester +hatchet +holster +home theater +honeycomb +hook +hoopskirt +horizontal bar +horse cart +hourglass +iPod +iron +jack-o'-lantern +jean +jeep +jersey +jigsaw puzzle +jinrikisha +joystick +kimono +knee pad +knot +lab coat +ladle +lampshade +laptop +lawn mower +lens cap +letter opener +library +lifeboat +lighter +limousine +liner +lipstick +Loafer +lotion +loudspeaker +loupe +lumbermill +magnetic compass +mailbag +mailbox +maillot +maillot +manhole cover +maraca +marimba +mask +matchstick +maypole +maze +measuring cup +medicine chest +megalith +microphone +microwave +military uniform +milk can +minibus +miniskirt +minivan +missile +mitten +mixing bowl +mobile home +Model T +modem +monastery +monitor +moped +mortar +mortarboard +mosque +mosquito net +motor scooter +mountain bike +mountain tent +mouse +mousetrap +moving van +muzzle +nail +neck brace +necklace +nipple +notebook +obelisk +oboe +ocarina +odometer +oil filter +organ +oscilloscope +overskirt +oxcart +oxygen mask +packet +paddle +paddlewheel +padlock +paintbrush +pajama +palace +panpipe +paper towel +parachute +parallel bars +park bench +parking meter +passenger car +patio +pay-phone +pedestal +pencil box +pencil sharpener +perfume +Petri dish +photocopier +pick +pickelhaube +picket fence +pickup +pier +piggy bank +pill bottle +pillow +ping-pong ball +pinwheel +pirate +pitcher +plane +planetarium +plastic bag +plate rack +plow +plunger +Polaroid camera +pole +police van +poncho +pool table +pop bottle +pot +potter's wheel +power drill +prayer rug +printer +prison +projectile +projector +puck +punching bag +purse +quill +quilt +racer +racket +radiator +radio +radio telescope +rain barrel +recreational vehicle +reel +reflex camera +refrigerator +remote control +restaurant +revolver +rifle +rocking chair +rotisserie +rubber eraser +rugby ball +rule +running shoe +safe +safety pin +saltshaker +sandal +sarong +sax +scabbard +scale +school bus +schooner +scoreboard +screen +screw +screwdriver +seat belt +sewing machine +shield +shoe shop +shoji +shopping basket +shopping cart +shovel +shower cap +shower curtain +ski +ski mask +sleeping bag +slide rule +sliding door +slot +snorkel +snowmobile +snowplow +soap dispenser +soccer ball +sock +solar dish +sombrero +soup bowl +space bar +space heater +space shuttle +spatula +speedboat +spider web +spindle +sports car +spotlight +stage +steam locomotive +steel arch bridge +steel drum +stethoscope +stole +stone wall +stopwatch +stove +strainer +streetcar +stretcher +studio couch +stupa +submarine +suit +sundial +sunglass +sunglasses +sunscreen +suspension bridge +swab +sweatshirt +swimming trunks +swing +switch +syringe +table lamp +tank +tape player +teapot +teddy +television +tennis ball +thatch +theater curtain +thimble +thresher +throne +tile roof +toaster +tobacco shop +toilet seat +torch +totem pole +tow truck +toyshop +tractor +trailer truck +tray +trench coat +tricycle +trimaran +tripod +triumphal arch +trolleybus +trombone +tub +turnstile +typewriter keyboard +umbrella +unicycle +upright +vacuum +vase +vault +velvet +vending machine +vestment +viaduct +violin +volleyball +waffle iron +wall clock +wallet +wardrobe +warplane +washbasin +washer +water bottle +water jug +water tower +whiskey jug +whistle +wig +window screen +window shade +Windsor tie +wine bottle +wing +wok +wooden spoon +wool +worm fence +wreck +yawl +yurt +web site +comic book +crossword puzzle +street sign +traffic light +book jacket +menu +plate +guacamole +consomme +hot pot +trifle +ice cream +ice lolly +French loaf +bagel +pretzel +cheeseburger +hotdog +mashed potato +head cabbage +broccoli +cauliflower +zucchini +spaghetti squash +acorn squash +butternut squash +cucumber +artichoke +bell pepper +cardoon +mushroom +Granny Smith +strawberry +orange +lemon +fig +pineapple +banana +jackfruit +custard apple +pomegranate +hay +carbonara +chocolate sauce +dough +meat loaf +pizza +potpie +burrito +red wine +espresso +cup +eggnog +alp +bubble +cliff +coral reef +geyser +lakeside +promontory +sandbar +seashore +valley +volcano +ballplayer +groom +scuba diver +rapeseed +daisy +yellow lady's slipper +corn +acorn +hip +buckeye +coral fungus +agaric +gyromitra +stinkhorn +earthstar +hen-of-the-woods +bolete +ear +toilet tissue diff --git a/plugins/tflite_v2-1.0.0/example/assets/posenet_mv1_075_float_from_checkpoints.tflite b/plugins/tflite_v2-1.0.0/example/assets/posenet_mv1_075_float_from_checkpoints.tflite new file mode 100644 index 0000000..4ccbcc5 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/assets/posenet_mv1_075_float_from_checkpoints.tflite differ diff --git a/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.tflite b/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.tflite new file mode 100644 index 0000000..8015ee5 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.tflite differ diff --git a/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.txt b/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.txt new file mode 100644 index 0000000..5a70ff8 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/assets/ssd_mobilenet.txt @@ -0,0 +1,91 @@ +??? +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +traffic light +fire hydrant +??? +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +??? +backpack +umbrella +??? +??? +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +??? +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +couch +potted plant +bed +??? +dining table +??? +??? +toilet +??? +tv +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +??? +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.tflite b/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.tflite new file mode 100644 index 0000000..cda34b4 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.tflite differ diff --git a/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.txt b/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.txt new file mode 100644 index 0000000..ca76c80 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/assets/yolov2_tiny.txt @@ -0,0 +1,80 @@ +person +bicycle +car +motorbike +aeroplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +sofa +pottedplant +bed +diningtable +toilet +tvmonitor +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/plugins/tflite_v2-1.0.0/example/ios/Flutter/AppFrameworkInfo.plist b/plugins/tflite_v2-1.0.0/example/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000..9367d48 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 8.0 + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Flutter/Debug.xcconfig b/plugins/tflite_v2-1.0.0/example/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000..e8efba1 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Flutter/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "Generated.xcconfig" diff --git a/plugins/tflite_v2-1.0.0/example/ios/Flutter/Release.xcconfig b/plugins/tflite_v2-1.0.0/example/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000..399e934 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Flutter/Release.xcconfig @@ -0,0 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "Generated.xcconfig" diff --git a/plugins/tflite_v2-1.0.0/example/ios/Podfile b/plugins/tflite_v2-1.0.0/example/ios/Podfile new file mode 100644 index 0000000..f7d6a5e --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Podfile @@ -0,0 +1,38 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/plugins/tflite_v2-1.0.0/example/ios/Podfile.lock b/plugins/tflite_v2-1.0.0/example/ios/Podfile.lock new file mode 100644 index 0000000..6286399 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Podfile.lock @@ -0,0 +1,35 @@ +PODS: + - Flutter (1.0.0) + - image_picker (0.0.1): + - Flutter + - TensorFlowLiteC (2.2.0) + - tflite (1.1.2): + - Flutter + - TensorFlowLiteC + +DEPENDENCIES: + - Flutter (from `Flutter`) + - image_picker (from `.symlinks/plugins/image_picker/ios`) + - tflite (from `.symlinks/plugins/tflite/ios`) + +SPEC REPOS: + trunk: + - TensorFlowLiteC + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + image_picker: + :path: ".symlinks/plugins/image_picker/ios" + tflite: + :path: ".symlinks/plugins/tflite/ios" + +SPEC CHECKSUMS: + Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + image_picker: a211f28b95a560433c00f5cd3773f4710a20404d + TensorFlowLiteC: b3ab9e867b0b71052ca102a32a786555b330b02e + tflite: f0403a894740019d63ab5662253bba5b2dd37296 + +PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d + +COCOAPODS: 1.10.1 diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.pbxproj b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1252660 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,483 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + A8FCB07931B147D0C738D807 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A034B01AB21E851714E03C /* libPods-Runner.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 864E0E2308AE5F3A9409E901 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A4A034B01AB21E851714E03C /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + E0C0C115F9024C6ADB3B2DB5 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A8FCB07931B147D0C738D807 /* libPods-Runner.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7670CC45CF9B055E20C18D9C /* Frameworks */ = { + isa = PBXGroup; + children = ( + A4A034B01AB21E851714E03C /* libPods-Runner.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 8EE3D73475BA2048B61051C2 /* Pods */ = { + isa = PBXGroup; + children = ( + E0C0C115F9024C6ADB3B2DB5 /* Pods-Runner.debug.xcconfig */, + 864E0E2308AE5F3A9409E901 /* Pods-Runner.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 8EE3D73475BA2048B61051C2 /* Pods */, + 7670CC45CF9B055E20C18D9C /* Frameworks */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 97C146F11CF9000F007C117D /* Supporting Files */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 97C146F21CF9000F007C117D /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + FAEC5F0CFA3366178E53C4C5 /* [CP] Check Pods Manifest.lock */, + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0910; + ORGANIZATIONNAME = "The Chromium Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = ZJG3P98JS9; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; + FAEC5F0CFA3366178E53C4C5 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 97C146F31CF9000F007C117D /* main.m in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ZJG3P98JS9; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "'${SRCROOT}/Pods/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers'", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/Flutter\"", + "\"${PODS_ROOT}/Headers/Public/TensorFlowLite\"", + "\"${PODS_ROOT}/Headers/Public/tflite\"", + ); + INFOPLIST_FILE = Runner/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = sq.flutter.tfliteExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ZJG3P98JS9; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "'${SRCROOT}/Pods/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers'", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/Flutter\"", + "\"${PODS_ROOT}/Headers/Public/TensorFlowLite\"", + "\"${PODS_ROOT}/Headers/Public/tflite\"", + ); + INFOPLIST_FILE = Runner/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = sq.flutter.tfliteExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..6c78381 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..21a3cc1 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.h b/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.h new file mode 100644 index 0000000..36e21bb --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.h @@ -0,0 +1,6 @@ +#import +#import + +@interface AppDelegate : FlutterAppDelegate + +@end diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.m b/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.m new file mode 100644 index 0000000..59a72e9 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/AppDelegate.m @@ -0,0 +1,13 @@ +#include "AppDelegate.h" +#include "GeneratedPluginRegistrant.h" + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + // Override point for customization after application launch. + return [super application:application didFinishLaunchingWithOptions:launchOptions]; +} + +@end diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d36b1fa --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000..3d43d11 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png new file mode 100644 index 0000000..28c6bf0 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000..2ccbfd9 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000..f091b6b Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000..4cde121 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000..d0ef06e Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000..dcdc230 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000..2ccbfd9 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000..c8f9ed8 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000..a6d6b86 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000..a6d6b86 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000..75b2d16 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000..c4df70d Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000..6a84f41 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000..d0e1f58 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000..0bedcf2 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png differ diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 0000000..89c2725 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f2e259c --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/Main.storyboard b/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f3c2851 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/Info.plist b/plugins/tflite_v2-1.0.0/example/ios/Runner/Info.plist new file mode 100644 index 0000000..3fef927 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/Info.plist @@ -0,0 +1,51 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + tflite_example + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + NSPhotoLibraryUsageDescription + We need your permission to access photo gallery + NSCameraUsageDescription + We need your permission to use phone camera + NSMicrophoneUsageDescription + We need your permission to use microsphone + + diff --git a/plugins/tflite_v2-1.0.0/example/ios/Runner/main.m b/plugins/tflite_v2-1.0.0/example/ios/Runner/main.m new file mode 100644 index 0000000..dff6597 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/ios/Runner/main.m @@ -0,0 +1,9 @@ +#import +#import +#import "AppDelegate.h" + +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/plugins/tflite_v2-1.0.0/example/lib/main.dart b/plugins/tflite_v2-1.0.0/example/lib/main.dart new file mode 100644 index 0000000..b02b5f6 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/lib/main.dart @@ -0,0 +1,473 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:math'; +import 'dart:typed_data'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:image/image.dart' as img; + +import 'package:tflite_v2/tflite_v2.dart'; +import 'package:image_picker/image_picker.dart'; + +void main() => runApp(new App()); + +const String mobile = "MobileNet"; +const String ssd = "SSD MobileNet"; +const String yolo = "Tiny YOLOv2"; +const String deeplab = "DeepLab"; +const String posenet = "PoseNet"; + +class App extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: MyApp(), + ); + } +} + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => new _MyAppState(); +} + +class _MyAppState extends State { + File _image; + List _recognitions; + String _model = mobile; + double _imageHeight; + double _imageWidth; + bool _busy = false; + + Future predictImagePicker() async { + var image = await ImagePicker.pickImage(source: ImageSource.gallery); + if (image == null) return; + setState(() { + _busy = true; + }); + predictImage(image); + } + + Future predictImage(File image) async { + if (image == null) return; + + switch (_model) { + case yolo: + await yolov2Tiny(image); + break; + case ssd: + await ssdMobileNet(image); + break; + case deeplab: + await segmentMobileNet(image); + break; + case posenet: + await poseNet(image); + break; + default: + await recognizeImage(image); + // await recognizeImageBinary(image); + } + + new FileImage(image) + .resolve(new ImageConfiguration()) + .addListener(ImageStreamListener((ImageInfo info, bool _) { + setState(() { + _imageHeight = info.image.height.toDouble(); + _imageWidth = info.image.width.toDouble(); + }); + })); + + setState(() { + _image = image; + _busy = false; + }); + } + + @override + void initState() { + super.initState(); + + _busy = true; + + loadModel().then((val) { + setState(() { + _busy = false; + }); + }); + } + + Future loadModel() async { + Tflite.close(); + try { + String res; + switch (_model) { + case yolo: + res = await Tflite.loadModel( + model: "assets/yolov2_tiny.tflite", + labels: "assets/yolov2_tiny.txt", + // useGpuDelegate: true, + ); + break; + case ssd: + res = await Tflite.loadModel( + model: "assets/ssd_mobilenet.tflite", + labels: "assets/ssd_mobilenet.txt", + // useGpuDelegate: true, + ); + break; + case deeplab: + res = await Tflite.loadModel( + model: "assets/deeplabv3_257_mv_gpu.tflite", + labels: "assets/deeplabv3_257_mv_gpu.txt", + // useGpuDelegate: true, + ); + break; + case posenet: + res = await Tflite.loadModel( + model: "assets/posenet_mv1_075_float_from_checkpoints.tflite", + // useGpuDelegate: true, + ); + break; + default: + res = await Tflite.loadModel( + model: "assets/mobilenet_v1_1.0_224.tflite", + labels: "assets/mobilenet_v1_1.0_224.txt", + // useGpuDelegate: true, + ); + } + print(res); + } on PlatformException { + print('Failed to load model.'); + } + } + + Uint8List imageToByteListFloat32( + img.Image image, int inputSize, double mean, double std) { + var convertedBytes = Float32List(1 * inputSize * inputSize * 3); + var buffer = Float32List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; + } + } + return convertedBytes.buffer.asUint8List(); + } + + Uint8List imageToByteListUint8(img.Image image, int inputSize) { + var convertedBytes = Uint8List(1 * inputSize * inputSize * 3); + var buffer = Uint8List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = img.getRed(pixel); + buffer[pixelIndex++] = img.getGreen(pixel); + buffer[pixelIndex++] = img.getBlue(pixel); + } + } + return convertedBytes.buffer.asUint8List(); + } + + Future recognizeImage(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runModelOnImage( + path: image.path, + numResults: 6, + threshold: 0.05, + imageMean: 127.5, + imageStd: 127.5, + ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future recognizeImageBinary(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var imageBytes = (await rootBundle.load(image.path)).buffer; + img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + img.Image resizedImage = img.copyResize(oriImage, height: 224, width: 224); + var recognitions = await Tflite.runModelOnBinary( + binary: imageToByteListFloat32(resizedImage, 224, 127.5, 127.5), + numResults: 6, + threshold: 0.05, + ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future yolov2Tiny(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.detectObjectOnImage( + path: image.path, + model: "YOLO", + threshold: 0.3, + imageMean: 0.0, + imageStd: 255.0, + numResultsPerClass: 1, + ); + // var imageBytes = (await rootBundle.load(image.path)).buffer; + // img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + // img.Image resizedImage = img.copyResize(oriImage, 416, 416); + // var recognitions = await Tflite.detectObjectOnBinary( + // binary: imageToByteListFloat32(resizedImage, 416, 0.0, 255.0), + // model: "YOLO", + // threshold: 0.3, + // numResultsPerClass: 1, + // ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future ssdMobileNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.detectObjectOnImage( + path: image.path, + numResultsPerClass: 1, + ); + // var imageBytes = (await rootBundle.load(image.path)).buffer; + // img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + // img.Image resizedImage = img.copyResize(oriImage, 300, 300); + // var recognitions = await Tflite.detectObjectOnBinary( + // binary: imageToByteListUint8(resizedImage, 300), + // numResultsPerClass: 1, + // ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future segmentMobileNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runSegmentationOnImage( + path: image.path, + imageMean: 127.5, + imageStd: 127.5, + ); + + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}"); + } + + Future poseNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runPoseNetOnImage( + path: image.path, + numResults: 2, + ); + + print(recognitions); + + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + onSelect(model) async { + setState(() { + _busy = true; + _model = model; + _recognitions = null; + }); + await loadModel(); + + if (_image != null) + predictImage(_image); + else + setState(() { + _busy = false; + }); + } + + List renderBoxes(Size screen) { + if (_recognitions == null) return []; + if (_imageHeight == null || _imageWidth == null) return []; + + double factorX = screen.width; + double factorY = _imageHeight / _imageWidth * screen.width; + Color blue = Color.fromRGBO(37, 213, 253, 1.0); + return _recognitions.map((re) { + return Positioned( + left: re["rect"]["x"] * factorX, + top: re["rect"]["y"] * factorY, + width: re["rect"]["w"] * factorX, + height: re["rect"]["h"] * factorY, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.0)), + border: Border.all( + color: blue, + width: 2, + ), + ), + child: Text( + "${re["detectedClass"]} ${(re["confidenceInClass"] * 100).toStringAsFixed(0)}%", + style: TextStyle( + background: Paint()..color = blue, + color: Colors.white, + fontSize: 12.0, + ), + ), + ), + ); + }).toList(); + } + + List renderKeypoints(Size screen) { + if (_recognitions == null) return []; + if (_imageHeight == null || _imageWidth == null) return []; + + double factorX = screen.width; + double factorY = _imageHeight / _imageWidth * screen.width; + + var lists = []; + _recognitions.forEach((re) { + var color = Color((Random().nextDouble() * 0xFFFFFF).toInt() << 0) + .withOpacity(1.0); + var list = re["keypoints"].values.map((k) { + return Positioned( + left: k["x"] * factorX - 6, + top: k["y"] * factorY - 6, + width: 100, + height: 12, + child: Text( + "● ${k["part"]}", + style: TextStyle( + color: color, + fontSize: 12.0, + ), + ), + ); + }).toList(); + + lists..addAll(list); + }); + + return lists; + } + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + List stackChildren = []; + + if (_model == deeplab && _recognitions != null) { + stackChildren.add(Positioned( + top: 0.0, + left: 0.0, + width: size.width, + child: _image == null + ? Text('No image selected.') + : Container( + decoration: BoxDecoration( + image: DecorationImage( + alignment: Alignment.topCenter, + image: MemoryImage(_recognitions), + fit: BoxFit.fill)), + child: Opacity(opacity: 0.3, child: Image.file(_image))), + )); + } else { + stackChildren.add(Positioned( + top: 0.0, + left: 0.0, + width: size.width, + child: _image == null ? Text('No image selected.') : Image.file(_image), + )); + } + + if (_model == mobile) { + stackChildren.add(Center( + child: Column( + children: _recognitions != null + ? _recognitions.map((res) { + return Text( + "${res["index"]} - ${res["label"]}: ${res["confidence"].toStringAsFixed(3)}", + style: TextStyle( + color: Colors.black, + fontSize: 20.0, + background: Paint()..color = Colors.white, + ), + ); + }).toList() + : [], + ), + )); + } else if (_model == ssd || _model == yolo) { + stackChildren.addAll(renderBoxes(size)); + } else if (_model == posenet) { + stackChildren.addAll(renderKeypoints(size)); + } + + if (_busy) { + stackChildren.add(const Opacity( + child: ModalBarrier(dismissible: false, color: Colors.grey), + opacity: 0.3, + )); + stackChildren.add(const Center(child: CircularProgressIndicator())); + } + + return Scaffold( + appBar: AppBar( + title: const Text('tflite example app'), + actions: [ + PopupMenuButton( + onSelected: onSelect, + itemBuilder: (context) { + List> menuEntries = [ + const PopupMenuItem( + child: Text(mobile), + value: mobile, + ), + const PopupMenuItem( + child: Text(ssd), + value: ssd, + ), + const PopupMenuItem( + child: Text(yolo), + value: yolo, + ), + const PopupMenuItem( + child: Text(deeplab), + value: deeplab, + ), + const PopupMenuItem( + child: Text(posenet), + value: posenet, + ) + ]; + return menuEntries; + }, + ) + ], + ), + body: Stack( + children: stackChildren, + ), + floatingActionButton: FloatingActionButton( + onPressed: predictImagePicker, + tooltip: 'Pick Image', + child: Icon(Icons.image), + ), + ); + } +} diff --git a/plugins/tflite_v2-1.0.0/example/pubspec.yaml b/plugins/tflite_v2-1.0.0/example/pubspec.yaml new file mode 100644 index 0000000..ceb496c --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/pubspec.yaml @@ -0,0 +1,83 @@ +name: tflite_example +description: Demonstrates how to use the tflite plugin. + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# Read more about versioning at semver.org. +version: 1.0.0+1 + +environment: + sdk: ">=2.0.0-dev.68.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^0.1.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + image_picker: ^0.6.7 + + image: ^2.1.4 + + tflite: + path: ../ + + test: ^1.12.0 +# For information on the generic Dart part of this file, see the +# following page: https://www.dartlang.org/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + assets: + - assets/mobilenet_v1_1.0_224.txt + - assets/mobilenet_v1_1.0_224.tflite + - assets/yolov2_tiny.tflite + - assets/yolov2_tiny.txt + - assets/ssd_mobilenet.tflite + - assets/ssd_mobilenet.txt + - assets/deeplabv3_257_mv_gpu.tflite + - assets/deeplabv3_257_mv_gpu.txt + - assets/posenet_mv1_075_float_from_checkpoints.tflite + + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.io/assets-and-images/#resolution-aware. + + # For details regarding adding assets from package dependencies, see + # https://flutter.io/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.io/custom-fonts/#from-packages diff --git a/plugins/tflite_v2-1.0.0/example/test/widget_test.dart b/plugins/tflite_v2-1.0.0/example/test/widget_test.dart new file mode 100644 index 0000000..00a807f --- /dev/null +++ b/plugins/tflite_v2-1.0.0/example/test/widget_test.dart @@ -0,0 +1,25 @@ +// This is a basic Flutter widget test. +// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter +// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to +// find child widgets in the widget tree, read text, and verify that the values of widget properties +// are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:tflite_example/main.dart'; + +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(new MyApp()); + + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => + widget is Text && widget.data.startsWith('Running on:'), + ), + findsOneWidget); + }); +} diff --git a/plugins/tflite_v2-1.0.0/example/yolo.jpg b/plugins/tflite_v2-1.0.0/example/yolo.jpg new file mode 100644 index 0000000..33f6714 Binary files /dev/null and b/plugins/tflite_v2-1.0.0/example/yolo.jpg differ diff --git a/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.h b/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.h new file mode 100644 index 0000000..5f12511 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.h @@ -0,0 +1,4 @@ +#import + +@interface TflitePlugin : NSObject +@end diff --git a/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.mm b/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.mm new file mode 100644 index 0000000..049891a --- /dev/null +++ b/plugins/tflite_v2-1.0.0/ios/Classes/TflitePlugin.mm @@ -0,0 +1,1501 @@ +//#define CONTRIB_PATH +#define TFLITE2 + +#import "TflitePlugin.h" + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONTRIB_PATH +#include "tensorflow/contrib/lite/kernels/register.h" +#include "tensorflow/contrib/lite/model.h" +#include "tensorflow/contrib/lite/string_util.h" +#include "tensorflow/contrib/lite/op_resolver.h" +#elif defined TFLITE2 +#import "TensorFlowLiteC.h" +#import "metal_delegate.h" +#else +#include "tensorflow/lite/kernels/register.h" +#include "tensorflow/lite/model.h" +#include "tensorflow/lite/string_util.h" +#include "tensorflow/lite/op_resolver.h" +#endif + +#include "ios_image_load.h" + +#define LOG(x) std::cerr + +typedef void (^TfLiteStatusCallback)(TfLiteStatus); +NSString* loadModel(NSObject* _registrar, NSDictionary* args); +void runTflite(NSDictionary* args, TfLiteStatusCallback cb); +void runModelOnImage(NSDictionary* args, FlutterResult result); +void runModelOnBinary(NSDictionary* args, FlutterResult result); +void runModelOnFrame(NSDictionary* args, FlutterResult result); +void detectObjectOnImage(NSDictionary* args, FlutterResult result); +void detectObjectOnBinary(NSDictionary* args, FlutterResult result); +void detectObjectOnFrame(NSDictionary* args, FlutterResult result); +void runPix2PixOnImage(NSDictionary* args, FlutterResult result); +void runPix2PixOnBinary(NSDictionary* args, FlutterResult result); +void runPix2PixOnFrame(NSDictionary* args, FlutterResult result); +void runSegmentationOnImage(NSDictionary* args, FlutterResult result); +void runSegmentationOnBinary(NSDictionary* args, FlutterResult result); +void runSegmentationOnFrame(NSDictionary* args, FlutterResult result); +void runPoseNetOnImage(NSDictionary* args, FlutterResult result); +void runPoseNetOnBinary(NSDictionary* args, FlutterResult result); +void runPoseNetOnFrame(NSDictionary* args, FlutterResult result); +void close(); + +@implementation TflitePlugin { + NSObject* _registrar; +} + ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:@"tflite" + binaryMessenger:[registrar messenger]]; + TflitePlugin* instance = [[TflitePlugin alloc] initWithRegistrar:registrar]; + [registrar addMethodCallDelegate:instance channel:channel]; +} + +- (instancetype)initWithRegistrar:(NSObject*)registrar { + self = [super init]; + if (self) { + _registrar = registrar; + } + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + if ([@"loadModel" isEqualToString:call.method]) { + NSString* load_result = loadModel(_registrar, call.arguments); + result(load_result); + } else if ([@"runModelOnImage" isEqualToString:call.method]) { + runModelOnImage(call.arguments, result); + } else if ([@"runModelOnBinary" isEqualToString:call.method]) { + runModelOnBinary(call.arguments, result); + } else if ([@"runModelOnFrame" isEqualToString:call.method]) { + runModelOnFrame(call.arguments, result); + } else if ([@"detectObjectOnImage" isEqualToString:call.method]) { + detectObjectOnImage(call.arguments, result); + } else if ([@"detectObjectOnBinary" isEqualToString:call.method]) { + detectObjectOnBinary(call.arguments, result); + } else if ([@"detectObjectOnFrame" isEqualToString:call.method]) { + detectObjectOnFrame(call.arguments, result); + } else if ([@"runPix2PixOnImage" isEqualToString:call.method]) { + runPix2PixOnImage(call.arguments, result); + } else if ([@"runPix2PixOnBinary" isEqualToString:call.method]) { + runPix2PixOnBinary(call.arguments, result); + } else if ([@"runPix2PixOnFrame" isEqualToString:call.method]) { + runPix2PixOnFrame(call.arguments, result); + } else if ([@"runSegmentationOnImage" isEqualToString:call.method]) { + runSegmentationOnImage(call.arguments, result); + } else if ([@"runSegmentationOnBinary" isEqualToString:call.method]) { + runSegmentationOnBinary(call.arguments, result); + } else if ([@"runSegmentationOnFrame" isEqualToString:call.method]) { + runSegmentationOnFrame(call.arguments, result); + } else if ([@"runPoseNetOnImage" isEqualToString:call.method]) { + runPoseNetOnImage(call.arguments, result); + } else if ([@"runPoseNetOnBinary" isEqualToString:call.method]) { + runPoseNetOnBinary(call.arguments, result); + } else if ([@"runPoseNetOnFrame" isEqualToString:call.method]) { + runPoseNetOnFrame(call.arguments, result); + } else if ([@"close" isEqualToString:call.method]) { + close(); + } else { + result(FlutterMethodNotImplemented); + } +} + +@end + +std::vector labels; +#ifdef TFLITE2 +TfLiteInterpreter *interpreter = nullptr; +TfLiteModel *model = nullptr; +TfLiteDelegate *delegate = nullptr; +#else +std::unique_ptr model; +std::unique_ptr interpreter; +#endif +bool interpreter_busy = false; + +static void LoadLabels(NSString* labels_path, + std::vector* label_strings) { + if (!labels_path) { + LOG(ERROR) << "Failed to find label file at" << labels_path; + } + std::ifstream t; + t.open([labels_path UTF8String]); + label_strings->clear(); + for (std::string line; std::getline(t, line); ) { + label_strings->push_back(line); + } + t.close(); +} + +NSString* loadModel(NSObject* _registrar, NSDictionary* args) { + NSString* graph_path; + NSString* key; + NSNumber* isAssetNumber = args[@"isAsset"]; + bool isAsset = [isAssetNumber boolValue]; + if(isAsset){ + key = [_registrar lookupKeyForAsset:args[@"model"]]; + graph_path = [[NSBundle mainBundle] pathForResource:key ofType:nil]; + }else{ + graph_path = args[@"model"]; + } + + const int num_threads = [args[@"numThreads"] intValue]; + +#ifdef TFLITE2 + TfLiteInterpreterOptions *options = nullptr; + model = TfLiteModelCreateFromFile(graph_path.UTF8String); + if (!model) { + return [NSString stringWithFormat:@"%s %@", "Failed to mmap model", graph_path]; + } + options = TfLiteInterpreterOptionsCreate(); + TfLiteInterpreterOptionsSetNumThreads(options, num_threads); + + bool useGpuDelegate = [args[@"useGpuDelegate"] boolValue]; + if (useGpuDelegate) { + delegate = TFLGpuDelegateCreate(nullptr); + TfLiteInterpreterOptionsAddDelegate(options, delegate); + } +#else + model = tflite::FlatBufferModel::BuildFromFile([graph_path UTF8String]); + if (!model) { + return [NSString stringWithFormat:@"%s %@", "Failed to mmap model", graph_path]; + } + LOG(INFO) << "Loaded model " << graph_path; + model->error_reporter(); + LOG(INFO) << "resolved reporter"; +#endif + + if ([args[@"labels"] length] > 0) { + NSString* labels_path; + if(isAsset){ + key = [_registrar lookupKeyForAsset:args[@"labels"]]; + labels_path = [[NSBundle mainBundle] pathForResource:key ofType:nil]; + }else{ + labels_path = args[@"labels"]; + } + LoadLabels(labels_path, &labels); + } + +#ifdef TFLITE2 + interpreter = TfLiteInterpreterCreate(model, options); + if (!interpreter) { + return @"Failed to construct interpreter"; + } + + if (TfLiteInterpreterAllocateTensors(interpreter) != kTfLiteOk) { + return @"Failed to allocate tensors!"; + } +#else + tflite::ops::builtin::BuiltinOpResolver resolver; + tflite::InterpreterBuilder(*model, resolver)(&interpreter); + if (!interpreter) { + return @"Failed to construct interpreter"; + } + + if (interpreter->AllocateTensors() != kTfLiteOk) { + return @"Failed to allocate tensors!"; + } + + if (num_threads != -1) { + interpreter->SetNumThreads(num_threads); + } + #endif + + return @"success"; +} + + +void runTflite(NSDictionary* args, TfLiteStatusCallback cb) { + const bool asynch = [args[@"asynch"] boolValue]; + if (asynch) { + interpreter_busy = true; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ +#ifdef TFLITE2 + TfLiteStatus status = TfLiteInterpreterInvoke(interpreter); +#else + TfLiteStatus status = interpreter->Invoke(); +#endif + dispatch_async(dispatch_get_main_queue(), ^(void){ + interpreter_busy = false; + cb(status); + }); + }); + } else { +#ifdef TFLITE2 + TfLiteStatus status = TfLiteInterpreterInvoke(interpreter); +#else + TfLiteStatus status = interpreter->Invoke(); +#endif + cb(status); + } +} + +NSMutableData *feedOutputTensor(int outputChannelsIn, float mean, float std, bool convertToUint8, + int *widthOut, int *heightOut) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 1); + const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + assert(interpreter->outputs().size() == 1); + int output = interpreter->outputs()[0]; + TfLiteTensor* output_tensor = interpreter->tensor(output); +#endif + const int width = output_tensor->dims->data[2]; + const int channels = output_tensor->dims->data[3]; + const int outputChannels = outputChannelsIn ? outputChannelsIn : channels; + assert(outputChannels >= channels); + if (widthOut) *widthOut = width; + if (heightOut) *heightOut = width; + + NSMutableData *data = nil; + if (output_tensor->type == kTfLiteUInt8) { + int size = width*width*outputChannels; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + uint8_t* out = (uint8_t*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + const uint8_t* bytes = output_tensor->data.uint8; +#else + const uint8_t* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = *bytes++; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } else { // kTfLiteFloat32 + if (convertToUint8) { + int size = width*width*outputChannels; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + uint8_t* out = (uint8_t*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + const float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = (*bytes++ * std) + mean; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } else { // kTfLiteFloat32 + int size = width*width*outputChannels*4; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + float* out = (float*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = (*bytes++ * std) + mean; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } + } + return data; +} + +void feedInputTensorBinary(const FlutterStandardTypedData* typedData, int* input_size) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetInputTensorCount(interpreter) == 1); + TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0); +#else + assert(interpreter->inputs().size() == 1); + int input = interpreter->inputs()[0]; + TfLiteTensor* input_tensor = interpreter->tensor(input); +#endif + const int width = input_tensor->dims->data[2]; + *input_size = width; + NSData* in = [typedData data]; + + if (input_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + TfLiteTensorCopyFromBuffer(input_tensor, in.bytes, in.length); +#else + uint8_t* out = interpreter->typed_tensor(input); + const uint8_t* bytes = (const uint8_t*)[in bytes]; + for (int index = 0; index < [in length]; index++) + out[index] = bytes[index]; +#endif + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + TfLiteTensorCopyFromBuffer(input_tensor, in.bytes, in.length); +#else + float* out = interpreter->typed_tensor(input); + const float* bytes = (const float*)[in bytes]; + for (int index = 0; index < [in length]/4; index++) + out[index] = bytes[index]; +#endif + } +} + +void feedInputTensor(uint8_t* in, int* input_size, int image_height, int image_width, int image_channels, float input_mean, float input_std) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetInputTensorCount(interpreter) == 1); + TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0); +#else + assert(interpreter->inputs().size() == 1); + int input = interpreter->inputs()[0]; + TfLiteTensor* input_tensor = interpreter->tensor(input); +#endif + const int input_channels = input_tensor->dims->data[3]; + const int width = input_tensor->dims->data[2]; + const int height = input_tensor->dims->data[1]; + *input_size = width; + + if (input_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + uint8_t* out = input_tensor->data.uint8; +#else + uint8_t* out = interpreter->typed_tensor(input); +#endif + for (int y = 0; y < height; ++y) { + const int in_y = (y * image_height) / height; + uint8_t* in_row = in + (in_y * image_width * image_channels); + uint8_t* out_row = out + (y * width * input_channels); + for (int x = 0; x < width; ++x) { + const int in_x = (x * image_width) / width; + uint8_t* in_pixel = in_row + (in_x * image_channels); + uint8_t* out_pixel = out_row + (x * input_channels); + for (int c = 0; c < input_channels; ++c) { + out_pixel[c] = in_pixel[c]; + } + } + } + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + float* out = input_tensor->data.f; +#else + float* out = interpreter->typed_tensor(input); +#endif + for (int y = 0; y < height; ++y) { + const int in_y = (y * image_height) / height; + uint8_t* in_row = in + (in_y * image_width * image_channels); + float* out_row = out + (y * width * input_channels); + for (int x = 0; x < width; ++x) { + const int in_x = (x * image_width) / width; + uint8_t* in_pixel = in_row + (in_x * image_channels); + float* out_pixel = out_row + (x * input_channels); + for (int c = 0; c < input_channels; ++c) { + out_pixel[c] = (in_pixel[c] - input_mean) / input_std; + } + } + } + } +} + +void feedInputTensorImage(const NSString* image_path, float input_mean, float input_std, int* input_size) { + int image_channels; + int image_height; + int image_width; + std::vector image_data = LoadImageFromFile([image_path UTF8String], &image_width, &image_height, &image_channels); + uint8_t* in = image_data.data(); + feedInputTensor(in, input_size, image_height, image_width, image_channels, input_mean, input_std); +} + +void feedInputTensorFrame(const FlutterStandardTypedData* typedData, int* input_size, + int image_height, int image_width, int image_channels, float input_mean, float input_std) { + uint8_t* in = (uint8_t*)[[typedData data] bytes]; + feedInputTensor(in, input_size, image_height, image_width, image_channels, input_mean, input_std); +} + +NSMutableArray* GetTopN(const float* prediction, const unsigned long prediction_size, const int num_results, + const float threshold) { + std::priority_queue, std::vector>, + std::greater>> top_result_pq; + std::vector> top_results; + + const long count = prediction_size; + for (int i = 0; i < count; ++i) { + const float value = prediction[i]; + + if (value < threshold) { + continue; + } + + top_result_pq.push(std::pair(value, i)); + + if (top_result_pq.size() > num_results) { + top_result_pq.pop(); + } + } + + while (!top_result_pq.empty()) { + top_results.push_back(top_result_pq.top()); + top_result_pq.pop(); + } + std::reverse(top_results.begin(), top_results.end()); + + NSMutableArray* predictions = [NSMutableArray array]; + for (const auto& result : top_results) { + const float confidence = result.first; + const int index = result.second; + NSString* labelObject = [NSString stringWithUTF8String:labels[index].c_str()]; + NSNumber* valueObject = [NSNumber numberWithFloat:confidence]; + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + [res setValue:[NSNumber numberWithInt:index] forKey:@"index"]; + [res setObject:labelObject forKey:@"label"]; + [res setObject:valueObject forKey:@"confidence"]; + [predictions addObject:res]; + } + + return predictions; +} + +void runModelOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +void runModelOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +void runModelOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +NSMutableArray* parseSSDMobileNet(float threshold, int num_results_per_class) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 4); +#else + assert(interpreter->outputs().size() == 4); +#endif + NSMutableArray* results = [NSMutableArray array]; +#ifdef TFLITE2 + float* output_locations = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; + float* output_classes = TfLiteInterpreterGetOutputTensor(interpreter, 1)->data.f; + float* output_scores = TfLiteInterpreterGetOutputTensor(interpreter, 2)->data.f; + float* num_detections = TfLiteInterpreterGetOutputTensor(interpreter, 3)->data.f; +#else + float* output_locations = interpreter->typed_output_tensor(0); + float* output_classes = interpreter->typed_output_tensor(1); + float* output_scores = interpreter->typed_output_tensor(2); + float* num_detections = interpreter->typed_output_tensor(3); +#endif + + NSMutableDictionary* counters = [NSMutableDictionary dictionary]; + for (int d = 0; d < *num_detections; d++) + { + const int detected_class = output_classes[d]; + float score = output_scores[d]; + + if (score < threshold) continue; + + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + NSString* class_name = [NSString stringWithUTF8String:labels[detected_class + 1].c_str()]; + NSObject* counter = [counters objectForKey:class_name]; + + if (counter) { + int countValue = [(NSNumber*)counter intValue] + 1; + if (countValue > num_results_per_class) { + continue; + } + [counters setObject:@(countValue) forKey:class_name]; + } else { + [counters setObject:@(1) forKey:class_name]; + } + + [res setObject:@(score) forKey:@"confidenceInClass"]; + [res setObject:class_name forKey:@"detectedClass"]; + + const float ymin = fmax(0, output_locations[d * 4]); + const float xmin = fmax(0, output_locations[d * 4 + 1]); + const float ymax = output_locations[d * 4 + 2]; + const float xmax = output_locations[d * 4 + 3]; + + NSMutableDictionary* rect = [NSMutableDictionary dictionary]; + [rect setObject:@(xmin) forKey:@"x"]; + [rect setObject:@(ymin) forKey:@"y"]; + [rect setObject:@(fmin(1 - xmin, xmax - xmin)) forKey:@"w"]; + [rect setObject:@(fmin(1 - ymin, ymax - ymin)) forKey:@"h"]; + + [res setObject:rect forKey:@"rect"]; + [results addObject:res]; + } + return results; +} + +float sigmoid(float x) { + return 1.0 / (1.0 + exp(-x)); +} + +void softmax(float vals[], int count) { + float max = -FLT_MAX; + for (int i=0; idata.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + NSMutableArray* results = [NSMutableArray array]; + std::priority_queue, std::vector>, + std::less>> top_result_pq; + + int grid_size = input_size / block_size; + for (int y = 0; y < grid_size; ++y) { + for (int x = 0; x < grid_size; ++x) { + for (int b = 0; b < num_boxes_per_bolock; ++b) { + int offset = (grid_size * (num_boxes_per_bolock * (num_classes + 5))) * y + + (num_boxes_per_bolock * (num_classes + 5)) * x + + (num_classes + 5) * b; + + float confidence = sigmoid(output[offset + 4]); + + float classes[num_classes]; + for (int c = 0; c < num_classes; ++c) { + classes[c] = output[offset + 5 + c]; + } + + softmax(classes, num_classes); + + int detected_class = -1; + float max_class = 0; + for (int c = 0; c < num_classes; ++c) { + if (classes[c] > max_class) { + detected_class = c; + max_class = classes[c]; + } + } + + float confidence_in_class = max_class * confidence; + if (confidence_in_class > threshold) { + NSMutableDictionary* rect = [NSMutableDictionary dictionary]; + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + + float xPos = (x + sigmoid(output[offset + 0])) * block_size; + float yPos = (y + sigmoid(output[offset + 1])) * block_size; + + float anchor_w = [[anchors objectAtIndex:(2 * b + 0)] floatValue]; + float anchor_h = [[anchors objectAtIndex:(2 * b + 1)] floatValue]; + float w = (float) (exp(output[offset + 2]) * anchor_w) * block_size; + float h = (float) (exp(output[offset + 3]) * anchor_h) * block_size; + + float x = fmax(0, (xPos - w / 2) / input_size); + float y = fmax(0, (yPos - h / 2) / input_size); + [rect setObject:@(x) forKey:@"x"]; + [rect setObject:@(y) forKey:@"y"]; + [rect setObject:@(fmin(1 - x, w / input_size)) forKey:@"w"]; + [rect setObject:@(fmin(1 - y, h / input_size)) forKey:@"h"]; + + [res setObject:rect forKey:@"rect"]; + [res setObject:@(confidence_in_class) forKey:@"confidenceInClass"]; + NSString* class_name = [NSString stringWithUTF8String:labels[detected_class].c_str()]; + [res setObject:class_name forKey:@"detectedClass"]; + + top_result_pq.push(std::pair(confidence_in_class, res)); + } + } + } + } + + NSMutableDictionary* counters = [NSMutableDictionary dictionary]; + while (!top_result_pq.empty()) { + NSMutableDictionary* result = top_result_pq.top().second; + top_result_pq.pop(); + + NSString* detected_class = [result objectForKey:@"detectedClass"]; + NSObject* counter = [counters objectForKey:detected_class]; + if (counter) { + int countValue = [(NSNumber*)counter intValue] + 1; + if (countValue > num_results_per_class) { + continue; + } + [counters setObject:@(countValue) forKey:detected_class]; + } else { + [counters setObject:@(1) forKey:detected_class]; + } + [results addObject:result]; + } + + return results; +} + +void detectObjectOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const NSString* model = args[@"model"]; + const float threshold = [args[@"threshold"] floatValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)labels.size(), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void detectObjectOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const NSString* model = args[@"model"]; + const float threshold = [args[@"threshold"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)(labels.size() - 1), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void detectObjectOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const NSString* model = args[@"model"]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)labels.size(), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void runPix2PixOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(4, input_mean, input_std, true, &width, &height); + if (output == NULL) + return result(empty); + + if ([outputType isEqual: @"png"]) { + return result(CompressImage(output, width, height, 1)); + } else { + return result(output); + } + }); +} + +void runPix2PixOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(0, 0, 1, false, &width, &height); + if (output == NULL) + return result(empty); + + return result(output); + }); +} + +void runPix2PixOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(image_channels, input_mean, input_std, true, &width, &height); + if (output == NULL) + return result(empty); + + if ([outputType isEqual: @"png"]) { + return result(CompressImage(output, width, height, 1)); + } else { + return result(output); + } + }); +} + +void setPixel(char* rgba, int index, long color) { + rgba[index * 4] = (color >> 16) & 0xFF; + rgba[index * 4 + 1] = (color >> 8) & 0xFF; + rgba[index * 4 + 2] = color & 0xFF; + rgba[index * 4 + 3] = (color >> 24) & 0xFF; +} + +NSData* fetchArgmax(const NSArray* labelColors, const NSString* outputType) { +#ifdef TFLITE2 + const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + int output = interpreter->outputs()[0]; + TfLiteTensor* output_tensor = interpreter->tensor(output); +#endif + const int height = output_tensor->dims->data[1]; + const int width = output_tensor->dims->data[2]; + const int channels = output_tensor->dims->data[3]; + + NSMutableData *data = nil; + int size = height * width * 4; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + char* out = (char*)[data bytes]; + if (output_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + const uint8_t* bytes = output_tensor->data.uint8; +#else + const uint8_t* bytes = interpreter->typed_tensor(output); +#endif + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int index = i * width + j; + int maxIndex = 0; + int maxValue = 0; + for (int c = 0; c < channels; ++c) { + int outputValue = bytes[index* channels + c]; + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + long labelColor = [[labelColors objectAtIndex:maxIndex] longValue]; + setPixel(out, index, labelColor); + } + } + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + const float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int index = i * width + j; + int maxIndex = 0; + float maxValue = .0f; + for (int c = 0; c < channels; ++c) { + float outputValue = bytes[index * channels + c]; + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + long labelColor = [[labelColors objectAtIndex:maxIndex] longValue]; + setPixel(out, index, labelColor); + } + } + } + + if ([outputType isEqual: @"png"]) { + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bitmapContext = CGBitmapContextCreate(out, + width, + height, + 8, // bitsPerComponent + 4 * width, // bytesPerRow + colorSpace, + kCGImageAlphaNoneSkipLast); + + CFRelease(colorSpace); + CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext); + NSData* image = UIImagePNGRepresentation([[UIImage alloc] initWithCGImage:cgImage]); + CFRelease(cgImage); + CFRelease(bitmapContext); + return image; + } else { + return data; + } +} + +void runSegmentationOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + +void runSegmentationOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + +void runSegmentationOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + + +NSArray* _tflite_part_names = @[ + @"nose", @"leftEye", @"rightEye", @"leftEar", @"rightEar", @"leftShoulder", + @"rightShoulder", @"leftElbow", @"rightElbow", @"leftWrist", @"rightWrist", + @"leftHip", @"rightHip", @"leftKnee", @"rightKnee", @"leftAnkle", @"rightAnkle" +]; + +NSArray* _tflite_pose_chain = @[ + @[@"nose", @"leftEye"], @[@"leftEye", @"leftEar"], @[@"nose", @"rightEye"], + @[@"rightEye", @"rightEar"], @[@"nose", @"leftShoulder"], + @[@"leftShoulder", @"leftElbow"], @[@"leftElbow", @"leftWrist"], + @[@"leftShoulder", @"leftHip"], @[@"leftHip", @"leftKnee"], + @[@"leftKnee", @"leftAnkle"], @[@"nose", @"rightShoulder"], + @[@"rightShoulder", @"rightElbow"], @[@"rightElbow", @"rightWrist"], + @[@"rightShoulder", @"rightHip"], @[@"rightHip", @"rightKnee"], + @[@"rightKnee", @"rightAnkle"] +]; + +NSMutableDictionary* _tflite_parts_ids = [NSMutableDictionary dictionary]; +NSMutableArray* _tflite_parent_to_child_edges = [NSMutableArray array]; +NSMutableArray* _tflite_child_to_parent_edges = [NSMutableArray array]; +int _tflite_local_maximum_radius = 1; +int _tflite_output_stride = 16; +int _tflite_height; +int _tflite_width; +int _tflite_num_keypoints; + +void initPoseNet() { + if ([_tflite_parts_ids count] == 0) { + for (int i = 0; i < [_tflite_part_names count]; ++i) + [_tflite_parts_ids setValue:[NSNumber numberWithInt:i] forKey:_tflite_part_names[i]]; + + for (int i = 0; i < [_tflite_pose_chain count]; ++i) { + [_tflite_parent_to_child_edges addObject:_tflite_parts_ids[_tflite_pose_chain[i][1]]]; + [_tflite_child_to_parent_edges addObject:_tflite_parts_ids[_tflite_pose_chain[i][0]]]; + } + } +} + +bool scoreIsMaximumInLocalWindow(int keypoint_id, + float score, + int heatmap_y, + int heatmap_x, + int local_maximum_radius, + float* scores) { + bool local_maxium = true; + + int y_start = MAX(heatmap_y - local_maximum_radius, 0); + int y_end = MIN(heatmap_y + local_maximum_radius + 1, _tflite_height); + for (int y_current = y_start; y_current < y_end; ++y_current) { + int x_start = MAX(heatmap_x - local_maximum_radius, 0); + int x_end = MIN(heatmap_x + local_maximum_radius + 1, _tflite_width); + for (int x_current = x_start; x_current < x_end; ++x_current) { + if (sigmoid(scores[(y_current * _tflite_width + x_current) * _tflite_num_keypoints + keypoint_id]) > score) { + local_maxium = false; + break; + } + } + if (!local_maxium) { + break; + } + } + return local_maxium; +} + +typedef std::priority_queue, +std::vector>, +std::less>> PriorityQueue; + +PriorityQueue buildPartWithScoreQueue(float* scores, + float threshold, + int local_maximum_radius) { + PriorityQueue pq; + for (int heatmap_y = 0; heatmap_y < _tflite_height; ++heatmap_y) { + for (int heatmap_x = 0; heatmap_x < _tflite_width; ++heatmap_x) { + for (int keypoint_id = 0; keypoint_id < _tflite_num_keypoints; ++keypoint_id) { + float score = sigmoid(scores[(heatmap_y * _tflite_width + heatmap_x) * + _tflite_num_keypoints + keypoint_id]); + if (score < threshold) continue; + + if (scoreIsMaximumInLocalWindow(keypoint_id, score, heatmap_y, heatmap_x, + local_maximum_radius, scores)) { + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + [res setValue:[NSNumber numberWithFloat:score] forKey:@"score"]; + [res setValue:[NSNumber numberWithInt:heatmap_y] forKey:@"y"]; + [res setValue:[NSNumber numberWithInt:heatmap_x] forKey:@"x"]; + [res setValue:[NSNumber numberWithInt:keypoint_id] forKey:@"partId"]; + pq.push(std::pair(score, res)); + } + } + } + } + return pq; +} + +void getImageCoords(float* res, + NSMutableDictionary* keypoint, + float* offsets) { + int heatmap_y = [keypoint[@"y"] intValue]; + int heatmap_x = [keypoint[@"x"] intValue]; + int keypoint_id = [keypoint[@"partId"] intValue]; + + int offset = (heatmap_y * _tflite_width + heatmap_x) * _tflite_num_keypoints * 2 + keypoint_id; + float offset_y = offsets[offset]; + float offset_x = offsets[offset + _tflite_num_keypoints]; + res[0] = heatmap_y * _tflite_output_stride + offset_y; + res[1] = heatmap_x * _tflite_output_stride + offset_x; +} + + +bool withinNmsRadiusOfCorrespondingPoint(NSMutableArray* poses, + float squared_nms_radius, + float y, + float x, + int keypoint_id, + int input_size) { + for (NSMutableDictionary* pose in poses) { + NSMutableDictionary* keypoints = pose[@"keypoints"]; + NSMutableDictionary* correspondingKeypoint = keypoints[[NSNumber numberWithInt:keypoint_id]]; + float _x = [correspondingKeypoint[@"x"] floatValue] * input_size - x; + float _y = [correspondingKeypoint[@"y"] floatValue] * input_size - y; + float squaredDistance = _x * _x + _y * _y; + if (squaredDistance <= squared_nms_radius) + return true; + } + return false; +} + +void getStridedIndexNearPoint(int* res, float _y, float _x) { + int y_ = round(_y / _tflite_output_stride); + int x_ = round(_x / _tflite_output_stride); + int y = y_ < 0 ? 0 : y_ > _tflite_height - 1 ? _tflite_height - 1 : y_; + int x = x_ < 0 ? 0 : x_ > _tflite_width - 1 ? _tflite_width - 1 : x_; + res[0] = y; + res[1] = x; +} + +void getDisplacement(float* res, int edgeId, int* keypoint, float* displacements) { + int num_edges = (int)[_tflite_parent_to_child_edges count]; + int y = keypoint[0]; + int x = keypoint[1]; + int offset = (y * _tflite_width + x) * num_edges * 2 + edgeId; + res[0] = displacements[offset]; + res[1] = displacements[offset + num_edges]; +} + +float getInstanceScore(NSMutableDictionary* keypoints) { + float scores = 0; + for (NSMutableDictionary* keypoint in keypoints.allValues) + scores += [keypoint[@"score"] floatValue]; + return scores / _tflite_num_keypoints; +} + +NSMutableDictionary* traverseToTargetKeypoint(int edge_id, + NSMutableDictionary* source_keypoint, + int target_keypoint_id, + float* scores, + float* offsets, + float* displacements, + int input_size) { + float source_keypoint_y = [source_keypoint[@"y"] floatValue] * input_size; + float source_keypoint_x = [source_keypoint[@"x"] floatValue] * input_size; + + int source_keypoint_indices[2]; + getStridedIndexNearPoint(source_keypoint_indices, source_keypoint_y, source_keypoint_x); + + float displacement[2]; + getDisplacement(displacement, edge_id, source_keypoint_indices, displacements); + + float displaced_point[2]; + displaced_point[0] = source_keypoint_y + displacement[0]; + displaced_point[1] = source_keypoint_x + displacement[1]; + + float* target_keypoint = displaced_point; + + int offset_refine_step = 2; + for (int i = 0; i < offset_refine_step; i++) { + int target_keypoint_indices[2]; + getStridedIndexNearPoint(target_keypoint_indices, target_keypoint[0], target_keypoint[1]); + + int target_keypoint_y = target_keypoint_indices[0]; + int target_keypoint_x = target_keypoint_indices[1]; + + int offset = (target_keypoint_y * _tflite_width + target_keypoint_x) * _tflite_num_keypoints * 2 + target_keypoint_id; + float offset_y = offsets[offset]; + float offset_x = offsets[offset + _tflite_num_keypoints]; + + target_keypoint[0] = target_keypoint_y * _tflite_output_stride + offset_y; + target_keypoint[1] = target_keypoint_x * _tflite_output_stride + offset_x; + } + + int target_keypoint_indices[2]; + getStridedIndexNearPoint(target_keypoint_indices, target_keypoint[0], target_keypoint[1]); + + float score = sigmoid(scores[(target_keypoint_indices[0] * _tflite_width + + target_keypoint_indices[1]) * _tflite_num_keypoints + target_keypoint_id]); + + NSMutableDictionary* keypoint = [NSMutableDictionary dictionary]; + [keypoint setValue:[NSNumber numberWithFloat:score] forKey:@"score"]; + [keypoint setValue:[NSNumber numberWithFloat:target_keypoint[0] / input_size] forKey:@"y"]; + [keypoint setValue:[NSNumber numberWithFloat:target_keypoint[1] / input_size] forKey:@"x"]; + [keypoint setValue:_tflite_part_names[target_keypoint_id] forKey:@"part"]; + return keypoint; +} + +NSMutableArray* parsePoseNet(int num_results, float threshold, int nms_radius, int input_size) { + initPoseNet(); + +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 4); + const TfLiteTensor* scores_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + assert(interpreter->outputs().size() == 4); + TfLiteTensor* scores_tensor = interpreter->tensor(interpreter->outputs()[0]); +#endif + _tflite_height = scores_tensor->dims->data[1]; + _tflite_width = scores_tensor->dims->data[2]; + _tflite_num_keypoints = scores_tensor->dims->data[3]; + +#ifdef TFLITE2 + float* scores = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; + float* offsets = TfLiteInterpreterGetOutputTensor(interpreter, 1)->data.f; + float* displacements_fwd = TfLiteInterpreterGetOutputTensor(interpreter, 2)->data.f; + float* displacements_bwd = TfLiteInterpreterGetOutputTensor(interpreter, 3)->data.f; +#else + float* scores = interpreter->typed_output_tensor(0); + float* offsets = interpreter->typed_output_tensor(1); + float* displacements_fwd = interpreter->typed_output_tensor(2); + float* displacements_bwd = interpreter->typed_output_tensor(3); +#endif + PriorityQueue pq = buildPartWithScoreQueue(scores, threshold, _tflite_local_maximum_radius); + + int num_edges = (int)[_tflite_parent_to_child_edges count]; + int sqared_nms_radius = nms_radius * nms_radius; + + NSMutableArray* results = [NSMutableArray array]; + + while([results count] < num_results && !pq.empty()) { + NSMutableDictionary* root = pq.top().second; + pq.pop(); + + float root_point[2]; + getImageCoords(root_point, root, offsets); + + if (withinNmsRadiusOfCorrespondingPoint(results, sqared_nms_radius, root_point[0], root_point[1], + [root[@"partId"] intValue], input_size)) + continue; + + NSMutableDictionary* keypoint = [NSMutableDictionary dictionary]; + [keypoint setValue:[NSNumber numberWithFloat:[root[@"score"] floatValue]] forKey:@"score"]; + [keypoint setValue:[NSNumber numberWithFloat:root_point[0] / input_size] forKey:@"y"]; + [keypoint setValue:[NSNumber numberWithFloat:root_point[1] / input_size] forKey:@"x"]; + [keypoint setValue:_tflite_part_names[[root[@"partId"] intValue]] forKey:@"part"]; + + NSMutableDictionary* keypoints = [NSMutableDictionary dictionary]; + [keypoints setObject:keypoint forKey:root[@"partId"]]; + + for (int edge = num_edges - 1; edge >= 0; --edge) { + int source_keypoint_id = [_tflite_parent_to_child_edges[edge] intValue]; + int target_keypoint_id = [_tflite_child_to_parent_edges[edge] intValue]; + if (keypoints[[NSNumber numberWithInt:source_keypoint_id]] && + !(keypoints[[NSNumber numberWithInt:target_keypoint_id]])) { + keypoint = traverseToTargetKeypoint(edge, keypoints[[NSNumber numberWithInt:source_keypoint_id]], + target_keypoint_id, scores, offsets, displacements_bwd, input_size); + [keypoints setObject:keypoint forKey:[NSNumber numberWithInt:target_keypoint_id]]; + } + } + + for (int edge = 0; edge < num_edges; ++edge) { + int source_keypoint_id = [_tflite_child_to_parent_edges[edge] intValue]; + int target_keypoint_id = [_tflite_parent_to_child_edges[edge] intValue]; + if (keypoints[[NSNumber numberWithInt:source_keypoint_id]] && + !(keypoints[[NSNumber numberWithInt:target_keypoint_id]])) { + keypoint = traverseToTargetKeypoint(edge, keypoints[[NSNumber numberWithInt:source_keypoint_id]], + target_keypoint_id, scores, offsets, displacements_fwd, input_size); + [keypoints setObject:keypoint forKey:[NSNumber numberWithInt:target_keypoint_id]]; + } + } + + NSMutableDictionary* result = [NSMutableDictionary dictionary]; + [result setObject:keypoints forKey:@"keypoints"]; + [result setValue:[NSNumber numberWithFloat:getInstanceScore(keypoints)] forKey:@"score"]; + [results addObject:result]; + } + + return results; +} + +void runPoseNetOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void runPoseNetOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void runPoseNetOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void close() { +#ifdef TFLITE2 + interpreter = nullptr; + if (delegate != nullptr) + TFLGpuDelegateDelete(delegate); + delegate = nullptr; +#else + interpreter.release(); + interpreter = NULL; +#endif + model = NULL; + labels.clear(); +} + diff --git a/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.h b/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.h new file mode 100644 index 0000000..faec1be --- /dev/null +++ b/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.h @@ -0,0 +1,12 @@ +#include + +std::vector LoadImageFromFile(const char* file_name, + int* out_width, + int* out_height, + int* out_channels); + +NSData *CompressImage(NSMutableData*, + int width, + int height, + int bytesPerPixel); + diff --git a/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.mm b/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.mm new file mode 100644 index 0000000..421b702 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/ios/Classes/ios_image_load.mm @@ -0,0 +1,93 @@ +#import +#include "ios_image_load.h" + +#include +#include +#include +#include + +#import +#import + +std::vector LoadImageFromFile(const char* file_name, + int* out_width, int* out_height, + int* out_channels) { + FILE* file_handle = fopen(file_name, "rb"); + fseek(file_handle, 0, SEEK_END); + const size_t bytes_in_file = ftell(file_handle); + fseek(file_handle, 0, SEEK_SET); + std::vector file_data(bytes_in_file); + fread(file_data.data(), 1, bytes_in_file, file_handle); + fclose(file_handle); + + CFDataRef file_data_ref = CFDataCreateWithBytesNoCopy(NULL, file_data.data(), + bytes_in_file, + kCFAllocatorNull); + CGDataProviderRef image_provider = CGDataProviderCreateWithCFData(file_data_ref); + + const char* suffix = strrchr(file_name, '.'); + if (!suffix || suffix == file_name) { + suffix = ""; + } + CGImageRef image; + if (strcasecmp(suffix, ".png") == 0) { + image = CGImageCreateWithPNGDataProvider(image_provider, NULL, true, + kCGRenderingIntentDefault); + } else if ((strcasecmp(suffix, ".jpg") == 0) || + (strcasecmp(suffix, ".jpeg") == 0)) { + image = CGImageCreateWithJPEGDataProvider(image_provider, NULL, true, + kCGRenderingIntentDefault); + } else { + CFRelease(image_provider); + CFRelease(file_data_ref); + fprintf(stderr, "Unknown suffix for file '%s'\n", file_name); + out_width = 0; + out_height = 0; + *out_channels = 0; + return std::vector(); + } + + int width = (int)CGImageGetWidth(image); + int height = (int)CGImageGetHeight(image); + const int channels = 4; + CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); + const int bytes_per_row = (width * channels); + const int bytes_in_image = (bytes_per_row * height); + std::vector result(bytes_in_image); + const int bits_per_component = 8; + + CGContextRef context = CGBitmapContextCreate(result.data(), width, height, + bits_per_component, bytes_per_row, color_space, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(color_space); + CGContextDrawImage(context, CGRectMake(0, 0, width, height), image); + CGContextRelease(context); + CFRelease(image); + CFRelease(image_provider); + CFRelease(file_data_ref); + + *out_width = width; + *out_height = height; + *out_channels = channels; + return result; +} + +NSData *CompressImage(NSMutableData *image, int width, int height, int bytesPerPixel) { + const int channels = 4; + CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate([image mutableBytes], width, height, + bytesPerPixel*8, width*channels*bytesPerPixel, color_space, + kCGImageAlphaPremultipliedLast | (bytesPerPixel == 4 ? kCGBitmapFloatComponents : kCGBitmapByteOrder32Big)); + CGColorSpaceRelease(color_space); + if (context == nil) return nil; + + CGImageRef imgRef = CGBitmapContextCreateImage(context); + CGContextRelease(context); + if (imgRef == nil) return nil; + + UIImage* img = [UIImage imageWithCGImage:imgRef]; + CGImageRelease(imgRef); + if (img == nil) return nil; + + return UIImagePNGRepresentation(img); +} diff --git a/plugins/tflite_v2-1.0.0/ios/tflite.podspec b/plugins/tflite_v2-1.0.0/ios/tflite.podspec new file mode 100644 index 0000000..d91a6ef --- /dev/null +++ b/plugins/tflite_v2-1.0.0/ios/tflite.podspec @@ -0,0 +1,24 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'tflite' + s.version = '1.1.2' + s.summary = 'A Flutter plugin for accessing TensorFlow Lite.' + s.description = <<-DESC +A Flutter plugin for accessing TensorFlow Lite. Supports both iOS and Android. + DESC + s.homepage = 'https://github.com/shaqian/flutter_tflite' + s.license = { :file => '../LICENSE' } + s.author = { 'Qian Sha' => 'https://github.com/shaqian' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + s.dependency 'TensorFlowLiteC' + s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/tflite" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Flutter" "${PODS_ROOT}/Headers/Public/TensorFlowLite/tensorflow_lite" "${PODS_ROOT}/Headers/Public/tflite" "${PODS_ROOT}/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteC.framework/Headers"' } + + s.ios.deployment_target = '9.0' + s.static_framework = true +end + diff --git a/plugins/tflite_v2-1.0.0/lib/tflite_v2.dart b/plugins/tflite_v2-1.0.0/lib/tflite_v2.dart new file mode 100644 index 0000000..e7a74b4 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/lib/tflite_v2.dart @@ -0,0 +1,407 @@ +import 'dart:async'; +import 'package:flutter/services.dart'; + +class Tflite { + static const MethodChannel _channel = const MethodChannel('tflite'); + + static Future loadModel( + {required String model, + String labels = "", + int numThreads = 1, + bool isAsset = true, + bool useGpuDelegate = false}) async { + return await _channel.invokeMethod( + 'loadModel', + { + "model": model, + "labels": labels, + "numThreads": numThreads, + "isAsset": isAsset, + 'useGpuDelegate': useGpuDelegate + }, + ); + } + + static Future runModelOnImage( + {required String path, + double imageMean = 117.0, + double imageStd = 1.0, + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static Future runModelOnBinary( + {required Uint8List binary, + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnBinary', + { + "binary": binary, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static Future runModelOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + int rotation = 90, // Android only + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static const anchors = [ + 0.57273, + 0.677385, + 1.87446, + 2.06253, + 3.33843, + 5.47434, + 7.88282, + 3.52778, + 9.77052, + 9.16828 + ]; + + static Future detectObjectOnImage({ + required String path, + String model = "SSDMobileNet", + double imageMean = 127.5, + double imageStd = 127.5, + double threshold = 0.1, + int numResultsPerClass = 5, + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnImage', + { + "path": path, + "model": model, + "imageMean": imageMean, + "imageStd": imageStd, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future detectObjectOnBinary({ + required Uint8List binary, + String model = "SSDMobileNet", + double threshold = 0.1, + int numResultsPerClass = 5, + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnBinary', + { + "binary": binary, + "model": model, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future detectObjectOnFrame({ + required List bytesList, + String model = "SSDMobileNet", + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + double threshold = 0.1, + int numResultsPerClass = 5, + int rotation = 90, // Android only + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnFrame', + { + "bytesList": bytesList, + "model": model, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future close() async { + return await _channel.invokeMethod('close'); + } + + static Future runPix2PixOnImage( + {required String path, + double imageMean = 0, + double imageStd = 255.0, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPix2PixOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + static Future runPix2PixOnBinary( + {required Uint8List binary, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPix2PixOnBinary', + { + "binary": binary, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + static Future runPix2PixOnFrame({ + required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 0, + double imageStd = 255.0, + int rotation = 90, // Android only + String outputType = "png", + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'runPix2PixOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + // https://github.com/meetshah1995/pytorch-semseg/blob/master/ptsemseg/loader/pascal_voc_loader.py + static List pascalVOCLabelColors = [ + Color.fromARGB(255, 0, 0, 0).value, // background + Color.fromARGB(255, 128, 0, 0).value, // aeroplane + Color.fromARGB(255, 0, 128, 0).value, // biyclce + Color.fromARGB(255, 128, 128, 0).value, // bird + Color.fromARGB(255, 0, 0, 128).value, // boat + Color.fromARGB(255, 128, 0, 128).value, // bottle + Color.fromARGB(255, 0, 128, 128).value, // bus + Color.fromARGB(255, 128, 128, 128).value, // car + Color.fromARGB(255, 64, 0, 0).value, // cat + Color.fromARGB(255, 192, 0, 0).value, // chair + Color.fromARGB(255, 64, 128, 0).value, // cow + Color.fromARGB(255, 192, 128, 0).value, // diningtable + Color.fromARGB(255, 64, 0, 128).value, // dog + Color.fromARGB(255, 192, 0, 128).value, // horse + Color.fromARGB(255, 64, 128, 128).value, // motorbike + Color.fromARGB(255, 192, 128, 128).value, // person + Color.fromARGB(255, 0, 64, 0).value, // potted plant + Color.fromARGB(255, 128, 64, 0).value, // sheep + Color.fromARGB(255, 0, 192, 0).value, // sofa + Color.fromARGB(255, 128, 192, 0).value, // train + Color.fromARGB(255, 0, 64, 128).value, // tv-monitor + ]; + + static Future runSegmentationOnImage( + {required String path, + double imageMean = 0, + double imageStd = 255.0, + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runSegmentationOnBinary( + {required Uint8List binary, + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnBinary', + { + "binary": binary, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runSegmentationOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 0, + double imageStd = 255.0, + int rotation = 90, // Android only + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnImage( + {required String path, + double imageMean = 127.5, + double imageStd = 127.5, + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnBinary( + {required Uint8List binary, + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnBinary', + { + "binary": binary, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + int rotation = 90, // Android only + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } +} diff --git a/plugins/tflite_v2-1.0.0/pubspec.yaml b/plugins/tflite_v2-1.0.0/pubspec.yaml new file mode 100644 index 0000000..716d0b4 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/pubspec.yaml @@ -0,0 +1,64 @@ +name: tflite_v2 +description: A Flutter plugin for accessing TensorFlow Lite, fixed android embedding v2 error. Supports both iOS and Android. +version: 1.0.0 +homepage: https://github.com/Niketgoriya/flutter_tflite + +environment: + sdk: '>=2.12.0 <3.0.0' + flutter: ">=1.10.0" + +dependencies: + flutter: + sdk: flutter + + meta: ^1.3.0 + +dev_dependencies: + flutter_test: + sdk: flutter + test: ^1.16.5 + +# For information on the generic Dart part of this file, see the +# following page: https://www.dartlang.org/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + plugin: + platforms: + android: + package: sq.flutter.tflite + pluginClass: TflitePlugin + ios: + pluginClass: TflitePlugin + + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.io/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.io/assets-and-images/#resolution-aware. + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.io/custom-fonts/#from-packages diff --git a/plugins/tflite_v2-1.0.0/test/tflite_test.dart b/plugins/tflite_v2-1.0.0/test/tflite_test.dart new file mode 100644 index 0000000..acbf341 --- /dev/null +++ b/plugins/tflite_v2-1.0.0/test/tflite_test.dart @@ -0,0 +1,568 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:tflite_v2/tflite_v2.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + const MethodChannel channel = MethodChannel( + 'tflite', + ); + + final List log = []; + + setUp(() async { + channel.setMockMethodCallHandler((MethodCall methodCall) { + log.add(methodCall); + return null; + }); + log.clear(); + }); + test('loadModel', () async { + await Tflite.loadModel( + model: 'assets/mobilenet_v1_1.0_224.tflite', + labels: 'assets/mobilenet_v1_1.0_224.txt', + numThreads: 2, + isAsset: false, + useGpuDelegate: true, + ); + expect( + log, + [ + isMethodCall( + 'loadModel', + arguments: { + 'model': 'assets/mobilenet_v1_1.0_224.tflite', + 'labels': 'assets/mobilenet_v1_1.0_224.txt', + 'numThreads': 2, + 'isAsset': false, + 'useGpuDelegate': true, + }, + ), + ], + ); + }); + + test('runModelOnImage', () async { + await Tflite.runModelOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + numResults: 6, + threshold: 0.1, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'numResults': 6, + 'threshold': 0.1, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runModelOnBinary', () async { + await Tflite.runModelOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + numResults: 15, + threshold: 0.8, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'numResults': 15, + 'threshold': 0.8, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runModelOnFrame', () async { + await Tflite.runModelOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + numResults: 10, + threshold: 0.2, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'numResults': 10, + 'threshold': 0.2, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnImage', () async { + await Tflite.detectObjectOnImage( + path: '/image/path', + model: 'YOLO', + imageMean: 127.5, + imageStd: 0.5, + threshold: 0.1, + numResultsPerClass: 5, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnImage', + arguments: { + 'path': '/image/path', + 'model': 'YOLO', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'threshold': 0.1, + 'numResultsPerClass': 5, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnBinary', () async { + await Tflite.detectObjectOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + model: "YOLO", + threshold: 0.2, + numResultsPerClass: 10, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'model': "YOLO", + 'threshold': 0.2, + 'numResultsPerClass': 10, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnFrame', () async { + await Tflite.detectObjectOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + model: "YOLO", + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + threshold: 0.2, + numResultsPerClass: 10, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'model': "YOLO", + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'threshold': 0.2, + 'numResultsPerClass': 10, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnImage', () async { + await Tflite.runPix2PixOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnBinary', () async { + await Tflite.runPix2PixOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnFrame', () async { + await Tflite.runPix2PixOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnImage', () async { + await Tflite.runSegmentationOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnBinary', () async { + await Tflite.runSegmentationOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnFrame', () async { + await Tflite.runSegmentationOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); +} diff --git a/plugins/tflite_v2/CHANGELOG.md b/plugins/tflite_v2/CHANGELOG.md new file mode 100644 index 0000000..3c5c4d2 --- /dev/null +++ b/plugins/tflite_v2/CHANGELOG.md @@ -0,0 +1,74 @@ +## 1.1.2 + +- Add null safety support for Android + +## 1.1.1 + +- Fix error: ';' expected on Android + +## 1.1.0 + +- Upgrade to TensorFlowLiteObjC 2.2. +- Add support for GPU delegate. +- Fix label size for YOLO. + +## 1.0.6 + +* Add support for resources outside packaged assets. +* Upgrade version of Flutter SDK and Android Studio. +* Set mininum SDK version to 2.1.0 + +## 1.0.5 + +* Set compileSdkVersion to 28, fixing build error "Execution failed for task ':tflite:verifyReleaseResources'." +* Add notes about CONTRIB_PATH. +* Update pubspec.yaml for Flutter 1.10.0 and later. +* Update example app to use image plugin 2.1.4. + +## 1.0.4 + +* Add PoseNet support + +## 1.0.3 + +* Add an asynch option to offload the TfLite run from the UI thread +* Add Deeplab support + +## 1.0.2 + +* Add pix2pix support +* Make number of detections dynamic in Android + +## 1.0.1 + +* Add detectObjectOnBinary +* Add runModelOnFrame +* Add detectObjectOnFrame + +## 1.0.0 + +* Support Object Detection with SSD MobileNet and Tiny Yolov2. +* Updated to TensorFlow Lite API v1.12.0. +* No longer accepts parameter `inputSize` and `numChannels`. They will be retrieved from input tensor. +* `numThreads` is moved to `Tflite.loadModel`. + +## 0.0.5 + +* Support byte list: runModelOnBinary + +## 0.0.4 + +* Support Swift based project + +## 0.0.3 + +* Pass error message in channel in Android. +* Use non hard coded label size in iOS. + +## 0.0.2 + +* Fixed link. + +## 0.0.1 + +* Initial release. diff --git a/plugins/tflite_v2/LICENSE b/plugins/tflite_v2/LICENSE new file mode 100644 index 0000000..59c6ea2 --- /dev/null +++ b/plugins/tflite_v2/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 Qian Sha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/plugins/tflite_v2/README.md b/plugins/tflite_v2/README.md new file mode 100644 index 0000000..216b457 --- /dev/null +++ b/plugins/tflite_v2/README.md @@ -0,0 +1,513 @@ +# tflite + +A Flutter plugin for accessing TensorFlow Lite API. Supports image classification, object detection ([SSD](https://github.com/tensorflow/models/tree/master/research/object_detection) and [YOLO](https://pjreddie.com/darknet/yolov2/)), [Pix2Pix](https://phillipi.github.io/pix2pix/) and [Deeplab](https://github.com/tensorflow/models/tree/master/research/deeplab) and [PoseNet](https://www.tensorflow.org/lite/models/pose_estimation/overview) on both iOS and Android. + +### Table of Contents + +- [Installation](#Installation) +- [Usage](#Usage) + - [Image Classification](#Image-Classification) + - [Object Detection](#Object-Detection) + - [SSD MobileNet](#SSD-MobileNet) + - [YOLO](#Tiny-YOLOv2) + - [Pix2Pix](#Pix2Pix) + - [Deeplab](#Deeplab) + - [PoseNet](#PoseNet) +- [Example](#Example) + - [Prediction in Static Images](#Prediction-in-Static-Images) + - [Real-time Detection](#Real-time-Detection) + +### Breaking changes + +#### Since 1.1.0: + +1. iOS TensorFlow Lite library is upgraded from TensorFlowLite 1.x to TensorFlowLiteObjC 2.x. Changes to native code are denoted with `TFLITE2`. + +#### Since 1.0.0: + +1. Updated to TensorFlow Lite API v1.12.0. +2. No longer accepts parameter `inputSize` and `numChannels`. They will be retrieved from input tensor. +3. `numThreads` is moved to `Tflite.loadModel`. + +## Installation + +Add `tflite` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/). + +### Android + +In `android/app/build.gradle`, add the following setting in `android` block. + +``` + aaptOptions { + noCompress 'tflite' + noCompress 'lite' + } +``` + +### iOS + +Solutions to build errors on iOS: + +* 'vector' file not found" + + Open `ios/Runner.xcworkspace` in Xcode, click Runner > Tagets > Runner > Build Settings, search `Compile Sources As`, change the value to `Objective-C++` + +* 'tensorflow/lite/kernels/register.h' file not found + + The plugin assumes the tensorflow header files are located in path "tensorflow/lite/kernels". + + However, for early versions of tensorflow the header path is "tensorflow/contrib/lite/kernels". + + Use `CONTRIB_PATH` to toggle the path. Uncomment `//#define CONTRIB_PATH` from here: + https://github.com/shaqian/flutter_tflite/blob/master/ios/Classes/TflitePlugin.mm#L1 + +## Usage + +1. Create a `assets` folder and place your label file and model file in it. In `pubspec.yaml` add: + +``` + assets: + - assets/labels.txt + - assets/mobilenet_v1_1.0_224.tflite +``` + +2. Import the library: + +```dart +import 'package:tflite/tflite.dart'; +``` + +3. Load the model and labels: + +```dart +String res = await Tflite.loadModel( + model: "assets/mobilenet_v1_1.0_224.tflite", + labels: "assets/labels.txt", + numThreads: 1, // defaults to 1 + isAsset: true, // defaults to true, set to false to load resources outside assets + useGpuDelegate: false // defaults to false, set to true to use GPU delegate +); +``` + +4. See the section for the respective model below. + +5. Release resources: + +``` +await Tflite.close(); +``` + +### GPU Delegate + +When using GPU delegate, refer to [this step](https://www.tensorflow.org/lite/performance/gpu#step_5_release_mode) for release mode setting to get better performance. + +### Image Classification + +- Output format: +``` +{ + index: 0, + label: "person", + confidence: 0.629 +} +``` + +- Run on image: + +```dart +var recognitions = await Tflite.runModelOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 117.0 + imageStd: 255.0, // defaults to 1.0 + numResults: 2, // defaults to 5 + threshold: 0.2, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.runModelOnBinary( + binary: imageToByteListFloat32(image, 224, 127.5, 127.5),// required + numResults: 6, // defaults to 5 + threshold: 0.05, // defaults to 0.1 + asynch: true // defaults to true +); + +Uint8List imageToByteListFloat32( + img.Image image, int inputSize, double mean, double std) { + var convertedBytes = Float32List(1 * inputSize * inputSize * 3); + var buffer = Float32List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; + } + } + return convertedBytes.buffer.asUint8List(); +} + +Uint8List imageToByteListUint8(img.Image image, int inputSize) { + var convertedBytes = Uint8List(1 * inputSize * inputSize * 3); + var buffer = Uint8List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = img.getRed(pixel); + buffer[pixelIndex++] = img.getGreen(pixel); + buffer[pixelIndex++] = img.getBlue(pixel); + } + } + return convertedBytes.buffer.asUint8List(); +} +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.runModelOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, + imageWidth: img.width, + imageMean: 127.5, // defaults to 127.5 + imageStd: 127.5, // defaults to 127.5 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +### Object Detection + +- Output format: + +`x, y, w, h` are between [0, 1]. You can scale `x, w` by the width and `y, h` by the height of the image. + +``` +{ + detectedClass: "hot dog", + confidenceInClass: 0.123, + rect: { + x: 0.15, + y: 0.33, + w: 0.80, + h: 0.27 + } +} +``` + +#### SSD MobileNet: + +- Run on image: + +```dart +var recognitions = await Tflite.detectObjectOnImage( + path: filepath, // required + model: "SSDMobileNet", + imageMean: 127.5, + imageStd: 127.5, + threshold: 0.4, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.detectObjectOnBinary( + binary: imageToByteListUint8(resizedImage, 300), // required + model: "SSDMobileNet", + threshold: 0.4, // defaults to 0.1 + numResultsPerClass: 2, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.detectObjectOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + model: "SSDMobileNet", + imageHeight: img.height, + imageWidth: img.width, + imageMean: 127.5, // defaults to 127.5 + imageStd: 127.5, // defaults to 127.5 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + asynch: true // defaults to true +); +``` + +#### Tiny YOLOv2: + +- Run on image: + +```dart +var recognitions = await Tflite.detectObjectOnImage( + path: filepath, // required + model: "YOLO", + imageMean: 0.0, + imageStd: 255.0, + threshold: 0.3, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var recognitions = await Tflite.detectObjectOnBinary( + binary: imageToByteListFloat32(resizedImage, 416, 0.0, 255.0), // required + model: "YOLO", + threshold: 0.3, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +> Works with [camera plugin 4.0.0](https://pub.dartlang.org/packages/camera). Video format: (iOS) kCVPixelFormatType_32BGRA, (Android) YUV_420_888. + +```dart +var recognitions = await Tflite.detectObjectOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + model: "YOLO", + imageHeight: img.height, + imageWidth: img.width, + imageMean: 0, // defaults to 127.5 + imageStd: 255.0, // defaults to 127.5 + numResults: 2, // defaults to 5 + threshold: 0.1, // defaults to 0.1 + numResultsPerClass: 2,// defaults to 5 + anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828] + blockSize: 32, // defaults to 32 + numBoxesPerBlock: 5, // defaults to 5 + asynch: true // defaults to true +); +``` + +### Pix2Pix + +> Thanks to [RP](https://github.com/shaqian/flutter_tflite/pull/18) from [Green Appers](https://github.com/GreenAppers) + +- Output format: + + The output of Pix2Pix inference is Uint8List type. Depending on the `outputType` used, the output is: + + - (if outputType is png) byte array of a png image + + - (otherwise) byte array of the raw output + +- Run on image: + +```dart +var result = await runPix2PixOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 0.0 + imageStd: 255.0, // defaults to 255.0 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runPix2PixOnBinary( + binary: binary, // required + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runPix2PixOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 127.5, // defaults to 0.0 + imageStd: 127.5, // defaults to 255.0 + rotation: 90, // defaults to 90, Android only + asynch: true // defaults to true +); +``` + +### Deeplab + +> Thanks to [RP](https://github.com/shaqian/flutter_tflite/pull/22) from [see--](https://github.com/see--) for Android implementation. + +- Output format: + + The output of Deeplab inference is Uint8List type. Depending on the `outputType` used, the output is: + + - (if outputType is png) byte array of a png image + + - (otherwise) byte array of r, g, b, a values of the pixels + +- Run on image: + +```dart +var result = await runSegmentationOnImage( + path: filepath, // required + imageMean: 0.0, // defaults to 0.0 + imageStd: 255.0, // defaults to 255.0 + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runSegmentationOnBinary( + binary: binary, // required + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runSegmentationOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 127.5, // defaults to 0.0 + imageStd: 127.5, // defaults to 255.0 + rotation: 90, // defaults to 90, Android only + labelColors: [...], // defaults to https://github.com/shaqian/flutter_tflite/blob/master/lib/tflite.dart#L219 + outputType: "png", // defaults to "png" + asynch: true // defaults to true +); +``` + +### PoseNet + +> Model is from [StackOverflow thread](https://stackoverflow.com/a/55288616). + +- Output format: + +`x, y` are between [0, 1]. You can scale `x` by the width and `y` by the height of the image. + +``` +[ // array of poses/persons + { // pose #1 + score: 0.6324902, + keypoints: { + 0: { + x: 0.250, + y: 0.125, + part: nose, + score: 0.9971070 + }, + 1: { + x: 0.230, + y: 0.105, + part: leftEye, + score: 0.9978438 + } + ...... + } + }, + { // pose #2 + score: 0.32534285, + keypoints: { + 0: { + x: 0.402, + y: 0.538, + part: nose, + score: 0.8798978 + }, + 1: { + x: 0.380, + y: 0.513, + part: leftEye, + score: 0.7090239 + } + ...... + } + }, + ...... +] +``` + +- Run on image: + +```dart +var result = await runPoseNetOnImage( + path: filepath, // required + imageMean: 125.0, // defaults to 125.0 + imageStd: 125.0, // defaults to 125.0 + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +- Run on binary: + +```dart +var result = await runPoseNetOnBinary( + binary: binary, // required + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +- Run on image stream (video frame): + +```dart +var result = await runPoseNetOnFrame( + bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required + imageHeight: img.height, // defaults to 1280 + imageWidth: img.width, // defaults to 720 + imageMean: 125.0, // defaults to 125.0 + imageStd: 125.0, // defaults to 125.0 + rotation: 90, // defaults to 90, Android only + numResults: 2, // defaults to 5 + threshold: 0.7, // defaults to 0.5 + nmsRadius: 10, // defaults to 20 + asynch: true // defaults to true +); +``` + +## Example + +### Prediction in Static Images + + Refer to the [example](https://github.com/shaqian/flutter_tflite/tree/master/example). + +### Real-time detection + + Refer to [flutter_realtime_Detection](https://github.com/shaqian/flutter_realtime_detection). + +## Run test cases + +`flutter test test/tflite_test.dart` \ No newline at end of file diff --git a/plugins/tflite_v2/android/build.gradle b/plugins/tflite_v2/android/build.gradle new file mode 100644 index 0000000..ace2f02 --- /dev/null +++ b/plugins/tflite_v2/android/build.gradle @@ -0,0 +1,41 @@ +group 'sq.flutter.tflite' +version '1.0-SNAPSHOT' + +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:8.2.2' + } +} + +rootProject.allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' + +android { + namespace "sq.flutter.tflite" + compileSdk 34 + + defaultConfig { + minSdk 19 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + lint { + disable "InvalidPackage" + } + + dependencies { + implementation "org.tensorflow:tensorflow-lite:2.14.0" + implementation "org.tensorflow:tensorflow-lite-gpu:2.14.0" + } +} diff --git a/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml b/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml new file mode 100644 index 0000000..958d677 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json b/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json new file mode 100644 index 0000000..1c292f0 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json @@ -0,0 +1,18 @@ +{ + "version": 3, + "artifactType": { + "type": "AAPT_FRIENDLY_MERGED_MANIFESTS", + "kind": "Directory" + }, + "applicationId": "sq.flutter.tflite", + "variantName": "debug", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "attributes": [], + "outputFile": "AndroidManifest.xml" + } + ], + "elementType": "File" +} \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/aar_metadata/debug/aar-metadata.properties b/plugins/tflite_v2/android/build/intermediates/aar_metadata/debug/aar-metadata.properties new file mode 100644 index 0000000..776557e --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/aar_metadata/debug/aar-metadata.properties @@ -0,0 +1,5 @@ +aarFormatVersion=1.0 +aarMetadataVersion=1.0 +minCompileSdk=1 +minCompileSdkExtension=0 +minAndroidGradlePluginVersion=1.0.0 diff --git a/plugins/tflite_v2/android/build/intermediates/compile_r_class_jar/debug/R.jar b/plugins/tflite_v2/android/build/intermediates/compile_r_class_jar/debug/R.jar new file mode 100644 index 0000000..0a26c8f Binary files /dev/null and b/plugins/tflite_v2/android/build/intermediates/compile_r_class_jar/debug/R.jar differ diff --git a/plugins/tflite_v2/android/build/intermediates/compile_symbol_list/debug/R.txt b/plugins/tflite_v2/android/build/intermediates/compile_symbol_list/debug/R.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties b/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties new file mode 100644 index 0000000..494802b --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties @@ -0,0 +1 @@ +#Wed Dec 31 13:31:17 WIB 2025 diff --git a/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml b/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml new file mode 100644 index 0000000..e3a941d --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/incremental/mergeDebugShaders/merger.xml b/plugins/tflite_v2/android/build/intermediates/incremental/mergeDebugShaders/merger.xml new file mode 100644 index 0000000..edf9849 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/incremental/mergeDebugShaders/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/incremental/packageDebugAssets/merger.xml b/plugins/tflite_v2/android/build/intermediates/incremental/packageDebugAssets/merger.xml new file mode 100644 index 0000000..857dc88 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/incremental/packageDebugAssets/merger.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/local_only_symbol_list/debug/R-def.txt b/plugins/tflite_v2/android/build/intermediates/local_only_symbol_list/debug/R-def.txt new file mode 100644 index 0000000..78ac5b8 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/local_only_symbol_list/debug/R-def.txt @@ -0,0 +1,2 @@ +R_DEF: Internal format may change without notice +local diff --git a/plugins/tflite_v2/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt b/plugins/tflite_v2/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt new file mode 100644 index 0000000..a354e08 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt @@ -0,0 +1,7 @@ +1 +2 +4 +5 +6 +7 diff --git a/plugins/tflite_v2/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml b/plugins/tflite_v2/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml new file mode 100644 index 0000000..958d677 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/navigation_json/debug/navigation.json b/plugins/tflite_v2/android/build/intermediates/navigation_json/debug/navigation.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/navigation_json/debug/navigation.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/plugins/tflite_v2/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt b/plugins/tflite_v2/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt new file mode 100644 index 0000000..3388a3e --- /dev/null +++ b/plugins/tflite_v2/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt @@ -0,0 +1 @@ +sq.flutter.tflite diff --git a/plugins/tflite_v2/android/build/outputs/logs/manifest-merger-debug-report.txt b/plugins/tflite_v2/android/build/outputs/logs/manifest-merger-debug-report.txt new file mode 100644 index 0000000..44c0191 --- /dev/null +++ b/plugins/tflite_v2/android/build/outputs/logs/manifest-merger-debug-report.txt @@ -0,0 +1,17 @@ +-- Merging decision tree log --- +manifest +ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:1-3:12 +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:1-3:12 + package + ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:2:3-30 + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + xmlns:android + ADDED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml:1:11-69 +uses-sdk +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml reason: use-sdk injection requested +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml +INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + android:targetSdkVersion + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml + android:minSdkVersion + INJECTED from C:\Users\septi\AppData\Local\Pub\Cache\hosted\pub.dev\tflite_v2-1.0.0\android\src\main\AndroidManifest.xml diff --git a/plugins/tflite_v2/android/gradle.properties b/plugins/tflite_v2/android/gradle.properties new file mode 100644 index 0000000..4167249 --- /dev/null +++ b/plugins/tflite_v2/android/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true +android.enableR8=true \ No newline at end of file diff --git a/plugins/tflite_v2/android/settings.gradle b/plugins/tflite_v2/android/settings.gradle new file mode 100644 index 0000000..cf4f116 --- /dev/null +++ b/plugins/tflite_v2/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'tflite' diff --git a/plugins/tflite_v2/android/src/main/AndroidManifest.xml b/plugins/tflite_v2/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a2f47b6 --- /dev/null +++ b/plugins/tflite_v2/android/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/plugins/tflite_v2/android/src/main/java/sq/flutter/tflite/TflitePlugin.java b/plugins/tflite_v2/android/src/main/java/sq/flutter/tflite/TflitePlugin.java new file mode 100644 index 0000000..54582c1 --- /dev/null +++ b/plugins/tflite_v2/android/src/main/java/sq/flutter/tflite/TflitePlugin.java @@ -0,0 +1,1622 @@ +package sq.flutter.tflite; + +import android.app.Activity; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.os.SystemClock; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.ScriptIntrinsicYuvToRGB; +import android.renderscript.Type; +import android.util.Log; + +import androidx.annotation.NonNull; + +import io.flutter.FlutterInjector; +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.loader.FlutterLoader; +import io.flutter.embedding.engine.plugins.activity.ActivityAware; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.PluginRegistry; + +import org.tensorflow.lite.DataType; +import org.tensorflow.lite.Interpreter; +import org.tensorflow.lite.Tensor; + +import org.tensorflow.lite.gpu.GpuDelegate; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Vector; + + +public class TflitePlugin implements FlutterPlugin, MethodCallHandler, ActivityAware { + private Activity activity; + private Interpreter tfLite; + private boolean tfLiteBusy = false; + private int inputSize = 0; + private Vector labels; + float[][] labelProb; + private static final int BYTES_PER_CHANNEL = 4; + + String[] partNames = { + "nose", "leftEye", "rightEye", "leftEar", "rightEar", "leftShoulder", + "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", + "leftHip", "rightHip", "leftKnee", "rightKnee", "leftAnkle", "rightAnkle" + }; + + String[][] poseChain = { + {"nose", "leftEye"}, {"leftEye", "leftEar"}, {"nose", "rightEye"}, + {"rightEye", "rightEar"}, {"nose", "leftShoulder"}, + {"leftShoulder", "leftElbow"}, {"leftElbow", "leftWrist"}, + {"leftShoulder", "leftHip"}, {"leftHip", "leftKnee"}, + {"leftKnee", "leftAnkle"}, {"nose", "rightShoulder"}, + {"rightShoulder", "rightElbow"}, {"rightElbow", "rightWrist"}, + {"rightShoulder", "rightHip"}, {"rightHip", "rightKnee"}, + {"rightKnee", "rightAnkle"} + }; + + Map partsIds = new HashMap<>(); + List parentToChildEdges = new ArrayList<>(); + List childToParentEdges = new ArrayList<>(); + + private MethodChannel channel; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "tflite"); + channel.setMethodCallHandler(this); + } + + @Override + public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) { + activity = binding.getActivity(); + } + + @Override + public void onDetachedFromActivity() { + activity = null; + } + + @Override + public void onDetachedFromActivityForConfigChanges() { + this.onDetachedFromActivity(); + } + + @Override + public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { + this.onAttachedToActivity(binding); + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + if (call.method.equals("loadModel")) { + try { + String res = loadModel((HashMap) call.arguments); + result.success(res); + } catch (Exception e) { + result.error("Failed to load model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnImage")) { + try { + new RunModelOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnBinary")) { + try { + new RunModelOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runModelOnFrame")) { + try { + new RunModelOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnImage")) { + try { + detectObjectOnImage((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnBinary")) { + try { + detectObjectOnBinary((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("detectObjectOnFrame")) { + try { + detectObjectOnFrame((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("close")) { + close(); + } else if (call.method.equals("runPix2PixOnImage")) { + try { + new RunPix2PixOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPix2PixOnBinary")) { + try { + new RunPix2PixOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPix2PixOnFrame")) { + try { + new RunPix2PixOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnImage")) { + try { + new RunSegmentationOnImage((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnBinary")) { + try { + new RunSegmentationOnBinary((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runSegmentationOnFrame")) { + try { + new RunSegmentationOnFrame((HashMap) call.arguments, result).executeTfliteTask(); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnImage")) { + try { + runPoseNetOnImage((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnBinary")) { + try { + runPoseNetOnBinary((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else if (call.method.equals("runPoseNetOnFrame")) { + try { + runPoseNetOnFrame((HashMap) call.arguments, result); + } catch (Exception e) { + result.error("Failed to run model", e.getMessage(), e); + } + } else { + result.error("Invalid method", call.method.toString(), ""); + } + } + + private String loadModel(HashMap args) throws IOException { + String model = args.get("model").toString(); + Object isAssetObj = args.get("isAsset"); + boolean isAsset = isAssetObj == null ? false : (boolean) isAssetObj; + MappedByteBuffer buffer = null; + String key = null; + AssetManager assetManager = null; + if (isAsset) { + assetManager = activity.getApplicationContext().getAssets(); + FlutterLoader loader = FlutterInjector.instance().flutterLoader(); + key = loader.getLookupKeyForAsset(model); + AssetFileDescriptor fileDescriptor = assetManager.openFd(key); + FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); + FileChannel fileChannel = inputStream.getChannel(); + long startOffset = fileDescriptor.getStartOffset(); + long declaredLength = fileDescriptor.getDeclaredLength(); + buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); + } else { + FileInputStream inputStream = new FileInputStream(new File(model)); + FileChannel fileChannel = inputStream.getChannel(); + long declaredLength = fileChannel.size(); + buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, declaredLength); + } + + int numThreads = (int) args.get("numThreads"); + Boolean useGpuDelegate = (Boolean) args.get("useGpuDelegate"); + if (useGpuDelegate == null) { + useGpuDelegate = false; + } + + final Interpreter.Options tfliteOptions = new Interpreter.Options(); + tfliteOptions.setNumThreads(numThreads); + if (useGpuDelegate){ + GpuDelegate delegate = new GpuDelegate(); + tfliteOptions.addDelegate(delegate); + } + tfLite = new Interpreter(buffer, tfliteOptions); + + String labels = args.get("labels").toString(); + + if (labels.length() > 0) { + if (isAsset) { + FlutterLoader loader = FlutterInjector.instance().flutterLoader(); + key = loader.getLookupKeyForAsset(labels); + loadLabels(assetManager, key); + } else { + loadLabels(null, labels); + } + } + + return "success"; + } + + private void loadLabels(AssetManager assetManager, String path) { + BufferedReader br; + try { + if (assetManager != null) { + br = new BufferedReader(new InputStreamReader(assetManager.open(path))); + } else { + br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path)))); + } + String line; + labels = new Vector<>(); + while ((line = br.readLine()) != null) { + labels.add(line); + } + labelProb = new float[1][labels.size()]; + br.close(); + } catch (IOException e) { + throw new RuntimeException("Failed to read label file", e); + } + } + + private List> GetTopN(int numResults, float threshold) { + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("confidence"), (float) lhs.get("confidence")); + } + }); + + for (int i = 0; i < labels.size(); ++i) { + float confidence = labelProb[0][i]; + if (confidence > threshold) { + Map res = new HashMap<>(); + res.put("index", i); + res.put("label", labels.size() > i ? labels.get(i) : "unknown"); + res.put("confidence", confidence); + pq.add(res); + } + } + + final ArrayList> recognitions = new ArrayList<>(); + int recognitionsSize = Math.min(pq.size(), numResults); + for (int i = 0; i < recognitionsSize; ++i) { + recognitions.add(pq.poll()); + } + + return recognitions; + } + + Bitmap feedOutput(ByteBuffer imgData, float mean, float std) { + Tensor tensor = tfLite.getOutputTensor(0); + int outputSize = tensor.shape()[1]; + Bitmap bitmapRaw = Bitmap.createBitmap(outputSize, outputSize, Bitmap.Config.ARGB_8888); + + if (tensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < outputSize; ++i) { + for (int j = 0; j < outputSize; ++j) { + int pixelValue = 0xFF << 24; + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF) << 16); + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF) << 8); + pixelValue |= ((Math.round(imgData.getFloat() * std + mean) & 0xFF)); + bitmapRaw.setPixel(j, i, pixelValue); + } + } + } else { + for (int i = 0; i < outputSize; ++i) { + for (int j = 0; j < outputSize; ++j) { + int pixelValue = 0xFF << 24; + pixelValue |= ((imgData.get() & 0xFF) << 16); + pixelValue |= ((imgData.get() & 0xFF) << 8); + pixelValue |= ((imgData.get() & 0xFF)); + bitmapRaw.setPixel(j, i, pixelValue); + } + } + } + return bitmapRaw; + } + + ByteBuffer feedInputTensor(Bitmap bitmapRaw, float mean, float std) throws IOException { + Tensor tensor = tfLite.getInputTensor(0); + int[] shape = tensor.shape(); + inputSize = shape[1]; + int inputChannels = shape[3]; + + int bytePerChannel = tensor.dataType() == DataType.UINT8 ? 1 : BYTES_PER_CHANNEL; + ByteBuffer imgData = ByteBuffer.allocateDirect(1 * inputSize * inputSize * inputChannels * bytePerChannel); + imgData.order(ByteOrder.nativeOrder()); + + Bitmap bitmap = bitmapRaw; + if (bitmapRaw.getWidth() != inputSize || bitmapRaw.getHeight() != inputSize) { + Matrix matrix = getTransformationMatrix(bitmapRaw.getWidth(), bitmapRaw.getHeight(), + inputSize, inputSize, false); + bitmap = Bitmap.createBitmap(inputSize, inputSize, Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(bitmap); + if (inputChannels == 1){ + Paint paint = new Paint(); + ColorMatrix cm = new ColorMatrix(); + cm.setSaturation(0); + ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); + paint.setColorFilter(f); + canvas.drawBitmap(bitmapRaw, matrix, paint); + } else { + canvas.drawBitmap(bitmapRaw, matrix, null); + } + } + + if (tensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < inputSize; ++i) { + for (int j = 0; j < inputSize; ++j) { + int pixelValue = bitmap.getPixel(j, i); + if (inputChannels > 1){ + imgData.putFloat((((pixelValue >> 16) & 0xFF) - mean) / std); + imgData.putFloat((((pixelValue >> 8) & 0xFF) - mean) / std); + imgData.putFloat(((pixelValue & 0xFF) - mean) / std); + } else { + imgData.putFloat((((pixelValue >> 16 | pixelValue >> 8 | pixelValue) & 0xFF) - mean) / std); + } + } + } + } else { + for (int i = 0; i < inputSize; ++i) { + for (int j = 0; j < inputSize; ++j) { + int pixelValue = bitmap.getPixel(j, i); + if (inputChannels > 1){ + imgData.put((byte) ((pixelValue >> 16) & 0xFF)); + imgData.put((byte) ((pixelValue >> 8) & 0xFF)); + imgData.put((byte) (pixelValue & 0xFF)); + } else { + imgData.put((byte) ((pixelValue >> 16 | pixelValue >> 8 | pixelValue) & 0xFF)); + } + } + } + } + + return imgData; + } + + ByteBuffer feedInputTensorImage(String path, float mean, float std) throws IOException { + InputStream inputStream = new FileInputStream(path.replace("file://", "")); + Bitmap bitmapRaw = BitmapFactory.decodeStream(inputStream); + + return feedInputTensor(bitmapRaw, mean, std); + } + + ByteBuffer feedInputTensorFrame(List bytesList, int imageHeight, int imageWidth, float mean, float std, int rotation) throws IOException { + ByteBuffer Y = ByteBuffer.wrap(bytesList.get(0)); + ByteBuffer U = ByteBuffer.wrap(bytesList.get(1)); + ByteBuffer V = ByteBuffer.wrap(bytesList.get(2)); + + int Yb = Y.remaining(); + int Ub = U.remaining(); + int Vb = V.remaining(); + + byte[] data = new byte[Yb + Ub + Vb]; + + Y.get(data, 0, Yb); + V.get(data, Yb, Vb); + U.get(data, Yb + Vb, Ub); + + Bitmap bitmapRaw = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888); + Allocation bmData = renderScriptNV21ToRGBA888( + activity.getApplicationContext(), + imageWidth, + imageHeight, + data); + bmData.copyTo(bitmapRaw); + + Matrix matrix = new Matrix(); + matrix.postRotate(rotation); + bitmapRaw = Bitmap.createBitmap(bitmapRaw, 0, 0, bitmapRaw.getWidth(), bitmapRaw.getHeight(), matrix, true); + + return feedInputTensor(bitmapRaw, mean, std); + } + + public Allocation renderScriptNV21ToRGBA888(Context context, int width, int height, byte[] nv21) { + // https://stackoverflow.com/a/36409748 + RenderScript rs = RenderScript.create(context); + ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs)); + + Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length); + Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT); + + Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height); + Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT); + + in.copyFrom(nv21); + + yuvToRgbIntrinsic.setInput(in); + yuvToRgbIntrinsic.forEach(out); + return out; + } + + private abstract class TfliteTask extends AsyncTask { + Result result; + boolean asynch; + + TfliteTask(HashMap args, Result result) { + if (tfLiteBusy) throw new RuntimeException("Interpreter busy"); + else tfLiteBusy = true; + Object asynch = args.get("asynch"); + this.asynch = asynch == null ? false : (boolean) asynch; + this.result = result; + } + + abstract void runTflite(); + + abstract void onRunTfliteDone(); + + public void executeTfliteTask() { + if (asynch) execute(); + else { + runTflite(); + tfLiteBusy = false; + onRunTfliteDone(); + } + } + + protected Void doInBackground(Void... backgroundArguments) { + runTflite(); + return null; + } + + protected void onPostExecute(Void backgroundResult) { + tfLiteBusy = false; + onRunTfliteDone(); + } + } + + private class RunModelOnImage extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + ByteBuffer input; + long startTime; + + RunModelOnImage(HashMap args, Result result) throws IOException { + super(args, result); + + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + } + + protected void runTflite() { + tfLite.run(input, labelProb); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + private class RunModelOnBinary extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + ByteBuffer imgData; + + RunModelOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + + byte[] binary = (byte[]) args.get("binary"); + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + imgData = ByteBuffer.wrap(binary); + } + + protected void runTflite() { + tfLite.run(imgData, labelProb); + } + + protected void onRunTfliteDone() { + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + private class RunModelOnFrame extends TfliteTask { + int NUM_RESULTS; + float THRESHOLD; + long startTime; + ByteBuffer imgData; + + RunModelOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + NUM_RESULTS = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + THRESHOLD = (float) threshold; + + startTime = SystemClock.uptimeMillis(); + + imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + } + + protected void runTflite() { + tfLite.run(imgData, labelProb); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + result.success(GetTopN(NUM_RESULTS, THRESHOLD)); + } + } + + void detectObjectOnImage(HashMap args, Result result) throws IOException { + String path = args.get("path").toString(); + String model = args.get("model").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + ByteBuffer imgData = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + void detectObjectOnBinary(HashMap args, Result result) throws IOException { + byte[] binary = (byte[]) args.get("binary"); + String model = args.get("model").toString(); + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + ByteBuffer imgData = ByteBuffer.wrap(binary); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + void detectObjectOnFrame(HashMap args, Result result) throws IOException { + List bytesList = (ArrayList) args.get("bytesList"); + String model = args.get("model").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + double threshold = (double) args.get("threshold"); + float THRESHOLD = (float) threshold; + int NUM_RESULTS_PER_CLASS = (int) args.get("numResultsPerClass"); + + List ANCHORS = (ArrayList) args.get("anchors"); + int BLOCK_SIZE = (int) args.get("blockSize"); + int NUM_BOXES_PER_BLOCK = (int) args.get("numBoxesPerBlock"); + + ByteBuffer imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + + if (model.equals("SSDMobileNet")) { + new RunSSDMobileNet(args, imgData, NUM_RESULTS_PER_CLASS, THRESHOLD, result).executeTfliteTask(); + } else { + new RunYOLO(args, imgData, BLOCK_SIZE, NUM_BOXES_PER_BLOCK, ANCHORS, THRESHOLD, NUM_RESULTS_PER_CLASS, result).executeTfliteTask(); + } + } + + private class RunSSDMobileNet extends TfliteTask { + int num; + int numResultsPerClass; + float threshold; + float[][][] outputLocations; + float[][] outputClasses; + float[][] outputScores; + float[] numDetections = new float[1]; + Object[] inputArray; + Map outputMap = new HashMap<>(); + long startTime; + + RunSSDMobileNet(HashMap args, ByteBuffer imgData, int numResultsPerClass, float threshold, Result result) { + super(args, result); + this.num = tfLite.getOutputTensor(0).shape()[1]; + this.numResultsPerClass = numResultsPerClass; + this.threshold = threshold; + this.outputLocations = new float[1][num][4]; + this.outputClasses = new float[1][num]; + this.outputScores = new float[1][num]; + this.inputArray = new Object[]{imgData}; + + outputMap.put(0, outputLocations); + outputMap.put(1, outputClasses); + outputMap.put(2, outputScores); + outputMap.put(3, numDetections); + + startTime = SystemClock.uptimeMillis(); + } + + protected void runTflite() { + tfLite.runForMultipleInputsOutputs(inputArray, outputMap); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + Map counters = new HashMap<>(); + final List> results = new ArrayList<>(); + + for (int i = 0; i < numDetections[0]; ++i) { + if (outputScores[0][i] < threshold) continue; + + String detectedClass = labels.get((int) outputClasses[0][i] + 1); + + if (counters.get(detectedClass) == null) { + counters.put(detectedClass, 1); + } else { + int count = counters.get(detectedClass); + if (count >= numResultsPerClass) { + continue; + } else { + counters.put(detectedClass, count + 1); + } + } + + Map rect = new HashMap<>(); + float ymin = Math.max(0, outputLocations[0][i][0]); + float xmin = Math.max(0, outputLocations[0][i][1]); + float ymax = outputLocations[0][i][2]; + float xmax = outputLocations[0][i][3]; + rect.put("x", xmin); + rect.put("y", ymin); + rect.put("w", Math.min(1 - xmin, xmax - xmin)); + rect.put("h", Math.min(1 - ymin, ymax - ymin)); + + Map ret = new HashMap<>(); + ret.put("rect", rect); + ret.put("confidenceInClass", outputScores[0][i]); + ret.put("detectedClass", detectedClass); + + results.add(ret); + } + + result.success(results); + } + } + + private class RunYOLO extends TfliteTask { + ByteBuffer imgData; + int blockSize; + int numBoxesPerBlock; + List anchors; + float threshold; + int numResultsPerClass; + long startTime; + int gridSize; + int numClasses; + final float[][][][] output; + + RunYOLO(HashMap args, + ByteBuffer imgData, + int blockSize, + int numBoxesPerBlock, + List anchors, + float threshold, + int numResultsPerClass, + Result result) { + super(args, result); + this.imgData = imgData; + this.blockSize = blockSize; + this.numBoxesPerBlock = numBoxesPerBlock; + this.anchors = anchors; + this.threshold = threshold; + this.numResultsPerClass = numResultsPerClass; + this.startTime = SystemClock.uptimeMillis(); + + Tensor tensor = tfLite.getInputTensor(0); + inputSize = tensor.shape()[1]; + + this.gridSize = inputSize / blockSize; + this.numClasses = labels.size(); + this.output = new float[1][gridSize][gridSize][(numClasses + 5) * numBoxesPerBlock]; + } + + protected void runTflite() { + tfLite.run(imgData, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("confidenceInClass"), (float) lhs.get("confidenceInClass")); + } + }); + + for (int y = 0; y < gridSize; ++y) { + for (int x = 0; x < gridSize; ++x) { + for (int b = 0; b < numBoxesPerBlock; ++b) { + final int offset = (numClasses + 5) * b; + + final float confidence = sigmoid(output[0][y][x][offset + 4]); + + final float[] classes = new float[numClasses]; + for (int c = 0; c < numClasses; ++c) { + classes[c] = output[0][y][x][offset + 5 + c]; + } + softmax(classes); + + int detectedClass = -1; + float maxClass = 0; + for (int c = 0; c < numClasses; ++c) { + if (classes[c] > maxClass) { + detectedClass = c; + maxClass = classes[c]; + } + } + + final float confidenceInClass = maxClass * confidence; + if (confidenceInClass > threshold) { + final float xPos = (x + sigmoid(output[0][y][x][offset + 0])) * blockSize; + final float yPos = (y + sigmoid(output[0][y][x][offset + 1])) * blockSize; + + final float w = (float) (Math.exp(output[0][y][x][offset + 2]) * anchors.get(2 * b + 0)) * blockSize; + final float h = (float) (Math.exp(output[0][y][x][offset + 3]) * anchors.get(2 * b + 1)) * blockSize; + + final float xmin = Math.max(0, (xPos - w / 2) / inputSize); + final float ymin = Math.max(0, (yPos - h / 2) / inputSize); + + Map rect = new HashMap<>(); + rect.put("x", xmin); + rect.put("y", ymin); + rect.put("w", Math.min(1 - xmin, w / inputSize)); + rect.put("h", Math.min(1 - ymin, h / inputSize)); + + Map ret = new HashMap<>(); + ret.put("rect", rect); + ret.put("confidenceInClass", confidenceInClass); + ret.put("detectedClass", labels.get(detectedClass)); + + pq.add(ret); + } + } + } + } + + Map counters = new HashMap<>(); + List> results = new ArrayList<>(); + + for (int i = 0; i < pq.size(); ++i) { + Map ret = pq.poll(); + String detectedClass = ret.get("detectedClass").toString(); + + if (counters.get(detectedClass) == null) { + counters.put(detectedClass, 1); + } else { + int count = counters.get(detectedClass); + if (count >= numResultsPerClass) { + continue; + } else { + counters.put(detectedClass, count + 1); + } + } + results.add(ret); + } + result.success(results); + } + } + + private class RunPix2PixOnImage extends TfliteTask { + String path, outputType; + float IMAGE_MEAN, IMAGE_STD; + long startTime; + ByteBuffer input, output; + + RunPix2PixOnImage(HashMap args, Result result) throws IOException { + super(args, result); + path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + IMAGE_STD = (float) std; + + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + Bitmap bitmapRaw = feedOutput(output, IMAGE_MEAN, IMAGE_STD); + + if (outputType.equals("png")) { + result.success(compressPNG(bitmapRaw)); + } else { + result.success(bitmapRaw); + } + } + } + + private class RunPix2PixOnBinary extends TfliteTask { + long startTime; + String outputType; + ByteBuffer input, output; + + RunPix2PixOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + byte[] binary = (byte[]) args.get("binary"); + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = ByteBuffer.wrap(binary); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + result.success(output.array()); + } + } + + private class RunPix2PixOnFrame extends TfliteTask { + long startTime; + String outputType; + float IMAGE_MEAN, IMAGE_STD; + ByteBuffer input, output; + + RunPix2PixOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + + outputType = args.get("outputType").toString(); + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + output = ByteBuffer.allocateDirect(input.limit()); + output.order(ByteOrder.nativeOrder()); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != 0) { + result.error("Unexpected output position", null, null); + return; + } + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Generating took " + (SystemClock.uptimeMillis() - startTime)); + if (output.position() != input.limit()) { + result.error("Mismatching input/output position", null, null); + return; + } + + output.flip(); + Bitmap bitmapRaw = feedOutput(output, IMAGE_MEAN, IMAGE_STD); + + if (outputType.equals("png")) { + result.success(compressPNG(bitmapRaw)); + } else { + result.success(bitmapRaw); + } + } + } + + private class RunSegmentationOnImage extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnImage(HashMap args, Result result) throws IOException { + super(args, result); + + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + private class RunSegmentationOnBinary extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnBinary(HashMap args, Result result) throws IOException { + super(args, result); + + byte[] binary = (byte[]) args.get("binary"); + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = ByteBuffer.wrap(binary); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + private class RunSegmentationOnFrame extends TfliteTask { + List labelColors; + String outputType; + long startTime; + ByteBuffer input, output; + + RunSegmentationOnFrame(HashMap args, Result result) throws IOException { + super(args, result); + + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + labelColors = (ArrayList) args.get("labelColors"); + outputType = args.get("outputType").toString(); + + startTime = SystemClock.uptimeMillis(); + input = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + output = ByteBuffer.allocateDirect(tfLite.getOutputTensor(0).numBytes()); + output.order(ByteOrder.nativeOrder()); + } + + protected void runTflite() { + tfLite.run(input, output); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + if (input.limit() == 0) { + result.error("Unexpected input position, bad file?", null, null); + return; + } + if (output.position() != output.limit()) { + result.error("Unexpected output position", null, null); + return; + } + output.flip(); + + result.success(fetchArgmax(output, labelColors, outputType)); + } + } + + + byte[] fetchArgmax(ByteBuffer output, List labelColors, String outputType) { + Tensor outputTensor = tfLite.getOutputTensor(0); + int outputBatchSize = outputTensor.shape()[0]; + assert outputBatchSize == 1; + int outputHeight = outputTensor.shape()[1]; + int outputWidth = outputTensor.shape()[2]; + int outputChannels = outputTensor.shape()[3]; + + Bitmap outputArgmax = null; + byte[] outputBytes = new byte[outputWidth * outputHeight * 4]; + if (outputType.equals("png")) { + outputArgmax = Bitmap.createBitmap(outputWidth, outputHeight, Bitmap.Config.ARGB_8888); + } + + if (outputTensor.dataType() == DataType.FLOAT32) { + for (int i = 0; i < outputHeight; ++i) { + for (int j = 0; j < outputWidth; ++j) { + int maxIndex = 0; + float maxValue = 0.0f; + for (int c = 0; c < outputChannels; ++c) { + float outputValue = output.getFloat(); + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + int labelColor = labelColors.get(maxIndex).intValue(); + if (outputType.equals("png")) { + outputArgmax.setPixel(j, i, labelColor); + } else { + setPixel(outputBytes, i * outputWidth + j, labelColor); + } + } + } + } else { + for (int i = 0; i < outputHeight; ++i) { + for (int j = 0; j < outputWidth; ++j) { + int maxIndex = 0; + int maxValue = 0; + for (int c = 0; c < outputChannels; ++c) { + int outputValue = output.get(); + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + int labelColor = labelColors.get(maxIndex).intValue(); + if (outputType.equals("png")) { + outputArgmax.setPixel(j, i, labelColor); + } else { + setPixel(outputBytes, i * outputWidth + j, labelColor); + } + } + } + } + if (outputType.equals("png")) { + return compressPNG(outputArgmax); + } else { + return outputBytes; + } + } + + void setPixel(byte[] rgba, int index, long color) { + rgba[index * 4] = (byte) ((color >> 16) & 0xFF); + rgba[index * 4 + 1] = (byte) ((color >> 8) & 0xFF); + rgba[index * 4 + 2] = (byte) (color & 0xFF); + rgba[index * 4 + 3] = (byte) ((color >> 24) & 0xFF); + } + + byte[] compressPNG(Bitmap bitmap) { + // https://stackoverflow.com/questions/4989182/converting-java-bitmap-to-byte-array#4989543 + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); + byte[] byteArray = stream.toByteArray(); + // bitmap.recycle(); + return byteArray; + } + + void runPoseNetOnImage(HashMap args, Result result) throws IOException { + String path = args.get("path").toString(); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = feedInputTensorImage(path, IMAGE_MEAN, IMAGE_STD); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void runPoseNetOnBinary(HashMap args, Result result) throws IOException { + byte[] binary = (byte[]) args.get("binary"); + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = ByteBuffer.wrap(binary); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void runPoseNetOnFrame(HashMap args, Result result) throws IOException { + List bytesList = (ArrayList) args.get("bytesList"); + double mean = (double) (args.get("imageMean")); + float IMAGE_MEAN = (float) mean; + double std = (double) (args.get("imageStd")); + float IMAGE_STD = (float) std; + int imageHeight = (int) (args.get("imageHeight")); + int imageWidth = (int) (args.get("imageWidth")); + int rotation = (int) (args.get("rotation")); + int numResults = (int) args.get("numResults"); + double threshold = (double) args.get("threshold"); + int nmsRadius = (int) args.get("nmsRadius"); + + ByteBuffer imgData = feedInputTensorFrame(bytesList, imageHeight, imageWidth, IMAGE_MEAN, IMAGE_STD, rotation); + + new RunPoseNet(args, imgData, numResults, threshold, nmsRadius, result).executeTfliteTask(); + } + + void initPoseNet(Map outputMap) { + if (partsIds.size() == 0) { + for (int i = 0; i < partNames.length; ++i) + partsIds.put(partNames[i], i); + + for (int i = 0; i < poseChain.length; ++i) { + parentToChildEdges.add(partsIds.get(poseChain[i][1])); + childToParentEdges.add(partsIds.get(poseChain[i][0])); + } + } + + for (int i = 0; i < tfLite.getOutputTensorCount(); i++) { + int[] shape = tfLite.getOutputTensor(i).shape(); + float[][][][] output = new float[shape[0]][shape[1]][shape[2]][shape[3]]; + outputMap.put(i, output); + } + } + + private class RunPoseNet extends TfliteTask { + long startTime; + Object[] input; + Map outputMap = new HashMap<>(); + int numResults; + double threshold; + int nmsRadius; + + int localMaximumRadius = 1; + int outputStride = 16; + + RunPoseNet(HashMap args, + ByteBuffer imgData, + int numResults, + double threshold, + int nmsRadius, + Result result) throws IOException { + super(args, result); + this.numResults = numResults; + this.threshold = threshold; + this.nmsRadius = nmsRadius; + + input = new Object[]{imgData}; + initPoseNet(outputMap); + + startTime = SystemClock.uptimeMillis(); + } + + protected void runTflite() { + tfLite.runForMultipleInputsOutputs(input, outputMap); + } + + protected void onRunTfliteDone() { + Log.v("time", "Inference took " + (SystemClock.uptimeMillis() - startTime)); + + float[][][] scores = ((float[][][][]) outputMap.get(0))[0]; + float[][][] offsets = ((float[][][][]) outputMap.get(1))[0]; + float[][][] displacementsFwd = ((float[][][][]) outputMap.get(2))[0]; + float[][][] displacementsBwd = ((float[][][][]) outputMap.get(3))[0]; + + PriorityQueue> pq = buildPartWithScoreQueue(scores, threshold, localMaximumRadius); + + int numParts = scores[0][0].length; + int numEdges = parentToChildEdges.size(); + int sqaredNmsRadius = nmsRadius * nmsRadius; + + List> results = new ArrayList<>(); + + while (results.size() < numResults && pq.size() > 0) { + Map root = pq.poll(); + float[] rootPoint = getImageCoords(root, outputStride, numParts, offsets); + + if (withinNmsRadiusOfCorrespondingPoint( + results, sqaredNmsRadius, rootPoint[0], rootPoint[1], (int) root.get("partId"))) + continue; + + Map keypoint = new HashMap<>(); + keypoint.put("score", root.get("score")); + keypoint.put("part", partNames[(int) root.get("partId")]); + keypoint.put("y", rootPoint[0] / inputSize); + keypoint.put("x", rootPoint[1] / inputSize); + + Map> keypoints = new HashMap<>(); + keypoints.put((int) root.get("partId"), keypoint); + + for (int edge = numEdges - 1; edge >= 0; --edge) { + int sourceKeypointId = parentToChildEdges.get(edge); + int targetKeypointId = childToParentEdges.get(edge); + if (keypoints.containsKey(sourceKeypointId) && !keypoints.containsKey(targetKeypointId)) { + keypoint = traverseToTargetKeypoint(edge, keypoints.get(sourceKeypointId), + targetKeypointId, scores, offsets, outputStride, displacementsBwd); + keypoints.put(targetKeypointId, keypoint); + } + } + + for (int edge = 0; edge < numEdges; ++edge) { + int sourceKeypointId = childToParentEdges.get(edge); + int targetKeypointId = parentToChildEdges.get(edge); + if (keypoints.containsKey(sourceKeypointId) && !keypoints.containsKey(targetKeypointId)) { + keypoint = traverseToTargetKeypoint(edge, keypoints.get(sourceKeypointId), + targetKeypointId, scores, offsets, outputStride, displacementsFwd); + keypoints.put(targetKeypointId, keypoint); + } + } + + Map result = new HashMap<>(); + result.put("keypoints", keypoints); + result.put("score", getInstanceScore(keypoints, numParts)); + results.add(result); + } + + result.success(results); + } + } + + PriorityQueue> buildPartWithScoreQueue(float[][][] scores, + double threshold, + int localMaximumRadius) { + PriorityQueue> pq = + new PriorityQueue<>( + 1, + new Comparator>() { + @Override + public int compare(Map lhs, Map rhs) { + return Float.compare((float) rhs.get("score"), (float) lhs.get("score")); + } + }); + + for (int heatmapY = 0; heatmapY < scores.length; ++heatmapY) { + for (int heatmapX = 0; heatmapX < scores[0].length; ++heatmapX) { + for (int keypointId = 0; keypointId < scores[0][0].length; ++keypointId) { + float score = sigmoid(scores[heatmapY][heatmapX][keypointId]); + if (score < threshold) continue; + + if (scoreIsMaximumInLocalWindow( + keypointId, score, heatmapY, heatmapX, localMaximumRadius, scores)) { + Map res = new HashMap<>(); + res.put("score", score); + res.put("y", heatmapY); + res.put("x", heatmapX); + res.put("partId", keypointId); + pq.add(res); + } + } + } + } + + return pq; + } + + boolean scoreIsMaximumInLocalWindow(int keypointId, + float score, + int heatmapY, + int heatmapX, + int localMaximumRadius, + float[][][] scores) { + boolean localMaximum = true; + int height = scores.length; + int width = scores[0].length; + + int yStart = Math.max(heatmapY - localMaximumRadius, 0); + int yEnd = Math.min(heatmapY + localMaximumRadius + 1, height); + for (int yCurrent = yStart; yCurrent < yEnd; ++yCurrent) { + int xStart = Math.max(heatmapX - localMaximumRadius, 0); + int xEnd = Math.min(heatmapX + localMaximumRadius + 1, width); + for (int xCurrent = xStart; xCurrent < xEnd; ++xCurrent) { + if (sigmoid(scores[yCurrent][xCurrent][keypointId]) > score) { + localMaximum = false; + break; + } + } + if (!localMaximum) { + break; + } + } + + return localMaximum; + } + + float[] getImageCoords(Map keypoint, + int outputStride, + int numParts, + float[][][] offsets) { + int heatmapY = (int) keypoint.get("y"); + int heatmapX = (int) keypoint.get("x"); + int keypointId = (int) keypoint.get("partId"); + float offsetY = offsets[heatmapY][heatmapX][keypointId]; + float offsetX = offsets[heatmapY][heatmapX][keypointId + numParts]; + + float y = heatmapY * outputStride + offsetY; + float x = heatmapX * outputStride + offsetX; + + return new float[]{y, x}; + } + + boolean withinNmsRadiusOfCorrespondingPoint(List> poses, + float squaredNmsRadius, + float y, + float x, + int keypointId) { + for (Map pose : poses) { + Map keypoints = (Map) pose.get("keypoints"); + Map correspondingKeypoint = (Map) keypoints.get(keypointId); + float _x = (float) correspondingKeypoint.get("x") * inputSize - x; + float _y = (float) correspondingKeypoint.get("y") * inputSize - y; + float squaredDistance = _x * _x + _y * _y; + if (squaredDistance <= squaredNmsRadius) + return true; + } + + return false; + } + + Map traverseToTargetKeypoint(int edgeId, + Map sourceKeypoint, + int targetKeypointId, + float[][][] scores, + float[][][] offsets, + int outputStride, + float[][][] displacements) { + int height = scores.length; + int width = scores[0].length; + int numKeypoints = scores[0][0].length; + float sourceKeypointY = (float) sourceKeypoint.get("y") * inputSize; + float sourceKeypointX = (float) sourceKeypoint.get("x") * inputSize; + + int[] sourceKeypointIndices = getStridedIndexNearPoint(sourceKeypointY, sourceKeypointX, + outputStride, height, width); + + float[] displacement = getDisplacement(edgeId, sourceKeypointIndices, displacements); + + float[] displacedPoint = new float[]{ + sourceKeypointY + displacement[0], + sourceKeypointX + displacement[1] + }; + + float[] targetKeypoint = displacedPoint; + + final int offsetRefineStep = 2; + for (int i = 0; i < offsetRefineStep; i++) { + int[] targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint[0], targetKeypoint[1], + outputStride, height, width); + + int targetKeypointY = targetKeypointIndices[0]; + int targetKeypointX = targetKeypointIndices[1]; + + float offsetY = offsets[targetKeypointY][targetKeypointX][targetKeypointId]; + float offsetX = offsets[targetKeypointY][targetKeypointX][targetKeypointId + numKeypoints]; + + targetKeypoint = new float[]{ + targetKeypointY * outputStride + offsetY, + targetKeypointX * outputStride + offsetX + }; + } + + int[] targetKeypointIndices = getStridedIndexNearPoint(targetKeypoint[0], targetKeypoint[1], + outputStride, height, width); + + float score = sigmoid(scores[targetKeypointIndices[0]][targetKeypointIndices[1]][targetKeypointId]); + + Map keypoint = new HashMap<>(); + keypoint.put("score", score); + keypoint.put("part", partNames[targetKeypointId]); + keypoint.put("y", targetKeypoint[0] / inputSize); + keypoint.put("x", targetKeypoint[1] / inputSize); + + return keypoint; + } + + int[] getStridedIndexNearPoint(float _y, float _x, int outputStride, int height, int width) { + int y_ = Math.round(_y / outputStride); + int x_ = Math.round(_x / outputStride); + int y = y_ < 0 ? 0 : y_ > height - 1 ? height - 1 : y_; + int x = x_ < 0 ? 0 : x_ > width - 1 ? width - 1 : x_; + return new int[]{y, x}; + } + + float[] getDisplacement(int edgeId, int[] keypoint, float[][][] displacements) { + int numEdges = displacements[0][0].length / 2; + int y = keypoint[0]; + int x = keypoint[1]; + return new float[]{displacements[y][x][edgeId], displacements[y][x][edgeId + numEdges]}; + } + + float getInstanceScore(Map> keypoints, int numKeypoints) { + float scores = 0; + for (Map.Entry> keypoint : keypoints.entrySet()) + scores += (float) keypoint.getValue().get("score"); + return scores / numKeypoints; + } + + private float sigmoid(final float x) { + return (float) (1. / (1. + Math.exp(-x))); + } + + private void softmax(final float[] vals) { + float max = Float.NEGATIVE_INFINITY; + for (final float val : vals) { + max = Math.max(max, val); + } + float sum = 0.0f; + for (int i = 0; i < vals.length; ++i) { + vals[i] = (float) Math.exp(vals[i] - max); + sum += vals[i]; + } + for (int i = 0; i < vals.length; ++i) { + vals[i] = vals[i] / sum; + } + } + + private static Matrix getTransformationMatrix(final int srcWidth, + final int srcHeight, + final int dstWidth, + final int dstHeight, + final boolean maintainAspectRatio) { + final Matrix matrix = new Matrix(); + + if (srcWidth != dstWidth || srcHeight != dstHeight) { + final float scaleFactorX = dstWidth / (float) srcWidth; + final float scaleFactorY = dstHeight / (float) srcHeight; + + if (maintainAspectRatio) { + final float scaleFactor = Math.max(scaleFactorX, scaleFactorY); + matrix.postScale(scaleFactor, scaleFactor); + } else { + matrix.postScale(scaleFactorX, scaleFactorY); + } + } + + matrix.invert(new Matrix()); + return matrix; + } + + private void close() { + if (tfLite != null) + tfLite.close(); + labels = null; + labelProb = null; + } +} diff --git a/plugins/tflite_v2/example/README.md b/plugins/tflite_v2/example/README.md new file mode 100644 index 0000000..849606f --- /dev/null +++ b/plugins/tflite_v2/example/README.md @@ -0,0 +1,35 @@ +# tflite_example + +Use tflite plugin to run model on images. The image is captured by camera or selected from gallery (with the help of [image_picker](https://pub.dartlang.org/packages/image_picker) plugin). + +![](yolo.jpg) + +## Prerequisites + +Create a `assets` folder. From https://github.com/shaqian/flutter_tflite/tree/master/example/assets +dowload the following files and place them in `assets` folder. + - mobilenet_v1_1.0_224.tflite + - mobilenet_v1_1.0_224.txt + - ssd_mobilenet.tflite + - ssd_mobilenet.txt + - yolov2_tiny.tflite + - yolov2_tiny.txt + - deeplabv3_257_mv_gpu.tflite + - deeplabv3_257_mv_gpu.txt + - posenet_mv1_075_float_from_checkpoints.tflite + +## Install + +``` +flutter packages get +``` + +## Run + +``` +flutter run +``` + +## Caveat + +```recognizeImageBinary(image)``` (sample code for ```runModelOnBinary```) is slow on iOS when decoding image due to a [known issue](https://github.com/brendan-duncan/image/issues/55) with image package. diff --git a/plugins/tflite_v2/example/android/app/build.gradle b/plugins/tflite_v2/example/android/app/build.gradle new file mode 100644 index 0000000..a627ccf --- /dev/null +++ b/plugins/tflite_v2/example/android/app/build.gradle @@ -0,0 +1,65 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion 28 + + lintOptions { + disable 'InvalidPackage' + } + + aaptOptions { + noCompress 'tflite' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "sq.flutter.tfliteexample" + minSdkVersion 19 + targetSdkVersion 28 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' +} diff --git a/plugins/tflite_v2/example/android/app/src/main/AndroidManifest.xml b/plugins/tflite_v2/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..aa3336f --- /dev/null +++ b/plugins/tflite_v2/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java b/plugins/tflite_v2/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java new file mode 100644 index 0000000..968a340 --- /dev/null +++ b/plugins/tflite_v2/example/android/app/src/main/java/sq/flutter/tfliteexample/MainActivity.java @@ -0,0 +1,13 @@ +package sq.flutter.tfliteexample; + +import android.os.Bundle; +import io.flutter.app.FlutterActivity; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class MainActivity extends FlutterActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } +} diff --git a/plugins/tflite_v2/example/android/app/src/main/res/drawable/launch_background.xml b/plugins/tflite_v2/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000..304732f --- /dev/null +++ b/plugins/tflite_v2/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/plugins/tflite_v2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..db77bb4 Binary files /dev/null and b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..17987b7 Binary files /dev/null and b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..09d4391 Binary files /dev/null and b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..d5f1c8d Binary files /dev/null and b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..4d6372e Binary files /dev/null and b/plugins/tflite_v2/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/plugins/tflite_v2/example/android/app/src/main/res/values/styles.xml b/plugins/tflite_v2/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..00fa441 --- /dev/null +++ b/plugins/tflite_v2/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + diff --git a/plugins/tflite_v2/example/android/build.gradle b/plugins/tflite_v2/example/android/build.gradle new file mode 100644 index 0000000..83f114c --- /dev/null +++ b/plugins/tflite_v2/example/android/build.gradle @@ -0,0 +1,29 @@ +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:3.6.1' + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/plugins/tflite_v2/example/android/gradle.properties b/plugins/tflite_v2/example/android/gradle.properties new file mode 100644 index 0000000..29bf260 --- /dev/null +++ b/plugins/tflite_v2/example/android/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.jvmargs=-Xmx1536M +target-platform=android-arm64 +android.useAndroidX=true +android.enableJetifier=true diff --git a/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.jar b/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.properties b/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..46510f3 --- /dev/null +++ b/plugins/tflite_v2/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Mar 28 00:33:22 ICT 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/plugins/tflite_v2/example/android/gradlew b/plugins/tflite_v2/example/android/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/plugins/tflite_v2/example/android/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/plugins/tflite_v2/example/android/gradlew.bat b/plugins/tflite_v2/example/android/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/plugins/tflite_v2/example/android/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/plugins/tflite_v2/example/android/settings.gradle b/plugins/tflite_v2/example/android/settings.gradle new file mode 100644 index 0000000..5a2f14f --- /dev/null +++ b/plugins/tflite_v2/example/android/settings.gradle @@ -0,0 +1,15 @@ +include ':app' + +def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + +def plugins = new Properties() +def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') +if (pluginsFile.exists()) { + pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } +} + +plugins.each { name, path -> + def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() + include ":$name" + project(":$name").projectDir = pluginDirectory +} diff --git a/plugins/tflite_v2/example/android/settings_aar.gradle b/plugins/tflite_v2/example/android/settings_aar.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/plugins/tflite_v2/example/android/settings_aar.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.tflite b/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.tflite new file mode 100644 index 0000000..d2d9a9b Binary files /dev/null and b/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.tflite differ diff --git a/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.txt b/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.txt new file mode 100644 index 0000000..ecfffa3 --- /dev/null +++ b/plugins/tflite_v2/example/assets/deeplabv3_257_mv_gpu.txt @@ -0,0 +1,21 @@ +background +aeroplane +biyclce +bird +boat +bottle +bus +car +cat +chair +cow +diningtable +dog +horse +motorbike +person +potted plant +sheep +sofa +train +tv-monitor diff --git a/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.tflite b/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.tflite new file mode 100644 index 0000000..d34691e Binary files /dev/null and b/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.tflite differ diff --git a/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.txt b/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.txt new file mode 100644 index 0000000..fe81123 --- /dev/null +++ b/plugins/tflite_v2/example/assets/mobilenet_v1_1.0_224.txt @@ -0,0 +1,1001 @@ +background +tench +goldfish +great white shark +tiger shark +hammerhead +electric ray +stingray +cock +hen +ostrich +brambling +goldfinch +house finch +junco +indigo bunting +robin +bulbul +jay +magpie +chickadee +water ouzel +kite +bald eagle +vulture +great grey owl +European fire salamander +common newt +eft +spotted salamander +axolotl +bullfrog +tree frog +tailed frog +loggerhead +leatherback turtle +mud turtle +terrapin +box turtle +banded gecko +common iguana +American chameleon +whiptail +agama +frilled lizard +alligator lizard +Gila monster +green lizard +African chameleon +Komodo dragon +African crocodile +American alligator +triceratops +thunder snake +ringneck snake +hognose snake +green snake +king snake +garter snake +water snake +vine snake +night snake +boa constrictor +rock python +Indian cobra +green mamba +sea snake +horned viper +diamondback +sidewinder +trilobite +harvestman +scorpion +black and gold garden spider +barn spider +garden spider +black widow +tarantula +wolf spider +tick +centipede +black grouse +ptarmigan +ruffed grouse +prairie chicken +peacock +quail +partridge +African grey +macaw +sulphur-crested cockatoo +lorikeet +coucal +bee eater +hornbill +hummingbird +jacamar +toucan +drake +red-breasted merganser +goose +black swan +tusker +echidna +platypus +wallaby +koala +wombat +jellyfish +sea anemone +brain coral +flatworm +nematode +conch +snail +slug +sea slug +chiton +chambered nautilus +Dungeness crab +rock crab +fiddler crab +king crab +American lobster +spiny lobster +crayfish +hermit crab +isopod +white stork +black stork +spoonbill +flamingo +little blue heron +American egret +bittern +crane +limpkin +European gallinule +American coot +bustard +ruddy turnstone +red-backed sandpiper +redshank +dowitcher +oystercatcher +pelican +king penguin +albatross +grey whale +killer whale +dugong +sea lion +Chihuahua +Japanese spaniel +Maltese dog +Pekinese +Shih-Tzu +Blenheim spaniel +papillon +toy terrier +Rhodesian ridgeback +Afghan hound +basset +beagle +bloodhound +bluetick +black-and-tan coonhound +Walker hound +English foxhound +redbone +borzoi +Irish wolfhound +Italian greyhound +whippet +Ibizan hound +Norwegian elkhound +otterhound +Saluki +Scottish deerhound +Weimaraner +Staffordshire bullterrier +American Staffordshire terrier +Bedlington terrier +Border terrier +Kerry blue terrier +Irish terrier +Norfolk terrier +Norwich terrier +Yorkshire terrier +wire-haired fox terrier +Lakeland terrier +Sealyham terrier +Airedale +cairn +Australian terrier +Dandie Dinmont +Boston bull +miniature schnauzer +giant schnauzer +standard schnauzer +Scotch terrier +Tibetan terrier +silky terrier +soft-coated wheaten terrier +West Highland white terrier +Lhasa +flat-coated retriever +curly-coated retriever +golden retriever +Labrador retriever +Chesapeake Bay retriever +German short-haired pointer +vizsla +English setter +Irish setter +Gordon setter +Brittany spaniel +clumber +English springer +Welsh springer spaniel +cocker spaniel +Sussex spaniel +Irish water spaniel +kuvasz +schipperke +groenendael +malinois +briard +kelpie +komondor +Old English sheepdog +Shetland sheepdog +collie +Border collie +Bouvier des Flandres +Rottweiler +German shepherd +Doberman +miniature pinscher +Greater Swiss Mountain dog +Bernese mountain dog +Appenzeller +EntleBucher +boxer +bull mastiff +Tibetan mastiff +French bulldog +Great Dane +Saint Bernard +Eskimo dog +malamute +Siberian husky +dalmatian +affenpinscher +basenji +pug +Leonberg +Newfoundland +Great Pyrenees +Samoyed +Pomeranian +chow +keeshond +Brabancon griffon +Pembroke +Cardigan +toy poodle +miniature poodle +standard poodle +Mexican hairless +timber wolf +white wolf +red wolf +coyote +dingo +dhole +African hunting dog +hyena +red fox +kit fox +Arctic fox +grey fox +tabby +tiger cat +Persian cat +Siamese cat +Egyptian cat +cougar +lynx +leopard +snow leopard +jaguar +lion +tiger +cheetah +brown bear +American black bear +ice bear +sloth bear +mongoose +meerkat +tiger beetle +ladybug +ground beetle +long-horned beetle +leaf beetle +dung beetle +rhinoceros beetle +weevil +fly +bee +ant +grasshopper +cricket +walking stick +cockroach +mantis +cicada +leafhopper +lacewing +dragonfly +damselfly +admiral +ringlet +monarch +cabbage butterfly +sulphur butterfly +lycaenid +starfish +sea urchin +sea cucumber +wood rabbit +hare +Angora +hamster +porcupine +fox squirrel +marmot +beaver +guinea pig +sorrel +zebra +hog +wild boar +warthog +hippopotamus +ox +water buffalo +bison +ram +bighorn +ibex +hartebeest +impala +gazelle +Arabian camel +llama +weasel +mink +polecat +black-footed ferret +otter +skunk +badger +armadillo +three-toed sloth +orangutan +gorilla +chimpanzee +gibbon +siamang +guenon +patas +baboon +macaque +langur +colobus +proboscis monkey +marmoset +capuchin +howler monkey +titi +spider monkey +squirrel monkey +Madagascar cat +indri +Indian elephant +African elephant +lesser panda +giant panda +barracouta +eel +coho +rock beauty +anemone fish +sturgeon +gar +lionfish +puffer +abacus +abaya +academic gown +accordion +acoustic guitar +aircraft carrier +airliner +airship +altar +ambulance +amphibian +analog clock +apiary +apron +ashcan +assault rifle +backpack +bakery +balance beam +balloon +ballpoint +Band Aid +banjo +bannister +barbell +barber chair +barbershop +barn +barometer +barrel +barrow +baseball +basketball +bassinet +bassoon +bathing cap +bath towel +bathtub +beach wagon +beacon +beaker +bearskin +beer bottle +beer glass +bell cote +bib +bicycle-built-for-two +bikini +binder +binoculars +birdhouse +boathouse +bobsled +bolo tie +bonnet +bookcase +bookshop +bottlecap +bow +bow tie +brass +brassiere +breakwater +breastplate +broom +bucket +buckle +bulletproof vest +bullet train +butcher shop +cab +caldron +candle +cannon +canoe +can opener +cardigan +car mirror +carousel +carpenter's kit +carton +car wheel +cash machine +cassette +cassette player +castle +catamaran +CD player +cello +cellular telephone +chain +chainlink fence +chain mail +chain saw +chest +chiffonier +chime +china cabinet +Christmas stocking +church +cinema +cleaver +cliff dwelling +cloak +clog +cocktail shaker +coffee mug +coffeepot +coil +combination lock +computer keyboard +confectionery +container ship +convertible +corkscrew +cornet +cowboy boot +cowboy hat +cradle +crane +crash helmet +crate +crib +Crock Pot +croquet ball +crutch +cuirass +dam +desk +desktop computer +dial telephone +diaper +digital clock +digital watch +dining table +dishrag +dishwasher +disk brake +dock +dogsled +dome +doormat +drilling platform +drum +drumstick +dumbbell +Dutch oven +electric fan +electric guitar +electric locomotive +entertainment center +envelope +espresso maker +face powder +feather boa +file +fireboat +fire engine +fire screen +flagpole +flute +folding chair +football helmet +forklift +fountain +fountain pen +four-poster +freight car +French horn +frying pan +fur coat +garbage truck +gasmask +gas pump +goblet +go-kart +golf ball +golfcart +gondola +gong +gown +grand piano +greenhouse +grille +grocery store +guillotine +hair slide +hair spray +half track +hammer +hamper +hand blower +hand-held computer +handkerchief +hard disc +harmonica +harp +harvester +hatchet +holster +home theater +honeycomb +hook +hoopskirt +horizontal bar +horse cart +hourglass +iPod +iron +jack-o'-lantern +jean +jeep +jersey +jigsaw puzzle +jinrikisha +joystick +kimono +knee pad +knot +lab coat +ladle +lampshade +laptop +lawn mower +lens cap +letter opener +library +lifeboat +lighter +limousine +liner +lipstick +Loafer +lotion +loudspeaker +loupe +lumbermill +magnetic compass +mailbag +mailbox +maillot +maillot +manhole cover +maraca +marimba +mask +matchstick +maypole +maze +measuring cup +medicine chest +megalith +microphone +microwave +military uniform +milk can +minibus +miniskirt +minivan +missile +mitten +mixing bowl +mobile home +Model T +modem +monastery +monitor +moped +mortar +mortarboard +mosque +mosquito net +motor scooter +mountain bike +mountain tent +mouse +mousetrap +moving van +muzzle +nail +neck brace +necklace +nipple +notebook +obelisk +oboe +ocarina +odometer +oil filter +organ +oscilloscope +overskirt +oxcart +oxygen mask +packet +paddle +paddlewheel +padlock +paintbrush +pajama +palace +panpipe +paper towel +parachute +parallel bars +park bench +parking meter +passenger car +patio +pay-phone +pedestal +pencil box +pencil sharpener +perfume +Petri dish +photocopier +pick +pickelhaube +picket fence +pickup +pier +piggy bank +pill bottle +pillow +ping-pong ball +pinwheel +pirate +pitcher +plane +planetarium +plastic bag +plate rack +plow +plunger +Polaroid camera +pole +police van +poncho +pool table +pop bottle +pot +potter's wheel +power drill +prayer rug +printer +prison +projectile +projector +puck +punching bag +purse +quill +quilt +racer +racket +radiator +radio +radio telescope +rain barrel +recreational vehicle +reel +reflex camera +refrigerator +remote control +restaurant +revolver +rifle +rocking chair +rotisserie +rubber eraser +rugby ball +rule +running shoe +safe +safety pin +saltshaker +sandal +sarong +sax +scabbard +scale +school bus +schooner +scoreboard +screen +screw +screwdriver +seat belt +sewing machine +shield +shoe shop +shoji +shopping basket +shopping cart +shovel +shower cap +shower curtain +ski +ski mask +sleeping bag +slide rule +sliding door +slot +snorkel +snowmobile +snowplow +soap dispenser +soccer ball +sock +solar dish +sombrero +soup bowl +space bar +space heater +space shuttle +spatula +speedboat +spider web +spindle +sports car +spotlight +stage +steam locomotive +steel arch bridge +steel drum +stethoscope +stole +stone wall +stopwatch +stove +strainer +streetcar +stretcher +studio couch +stupa +submarine +suit +sundial +sunglass +sunglasses +sunscreen +suspension bridge +swab +sweatshirt +swimming trunks +swing +switch +syringe +table lamp +tank +tape player +teapot +teddy +television +tennis ball +thatch +theater curtain +thimble +thresher +throne +tile roof +toaster +tobacco shop +toilet seat +torch +totem pole +tow truck +toyshop +tractor +trailer truck +tray +trench coat +tricycle +trimaran +tripod +triumphal arch +trolleybus +trombone +tub +turnstile +typewriter keyboard +umbrella +unicycle +upright +vacuum +vase +vault +velvet +vending machine +vestment +viaduct +violin +volleyball +waffle iron +wall clock +wallet +wardrobe +warplane +washbasin +washer +water bottle +water jug +water tower +whiskey jug +whistle +wig +window screen +window shade +Windsor tie +wine bottle +wing +wok +wooden spoon +wool +worm fence +wreck +yawl +yurt +web site +comic book +crossword puzzle +street sign +traffic light +book jacket +menu +plate +guacamole +consomme +hot pot +trifle +ice cream +ice lolly +French loaf +bagel +pretzel +cheeseburger +hotdog +mashed potato +head cabbage +broccoli +cauliflower +zucchini +spaghetti squash +acorn squash +butternut squash +cucumber +artichoke +bell pepper +cardoon +mushroom +Granny Smith +strawberry +orange +lemon +fig +pineapple +banana +jackfruit +custard apple +pomegranate +hay +carbonara +chocolate sauce +dough +meat loaf +pizza +potpie +burrito +red wine +espresso +cup +eggnog +alp +bubble +cliff +coral reef +geyser +lakeside +promontory +sandbar +seashore +valley +volcano +ballplayer +groom +scuba diver +rapeseed +daisy +yellow lady's slipper +corn +acorn +hip +buckeye +coral fungus +agaric +gyromitra +stinkhorn +earthstar +hen-of-the-woods +bolete +ear +toilet tissue diff --git a/plugins/tflite_v2/example/assets/posenet_mv1_075_float_from_checkpoints.tflite b/plugins/tflite_v2/example/assets/posenet_mv1_075_float_from_checkpoints.tflite new file mode 100644 index 0000000..4ccbcc5 Binary files /dev/null and b/plugins/tflite_v2/example/assets/posenet_mv1_075_float_from_checkpoints.tflite differ diff --git a/plugins/tflite_v2/example/assets/ssd_mobilenet.tflite b/plugins/tflite_v2/example/assets/ssd_mobilenet.tflite new file mode 100644 index 0000000..8015ee5 Binary files /dev/null and b/plugins/tflite_v2/example/assets/ssd_mobilenet.tflite differ diff --git a/plugins/tflite_v2/example/assets/ssd_mobilenet.txt b/plugins/tflite_v2/example/assets/ssd_mobilenet.txt new file mode 100644 index 0000000..5a70ff8 --- /dev/null +++ b/plugins/tflite_v2/example/assets/ssd_mobilenet.txt @@ -0,0 +1,91 @@ +??? +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +traffic light +fire hydrant +??? +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +??? +backpack +umbrella +??? +??? +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +??? +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +couch +potted plant +bed +??? +dining table +??? +??? +toilet +??? +tv +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +??? +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/plugins/tflite_v2/example/assets/yolov2_tiny.tflite b/plugins/tflite_v2/example/assets/yolov2_tiny.tflite new file mode 100644 index 0000000..cda34b4 Binary files /dev/null and b/plugins/tflite_v2/example/assets/yolov2_tiny.tflite differ diff --git a/plugins/tflite_v2/example/assets/yolov2_tiny.txt b/plugins/tflite_v2/example/assets/yolov2_tiny.txt new file mode 100644 index 0000000..ca76c80 --- /dev/null +++ b/plugins/tflite_v2/example/assets/yolov2_tiny.txt @@ -0,0 +1,80 @@ +person +bicycle +car +motorbike +aeroplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +sofa +pottedplant +bed +diningtable +toilet +tvmonitor +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/plugins/tflite_v2/example/ios/Flutter/AppFrameworkInfo.plist b/plugins/tflite_v2/example/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000..9367d48 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 8.0 + + diff --git a/plugins/tflite_v2/example/ios/Flutter/Debug.xcconfig b/plugins/tflite_v2/example/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000..e8efba1 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Flutter/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "Generated.xcconfig" diff --git a/plugins/tflite_v2/example/ios/Flutter/Release.xcconfig b/plugins/tflite_v2/example/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000..399e934 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Flutter/Release.xcconfig @@ -0,0 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "Generated.xcconfig" diff --git a/plugins/tflite_v2/example/ios/Podfile b/plugins/tflite_v2/example/ios/Podfile new file mode 100644 index 0000000..f7d6a5e --- /dev/null +++ b/plugins/tflite_v2/example/ios/Podfile @@ -0,0 +1,38 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/plugins/tflite_v2/example/ios/Podfile.lock b/plugins/tflite_v2/example/ios/Podfile.lock new file mode 100644 index 0000000..6286399 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Podfile.lock @@ -0,0 +1,35 @@ +PODS: + - Flutter (1.0.0) + - image_picker (0.0.1): + - Flutter + - TensorFlowLiteC (2.2.0) + - tflite (1.1.2): + - Flutter + - TensorFlowLiteC + +DEPENDENCIES: + - Flutter (from `Flutter`) + - image_picker (from `.symlinks/plugins/image_picker/ios`) + - tflite (from `.symlinks/plugins/tflite/ios`) + +SPEC REPOS: + trunk: + - TensorFlowLiteC + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + image_picker: + :path: ".symlinks/plugins/image_picker/ios" + tflite: + :path: ".symlinks/plugins/tflite/ios" + +SPEC CHECKSUMS: + Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + image_picker: a211f28b95a560433c00f5cd3773f4710a20404d + TensorFlowLiteC: b3ab9e867b0b71052ca102a32a786555b330b02e + tflite: f0403a894740019d63ab5662253bba5b2dd37296 + +PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d + +COCOAPODS: 1.10.1 diff --git a/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.pbxproj b/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1252660 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,483 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + A8FCB07931B147D0C738D807 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A4A034B01AB21E851714E03C /* libPods-Runner.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 864E0E2308AE5F3A9409E901 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A4A034B01AB21E851714E03C /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + E0C0C115F9024C6ADB3B2DB5 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A8FCB07931B147D0C738D807 /* libPods-Runner.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7670CC45CF9B055E20C18D9C /* Frameworks */ = { + isa = PBXGroup; + children = ( + A4A034B01AB21E851714E03C /* libPods-Runner.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 8EE3D73475BA2048B61051C2 /* Pods */ = { + isa = PBXGroup; + children = ( + E0C0C115F9024C6ADB3B2DB5 /* Pods-Runner.debug.xcconfig */, + 864E0E2308AE5F3A9409E901 /* Pods-Runner.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 8EE3D73475BA2048B61051C2 /* Pods */, + 7670CC45CF9B055E20C18D9C /* Frameworks */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 97C146F11CF9000F007C117D /* Supporting Files */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 97C146F21CF9000F007C117D /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + FAEC5F0CFA3366178E53C4C5 /* [CP] Check Pods Manifest.lock */, + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0910; + ORGANIZATIONNAME = "The Chromium Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = ZJG3P98JS9; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; + FAEC5F0CFA3366178E53C4C5 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 97C146F31CF9000F007C117D /* main.m in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ZJG3P98JS9; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "'${SRCROOT}/Pods/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers'", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/Flutter\"", + "\"${PODS_ROOT}/Headers/Public/TensorFlowLite\"", + "\"${PODS_ROOT}/Headers/Public/tflite\"", + ); + INFOPLIST_FILE = Runner/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = sq.flutter.tfliteExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ZJG3P98JS9; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "'${SRCROOT}/Pods/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers'", + "\"${PODS_ROOT}/Headers/Public\"", + "\"${PODS_ROOT}/Headers/Public/Flutter\"", + "\"${PODS_ROOT}/Headers/Public/TensorFlowLite\"", + "\"${PODS_ROOT}/Headers/Public/tflite\"", + ); + INFOPLIST_FILE = Runner/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = sq.flutter.tfliteExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/plugins/tflite_v2/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/plugins/tflite_v2/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..6c78381 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/plugins/tflite_v2/example/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..21a3cc1 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/plugins/tflite_v2/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/plugins/tflite_v2/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/plugins/tflite_v2/example/ios/Runner/AppDelegate.h b/plugins/tflite_v2/example/ios/Runner/AppDelegate.h new file mode 100644 index 0000000..36e21bb --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/AppDelegate.h @@ -0,0 +1,6 @@ +#import +#import + +@interface AppDelegate : FlutterAppDelegate + +@end diff --git a/plugins/tflite_v2/example/ios/Runner/AppDelegate.m b/plugins/tflite_v2/example/ios/Runner/AppDelegate.m new file mode 100644 index 0000000..59a72e9 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/AppDelegate.m @@ -0,0 +1,13 @@ +#include "AppDelegate.h" +#include "GeneratedPluginRegistrant.h" + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + // Override point for customization after application launch. + return [super application:application didFinishLaunchingWithOptions:launchOptions]; +} + +@end diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d36b1fa --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000..3d43d11 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png new file mode 100644 index 0000000..28c6bf0 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000..2ccbfd9 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000..f091b6b Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000..4cde121 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000..d0ef06e Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000..dcdc230 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000..2ccbfd9 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000..c8f9ed8 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000..a6d6b86 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000..a6d6b86 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000..75b2d16 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000..c4df70d Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000..6a84f41 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000..d0e1f58 Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000..0bedcf2 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png differ diff --git a/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 0000000..89c2725 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file diff --git a/plugins/tflite_v2/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/plugins/tflite_v2/example/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f2e259c --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2/example/ios/Runner/Base.lproj/Main.storyboard b/plugins/tflite_v2/example/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f3c2851 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/tflite_v2/example/ios/Runner/Info.plist b/plugins/tflite_v2/example/ios/Runner/Info.plist new file mode 100644 index 0000000..3fef927 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/Info.plist @@ -0,0 +1,51 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + tflite_example + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + NSPhotoLibraryUsageDescription + We need your permission to access photo gallery + NSCameraUsageDescription + We need your permission to use phone camera + NSMicrophoneUsageDescription + We need your permission to use microsphone + + diff --git a/plugins/tflite_v2/example/ios/Runner/main.m b/plugins/tflite_v2/example/ios/Runner/main.m new file mode 100644 index 0000000..dff6597 --- /dev/null +++ b/plugins/tflite_v2/example/ios/Runner/main.m @@ -0,0 +1,9 @@ +#import +#import +#import "AppDelegate.h" + +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/plugins/tflite_v2/example/lib/main.dart b/plugins/tflite_v2/example/lib/main.dart new file mode 100644 index 0000000..b02b5f6 --- /dev/null +++ b/plugins/tflite_v2/example/lib/main.dart @@ -0,0 +1,473 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:math'; +import 'dart:typed_data'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:image/image.dart' as img; + +import 'package:tflite_v2/tflite_v2.dart'; +import 'package:image_picker/image_picker.dart'; + +void main() => runApp(new App()); + +const String mobile = "MobileNet"; +const String ssd = "SSD MobileNet"; +const String yolo = "Tiny YOLOv2"; +const String deeplab = "DeepLab"; +const String posenet = "PoseNet"; + +class App extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: MyApp(), + ); + } +} + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => new _MyAppState(); +} + +class _MyAppState extends State { + File _image; + List _recognitions; + String _model = mobile; + double _imageHeight; + double _imageWidth; + bool _busy = false; + + Future predictImagePicker() async { + var image = await ImagePicker.pickImage(source: ImageSource.gallery); + if (image == null) return; + setState(() { + _busy = true; + }); + predictImage(image); + } + + Future predictImage(File image) async { + if (image == null) return; + + switch (_model) { + case yolo: + await yolov2Tiny(image); + break; + case ssd: + await ssdMobileNet(image); + break; + case deeplab: + await segmentMobileNet(image); + break; + case posenet: + await poseNet(image); + break; + default: + await recognizeImage(image); + // await recognizeImageBinary(image); + } + + new FileImage(image) + .resolve(new ImageConfiguration()) + .addListener(ImageStreamListener((ImageInfo info, bool _) { + setState(() { + _imageHeight = info.image.height.toDouble(); + _imageWidth = info.image.width.toDouble(); + }); + })); + + setState(() { + _image = image; + _busy = false; + }); + } + + @override + void initState() { + super.initState(); + + _busy = true; + + loadModel().then((val) { + setState(() { + _busy = false; + }); + }); + } + + Future loadModel() async { + Tflite.close(); + try { + String res; + switch (_model) { + case yolo: + res = await Tflite.loadModel( + model: "assets/yolov2_tiny.tflite", + labels: "assets/yolov2_tiny.txt", + // useGpuDelegate: true, + ); + break; + case ssd: + res = await Tflite.loadModel( + model: "assets/ssd_mobilenet.tflite", + labels: "assets/ssd_mobilenet.txt", + // useGpuDelegate: true, + ); + break; + case deeplab: + res = await Tflite.loadModel( + model: "assets/deeplabv3_257_mv_gpu.tflite", + labels: "assets/deeplabv3_257_mv_gpu.txt", + // useGpuDelegate: true, + ); + break; + case posenet: + res = await Tflite.loadModel( + model: "assets/posenet_mv1_075_float_from_checkpoints.tflite", + // useGpuDelegate: true, + ); + break; + default: + res = await Tflite.loadModel( + model: "assets/mobilenet_v1_1.0_224.tflite", + labels: "assets/mobilenet_v1_1.0_224.txt", + // useGpuDelegate: true, + ); + } + print(res); + } on PlatformException { + print('Failed to load model.'); + } + } + + Uint8List imageToByteListFloat32( + img.Image image, int inputSize, double mean, double std) { + var convertedBytes = Float32List(1 * inputSize * inputSize * 3); + var buffer = Float32List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; + buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; + } + } + return convertedBytes.buffer.asUint8List(); + } + + Uint8List imageToByteListUint8(img.Image image, int inputSize) { + var convertedBytes = Uint8List(1 * inputSize * inputSize * 3); + var buffer = Uint8List.view(convertedBytes.buffer); + int pixelIndex = 0; + for (var i = 0; i < inputSize; i++) { + for (var j = 0; j < inputSize; j++) { + var pixel = image.getPixel(j, i); + buffer[pixelIndex++] = img.getRed(pixel); + buffer[pixelIndex++] = img.getGreen(pixel); + buffer[pixelIndex++] = img.getBlue(pixel); + } + } + return convertedBytes.buffer.asUint8List(); + } + + Future recognizeImage(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runModelOnImage( + path: image.path, + numResults: 6, + threshold: 0.05, + imageMean: 127.5, + imageStd: 127.5, + ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future recognizeImageBinary(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var imageBytes = (await rootBundle.load(image.path)).buffer; + img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + img.Image resizedImage = img.copyResize(oriImage, height: 224, width: 224); + var recognitions = await Tflite.runModelOnBinary( + binary: imageToByteListFloat32(resizedImage, 224, 127.5, 127.5), + numResults: 6, + threshold: 0.05, + ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future yolov2Tiny(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.detectObjectOnImage( + path: image.path, + model: "YOLO", + threshold: 0.3, + imageMean: 0.0, + imageStd: 255.0, + numResultsPerClass: 1, + ); + // var imageBytes = (await rootBundle.load(image.path)).buffer; + // img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + // img.Image resizedImage = img.copyResize(oriImage, 416, 416); + // var recognitions = await Tflite.detectObjectOnBinary( + // binary: imageToByteListFloat32(resizedImage, 416, 0.0, 255.0), + // model: "YOLO", + // threshold: 0.3, + // numResultsPerClass: 1, + // ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future ssdMobileNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.detectObjectOnImage( + path: image.path, + numResultsPerClass: 1, + ); + // var imageBytes = (await rootBundle.load(image.path)).buffer; + // img.Image oriImage = img.decodeJpg(imageBytes.asUint8List()); + // img.Image resizedImage = img.copyResize(oriImage, 300, 300); + // var recognitions = await Tflite.detectObjectOnBinary( + // binary: imageToByteListUint8(resizedImage, 300), + // numResultsPerClass: 1, + // ); + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + Future segmentMobileNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runSegmentationOnImage( + path: image.path, + imageMean: 127.5, + imageStd: 127.5, + ); + + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}"); + } + + Future poseNet(File image) async { + int startTime = new DateTime.now().millisecondsSinceEpoch; + var recognitions = await Tflite.runPoseNetOnImage( + path: image.path, + numResults: 2, + ); + + print(recognitions); + + setState(() { + _recognitions = recognitions; + }); + int endTime = new DateTime.now().millisecondsSinceEpoch; + print("Inference took ${endTime - startTime}ms"); + } + + onSelect(model) async { + setState(() { + _busy = true; + _model = model; + _recognitions = null; + }); + await loadModel(); + + if (_image != null) + predictImage(_image); + else + setState(() { + _busy = false; + }); + } + + List renderBoxes(Size screen) { + if (_recognitions == null) return []; + if (_imageHeight == null || _imageWidth == null) return []; + + double factorX = screen.width; + double factorY = _imageHeight / _imageWidth * screen.width; + Color blue = Color.fromRGBO(37, 213, 253, 1.0); + return _recognitions.map((re) { + return Positioned( + left: re["rect"]["x"] * factorX, + top: re["rect"]["y"] * factorY, + width: re["rect"]["w"] * factorX, + height: re["rect"]["h"] * factorY, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(8.0)), + border: Border.all( + color: blue, + width: 2, + ), + ), + child: Text( + "${re["detectedClass"]} ${(re["confidenceInClass"] * 100).toStringAsFixed(0)}%", + style: TextStyle( + background: Paint()..color = blue, + color: Colors.white, + fontSize: 12.0, + ), + ), + ), + ); + }).toList(); + } + + List renderKeypoints(Size screen) { + if (_recognitions == null) return []; + if (_imageHeight == null || _imageWidth == null) return []; + + double factorX = screen.width; + double factorY = _imageHeight / _imageWidth * screen.width; + + var lists = []; + _recognitions.forEach((re) { + var color = Color((Random().nextDouble() * 0xFFFFFF).toInt() << 0) + .withOpacity(1.0); + var list = re["keypoints"].values.map((k) { + return Positioned( + left: k["x"] * factorX - 6, + top: k["y"] * factorY - 6, + width: 100, + height: 12, + child: Text( + "● ${k["part"]}", + style: TextStyle( + color: color, + fontSize: 12.0, + ), + ), + ); + }).toList(); + + lists..addAll(list); + }); + + return lists; + } + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + List stackChildren = []; + + if (_model == deeplab && _recognitions != null) { + stackChildren.add(Positioned( + top: 0.0, + left: 0.0, + width: size.width, + child: _image == null + ? Text('No image selected.') + : Container( + decoration: BoxDecoration( + image: DecorationImage( + alignment: Alignment.topCenter, + image: MemoryImage(_recognitions), + fit: BoxFit.fill)), + child: Opacity(opacity: 0.3, child: Image.file(_image))), + )); + } else { + stackChildren.add(Positioned( + top: 0.0, + left: 0.0, + width: size.width, + child: _image == null ? Text('No image selected.') : Image.file(_image), + )); + } + + if (_model == mobile) { + stackChildren.add(Center( + child: Column( + children: _recognitions != null + ? _recognitions.map((res) { + return Text( + "${res["index"]} - ${res["label"]}: ${res["confidence"].toStringAsFixed(3)}", + style: TextStyle( + color: Colors.black, + fontSize: 20.0, + background: Paint()..color = Colors.white, + ), + ); + }).toList() + : [], + ), + )); + } else if (_model == ssd || _model == yolo) { + stackChildren.addAll(renderBoxes(size)); + } else if (_model == posenet) { + stackChildren.addAll(renderKeypoints(size)); + } + + if (_busy) { + stackChildren.add(const Opacity( + child: ModalBarrier(dismissible: false, color: Colors.grey), + opacity: 0.3, + )); + stackChildren.add(const Center(child: CircularProgressIndicator())); + } + + return Scaffold( + appBar: AppBar( + title: const Text('tflite example app'), + actions: [ + PopupMenuButton( + onSelected: onSelect, + itemBuilder: (context) { + List> menuEntries = [ + const PopupMenuItem( + child: Text(mobile), + value: mobile, + ), + const PopupMenuItem( + child: Text(ssd), + value: ssd, + ), + const PopupMenuItem( + child: Text(yolo), + value: yolo, + ), + const PopupMenuItem( + child: Text(deeplab), + value: deeplab, + ), + const PopupMenuItem( + child: Text(posenet), + value: posenet, + ) + ]; + return menuEntries; + }, + ) + ], + ), + body: Stack( + children: stackChildren, + ), + floatingActionButton: FloatingActionButton( + onPressed: predictImagePicker, + tooltip: 'Pick Image', + child: Icon(Icons.image), + ), + ); + } +} diff --git a/plugins/tflite_v2/example/pubspec.yaml b/plugins/tflite_v2/example/pubspec.yaml new file mode 100644 index 0000000..ceb496c --- /dev/null +++ b/plugins/tflite_v2/example/pubspec.yaml @@ -0,0 +1,83 @@ +name: tflite_example +description: Demonstrates how to use the tflite plugin. + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# Read more about versioning at semver.org. +version: 1.0.0+1 + +environment: + sdk: ">=2.0.0-dev.68.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^0.1.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + image_picker: ^0.6.7 + + image: ^2.1.4 + + tflite: + path: ../ + + test: ^1.12.0 +# For information on the generic Dart part of this file, see the +# following page: https://www.dartlang.org/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + assets: + - assets/mobilenet_v1_1.0_224.txt + - assets/mobilenet_v1_1.0_224.tflite + - assets/yolov2_tiny.tflite + - assets/yolov2_tiny.txt + - assets/ssd_mobilenet.tflite + - assets/ssd_mobilenet.txt + - assets/deeplabv3_257_mv_gpu.tflite + - assets/deeplabv3_257_mv_gpu.txt + - assets/posenet_mv1_075_float_from_checkpoints.tflite + + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.io/assets-and-images/#resolution-aware. + + # For details regarding adding assets from package dependencies, see + # https://flutter.io/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.io/custom-fonts/#from-packages diff --git a/plugins/tflite_v2/example/test/widget_test.dart b/plugins/tflite_v2/example/test/widget_test.dart new file mode 100644 index 0000000..00a807f --- /dev/null +++ b/plugins/tflite_v2/example/test/widget_test.dart @@ -0,0 +1,25 @@ +// This is a basic Flutter widget test. +// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter +// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to +// find child widgets in the widget tree, read text, and verify that the values of widget properties +// are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:tflite_example/main.dart'; + +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(new MyApp()); + + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => + widget is Text && widget.data.startsWith('Running on:'), + ), + findsOneWidget); + }); +} diff --git a/plugins/tflite_v2/example/yolo.jpg b/plugins/tflite_v2/example/yolo.jpg new file mode 100644 index 0000000..33f6714 Binary files /dev/null and b/plugins/tflite_v2/example/yolo.jpg differ diff --git a/plugins/tflite_v2/ios/Classes/TflitePlugin.h b/plugins/tflite_v2/ios/Classes/TflitePlugin.h new file mode 100644 index 0000000..5f12511 --- /dev/null +++ b/plugins/tflite_v2/ios/Classes/TflitePlugin.h @@ -0,0 +1,4 @@ +#import + +@interface TflitePlugin : NSObject +@end diff --git a/plugins/tflite_v2/ios/Classes/TflitePlugin.mm b/plugins/tflite_v2/ios/Classes/TflitePlugin.mm new file mode 100644 index 0000000..049891a --- /dev/null +++ b/plugins/tflite_v2/ios/Classes/TflitePlugin.mm @@ -0,0 +1,1501 @@ +//#define CONTRIB_PATH +#define TFLITE2 + +#import "TflitePlugin.h" + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONTRIB_PATH +#include "tensorflow/contrib/lite/kernels/register.h" +#include "tensorflow/contrib/lite/model.h" +#include "tensorflow/contrib/lite/string_util.h" +#include "tensorflow/contrib/lite/op_resolver.h" +#elif defined TFLITE2 +#import "TensorFlowLiteC.h" +#import "metal_delegate.h" +#else +#include "tensorflow/lite/kernels/register.h" +#include "tensorflow/lite/model.h" +#include "tensorflow/lite/string_util.h" +#include "tensorflow/lite/op_resolver.h" +#endif + +#include "ios_image_load.h" + +#define LOG(x) std::cerr + +typedef void (^TfLiteStatusCallback)(TfLiteStatus); +NSString* loadModel(NSObject* _registrar, NSDictionary* args); +void runTflite(NSDictionary* args, TfLiteStatusCallback cb); +void runModelOnImage(NSDictionary* args, FlutterResult result); +void runModelOnBinary(NSDictionary* args, FlutterResult result); +void runModelOnFrame(NSDictionary* args, FlutterResult result); +void detectObjectOnImage(NSDictionary* args, FlutterResult result); +void detectObjectOnBinary(NSDictionary* args, FlutterResult result); +void detectObjectOnFrame(NSDictionary* args, FlutterResult result); +void runPix2PixOnImage(NSDictionary* args, FlutterResult result); +void runPix2PixOnBinary(NSDictionary* args, FlutterResult result); +void runPix2PixOnFrame(NSDictionary* args, FlutterResult result); +void runSegmentationOnImage(NSDictionary* args, FlutterResult result); +void runSegmentationOnBinary(NSDictionary* args, FlutterResult result); +void runSegmentationOnFrame(NSDictionary* args, FlutterResult result); +void runPoseNetOnImage(NSDictionary* args, FlutterResult result); +void runPoseNetOnBinary(NSDictionary* args, FlutterResult result); +void runPoseNetOnFrame(NSDictionary* args, FlutterResult result); +void close(); + +@implementation TflitePlugin { + NSObject* _registrar; +} + ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:@"tflite" + binaryMessenger:[registrar messenger]]; + TflitePlugin* instance = [[TflitePlugin alloc] initWithRegistrar:registrar]; + [registrar addMethodCallDelegate:instance channel:channel]; +} + +- (instancetype)initWithRegistrar:(NSObject*)registrar { + self = [super init]; + if (self) { + _registrar = registrar; + } + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + if ([@"loadModel" isEqualToString:call.method]) { + NSString* load_result = loadModel(_registrar, call.arguments); + result(load_result); + } else if ([@"runModelOnImage" isEqualToString:call.method]) { + runModelOnImage(call.arguments, result); + } else if ([@"runModelOnBinary" isEqualToString:call.method]) { + runModelOnBinary(call.arguments, result); + } else if ([@"runModelOnFrame" isEqualToString:call.method]) { + runModelOnFrame(call.arguments, result); + } else if ([@"detectObjectOnImage" isEqualToString:call.method]) { + detectObjectOnImage(call.arguments, result); + } else if ([@"detectObjectOnBinary" isEqualToString:call.method]) { + detectObjectOnBinary(call.arguments, result); + } else if ([@"detectObjectOnFrame" isEqualToString:call.method]) { + detectObjectOnFrame(call.arguments, result); + } else if ([@"runPix2PixOnImage" isEqualToString:call.method]) { + runPix2PixOnImage(call.arguments, result); + } else if ([@"runPix2PixOnBinary" isEqualToString:call.method]) { + runPix2PixOnBinary(call.arguments, result); + } else if ([@"runPix2PixOnFrame" isEqualToString:call.method]) { + runPix2PixOnFrame(call.arguments, result); + } else if ([@"runSegmentationOnImage" isEqualToString:call.method]) { + runSegmentationOnImage(call.arguments, result); + } else if ([@"runSegmentationOnBinary" isEqualToString:call.method]) { + runSegmentationOnBinary(call.arguments, result); + } else if ([@"runSegmentationOnFrame" isEqualToString:call.method]) { + runSegmentationOnFrame(call.arguments, result); + } else if ([@"runPoseNetOnImage" isEqualToString:call.method]) { + runPoseNetOnImage(call.arguments, result); + } else if ([@"runPoseNetOnBinary" isEqualToString:call.method]) { + runPoseNetOnBinary(call.arguments, result); + } else if ([@"runPoseNetOnFrame" isEqualToString:call.method]) { + runPoseNetOnFrame(call.arguments, result); + } else if ([@"close" isEqualToString:call.method]) { + close(); + } else { + result(FlutterMethodNotImplemented); + } +} + +@end + +std::vector labels; +#ifdef TFLITE2 +TfLiteInterpreter *interpreter = nullptr; +TfLiteModel *model = nullptr; +TfLiteDelegate *delegate = nullptr; +#else +std::unique_ptr model; +std::unique_ptr interpreter; +#endif +bool interpreter_busy = false; + +static void LoadLabels(NSString* labels_path, + std::vector* label_strings) { + if (!labels_path) { + LOG(ERROR) << "Failed to find label file at" << labels_path; + } + std::ifstream t; + t.open([labels_path UTF8String]); + label_strings->clear(); + for (std::string line; std::getline(t, line); ) { + label_strings->push_back(line); + } + t.close(); +} + +NSString* loadModel(NSObject* _registrar, NSDictionary* args) { + NSString* graph_path; + NSString* key; + NSNumber* isAssetNumber = args[@"isAsset"]; + bool isAsset = [isAssetNumber boolValue]; + if(isAsset){ + key = [_registrar lookupKeyForAsset:args[@"model"]]; + graph_path = [[NSBundle mainBundle] pathForResource:key ofType:nil]; + }else{ + graph_path = args[@"model"]; + } + + const int num_threads = [args[@"numThreads"] intValue]; + +#ifdef TFLITE2 + TfLiteInterpreterOptions *options = nullptr; + model = TfLiteModelCreateFromFile(graph_path.UTF8String); + if (!model) { + return [NSString stringWithFormat:@"%s %@", "Failed to mmap model", graph_path]; + } + options = TfLiteInterpreterOptionsCreate(); + TfLiteInterpreterOptionsSetNumThreads(options, num_threads); + + bool useGpuDelegate = [args[@"useGpuDelegate"] boolValue]; + if (useGpuDelegate) { + delegate = TFLGpuDelegateCreate(nullptr); + TfLiteInterpreterOptionsAddDelegate(options, delegate); + } +#else + model = tflite::FlatBufferModel::BuildFromFile([graph_path UTF8String]); + if (!model) { + return [NSString stringWithFormat:@"%s %@", "Failed to mmap model", graph_path]; + } + LOG(INFO) << "Loaded model " << graph_path; + model->error_reporter(); + LOG(INFO) << "resolved reporter"; +#endif + + if ([args[@"labels"] length] > 0) { + NSString* labels_path; + if(isAsset){ + key = [_registrar lookupKeyForAsset:args[@"labels"]]; + labels_path = [[NSBundle mainBundle] pathForResource:key ofType:nil]; + }else{ + labels_path = args[@"labels"]; + } + LoadLabels(labels_path, &labels); + } + +#ifdef TFLITE2 + interpreter = TfLiteInterpreterCreate(model, options); + if (!interpreter) { + return @"Failed to construct interpreter"; + } + + if (TfLiteInterpreterAllocateTensors(interpreter) != kTfLiteOk) { + return @"Failed to allocate tensors!"; + } +#else + tflite::ops::builtin::BuiltinOpResolver resolver; + tflite::InterpreterBuilder(*model, resolver)(&interpreter); + if (!interpreter) { + return @"Failed to construct interpreter"; + } + + if (interpreter->AllocateTensors() != kTfLiteOk) { + return @"Failed to allocate tensors!"; + } + + if (num_threads != -1) { + interpreter->SetNumThreads(num_threads); + } + #endif + + return @"success"; +} + + +void runTflite(NSDictionary* args, TfLiteStatusCallback cb) { + const bool asynch = [args[@"asynch"] boolValue]; + if (asynch) { + interpreter_busy = true; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ +#ifdef TFLITE2 + TfLiteStatus status = TfLiteInterpreterInvoke(interpreter); +#else + TfLiteStatus status = interpreter->Invoke(); +#endif + dispatch_async(dispatch_get_main_queue(), ^(void){ + interpreter_busy = false; + cb(status); + }); + }); + } else { +#ifdef TFLITE2 + TfLiteStatus status = TfLiteInterpreterInvoke(interpreter); +#else + TfLiteStatus status = interpreter->Invoke(); +#endif + cb(status); + } +} + +NSMutableData *feedOutputTensor(int outputChannelsIn, float mean, float std, bool convertToUint8, + int *widthOut, int *heightOut) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 1); + const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + assert(interpreter->outputs().size() == 1); + int output = interpreter->outputs()[0]; + TfLiteTensor* output_tensor = interpreter->tensor(output); +#endif + const int width = output_tensor->dims->data[2]; + const int channels = output_tensor->dims->data[3]; + const int outputChannels = outputChannelsIn ? outputChannelsIn : channels; + assert(outputChannels >= channels); + if (widthOut) *widthOut = width; + if (heightOut) *heightOut = width; + + NSMutableData *data = nil; + if (output_tensor->type == kTfLiteUInt8) { + int size = width*width*outputChannels; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + uint8_t* out = (uint8_t*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + const uint8_t* bytes = output_tensor->data.uint8; +#else + const uint8_t* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = *bytes++; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } else { // kTfLiteFloat32 + if (convertToUint8) { + int size = width*width*outputChannels; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + uint8_t* out = (uint8_t*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + const float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = (*bytes++ * std) + mean; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } else { // kTfLiteFloat32 + int size = width*width*outputChannels*4; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + float* out = (float*)[data bytes], *outEnd = out + width*width*outputChannels; +#ifdef TFLITE2 + float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + while (out != outEnd) { + for (int c = 0; c < channels; c++) + *out++ = (*bytes++ * std) + mean; + for (int c = 0; c < outputChannels - channels; c++) + *out++ = 255; + } + } + } + return data; +} + +void feedInputTensorBinary(const FlutterStandardTypedData* typedData, int* input_size) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetInputTensorCount(interpreter) == 1); + TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0); +#else + assert(interpreter->inputs().size() == 1); + int input = interpreter->inputs()[0]; + TfLiteTensor* input_tensor = interpreter->tensor(input); +#endif + const int width = input_tensor->dims->data[2]; + *input_size = width; + NSData* in = [typedData data]; + + if (input_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + TfLiteTensorCopyFromBuffer(input_tensor, in.bytes, in.length); +#else + uint8_t* out = interpreter->typed_tensor(input); + const uint8_t* bytes = (const uint8_t*)[in bytes]; + for (int index = 0; index < [in length]; index++) + out[index] = bytes[index]; +#endif + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + TfLiteTensorCopyFromBuffer(input_tensor, in.bytes, in.length); +#else + float* out = interpreter->typed_tensor(input); + const float* bytes = (const float*)[in bytes]; + for (int index = 0; index < [in length]/4; index++) + out[index] = bytes[index]; +#endif + } +} + +void feedInputTensor(uint8_t* in, int* input_size, int image_height, int image_width, int image_channels, float input_mean, float input_std) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetInputTensorCount(interpreter) == 1); + TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0); +#else + assert(interpreter->inputs().size() == 1); + int input = interpreter->inputs()[0]; + TfLiteTensor* input_tensor = interpreter->tensor(input); +#endif + const int input_channels = input_tensor->dims->data[3]; + const int width = input_tensor->dims->data[2]; + const int height = input_tensor->dims->data[1]; + *input_size = width; + + if (input_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + uint8_t* out = input_tensor->data.uint8; +#else + uint8_t* out = interpreter->typed_tensor(input); +#endif + for (int y = 0; y < height; ++y) { + const int in_y = (y * image_height) / height; + uint8_t* in_row = in + (in_y * image_width * image_channels); + uint8_t* out_row = out + (y * width * input_channels); + for (int x = 0; x < width; ++x) { + const int in_x = (x * image_width) / width; + uint8_t* in_pixel = in_row + (in_x * image_channels); + uint8_t* out_pixel = out_row + (x * input_channels); + for (int c = 0; c < input_channels; ++c) { + out_pixel[c] = in_pixel[c]; + } + } + } + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + float* out = input_tensor->data.f; +#else + float* out = interpreter->typed_tensor(input); +#endif + for (int y = 0; y < height; ++y) { + const int in_y = (y * image_height) / height; + uint8_t* in_row = in + (in_y * image_width * image_channels); + float* out_row = out + (y * width * input_channels); + for (int x = 0; x < width; ++x) { + const int in_x = (x * image_width) / width; + uint8_t* in_pixel = in_row + (in_x * image_channels); + float* out_pixel = out_row + (x * input_channels); + for (int c = 0; c < input_channels; ++c) { + out_pixel[c] = (in_pixel[c] - input_mean) / input_std; + } + } + } + } +} + +void feedInputTensorImage(const NSString* image_path, float input_mean, float input_std, int* input_size) { + int image_channels; + int image_height; + int image_width; + std::vector image_data = LoadImageFromFile([image_path UTF8String], &image_width, &image_height, &image_channels); + uint8_t* in = image_data.data(); + feedInputTensor(in, input_size, image_height, image_width, image_channels, input_mean, input_std); +} + +void feedInputTensorFrame(const FlutterStandardTypedData* typedData, int* input_size, + int image_height, int image_width, int image_channels, float input_mean, float input_std) { + uint8_t* in = (uint8_t*)[[typedData data] bytes]; + feedInputTensor(in, input_size, image_height, image_width, image_channels, input_mean, input_std); +} + +NSMutableArray* GetTopN(const float* prediction, const unsigned long prediction_size, const int num_results, + const float threshold) { + std::priority_queue, std::vector>, + std::greater>> top_result_pq; + std::vector> top_results; + + const long count = prediction_size; + for (int i = 0; i < count; ++i) { + const float value = prediction[i]; + + if (value < threshold) { + continue; + } + + top_result_pq.push(std::pair(value, i)); + + if (top_result_pq.size() > num_results) { + top_result_pq.pop(); + } + } + + while (!top_result_pq.empty()) { + top_results.push_back(top_result_pq.top()); + top_result_pq.pop(); + } + std::reverse(top_results.begin(), top_results.end()); + + NSMutableArray* predictions = [NSMutableArray array]; + for (const auto& result : top_results) { + const float confidence = result.first; + const int index = result.second; + NSString* labelObject = [NSString stringWithUTF8String:labels[index].c_str()]; + NSNumber* valueObject = [NSNumber numberWithFloat:confidence]; + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + [res setValue:[NSNumber numberWithInt:index] forKey:@"index"]; + [res setObject:labelObject forKey:@"label"]; + [res setObject:valueObject forKey:@"confidence"]; + [predictions addObject:res]; + } + + return predictions; +} + +void runModelOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +void runModelOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +void runModelOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + +#ifdef TFLITE2 + float* output = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + if (output == NULL) + return result(empty); + + const unsigned long output_size = labels.size(); + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + return result(GetTopN(output, output_size, num_results, threshold)); + }); +} + +NSMutableArray* parseSSDMobileNet(float threshold, int num_results_per_class) { +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 4); +#else + assert(interpreter->outputs().size() == 4); +#endif + NSMutableArray* results = [NSMutableArray array]; +#ifdef TFLITE2 + float* output_locations = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; + float* output_classes = TfLiteInterpreterGetOutputTensor(interpreter, 1)->data.f; + float* output_scores = TfLiteInterpreterGetOutputTensor(interpreter, 2)->data.f; + float* num_detections = TfLiteInterpreterGetOutputTensor(interpreter, 3)->data.f; +#else + float* output_locations = interpreter->typed_output_tensor(0); + float* output_classes = interpreter->typed_output_tensor(1); + float* output_scores = interpreter->typed_output_tensor(2); + float* num_detections = interpreter->typed_output_tensor(3); +#endif + + NSMutableDictionary* counters = [NSMutableDictionary dictionary]; + for (int d = 0; d < *num_detections; d++) + { + const int detected_class = output_classes[d]; + float score = output_scores[d]; + + if (score < threshold) continue; + + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + NSString* class_name = [NSString stringWithUTF8String:labels[detected_class + 1].c_str()]; + NSObject* counter = [counters objectForKey:class_name]; + + if (counter) { + int countValue = [(NSNumber*)counter intValue] + 1; + if (countValue > num_results_per_class) { + continue; + } + [counters setObject:@(countValue) forKey:class_name]; + } else { + [counters setObject:@(1) forKey:class_name]; + } + + [res setObject:@(score) forKey:@"confidenceInClass"]; + [res setObject:class_name forKey:@"detectedClass"]; + + const float ymin = fmax(0, output_locations[d * 4]); + const float xmin = fmax(0, output_locations[d * 4 + 1]); + const float ymax = output_locations[d * 4 + 2]; + const float xmax = output_locations[d * 4 + 3]; + + NSMutableDictionary* rect = [NSMutableDictionary dictionary]; + [rect setObject:@(xmin) forKey:@"x"]; + [rect setObject:@(ymin) forKey:@"y"]; + [rect setObject:@(fmin(1 - xmin, xmax - xmin)) forKey:@"w"]; + [rect setObject:@(fmin(1 - ymin, ymax - ymin)) forKey:@"h"]; + + [res setObject:rect forKey:@"rect"]; + [results addObject:res]; + } + return results; +} + +float sigmoid(float x) { + return 1.0 / (1.0 + exp(-x)); +} + +void softmax(float vals[], int count) { + float max = -FLT_MAX; + for (int i=0; idata.f; +#else + float* output = interpreter->typed_output_tensor(0); +#endif + NSMutableArray* results = [NSMutableArray array]; + std::priority_queue, std::vector>, + std::less>> top_result_pq; + + int grid_size = input_size / block_size; + for (int y = 0; y < grid_size; ++y) { + for (int x = 0; x < grid_size; ++x) { + for (int b = 0; b < num_boxes_per_bolock; ++b) { + int offset = (grid_size * (num_boxes_per_bolock * (num_classes + 5))) * y + + (num_boxes_per_bolock * (num_classes + 5)) * x + + (num_classes + 5) * b; + + float confidence = sigmoid(output[offset + 4]); + + float classes[num_classes]; + for (int c = 0; c < num_classes; ++c) { + classes[c] = output[offset + 5 + c]; + } + + softmax(classes, num_classes); + + int detected_class = -1; + float max_class = 0; + for (int c = 0; c < num_classes; ++c) { + if (classes[c] > max_class) { + detected_class = c; + max_class = classes[c]; + } + } + + float confidence_in_class = max_class * confidence; + if (confidence_in_class > threshold) { + NSMutableDictionary* rect = [NSMutableDictionary dictionary]; + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + + float xPos = (x + sigmoid(output[offset + 0])) * block_size; + float yPos = (y + sigmoid(output[offset + 1])) * block_size; + + float anchor_w = [[anchors objectAtIndex:(2 * b + 0)] floatValue]; + float anchor_h = [[anchors objectAtIndex:(2 * b + 1)] floatValue]; + float w = (float) (exp(output[offset + 2]) * anchor_w) * block_size; + float h = (float) (exp(output[offset + 3]) * anchor_h) * block_size; + + float x = fmax(0, (xPos - w / 2) / input_size); + float y = fmax(0, (yPos - h / 2) / input_size); + [rect setObject:@(x) forKey:@"x"]; + [rect setObject:@(y) forKey:@"y"]; + [rect setObject:@(fmin(1 - x, w / input_size)) forKey:@"w"]; + [rect setObject:@(fmin(1 - y, h / input_size)) forKey:@"h"]; + + [res setObject:rect forKey:@"rect"]; + [res setObject:@(confidence_in_class) forKey:@"confidenceInClass"]; + NSString* class_name = [NSString stringWithUTF8String:labels[detected_class].c_str()]; + [res setObject:class_name forKey:@"detectedClass"]; + + top_result_pq.push(std::pair(confidence_in_class, res)); + } + } + } + } + + NSMutableDictionary* counters = [NSMutableDictionary dictionary]; + while (!top_result_pq.empty()) { + NSMutableDictionary* result = top_result_pq.top().second; + top_result_pq.pop(); + + NSString* detected_class = [result objectForKey:@"detectedClass"]; + NSObject* counter = [counters objectForKey:detected_class]; + if (counter) { + int countValue = [(NSNumber*)counter intValue] + 1; + if (countValue > num_results_per_class) { + continue; + } + [counters setObject:@(countValue) forKey:detected_class]; + } else { + [counters setObject:@(1) forKey:detected_class]; + } + [results addObject:result]; + } + + return results; +} + +void detectObjectOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const NSString* model = args[@"model"]; + const float threshold = [args[@"threshold"] floatValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)labels.size(), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void detectObjectOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const NSString* model = args[@"model"]; + const float threshold = [args[@"threshold"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)(labels.size() - 1), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void detectObjectOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const NSString* model = args[@"model"]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int num_results_per_class = [args[@"numResultsPerClass"] intValue]; + + const NSArray* anchors = args[@"anchors"]; + const int num_boxes_per_block = [args[@"numBoxesPerBlock"] intValue]; + const int block_size = [args[@"blockSize"] floatValue]; + + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + if ([model isEqual: @"SSDMobileNet"]) + return result(parseSSDMobileNet(threshold, num_results_per_class)); + else + return result(parseYOLO((int)labels.size(), anchors, block_size, num_boxes_per_block, num_results_per_class, + threshold, input_size)); + }); +} + +void runPix2PixOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(4, input_mean, input_std, true, &width, &height); + if (output == NULL) + return result(empty); + + if ([outputType isEqual: @"png"]) { + return result(CompressImage(output, width, height, 1)); + } else { + return result(output); + } + }); +} + +void runPix2PixOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(0, 0, 1, false, &width, &height); + if (output == NULL) + return result(empty); + + return result(output); + }); +} + +void runPix2PixOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + int width = 0, height = 0; + NSMutableData* output = feedOutputTensor(image_channels, input_mean, input_std, true, &width, &height); + if (output == NULL) + return result(empty); + + if ([outputType isEqual: @"png"]) { + return result(CompressImage(output, width, height, 1)); + } else { + return result(output); + } + }); +} + +void setPixel(char* rgba, int index, long color) { + rgba[index * 4] = (color >> 16) & 0xFF; + rgba[index * 4 + 1] = (color >> 8) & 0xFF; + rgba[index * 4 + 2] = color & 0xFF; + rgba[index * 4 + 3] = (color >> 24) & 0xFF; +} + +NSData* fetchArgmax(const NSArray* labelColors, const NSString* outputType) { +#ifdef TFLITE2 + const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + int output = interpreter->outputs()[0]; + TfLiteTensor* output_tensor = interpreter->tensor(output); +#endif + const int height = output_tensor->dims->data[1]; + const int width = output_tensor->dims->data[2]; + const int channels = output_tensor->dims->data[3]; + + NSMutableData *data = nil; + int size = height * width * 4; + data = [[NSMutableData dataWithCapacity: size] initWithLength: size]; + char* out = (char*)[data bytes]; + if (output_tensor->type == kTfLiteUInt8) { +#ifdef TFLITE2 + const uint8_t* bytes = output_tensor->data.uint8; +#else + const uint8_t* bytes = interpreter->typed_tensor(output); +#endif + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int index = i * width + j; + int maxIndex = 0; + int maxValue = 0; + for (int c = 0; c < channels; ++c) { + int outputValue = bytes[index* channels + c]; + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + long labelColor = [[labelColors objectAtIndex:maxIndex] longValue]; + setPixel(out, index, labelColor); + } + } + } else { // kTfLiteFloat32 +#ifdef TFLITE2 + const float* bytes = output_tensor->data.f; +#else + const float* bytes = interpreter->typed_tensor(output); +#endif + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int index = i * width + j; + int maxIndex = 0; + float maxValue = .0f; + for (int c = 0; c < channels; ++c) { + float outputValue = bytes[index * channels + c]; + if (outputValue > maxValue) { + maxIndex = c; + maxValue = outputValue; + } + } + long labelColor = [[labelColors objectAtIndex:maxIndex] longValue]; + setPixel(out, index, labelColor); + } + } + } + + if ([outputType isEqual: @"png"]) { + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef bitmapContext = CGBitmapContextCreate(out, + width, + height, + 8, // bitsPerComponent + 4 * width, // bytesPerRow + colorSpace, + kCGImageAlphaNoneSkipLast); + + CFRelease(colorSpace); + CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext); + NSData* image = UIImagePNGRepresentation([[UIImage alloc] initWithCGImage:cgImage]); + CFRelease(cgImage); + CFRelease(bitmapContext); + return image; + } else { + return data; + } +} + +void runSegmentationOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + +void runSegmentationOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + +void runSegmentationOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const NSArray* labelColors = args[@"labelColors"]; + const NSString* outputType = args[@"outputType"]; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + NSData* output = fetchArgmax(labelColors, outputType); + FlutterStandardTypedData* ret = [FlutterStandardTypedData typedDataWithBytes: output]; + return result(ret); + }); +} + + +NSArray* _tflite_part_names = @[ + @"nose", @"leftEye", @"rightEye", @"leftEar", @"rightEar", @"leftShoulder", + @"rightShoulder", @"leftElbow", @"rightElbow", @"leftWrist", @"rightWrist", + @"leftHip", @"rightHip", @"leftKnee", @"rightKnee", @"leftAnkle", @"rightAnkle" +]; + +NSArray* _tflite_pose_chain = @[ + @[@"nose", @"leftEye"], @[@"leftEye", @"leftEar"], @[@"nose", @"rightEye"], + @[@"rightEye", @"rightEar"], @[@"nose", @"leftShoulder"], + @[@"leftShoulder", @"leftElbow"], @[@"leftElbow", @"leftWrist"], + @[@"leftShoulder", @"leftHip"], @[@"leftHip", @"leftKnee"], + @[@"leftKnee", @"leftAnkle"], @[@"nose", @"rightShoulder"], + @[@"rightShoulder", @"rightElbow"], @[@"rightElbow", @"rightWrist"], + @[@"rightShoulder", @"rightHip"], @[@"rightHip", @"rightKnee"], + @[@"rightKnee", @"rightAnkle"] +]; + +NSMutableDictionary* _tflite_parts_ids = [NSMutableDictionary dictionary]; +NSMutableArray* _tflite_parent_to_child_edges = [NSMutableArray array]; +NSMutableArray* _tflite_child_to_parent_edges = [NSMutableArray array]; +int _tflite_local_maximum_radius = 1; +int _tflite_output_stride = 16; +int _tflite_height; +int _tflite_width; +int _tflite_num_keypoints; + +void initPoseNet() { + if ([_tflite_parts_ids count] == 0) { + for (int i = 0; i < [_tflite_part_names count]; ++i) + [_tflite_parts_ids setValue:[NSNumber numberWithInt:i] forKey:_tflite_part_names[i]]; + + for (int i = 0; i < [_tflite_pose_chain count]; ++i) { + [_tflite_parent_to_child_edges addObject:_tflite_parts_ids[_tflite_pose_chain[i][1]]]; + [_tflite_child_to_parent_edges addObject:_tflite_parts_ids[_tflite_pose_chain[i][0]]]; + } + } +} + +bool scoreIsMaximumInLocalWindow(int keypoint_id, + float score, + int heatmap_y, + int heatmap_x, + int local_maximum_radius, + float* scores) { + bool local_maxium = true; + + int y_start = MAX(heatmap_y - local_maximum_radius, 0); + int y_end = MIN(heatmap_y + local_maximum_radius + 1, _tflite_height); + for (int y_current = y_start; y_current < y_end; ++y_current) { + int x_start = MAX(heatmap_x - local_maximum_radius, 0); + int x_end = MIN(heatmap_x + local_maximum_radius + 1, _tflite_width); + for (int x_current = x_start; x_current < x_end; ++x_current) { + if (sigmoid(scores[(y_current * _tflite_width + x_current) * _tflite_num_keypoints + keypoint_id]) > score) { + local_maxium = false; + break; + } + } + if (!local_maxium) { + break; + } + } + return local_maxium; +} + +typedef std::priority_queue, +std::vector>, +std::less>> PriorityQueue; + +PriorityQueue buildPartWithScoreQueue(float* scores, + float threshold, + int local_maximum_radius) { + PriorityQueue pq; + for (int heatmap_y = 0; heatmap_y < _tflite_height; ++heatmap_y) { + for (int heatmap_x = 0; heatmap_x < _tflite_width; ++heatmap_x) { + for (int keypoint_id = 0; keypoint_id < _tflite_num_keypoints; ++keypoint_id) { + float score = sigmoid(scores[(heatmap_y * _tflite_width + heatmap_x) * + _tflite_num_keypoints + keypoint_id]); + if (score < threshold) continue; + + if (scoreIsMaximumInLocalWindow(keypoint_id, score, heatmap_y, heatmap_x, + local_maximum_radius, scores)) { + NSMutableDictionary* res = [NSMutableDictionary dictionary]; + [res setValue:[NSNumber numberWithFloat:score] forKey:@"score"]; + [res setValue:[NSNumber numberWithInt:heatmap_y] forKey:@"y"]; + [res setValue:[NSNumber numberWithInt:heatmap_x] forKey:@"x"]; + [res setValue:[NSNumber numberWithInt:keypoint_id] forKey:@"partId"]; + pq.push(std::pair(score, res)); + } + } + } + } + return pq; +} + +void getImageCoords(float* res, + NSMutableDictionary* keypoint, + float* offsets) { + int heatmap_y = [keypoint[@"y"] intValue]; + int heatmap_x = [keypoint[@"x"] intValue]; + int keypoint_id = [keypoint[@"partId"] intValue]; + + int offset = (heatmap_y * _tflite_width + heatmap_x) * _tflite_num_keypoints * 2 + keypoint_id; + float offset_y = offsets[offset]; + float offset_x = offsets[offset + _tflite_num_keypoints]; + res[0] = heatmap_y * _tflite_output_stride + offset_y; + res[1] = heatmap_x * _tflite_output_stride + offset_x; +} + + +bool withinNmsRadiusOfCorrespondingPoint(NSMutableArray* poses, + float squared_nms_radius, + float y, + float x, + int keypoint_id, + int input_size) { + for (NSMutableDictionary* pose in poses) { + NSMutableDictionary* keypoints = pose[@"keypoints"]; + NSMutableDictionary* correspondingKeypoint = keypoints[[NSNumber numberWithInt:keypoint_id]]; + float _x = [correspondingKeypoint[@"x"] floatValue] * input_size - x; + float _y = [correspondingKeypoint[@"y"] floatValue] * input_size - y; + float squaredDistance = _x * _x + _y * _y; + if (squaredDistance <= squared_nms_radius) + return true; + } + return false; +} + +void getStridedIndexNearPoint(int* res, float _y, float _x) { + int y_ = round(_y / _tflite_output_stride); + int x_ = round(_x / _tflite_output_stride); + int y = y_ < 0 ? 0 : y_ > _tflite_height - 1 ? _tflite_height - 1 : y_; + int x = x_ < 0 ? 0 : x_ > _tflite_width - 1 ? _tflite_width - 1 : x_; + res[0] = y; + res[1] = x; +} + +void getDisplacement(float* res, int edgeId, int* keypoint, float* displacements) { + int num_edges = (int)[_tflite_parent_to_child_edges count]; + int y = keypoint[0]; + int x = keypoint[1]; + int offset = (y * _tflite_width + x) * num_edges * 2 + edgeId; + res[0] = displacements[offset]; + res[1] = displacements[offset + num_edges]; +} + +float getInstanceScore(NSMutableDictionary* keypoints) { + float scores = 0; + for (NSMutableDictionary* keypoint in keypoints.allValues) + scores += [keypoint[@"score"] floatValue]; + return scores / _tflite_num_keypoints; +} + +NSMutableDictionary* traverseToTargetKeypoint(int edge_id, + NSMutableDictionary* source_keypoint, + int target_keypoint_id, + float* scores, + float* offsets, + float* displacements, + int input_size) { + float source_keypoint_y = [source_keypoint[@"y"] floatValue] * input_size; + float source_keypoint_x = [source_keypoint[@"x"] floatValue] * input_size; + + int source_keypoint_indices[2]; + getStridedIndexNearPoint(source_keypoint_indices, source_keypoint_y, source_keypoint_x); + + float displacement[2]; + getDisplacement(displacement, edge_id, source_keypoint_indices, displacements); + + float displaced_point[2]; + displaced_point[0] = source_keypoint_y + displacement[0]; + displaced_point[1] = source_keypoint_x + displacement[1]; + + float* target_keypoint = displaced_point; + + int offset_refine_step = 2; + for (int i = 0; i < offset_refine_step; i++) { + int target_keypoint_indices[2]; + getStridedIndexNearPoint(target_keypoint_indices, target_keypoint[0], target_keypoint[1]); + + int target_keypoint_y = target_keypoint_indices[0]; + int target_keypoint_x = target_keypoint_indices[1]; + + int offset = (target_keypoint_y * _tflite_width + target_keypoint_x) * _tflite_num_keypoints * 2 + target_keypoint_id; + float offset_y = offsets[offset]; + float offset_x = offsets[offset + _tflite_num_keypoints]; + + target_keypoint[0] = target_keypoint_y * _tflite_output_stride + offset_y; + target_keypoint[1] = target_keypoint_x * _tflite_output_stride + offset_x; + } + + int target_keypoint_indices[2]; + getStridedIndexNearPoint(target_keypoint_indices, target_keypoint[0], target_keypoint[1]); + + float score = sigmoid(scores[(target_keypoint_indices[0] * _tflite_width + + target_keypoint_indices[1]) * _tflite_num_keypoints + target_keypoint_id]); + + NSMutableDictionary* keypoint = [NSMutableDictionary dictionary]; + [keypoint setValue:[NSNumber numberWithFloat:score] forKey:@"score"]; + [keypoint setValue:[NSNumber numberWithFloat:target_keypoint[0] / input_size] forKey:@"y"]; + [keypoint setValue:[NSNumber numberWithFloat:target_keypoint[1] / input_size] forKey:@"x"]; + [keypoint setValue:_tflite_part_names[target_keypoint_id] forKey:@"part"]; + return keypoint; +} + +NSMutableArray* parsePoseNet(int num_results, float threshold, int nms_radius, int input_size) { + initPoseNet(); + +#ifdef TFLITE2 + assert(TfLiteInterpreterGetOutputTensorCount(interpreter) == 4); + const TfLiteTensor* scores_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0); +#else + assert(interpreter->outputs().size() == 4); + TfLiteTensor* scores_tensor = interpreter->tensor(interpreter->outputs()[0]); +#endif + _tflite_height = scores_tensor->dims->data[1]; + _tflite_width = scores_tensor->dims->data[2]; + _tflite_num_keypoints = scores_tensor->dims->data[3]; + +#ifdef TFLITE2 + float* scores = TfLiteInterpreterGetOutputTensor(interpreter, 0)->data.f; + float* offsets = TfLiteInterpreterGetOutputTensor(interpreter, 1)->data.f; + float* displacements_fwd = TfLiteInterpreterGetOutputTensor(interpreter, 2)->data.f; + float* displacements_bwd = TfLiteInterpreterGetOutputTensor(interpreter, 3)->data.f; +#else + float* scores = interpreter->typed_output_tensor(0); + float* offsets = interpreter->typed_output_tensor(1); + float* displacements_fwd = interpreter->typed_output_tensor(2); + float* displacements_bwd = interpreter->typed_output_tensor(3); +#endif + PriorityQueue pq = buildPartWithScoreQueue(scores, threshold, _tflite_local_maximum_radius); + + int num_edges = (int)[_tflite_parent_to_child_edges count]; + int sqared_nms_radius = nms_radius * nms_radius; + + NSMutableArray* results = [NSMutableArray array]; + + while([results count] < num_results && !pq.empty()) { + NSMutableDictionary* root = pq.top().second; + pq.pop(); + + float root_point[2]; + getImageCoords(root_point, root, offsets); + + if (withinNmsRadiusOfCorrespondingPoint(results, sqared_nms_radius, root_point[0], root_point[1], + [root[@"partId"] intValue], input_size)) + continue; + + NSMutableDictionary* keypoint = [NSMutableDictionary dictionary]; + [keypoint setValue:[NSNumber numberWithFloat:[root[@"score"] floatValue]] forKey:@"score"]; + [keypoint setValue:[NSNumber numberWithFloat:root_point[0] / input_size] forKey:@"y"]; + [keypoint setValue:[NSNumber numberWithFloat:root_point[1] / input_size] forKey:@"x"]; + [keypoint setValue:_tflite_part_names[[root[@"partId"] intValue]] forKey:@"part"]; + + NSMutableDictionary* keypoints = [NSMutableDictionary dictionary]; + [keypoints setObject:keypoint forKey:root[@"partId"]]; + + for (int edge = num_edges - 1; edge >= 0; --edge) { + int source_keypoint_id = [_tflite_parent_to_child_edges[edge] intValue]; + int target_keypoint_id = [_tflite_child_to_parent_edges[edge] intValue]; + if (keypoints[[NSNumber numberWithInt:source_keypoint_id]] && + !(keypoints[[NSNumber numberWithInt:target_keypoint_id]])) { + keypoint = traverseToTargetKeypoint(edge, keypoints[[NSNumber numberWithInt:source_keypoint_id]], + target_keypoint_id, scores, offsets, displacements_bwd, input_size); + [keypoints setObject:keypoint forKey:[NSNumber numberWithInt:target_keypoint_id]]; + } + } + + for (int edge = 0; edge < num_edges; ++edge) { + int source_keypoint_id = [_tflite_child_to_parent_edges[edge] intValue]; + int target_keypoint_id = [_tflite_parent_to_child_edges[edge] intValue]; + if (keypoints[[NSNumber numberWithInt:source_keypoint_id]] && + !(keypoints[[NSNumber numberWithInt:target_keypoint_id]])) { + keypoint = traverseToTargetKeypoint(edge, keypoints[[NSNumber numberWithInt:source_keypoint_id]], + target_keypoint_id, scores, offsets, displacements_fwd, input_size); + [keypoints setObject:keypoint forKey:[NSNumber numberWithInt:target_keypoint_id]]; + } + } + + NSMutableDictionary* result = [NSMutableDictionary dictionary]; + [result setObject:keypoints forKey:@"keypoints"]; + [result setValue:[NSNumber numberWithFloat:getInstanceScore(keypoints)] forKey:@"score"]; + [results addObject:result]; + } + + return results; +} + +void runPoseNetOnImage(NSDictionary* args, FlutterResult result) { + const NSString* image_path = args[@"path"]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorImage(image_path, input_mean, input_std, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void runPoseNetOnBinary(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"binary"]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + feedInputTensorBinary(typedData, &input_size); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void runPoseNetOnFrame(NSDictionary* args, FlutterResult result) { + const FlutterStandardTypedData* typedData = args[@"bytesList"][0]; + const int image_height = [args[@"imageHeight"] intValue]; + const int image_width = [args[@"imageWidth"] intValue]; + const float input_mean = [args[@"imageMean"] floatValue]; + const float input_std = [args[@"imageStd"] floatValue]; + const int num_results = [args[@"numResults"] intValue]; + const float threshold = [args[@"threshold"] floatValue]; + const int nms_radius = [args[@"nmsRadius"] intValue];; + NSMutableArray* empty = [@[] mutableCopy]; + + if (!interpreter || interpreter_busy) { + NSLog(@"Failed to construct interpreter or busy."); + return result(empty); + } + + int input_size; + int image_channels = 4; + feedInputTensorFrame(typedData, &input_size, image_height, image_width, image_channels, input_mean, input_std); + + runTflite(args, ^(TfLiteStatus status) { + if (status != kTfLiteOk) { + NSLog(@"Failed to invoke!"); + return result(empty); + } + + return result(parsePoseNet(num_results, threshold, nms_radius, input_size)); + }); +} + +void close() { +#ifdef TFLITE2 + interpreter = nullptr; + if (delegate != nullptr) + TFLGpuDelegateDelete(delegate); + delegate = nullptr; +#else + interpreter.release(); + interpreter = NULL; +#endif + model = NULL; + labels.clear(); +} + diff --git a/plugins/tflite_v2/ios/Classes/ios_image_load.h b/plugins/tflite_v2/ios/Classes/ios_image_load.h new file mode 100644 index 0000000..faec1be --- /dev/null +++ b/plugins/tflite_v2/ios/Classes/ios_image_load.h @@ -0,0 +1,12 @@ +#include + +std::vector LoadImageFromFile(const char* file_name, + int* out_width, + int* out_height, + int* out_channels); + +NSData *CompressImage(NSMutableData*, + int width, + int height, + int bytesPerPixel); + diff --git a/plugins/tflite_v2/ios/Classes/ios_image_load.mm b/plugins/tflite_v2/ios/Classes/ios_image_load.mm new file mode 100644 index 0000000..421b702 --- /dev/null +++ b/plugins/tflite_v2/ios/Classes/ios_image_load.mm @@ -0,0 +1,93 @@ +#import +#include "ios_image_load.h" + +#include +#include +#include +#include + +#import +#import + +std::vector LoadImageFromFile(const char* file_name, + int* out_width, int* out_height, + int* out_channels) { + FILE* file_handle = fopen(file_name, "rb"); + fseek(file_handle, 0, SEEK_END); + const size_t bytes_in_file = ftell(file_handle); + fseek(file_handle, 0, SEEK_SET); + std::vector file_data(bytes_in_file); + fread(file_data.data(), 1, bytes_in_file, file_handle); + fclose(file_handle); + + CFDataRef file_data_ref = CFDataCreateWithBytesNoCopy(NULL, file_data.data(), + bytes_in_file, + kCFAllocatorNull); + CGDataProviderRef image_provider = CGDataProviderCreateWithCFData(file_data_ref); + + const char* suffix = strrchr(file_name, '.'); + if (!suffix || suffix == file_name) { + suffix = ""; + } + CGImageRef image; + if (strcasecmp(suffix, ".png") == 0) { + image = CGImageCreateWithPNGDataProvider(image_provider, NULL, true, + kCGRenderingIntentDefault); + } else if ((strcasecmp(suffix, ".jpg") == 0) || + (strcasecmp(suffix, ".jpeg") == 0)) { + image = CGImageCreateWithJPEGDataProvider(image_provider, NULL, true, + kCGRenderingIntentDefault); + } else { + CFRelease(image_provider); + CFRelease(file_data_ref); + fprintf(stderr, "Unknown suffix for file '%s'\n", file_name); + out_width = 0; + out_height = 0; + *out_channels = 0; + return std::vector(); + } + + int width = (int)CGImageGetWidth(image); + int height = (int)CGImageGetHeight(image); + const int channels = 4; + CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); + const int bytes_per_row = (width * channels); + const int bytes_in_image = (bytes_per_row * height); + std::vector result(bytes_in_image); + const int bits_per_component = 8; + + CGContextRef context = CGBitmapContextCreate(result.data(), width, height, + bits_per_component, bytes_per_row, color_space, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(color_space); + CGContextDrawImage(context, CGRectMake(0, 0, width, height), image); + CGContextRelease(context); + CFRelease(image); + CFRelease(image_provider); + CFRelease(file_data_ref); + + *out_width = width; + *out_height = height; + *out_channels = channels; + return result; +} + +NSData *CompressImage(NSMutableData *image, int width, int height, int bytesPerPixel) { + const int channels = 4; + CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate([image mutableBytes], width, height, + bytesPerPixel*8, width*channels*bytesPerPixel, color_space, + kCGImageAlphaPremultipliedLast | (bytesPerPixel == 4 ? kCGBitmapFloatComponents : kCGBitmapByteOrder32Big)); + CGColorSpaceRelease(color_space); + if (context == nil) return nil; + + CGImageRef imgRef = CGBitmapContextCreateImage(context); + CGContextRelease(context); + if (imgRef == nil) return nil; + + UIImage* img = [UIImage imageWithCGImage:imgRef]; + CGImageRelease(imgRef); + if (img == nil) return nil; + + return UIImagePNGRepresentation(img); +} diff --git a/plugins/tflite_v2/ios/tflite.podspec b/plugins/tflite_v2/ios/tflite.podspec new file mode 100644 index 0000000..d91a6ef --- /dev/null +++ b/plugins/tflite_v2/ios/tflite.podspec @@ -0,0 +1,24 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'tflite' + s.version = '1.1.2' + s.summary = 'A Flutter plugin for accessing TensorFlow Lite.' + s.description = <<-DESC +A Flutter plugin for accessing TensorFlow Lite. Supports both iOS and Android. + DESC + s.homepage = 'https://github.com/shaqian/flutter_tflite' + s.license = { :file => '../LICENSE' } + s.author = { 'Qian Sha' => 'https://github.com/shaqian' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.dependency 'Flutter' + s.dependency 'TensorFlowLiteC' + s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/tflite" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Flutter" "${PODS_ROOT}/Headers/Public/TensorFlowLite/tensorflow_lite" "${PODS_ROOT}/Headers/Public/tflite" "${PODS_ROOT}/TensorFlowLite/Frameworks/tensorflow_lite.framework/Headers" "${PODS_ROOT}/TensorFlowLiteC/Frameworks/TensorFlowLiteC.framework/Headers"' } + + s.ios.deployment_target = '9.0' + s.static_framework = true +end + diff --git a/plugins/tflite_v2/lib/tflite_v2.dart b/plugins/tflite_v2/lib/tflite_v2.dart new file mode 100644 index 0000000..e7a74b4 --- /dev/null +++ b/plugins/tflite_v2/lib/tflite_v2.dart @@ -0,0 +1,407 @@ +import 'dart:async'; +import 'package:flutter/services.dart'; + +class Tflite { + static const MethodChannel _channel = const MethodChannel('tflite'); + + static Future loadModel( + {required String model, + String labels = "", + int numThreads = 1, + bool isAsset = true, + bool useGpuDelegate = false}) async { + return await _channel.invokeMethod( + 'loadModel', + { + "model": model, + "labels": labels, + "numThreads": numThreads, + "isAsset": isAsset, + 'useGpuDelegate': useGpuDelegate + }, + ); + } + + static Future runModelOnImage( + {required String path, + double imageMean = 117.0, + double imageStd = 1.0, + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static Future runModelOnBinary( + {required Uint8List binary, + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnBinary', + { + "binary": binary, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static Future runModelOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + int rotation = 90, // Android only + int numResults = 5, + double threshold = 0.1, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runModelOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "numResults": numResults, + "threshold": threshold, + "asynch": asynch, + }, + ); + } + + static const anchors = [ + 0.57273, + 0.677385, + 1.87446, + 2.06253, + 3.33843, + 5.47434, + 7.88282, + 3.52778, + 9.77052, + 9.16828 + ]; + + static Future detectObjectOnImage({ + required String path, + String model = "SSDMobileNet", + double imageMean = 127.5, + double imageStd = 127.5, + double threshold = 0.1, + int numResultsPerClass = 5, + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnImage', + { + "path": path, + "model": model, + "imageMean": imageMean, + "imageStd": imageStd, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future detectObjectOnBinary({ + required Uint8List binary, + String model = "SSDMobileNet", + double threshold = 0.1, + int numResultsPerClass = 5, + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnBinary', + { + "binary": binary, + "model": model, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future detectObjectOnFrame({ + required List bytesList, + String model = "SSDMobileNet", + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + double threshold = 0.1, + int numResultsPerClass = 5, + int rotation = 90, // Android only + // Used in YOLO only + List anchors = anchors, + int blockSize = 32, + int numBoxesPerBlock = 5, + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'detectObjectOnFrame', + { + "bytesList": bytesList, + "model": model, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "threshold": threshold, + "numResultsPerClass": numResultsPerClass, + "anchors": anchors, + "blockSize": blockSize, + "numBoxesPerBlock": numBoxesPerBlock, + "asynch": asynch, + }, + ); + } + + static Future close() async { + return await _channel.invokeMethod('close'); + } + + static Future runPix2PixOnImage( + {required String path, + double imageMean = 0, + double imageStd = 255.0, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPix2PixOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + static Future runPix2PixOnBinary( + {required Uint8List binary, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPix2PixOnBinary', + { + "binary": binary, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + static Future runPix2PixOnFrame({ + required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 0, + double imageStd = 255.0, + int rotation = 90, // Android only + String outputType = "png", + bool asynch = true, + }) async { + return await _channel.invokeMethod( + 'runPix2PixOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "asynch": asynch, + "outputType": outputType, + }, + ); + } + + // https://github.com/meetshah1995/pytorch-semseg/blob/master/ptsemseg/loader/pascal_voc_loader.py + static List pascalVOCLabelColors = [ + Color.fromARGB(255, 0, 0, 0).value, // background + Color.fromARGB(255, 128, 0, 0).value, // aeroplane + Color.fromARGB(255, 0, 128, 0).value, // biyclce + Color.fromARGB(255, 128, 128, 0).value, // bird + Color.fromARGB(255, 0, 0, 128).value, // boat + Color.fromARGB(255, 128, 0, 128).value, // bottle + Color.fromARGB(255, 0, 128, 128).value, // bus + Color.fromARGB(255, 128, 128, 128).value, // car + Color.fromARGB(255, 64, 0, 0).value, // cat + Color.fromARGB(255, 192, 0, 0).value, // chair + Color.fromARGB(255, 64, 128, 0).value, // cow + Color.fromARGB(255, 192, 128, 0).value, // diningtable + Color.fromARGB(255, 64, 0, 128).value, // dog + Color.fromARGB(255, 192, 0, 128).value, // horse + Color.fromARGB(255, 64, 128, 128).value, // motorbike + Color.fromARGB(255, 192, 128, 128).value, // person + Color.fromARGB(255, 0, 64, 0).value, // potted plant + Color.fromARGB(255, 128, 64, 0).value, // sheep + Color.fromARGB(255, 0, 192, 0).value, // sofa + Color.fromARGB(255, 128, 192, 0).value, // train + Color.fromARGB(255, 0, 64, 128).value, // tv-monitor + ]; + + static Future runSegmentationOnImage( + {required String path, + double imageMean = 0, + double imageStd = 255.0, + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runSegmentationOnBinary( + {required Uint8List binary, + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnBinary', + { + "binary": binary, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runSegmentationOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 0, + double imageStd = 255.0, + int rotation = 90, // Android only + List? labelColors, + String outputType = "png", + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runSegmentationOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "labelColors": labelColors ?? pascalVOCLabelColors, + "outputType": outputType, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnImage( + {required String path, + double imageMean = 127.5, + double imageStd = 127.5, + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnImage', + { + "path": path, + "imageMean": imageMean, + "imageStd": imageStd, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnBinary( + {required Uint8List binary, + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnBinary', + { + "binary": binary, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } + + static Future runPoseNetOnFrame( + {required List bytesList, + int imageHeight = 1280, + int imageWidth = 720, + double imageMean = 127.5, + double imageStd = 127.5, + int rotation = 90, // Android only + int numResults = 5, + double threshold = 0.5, + int nmsRadius = 20, + bool asynch = true}) async { + return await _channel.invokeMethod( + 'runPoseNetOnFrame', + { + "bytesList": bytesList, + "imageHeight": imageHeight, + "imageWidth": imageWidth, + "imageMean": imageMean, + "imageStd": imageStd, + "rotation": rotation, + "numResults": numResults, + "threshold": threshold, + "nmsRadius": nmsRadius, + "asynch": asynch, + }, + ); + } +} diff --git a/plugins/tflite_v2/pubspec.yaml b/plugins/tflite_v2/pubspec.yaml new file mode 100644 index 0000000..716d0b4 --- /dev/null +++ b/plugins/tflite_v2/pubspec.yaml @@ -0,0 +1,64 @@ +name: tflite_v2 +description: A Flutter plugin for accessing TensorFlow Lite, fixed android embedding v2 error. Supports both iOS and Android. +version: 1.0.0 +homepage: https://github.com/Niketgoriya/flutter_tflite + +environment: + sdk: '>=2.12.0 <3.0.0' + flutter: ">=1.10.0" + +dependencies: + flutter: + sdk: flutter + + meta: ^1.3.0 + +dev_dependencies: + flutter_test: + sdk: flutter + test: ^1.16.5 + +# For information on the generic Dart part of this file, see the +# following page: https://www.dartlang.org/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + plugin: + platforms: + android: + package: sq.flutter.tflite + pluginClass: TflitePlugin + ios: + pluginClass: TflitePlugin + + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.io/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.io/assets-and-images/#resolution-aware. + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.io/custom-fonts/#from-packages diff --git a/plugins/tflite_v2/test/tflite_test.dart b/plugins/tflite_v2/test/tflite_test.dart new file mode 100644 index 0000000..acbf341 --- /dev/null +++ b/plugins/tflite_v2/test/tflite_test.dart @@ -0,0 +1,568 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:tflite_v2/tflite_v2.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + const MethodChannel channel = MethodChannel( + 'tflite', + ); + + final List log = []; + + setUp(() async { + channel.setMockMethodCallHandler((MethodCall methodCall) { + log.add(methodCall); + return null; + }); + log.clear(); + }); + test('loadModel', () async { + await Tflite.loadModel( + model: 'assets/mobilenet_v1_1.0_224.tflite', + labels: 'assets/mobilenet_v1_1.0_224.txt', + numThreads: 2, + isAsset: false, + useGpuDelegate: true, + ); + expect( + log, + [ + isMethodCall( + 'loadModel', + arguments: { + 'model': 'assets/mobilenet_v1_1.0_224.tflite', + 'labels': 'assets/mobilenet_v1_1.0_224.txt', + 'numThreads': 2, + 'isAsset': false, + 'useGpuDelegate': true, + }, + ), + ], + ); + }); + + test('runModelOnImage', () async { + await Tflite.runModelOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + numResults: 6, + threshold: 0.1, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'numResults': 6, + 'threshold': 0.1, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runModelOnBinary', () async { + await Tflite.runModelOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + numResults: 15, + threshold: 0.8, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'numResults': 15, + 'threshold': 0.8, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runModelOnFrame', () async { + await Tflite.runModelOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + numResults: 10, + threshold: 0.2, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runModelOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'numResults': 10, + 'threshold': 0.2, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnImage', () async { + await Tflite.detectObjectOnImage( + path: '/image/path', + model: 'YOLO', + imageMean: 127.5, + imageStd: 0.5, + threshold: 0.1, + numResultsPerClass: 5, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnImage', + arguments: { + 'path': '/image/path', + 'model': 'YOLO', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'threshold': 0.1, + 'numResultsPerClass': 5, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnBinary', () async { + await Tflite.detectObjectOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + model: "YOLO", + threshold: 0.2, + numResultsPerClass: 10, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'model': "YOLO", + 'threshold': 0.2, + 'numResultsPerClass': 10, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('detectObjectOnFrame', () async { + await Tflite.detectObjectOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + model: "YOLO", + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + threshold: 0.2, + numResultsPerClass: 10, + anchors: [ + 1, + 2, + 3, + 4, + ], + blockSize: 32, + numBoxesPerBlock: 5, + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'detectObjectOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'model': "YOLO", + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'threshold': 0.2, + 'numResultsPerClass': 10, + 'anchors': [ + 1, + 2, + 3, + 4, + ], + 'blockSize': 32, + 'numBoxesPerBlock': 5, + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnImage', () async { + await Tflite.runPix2PixOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnBinary', () async { + await Tflite.runPix2PixOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runPix2PixOnFrame', () async { + await Tflite.runPix2PixOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runPix2PixOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnImage', () async { + await Tflite.runSegmentationOnImage( + path: '/image/path', + imageMean: 127.5, + imageStd: 0.5, + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnImage', + arguments: { + 'path': '/image/path', + 'imageMean': 127.5, + 'imageStd': 0.5, + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnBinary', () async { + await Tflite.runSegmentationOnBinary( + binary: Uint8List.fromList([ + 0, + 1, + 2, + ]), + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnBinary', + arguments: { + 'binary': Uint8List.fromList([ + 0, + 1, + 2, + ]), + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); + + test('runSegmentationOnFrame', () async { + await Tflite.runSegmentationOnFrame( + bytesList: [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + imageHeight: 100, + imageWidth: 200, + imageMean: 127.5, + imageStd: 0.5, + rotation: 30, + labelColors: [ + 1, + 2, + 3, + ], + outputType: 'png', + asynch: false, + ); + expect( + log, + [ + isMethodCall( + 'runSegmentationOnFrame', + arguments: { + 'bytesList': [ + Uint8List.fromList([ + 0, + 1, + 2, + ]), + Uint8List.fromList([ + 0, + 1, + 2, + ]), + ], + 'imageHeight': 100, + 'imageWidth': 200, + 'imageMean': 127.5, + 'imageStd': 0.5, + 'rotation': 30, + 'labelColors': [ + 1, + 2, + 3, + ], + 'outputType': 'png', + 'asynch': false, + }, + ), + ], + ); + }); +} diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..5f83c12 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,473 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + characters: + dependency: transitive + description: + name: characters + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + cross_file: + dependency: transitive + description: + name: cross_file + sha256: "701dcfc06da0882883a2657c445103380e53e647060ad8d9dfb710c100996608" + url: "https://pub.dev" + source: hosted + version: "0.3.5+1" + crypto: + dependency: transitive + description: + name: crypto + sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf + url: "https://pub.dev" + source: hosted + version: "3.0.7" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" + source: hosted + version: "1.0.8" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + url: "https://pub.dev" + source: hosted + version: "1.3.3" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + file_selector_linux: + dependency: transitive + description: + name: file_selector_linux + sha256: "2567f398e06ac72dcf2e98a0c95df2a9edd03c2c2e0cacd4780f20cdf56263a0" + url: "https://pub.dev" + source: hosted + version: "0.9.4" + file_selector_macos: + dependency: transitive + description: + name: file_selector_macos + sha256: "5e0bbe9c312416f1787a68259ea1505b52f258c587f12920422671807c4d618a" + url: "https://pub.dev" + source: hosted + version: "0.9.5" + file_selector_platform_interface: + dependency: transitive + description: + name: file_selector_platform_interface + sha256: "35e0bd61ebcdb91a3505813b055b09b79dfdc7d0aee9c09a7ba59ae4bb13dc85" + url: "https://pub.dev" + source: hosted + version: "2.7.0" + file_selector_windows: + dependency: transitive + description: + name: file_selector_windows + sha256: "62197474ae75893a62df75939c777763d39c2bc5f73ce5b88497208bc269abfd" + url: "https://pub.dev" + source: hosted + version: "0.9.3+5" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1" + url: "https://pub.dev" + source: hosted + version: "5.0.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + sha256: ee8068e0e1cd16c4a82714119918efdeed33b3ba7772c54b5d094ab53f9b7fd1 + url: "https://pub.dev" + source: hosted + version: "2.0.33" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + sha256: ba03d03bcaa2f6cb7bd920e3b5027181db75ab524f8891c8bc3aa603885b8055 + url: "https://pub.dev" + source: hosted + version: "6.3.3" + http: + dependency: transitive + description: + name: http + sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412" + url: "https://pub.dev" + source: hosted + version: "1.6.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + image_picker: + dependency: "direct main" + description: + name: image_picker + sha256: "784210112be18ea55f69d7076e2c656a4e24949fa9e76429fe53af0c0f4fa320" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + image_picker_android: + dependency: transitive + description: + name: image_picker_android + sha256: "5e9bf126c37c117cf8094215373c6d561117a3cfb50ebc5add1a61dc6e224677" + url: "https://pub.dev" + source: hosted + version: "0.8.13+10" + image_picker_for_web: + dependency: transitive + description: + name: image_picker_for_web + sha256: "66257a3191ab360d23a55c8241c91a6e329d31e94efa7be9cf7a212e65850214" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + image_picker_ios: + dependency: transitive + description: + name: image_picker_ios + sha256: "956c16a42c0c708f914021666ffcd8265dde36e673c9fa68c81f7d085d9774ad" + url: "https://pub.dev" + source: hosted + version: "0.8.13+3" + image_picker_linux: + dependency: transitive + description: + name: image_picker_linux + sha256: "1f81c5f2046b9ab724f85523e4af65be1d47b038160a8c8deed909762c308ed4" + url: "https://pub.dev" + source: hosted + version: "0.2.2" + image_picker_macos: + dependency: transitive + description: + name: image_picker_macos + sha256: "86f0f15a309de7e1a552c12df9ce5b59fe927e71385329355aec4776c6a8ec91" + url: "https://pub.dev" + source: hosted + version: "0.2.2+1" + image_picker_platform_interface: + dependency: transitive + description: + name: image_picker_platform_interface + sha256: "567e056716333a1647c64bb6bd873cff7622233a5c3f694be28a583d4715690c" + url: "https://pub.dev" + source: hosted + version: "2.11.1" + image_picker_windows: + dependency: transitive + description: + name: image_picker_windows + sha256: d248c86554a72b5495a31c56f060cf73a41c7ff541689327b1a7dbccc33adfae + url: "https://pub.dev" + source: hosted + version: "0.2.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" + url: "https://pub.dev" + source: hosted + version: "11.0.2" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" + url: "https://pub.dev" + source: hosted + version: "3.0.10" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + lints: + dependency: transitive + description: + name: lints + sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7 + url: "https://pub.dev" + source: hosted + version: "5.1.1" + matcher: + dependency: transitive + description: + name: matcher + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + url: "https://pub.dev" + source: hosted + version: "0.12.17" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + mime: + dependency: transitive + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + path_provider: + dependency: transitive + description: + name: path_provider + sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: f2c65e21139ce2c3dad46922be8272bb5963516045659e71bb16e151c93b580e + url: "https://pub.dev" + source: hosted + version: "2.2.22" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: "6d13aece7b3f5c5a9731eaf553ff9dcbc2eff41087fd2df587fd0fed9a3eb0c4" + url: "https://pub.dev" + source: hosted + version: "2.5.1" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.dev" + source: hosted + version: "2.2.1" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 + url: "https://pub.dev" + source: hosted + version: "2.3.0" + platform: + dependency: transitive + description: + name: platform + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + url: "https://pub.dev" + source: hosted + version: "3.1.6" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test_api: + dependency: transitive + description: + name: test_api + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 + url: "https://pub.dev" + source: hosted + version: "0.7.7" + tflite_v2: + dependency: "direct main" + description: + path: "plugins/tflite_v2" + relative: true + source: path + version: "1.0.0" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b + url: "https://pub.dev" + source: hosted + version: "2.2.0" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" + url: "https://pub.dev" + source: hosted + version: "15.0.2" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" + url: "https://pub.dev" + source: hosted + version: "1.1.0" +sdks: + dart: ">=3.9.0 <4.0.0" + flutter: ">=3.35.0" diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..cacc761 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,43 @@ +name: fungid3 +description: "A new Flutter project." +publish_to: 'none' + +version: 1.0.0+1 + +environment: + sdk: ^3.5.4 + +dependencies: + flutter: + sdk: flutter + + cupertino_icons: ^1.0.8 + google_fonts: ^6.2.1 + image_picker: ^1.1.1 + tflite_v2: ^1.0.0 + +dependency_overrides: + tflite_v2: + path: plugins/tflite_v2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^5.0.0 + +flutter: + uses-material-design: true + + assets: + # Asset Sistem & Model + - assets/logo.png + - assets/scanjamur.png + - assets/warna_mencolok.jpeg + - assets/tempat_lembap.jpeg + - assets/bau_menyenga.jpeg + - assets/licin_berlendir.jpeg + - assets/model_cnn.tflite + - assets/labels.txt + + # Asset Gambar Jamur (Mendaftarkan seluruh folder agar file 1-15 terbaca otomatis) + - assets/ \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart new file mode 100644 index 0000000..a9759a8 --- /dev/null +++ b/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:fungid3_new/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/web/favicon.png b/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/web/favicon.png differ diff --git a/web/icons/Icon-192.png b/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/web/icons/Icon-192.png differ diff --git a/web/icons/Icon-512.png b/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/web/icons/Icon-512.png differ diff --git a/web/icons/Icon-maskable-192.png b/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/web/icons/Icon-maskable-192.png differ diff --git a/web/icons/Icon-maskable-512.png b/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/web/icons/Icon-maskable-512.png differ diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..7225af4 --- /dev/null +++ b/web/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + fungid3_new + + + + + + diff --git a/web/manifest.json b/web/manifest.json new file mode 100644 index 0000000..1fa25d4 --- /dev/null +++ b/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "fungid3_new", + "short_name": "fungid3_new", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/windows/.gitignore b/windows/.gitignore new file mode 100644 index 0000000..d492d0d --- /dev/null +++ b/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt new file mode 100644 index 0000000..8d0bb2a --- /dev/null +++ b/windows/CMakeLists.txt @@ -0,0 +1,108 @@ +# Project-level configuration. +cmake_minimum_required(VERSION 3.14) +project(fungid3_new LANGUAGES CXX) + +# The name of the executable created for the application. Change this to change +# the on-disk name of your application. +set(BINARY_NAME "fungid3_new") + +# Explicitly opt in to modern CMake behaviors to avoid warnings with recent +# versions of CMake. +cmake_policy(VERSION 3.14...3.25) + +# Define build configuration option. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() +# Define settings for the Profile build mode. +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +# +# Be cautious about adding new options here, as plugins use this function by +# default. In most cases, you should add new options to specific targets instead +# of modifying this function. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +# Flutter library and tool build rules. +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build; see runner/CMakeLists.txt. +add_subdirectory("runner") + + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Copy the native assets provided by the build.dart from all packages. +set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") +install(DIRECTORY "${NATIVE_ASSETS_DIR}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/windows/flutter/CMakeLists.txt b/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000..903f489 --- /dev/null +++ b/windows/flutter/CMakeLists.txt @@ -0,0 +1,109 @@ +# This file controls Flutter-level build steps. It should not be edited. +cmake_minimum_required(VERSION 3.14) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + ${FLUTTER_TARGET_PLATFORM} $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000..77ab7a0 --- /dev/null +++ b/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,14 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + +#include + +void RegisterPlugins(flutter::PluginRegistry* registry) { + FileSelectorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FileSelectorWindows")); +} diff --git a/windows/flutter/generated_plugin_registrant.h b/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000..dc139d8 --- /dev/null +++ b/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake new file mode 100644 index 0000000..a423a02 --- /dev/null +++ b/windows/flutter/generated_plugins.cmake @@ -0,0 +1,24 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + file_selector_windows +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt new file mode 100644 index 0000000..394917c --- /dev/null +++ b/windows/runner/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.14) +project(runner LANGUAGES CXX) + +# Define the application target. To change its name, change BINARY_NAME in the +# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer +# work. +# +# Any new source files that you add to the application should be added here. +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) + +# Apply the standard set of build settings. This can be removed for applications +# that need different build settings. +apply_standard_settings(${BINARY_NAME}) + +# Add preprocessor definitions for the build version. +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") +target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") + +# Disable Windows macros that collide with C++ standard library functions. +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") + +# Add dependency libraries and include directories. Add any application-specific +# dependencies here. +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") + +# Run the Flutter tool portions of the build. This must not be removed. +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc new file mode 100644 index 0000000..51ecbb3 --- /dev/null +++ b/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD +#else +#define VERSION_AS_NUMBER 1,0,0,0 +#endif + +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "fungid3_new" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "fungid3_new" "\0" + VALUE "LegalCopyright", "Copyright (C) 2025 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "fungid3_new.exe" "\0" + VALUE "ProductName", "fungid3_new" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/windows/runner/flutter_window.cpp b/windows/runner/flutter_window.cpp new file mode 100644 index 0000000..955ee30 --- /dev/null +++ b/windows/runner/flutter_window.cpp @@ -0,0 +1,71 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + + // Flutter can complete the first frame before the "show window" callback is + // registered. The following call ensures a frame is pending to ensure the + // window is shown. It is a no-op if the first frame hasn't completed yet. + flutter_controller_->ForceRedraw(); + + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/windows/runner/flutter_window.h b/windows/runner/flutter_window.h new file mode 100644 index 0000000..6da0652 --- /dev/null +++ b/windows/runner/flutter_window.h @@ -0,0 +1,33 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp new file mode 100644 index 0000000..cc45438 --- /dev/null +++ b/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.Create(L"fungid3_new", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/windows/runner/resource.h b/windows/runner/resource.h new file mode 100644 index 0000000..66a65d1 --- /dev/null +++ b/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/windows/runner/resources/app_icon.ico b/windows/runner/resources/app_icon.ico new file mode 100644 index 0000000..c04e20c Binary files /dev/null and b/windows/runner/resources/app_icon.ico differ diff --git a/windows/runner/runner.exe.manifest b/windows/runner/runner.exe.manifest new file mode 100644 index 0000000..153653e --- /dev/null +++ b/windows/runner/runner.exe.manifest @@ -0,0 +1,14 @@ + + + + + PerMonitorV2 + + + + + + + + + diff --git a/windows/runner/utils.cpp b/windows/runner/utils.cpp new file mode 100644 index 0000000..3a0b465 --- /dev/null +++ b/windows/runner/utils.cpp @@ -0,0 +1,65 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + unsigned int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr) + -1; // remove the trailing null character + int input_length = (int)wcslen(utf16_string); + std::string utf8_string; + if (target_length == 0 || target_length > utf8_string.max_size()) { + return utf8_string; + } + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + input_length, utf8_string.data(), target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/windows/runner/utils.h b/windows/runner/utils.h new file mode 100644 index 0000000..3879d54 --- /dev/null +++ b/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/windows/runner/win32_window.cpp b/windows/runner/win32_window.cpp new file mode 100644 index 0000000..60608d0 --- /dev/null +++ b/windows/runner/win32_window.cpp @@ -0,0 +1,288 @@ +#include "win32_window.h" + +#include +#include + +#include "resource.h" + +namespace { + +/// Window attribute that enables dark mode window decorations. +/// +/// Redefined in case the developer's machine has a Windows SDK older than +/// version 10.0.22000.0. +/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +/// Registry key for app theme preference. +/// +/// A value of 0 indicates apps should use dark mode. A non-zero or missing +/// value indicates apps should use light mode. +constexpr const wchar_t kGetPreferredBrightnessRegKey[] = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; +constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + } + FreeLibrary(user32_module); +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registrar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + UpdateTheme(window); + + return OnCreate(); +} + +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + + case WM_DWMCOLORIZATIONCOLORCHANGED: + UpdateTheme(hwnd); + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} + +void Win32Window::UpdateTheme(HWND const window) { + DWORD light_mode; + DWORD light_mode_size = sizeof(light_mode); + LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, + kGetPreferredBrightnessRegValue, + RRF_RT_REG_DWORD, nullptr, &light_mode, + &light_mode_size); + + if (result == ERROR_SUCCESS) { + BOOL enable_dark_mode = light_mode == 0; + DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, + &enable_dark_mode, sizeof(enable_dark_mode)); + } +} diff --git a/windows/runner/win32_window.h b/windows/runner/win32_window.h new file mode 100644 index 0000000..e901dde --- /dev/null +++ b/windows/runner/win32_window.h @@ -0,0 +1,102 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates a win32 window with |title| that is positioned and sized using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + // Update the window frame's theme to match the system theme. + static void UpdateTheme(HWND const window); + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_