Skip to content

Commit

Permalink
PMNG-6541 [platform] Reduce size of opencv by cherrypicking the modul…
Browse files Browse the repository at this point in the history
…es to include (#5)
  • Loading branch information
acecilia authored Feb 21, 2024
1 parent d6737a9 commit b6d6ab3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ build_4_5_2:
build_4_6_0:
Scripts/opencv_xcframework.sh build_4_6_0

build_4_9_0:
Scripts/opencv_xcframework.sh build_4_9_0

23 changes: 23 additions & 0 deletions docs/4.9.0/opencv-4.9.0-module_size_analysis.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Module name,Amount of lines,Percentage of total,Cherrypicked modules,Percentage of total,Why is needed,,"Baseline of which modules to include, obtained from https://github.com/nihui/opencv-mobile/tree/master?tab=readme-ov-file#opencv-modules-included",
core,221692,21.56589411,221692,37.7601319,Baseline,,Size reduction of cherrypicked VS full (percentage),57.11286753
dnn,219894,21.39098713,,0,,,,
imgproc,124210,12.08297867,124210,21.1563159,Baseline,,,
gapi,104092,10.12592719,,0,,,,
objdetect,60815,5.915999903,60815,10.35843613,Incode,,,
features2d,55363,5.38563681,55363,9.429813356,,,,
calib3d,52794,5.135728009,52794,8.992243309,Revolut,,,
videoio,42292,4.114107833,,0,,,,
ts,34142,3.321286996,,0,,,,
imgcodecs,15750,1.532138427,15750,2.682650152,Baseline,,,
video,14525,1.412972105,14525,2.473999584,Baseline,,,
highgui,13629,1.325810453,13629,2.321386598,Baseline,,,
ml,13311,1.294875848,13311,2.267222614,"Incode, IPCheckCapture",,,
java,10822,1.052749337,,0,,,,
python,10343,1.006152873,,0,,,,
stitching,9364,0.9109170943,,0,,,,
flann,8158,0.7935990661,8158,1.389527615,calib3d,,,
js,8099,0.7878596269,,0,,,,
photo,6859,0.6672341253,6859,1.16827285,Baseline,,,
objc,1717,0.1670274083,,0,,,,
world,104,0.01011697755,,0,,,,
TOTAL,1027975,100,587106,100,,,,
3 changes: 2 additions & 1 deletion opencv2.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"4.5.2": "https://github.com/revolut-mobile/opencv-binary/releases/download/4.5.2/opencv2.xcframework.zip",
"4.6.0": "https://github.com/revolut-mobile/opencv-binary/releases/download/4.6.0/opencv2.xcframework.zip"
"4.6.0": "https://github.com/revolut-mobile/opencv-binary/releases/download/4.6.0/opencv2.xcframework.zip",
"4.9.0": "https://github.com/revolut-mobile/opencv-binary/releases/download/4.9.0/opencv2.xcframework.zip"
}
54 changes: 54 additions & 0 deletions scripts/opencv_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,47 @@ build_xcframework() {
"$@"
}

build_xcframework_excluding_modules_4_9_0() {
readonly VERSION="4.9.0"

# Baseline of which modules to include, obtained from https://github.com/nihui/opencv-mobile/tree/master?tab=readme-ov-file#opencv-modules-included

# Remove below big files that Revolut does not use
find "${BUILD_DIR}/${VERSION}/modules/imgproc/src" -maxdepth 1 -type f -name 'imgwarp*' -delete # Delete 691KB of the final release binary

python3 "${BUILD_DIR}/${VERSION}/platforms/apple/build_xcframework.py" \
--build_only_specified_archs \
--iphoneos_archs arm64 \
--iphonesimulator_archs arm64,x86_64 \
--out "${OUTPUT_DIR}" \
`# --without calib3d # Needed by Revolut code` \
`# --without core # based on baseline` \
--without dnn \
`# --without features2d # based on baseline` \
`# --without flann # Needed by calib3d` \
--without gapi \
`# --without highgui # based on baseline` \
`# --without imgcodecs # Needed by Revolut code` \
`# --without imgproc # based on baseline` \
--without java \
--without js \
`# --without ml # Needed by Incode and IPCheckCapture2` \
--without objc \
`# --without objdetect # Needed by Incode` \
`# --without photo # based on baseline` \
--without python \
--without stitching \
--without ts \
`# --without video # based on baseline` \
--without videoio \
--without world \
"$@"

# Outcome at the time of testing, for a release-type build:
# * Before: opencv size is 13.5MB
# * After: opencv size is 4MB
}

# OpenCV builds frameworks with symlinks inside them: remove them here, for clarity
patch_xcframework_remove_symlinks() {
readonly TMP_DIR="${OUTPUT_DIR}/tmp_dir"
Expand Down Expand Up @@ -81,5 +122,18 @@ build_4_6_0() {
patch_xcframework_remove_symlinks
}

build_4_9_0() {
clone 4.9.0
disable_ios_visibility_warnings 4.9.0

# Fix PATH to find python
# See: https://github.com/opencv/opencv/issues/21926#issuecomment-1156755364
ln -s "$(which python3)" "$(pwd)/${BUILD_DIR}/python"
export PATH="$(pwd)/${BUILD_DIR}:${PATH}"

build_xcframework_excluding_modules_4_9_0
patch_xcframework_remove_symlinks
}

rm -rf "${BUILD_DIR}"
"$@"

0 comments on commit b6d6ab3

Please sign in to comment.