Skip to content
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

Move OpenCV to this app and statically link, then remove unused funtions #237

Open
EmmanuelMess opened this issue Oct 11, 2020 · 13 comments

Comments

@EmmanuelMess
Copy link
Contributor

Move OpenCV to this app and statically link, then remove unused funtions. This would allow for a smaller APK, and the need to download another app.

@allgood
Copy link
Owner

allgood commented Oct 11, 2020 via email

@EmmanuelMess
Copy link
Contributor Author

EmmanuelMess commented Oct 11, 2020

Do you mean transplant opencv source code? If yes, I tought of this before, but I wasn't capable of build it myself.

Not really, I mean the library, statically linked to another library, that would then be shipped in the app. What did you try?

@allgood
Copy link
Owner

allgood commented Oct 11, 2020 via email

@EmmanuelMess
Copy link
Contributor Author

This is already done in the embedded-opencv branch. Is is not on master because f-droid doesn't support splitted builds and the apk in fdroid would be huge be cause it needs to contain opencv for every arch supported.

Why is it so heavy? Couldn't you just strip unused functions on the second library?

@allgood
Copy link
Owner

allgood commented Oct 11, 2020 via email

@EmmanuelMess
Copy link
Contributor Author

I think I'm understanding now what you suggesting. It is to create a new library that will compile and statically link to the used opencv functions, generating a smaller binary that then will be called from ons. Did I got it?

Yes.

Do you know how to do this? I tried to build opencv myself without success, so to me it appears to be very hard!

I know how to compile and install opencv on Ubuntu, and I know how to dinamically link to opencv with a program written in C++. Not much after that. I'll see if I can learn how to do it in the next few days.

@EmmanuelMess
Copy link
Contributor Author

@allgood
Copy link
Owner

allgood commented Oct 13, 2020

Related: https://github.com/VlSomers/native-opencv-android-template

this guide shows how to use the dynamic libraries built by opencv project, this is already done in the embedded-opencv (with a different approach, through the inclusion of a maven dependency that includes the libraries).

Main problem is on how to build a custom opencv dynamic library only with functions needed by Open Note Scanner. I tried to build OpenCV libraries from source without success.

@EmmanuelMess
Copy link
Contributor Author

The sdk has the static libraries at sdk/natives/staticlibs/*, no need to recompile OpenCV.

@allgood
Copy link
Owner

allgood commented Oct 14, 2020

Great, please work on this in a branch, since I will try to propagate changes already made on master branch to the other ones.

I think that main problem can be publishing on f-droid, they don't like code with binaries and static libraries used on build may be activate some antifeatures there, if it is included through maven from another project, it is ok.

@EmmanuelMess
Copy link
Contributor Author

I am stuck, having these two issues: Build statically, missing cv::countNonZero(cv::_InputArray const&) and Building OpenCV statically in app fails “error: undefined reference to 'ippicvsRound_64f'”. The time for this project has ended, but will update if some answers come back.

@whatever42
Copy link

my 50ct regarding this discussion:

  1. I second that this would be an important improvement. When an app asks you for permission to install other Apps, then this is a serious security risk your users need to take in order to use this app. Not many people care when the download is a couple of Megabytes larger, but a lot of people care about the security of their phones.

  2. When the problem is rooted in the fact that OpenCV supports a lot of different architectures and hence provides several architecture-specific apks, then a pragmatic solution would be to also provide multiple architecture-specific apks each containing the matching version of OpenCV for that architecture. This way the download size would be increased only by the size of the one OpenCVs apk, not by all of them and still your app would be usable across all architectures supported by OpenCV. Of course this would make packaging your app a little more complicated, but things like these can be automated.

@allgood
Copy link
Owner

allgood commented Feb 23, 2022

@whatever42 ... this is already done on the apks available in the releases section of the project and also for app through Google Play... unfortunately F-Droid doesn't allow package bundles and on F-Droid this solution would embed on one apk all the versions of OpenCV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants