Skip to content

Commit

Permalink
drawing mono font, ci matrix release, source package (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Dec 10, 2023
1 parent fc01eab commit dd60637
Show file tree
Hide file tree
Showing 32 changed files with 6,159 additions and 3,933 deletions.
4,665 changes: 758 additions & 3,907 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@

:heavy_check_mark: All the binaries are compiled from source on github action, **no virus**, **no backdoor**, **no secret code**.

|opencv 4.8.1 source|package size|
|:-:|:-:|
|The official opencv|92.2 MB|
|opencv-mobile|10.5 MB|

|opencv 4.8.1 android|package size|
|:-:|:-:|
|The official opencv|189 MB|
|opencv-mobile|18.1 MB|
|opencv-mobile|17.9 MB|

|opencv 4.8.1 ios|package size|package size with bitcode|
|:-:|:-:|:-:|
|The official opencv|197 MB|missing :(|
|opencv-mobile|10 MB|34.7 MB|
|opencv-mobile|9.9 MB|34.3 MB|

# Download

https://github.com/nihui/opencv-mobile/releases/latest

|Platform|Arch|opencv-2.4.13.7|opencv-3.4.20|opencv-4.8.1|
|:-:|:-:|:-:|:-:|:-:|
|Source| |[![download-icon]][opencv2-source-url]|[![download-icon]][opencv3-source-url]|[![download-icon]][opencv4-source-url]|
|Android|armeabi-v7a<br />arm64-v8a<br />x86<br />x86_64|[![download-icon]][opencv2-android-url]|[![download-icon]][opencv3-android-url]|[![download-icon]][opencv4-android-url]|
|iOS|armv7<br />arm64<br />arm64e|[![download-icon]][opencv2-ios-url]<br />[![bitcode-icon]][opencv2-ios-bitcode-url]|[![download-icon]][opencv3-ios-url]<br />[![bitcode-icon]][opencv3-ios-bitcode-url]|[![download-icon]][opencv4-ios-url]<br />[![bitcode-icon]][opencv4-ios-bitcode-url]|
|iOS-Simulator|i386<br />x86_64<br />arm64|[![download-icon]][opencv2-ios-simulator-url]<br />[![bitcode-icon]][opencv2-ios-simulator-bitcode-url]|[![download-icon]][opencv3-ios-simulator-url]<br />[![bitcode-icon]][opencv3-ios-simulator-bitcode-url]|[![download-icon]][opencv4-ios-simulator-url]<br />[![bitcode-icon]][opencv4-ios-simulator-bitcode-url]|
Expand All @@ -59,6 +65,10 @@ https://github.com/nihui/opencv-mobile/releases/latest
[download-icon]: https://img.shields.io/badge/download-blue?style=for-the-badge
[bitcode-icon]: https://img.shields.io/badge/+bitcode-blue?style=for-the-badge

[opencv2-source-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-2.4.13.7.zip
[opencv3-source-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-3.4.20.zip
[opencv4-source-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.8.1.zip

[opencv2-android-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-2.4.13.7-android.zip
[opencv3-android-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-3.4.20-android.zip
[opencv4-android-url]: https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.8.1-android.zip
Expand Down Expand Up @@ -179,42 +189,42 @@ target_link_libraries(your_target ${OpenCV_LIBS})

# How-to-build your custom package

**step 1. download opencv source**
```shell
wget -q https://github.com/opencv/opencv/archive/4.8.1.zip -O opencv-4.8.1.zip
unzip -q opencv-4.8.1.zip
cd opencv-4.8.1
```
We reduce the binary size of opencv-mobile in 3 ways
1. Reimplement some modules (such as highgui) and functions (such as putText)
2. Apply patches to disable rtti/exceptions and do not install non-essential files
3. Carefully select cmake options to retain only the modules and functions you want

Steps 1 and 2 are relatively cumbersome and difficult, and require intrusive changes to the opencv source code. If you want to know the details, please refer to the steps in `.github/workflows/release.yml`

**step 2. strip zlib dependency and use stb-based highgui implementation (optional)**
The opencv-mobile source code package is the result of steps 1 and 2. Based on it, we can adjust the cmake option to compile our own package and further delete and add modules and other functions.

**step 1. download opencv-mobile source**
```shell
patch -p1 -i ../opencv-4.8.1-no-zlib.patch
truncate -s 0 cmake/OpenCVFindLibsGrfmt.cmake
rm -rf modules/gapi
rm -rf modules/highgui
cp -r ../highgui modules/
wget -q https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.8.1.zip
unzip -q opencv-mobile-4.8.1.zip
cd opencv-mobile-4.8.1
```

**step 3. patch opencv source for no-rtti build (optional)**
**step 2. apply your opencv option changes to options.txt**
```shell
patch -p1 -i ../opencv-4.8.1-no-rtti.patch
vim options.txt
```

**step 4. apply your opencv options to opencv4_cmake_options.txt**

**step 5. build your opencv package with cmake**
**step 3. build your opencv package with cmake**
```shell
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_BUILD_TYPE=Release \
`cat ../../opencv4_cmake_options.txt` \
-DBUILD_opencv_world=OFF ..
-DCMAKE_BUILD_TYPE=Release \
`cat ../options.txt` \
-DBUILD_opencv_world=OFF ..
make -j4
make install
```

**step 6. make a package**
**step 4. make a package**
```shell
zip -r -9 opencv-mobile-4.8.1.zip install
zip -r -9 opencv-mobile-4.8.1-mypackage.zip install
```

# Some notes
Expand Down
2 changes: 2 additions & 0 deletions opencv4_cmake_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
-DWITH_CLP=OFF
-DWITH_OPENCL=OFF
-DWITH_OPENCL_SVM=OFF
-DWITH_VA=OFF
-DWITH_VA_INTEL=OFF
-DWITH_ITT=OFF
-DWITH_PROTOBUF=OFF
-DWITH_IMGCODEC_HDR=OFF
Expand Down
4 changes: 2 additions & 2 deletions Info.plist → patches/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>__NAME__</string>
<string>OpenCV</string>
<key>CFBundleIdentifier</key>
<string>__IDENTIFIER__</string>
<string>org.opencv</string>
<key>CFBundleVersion</key>
<string>__VERSION__</string>
<key>CFBundleShortVersionString</key>
Expand Down
Loading

0 comments on commit dd60637

Please sign in to comment.