-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed OpenCV as dependency #91
base: main
Are you sure you want to change the base?
Conversation
I have read the CLA Document and I sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
👋 Hello @estebanuri, thank you for submitting this awesome PR to the
You’ve made an excellent contribution by removing unused dependencies and improving efficiency. For further details on our contribution process, please refer to the Contributing Guide. Please note, this is an automated response 🤖. An Ultralytics engineer will review your PR as soon as possible to provide additional insights or approval. Thank you for your dedication to Ultralytics! 🌟 |
667a28a
to
7259a1a
Compare
recheck |
e60493e
to
5689855
Compare
…ibrary to the binary
…educe the size of the final binary from almost 500 MB to around 50 MB. Anyway, I think PlayStore will optimize the binary if we create an appbundle.
5689855
to
4d5e9e7
Compare
recheck |
Thank you for your PR! We'll review it shortly. For future contributions, please ensure all changes align with our Contributing Guide and maintain compatibility with Ultralytics' cross-platform vision AI workflows. While OpenCV is typically integral for computer vision tasks, we'll evaluate this platform-specific optimization carefully. |
🛠️ PR Summary
In this PR, the OpenCV dependency was removed from the project, in the quest to reduce the binary size.
Since very shallow OpenCV functionality is used, it is easy to implement it directly in cpp, avoiding importing the entire library.
📊 Key Changes
The OpenCV library was removed
Android library Native cpp code
🎯 Purpose & Impact
If we want to develop final applications, it is important to consider the final product.
Many users will think twice before installing hundreds of Megabytes on their smartphones.
The main purpose of this PR is to try to reduce the binary size.
As explained this PR removes the OpenCV dependency since the only used functionality is the class Rect_, that can be extracted into the cpp code making it minimal.
If we compile the app using
flutter build apk --release
:Running Gradle task 'assembleRelease'... 60.7s ✓ Built build/app/outputs/flutter-apk/app-release.apk (487.0MB)
The resulting binary file is huge!
Actually we can create an app-bundle, so when deploying the Google Play Store will divide the required files for each abi, reducing the final binary size. To do that we can use a command like
flutter build appbundle --release
:Running Gradle task 'bundleRelease'... 89.5s ✓ Built build/app/outputs/bundle/release/app-release.aab (168.1MB)
Still very big!
Let's see if we can find out why using the command
flutter build appbundle --release --target-platform android-arm64 --analyze-size
:app-release.aab (total compressed) 149 MB ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BUNDLE-METADATA/ com.android.tools.build.libraries 4 KB com.android.tools.build.obfuscation 807 KB base/ assets 15 MB dex 573 KB lib 132 MB Dart AOT symbols accounted decompressed size 3 MB package:flutter 1 MB dart:core 257 KB dart:typed_data 159 KB dart:ui 156 KB dart:async 87 KB package:material_color_utilities 76 KB dart:convert 49 KB dart:io 39 KB dart:collection 38 KB dart:isolate 23 KB package:vector_math/ vector_math_64.dart 23 KB package:ultralytics_yolo 13 KB dart:ffi 11 KB package:path 9 KB package:ultralytics_yolo_example/ main.dart 6 KB package:permission_handler_platform_interface 4 KB dart:math 2 KB package:path_provider_android 2 KB dart:mirrors 1 KB package:path_provider_platform_interface 1 KB manifest 2 KB res 137 KB resources.pb 42 KB root 11 KB META-INF/ ANDROIDD.SF 19 KB ANDROIDD.RSA 1016 B MANIFEST.MF 18 KB ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ A summary of your AAB analysis can be found at: /Users/esteban/.flutter-devtools/aab-code-size-analysis_06.json To analyze your app size in Dart DevTools, run the following command: dart devtools --appSizeBase=aab-code-size-analysis_06.json ✓ Built build/app/outputs/bundle/release/app-release.aab (156.0MB)
As we can see the lib bundled directory is 132 MB.
The first thing I thought was, the binary file is very large because it includes the OpenCV library, but upon closer inspection it is seen that although OpenCV increases a few Megabytes, it is not the biggest problem with the size of the binary.
For example, for an arm-64 Android device, the binary reduction by removing the OpenCV dependency would be 12 MB.
![image](https://private-user-images.githubusercontent.com/9130985/407907157-55f0268d-1a3e-4830-a177-a202167a6feb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODk2OTYsIm5iZiI6MTczODk4OTM5NiwicGF0aCI6Ii85MTMwOTg1LzQwNzkwNzE1Ny01NWYwMjY4ZC0xYTNlLTQ4MzAtYTE3Ny1hMjAyMTY3YTZmZWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMDQzNjM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTdiMmUxMzc3ZjM1NWQxZTEwMzY0OTQwM2QxYTJkMThhY2ZiNjExNGYwOWM1NWYyY2QzYWVhY2IxOTViMGJmOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.z2vVvx8cAeWNOdhAeS_DcrXS7JsouGO6A8NZuQoQsC8)
I have read the CLA Document and I sign the CLA