drawing mono font, ci matrix release, source package (#76)

This commit is contained in:
nihui
2023-12-10 20:45:28 +08:00
committed by GitHub
parent fc01eab943
commit dd6063730d
32 changed files with 6219 additions and 3993 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,15 +25,20 @@
: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
@@ -41,6 +46,7 @@ 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]|
@@ -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
@@ -179,42 +189,42 @@ target_link_libraries(your_target ${OpenCV_LIBS})
# How-to-build your custom package
**step 1. download opencv source**
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`
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
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
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 2. strip zlib dependency and use stb-based highgui implementation (optional)**
**step 2. apply your opencv option changes to options.txt**
```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/
vim options.txt
```
**step 3. patch opencv source for no-rtti build (optional)**
```shell
patch -p1 -i ../opencv-4.8.1-no-rtti.patch
```
**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` \
`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

View File

@@ -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

View File

@@ -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>

691
patches/draw_text.h Normal file
View File

@@ -0,0 +1,691 @@
//
// Copyright (C) 2023 nihui
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#if __ARM_NEON
#include <arm_neon.h>
#endif // __ARM_NEON
#if __SSE2__
#include <emmintrin.h>
#endif
#include "mono_font_data.h"
namespace cv
{
static void get_text_drawing_size(const char* text, int fontpixelsize, int* w, int* h)
{
*w = 0;
*h = 0;
const int n = strlen(text);
int line_w = 0;
for (int i = 0; i < n; i++)
{
char ch = text[i];
if (ch == '\n')
{
// newline
*w = std::max(*w, line_w);
*h += fontpixelsize * 2;
line_w = 0;
}
if (isprint(ch) != 0)
{
line_w += fontpixelsize;
}
}
*w = std::max(*w, line_w);
*h += fontpixelsize * 2;
}
static void resize_bilinear_font(const unsigned char* font_bitmap, unsigned char* resized_font_bitmap, int fontpixelsize)
{
const int INTER_RESIZE_COEF_BITS = 11;
const int INTER_RESIZE_COEF_SCALE = 1 << INTER_RESIZE_COEF_BITS;
const int srcw = 20;
const int srch = 40;
const int w = fontpixelsize;
const int h = fontpixelsize * 2;
double scale = (double)srcw / w;
int* buf = new int[w + h + w + h];
int* xofs = buf; //new int[w];
int* yofs = buf + w; //new int[h];
short* ialpha = (short*)(buf + w + h); //new short[w * 2];
short* ibeta = (short*)(buf + w + h + w); //new short[h * 2];
float fx;
float fy;
int sx;
int sy;
#define SATURATE_CAST_SHORT(X) (short)::std::min(::std::max((int)(X + (X >= 0.f ? 0.5f : -0.5f)), SHRT_MIN), SHRT_MAX);
for (int dx = 0; dx < w; dx++)
{
fx = (float)((dx + 0.5) * scale - 0.5);
sx = static_cast<int>(floor(fx));
fx -= sx;
xofs[dx] = sx;
float a0 = (1.f - fx) * INTER_RESIZE_COEF_SCALE;
float a1 = fx * INTER_RESIZE_COEF_SCALE;
ialpha[dx * 2] = SATURATE_CAST_SHORT(a0);
ialpha[dx * 2 + 1] = SATURATE_CAST_SHORT(a1);
}
for (int dy = 0; dy < h; dy++)
{
fy = (float)((dy + 0.5) * scale - 0.5);
sy = static_cast<int>(floor(fy));
fy -= sy;
yofs[dy] = sy;
float b0 = (1.f - fy) * INTER_RESIZE_COEF_SCALE;
float b1 = fy * INTER_RESIZE_COEF_SCALE;
ibeta[dy * 2] = SATURATE_CAST_SHORT(b0);
ibeta[dy * 2 + 1] = SATURATE_CAST_SHORT(b1);
}
#undef SATURATE_CAST_SHORT
// loop body
std::vector<short> rowsbuf0(w);
std::vector<short> rowsbuf1(w);
short* rows0 = (short*)rowsbuf0.data();
short* rows1 = (short*)rowsbuf1.data();
{
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
rows1p[dx] = 0;
}
}
int prev_sy1 = -2;
for (int dy = 0; dy < h; dy++)
{
sy = yofs[dy];
if (sy == prev_sy1)
{
// reuse all rows
}
else if (sy == prev_sy1 + 1)
{
// hresize one row
short* rows0_old = rows0;
rows0 = rows1;
rows1 = rows0_old;
const unsigned char* S1 = font_bitmap + 10 * (sy + 1);
if (sy >= srch - 1)
{
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
rows1p[dx] = 0;
}
}
else
{
const short* ialphap = ialpha;
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
sx = xofs[dx];
short a0 = ialphap[0];
short a1 = ialphap[1];
unsigned char S1p0;
unsigned char S1p1;
if (sx < 0)
{
S1p0 = 0;
S1p1 = S1[0] & 0x0f;
}
else if (sx >= srcw - 1)
{
S1p0 = (S1[9] & 0xf0) >> 4;
S1p1 = 0;
}
else
{
S1p0 = sx % 2 == 0 ? S1[sx / 2] & 0x0f : (S1[sx / 2] & 0xf0) >> 4;
S1p1 = sx % 2 == 0 ? (S1[sx / 2] & 0xf0) >> 4 : S1[sx / 2 + 1] & 0x0f;
}
rows1p[dx] = (S1p0 * a0 + S1p1 * a1) * 17 >> 4;
ialphap += 2;
}
}
}
else
{
// hresize two rows
const unsigned char* S0 = font_bitmap + 10 * (sy);
const unsigned char* S1 = font_bitmap + 10 * (sy + 1);
if (sy >= srch - 1)
{
const short* ialphap = ialpha;
short* rows0p = rows0;
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
sx = xofs[dx];
short a0 = ialphap[0];
short a1 = ialphap[1];
unsigned char S0p0;
unsigned char S0p1;
if (sx < 0)
{
S0p0 = 0;
S0p1 = S0[0] & 0x0f;
}
else if (sx >= srcw - 1)
{
S0p0 = (S0[9] & 0xf0) >> 4;
S0p1 = 0;
}
else
{
S0p0 = sx % 2 == 0 ? S0[sx / 2] & 0x0f : (S0[sx / 2] & 0xf0) >> 4;
S0p1 = sx % 2 == 0 ? (S0[sx / 2] & 0xf0) >> 4 : S0[sx / 2 + 1] & 0x0f;
}
rows0p[dx] = (S0p0 * a0 + S0p1 * a1) * 17 >> 4;
rows1p[dx] = 0;
ialphap += 2;
}
}
else
{
const short* ialphap = ialpha;
short* rows0p = rows0;
short* rows1p = rows1;
for (int dx = 0; dx < w; dx++)
{
sx = xofs[dx];
short a0 = ialphap[0];
short a1 = ialphap[1];
unsigned char S0p0;
unsigned char S0p1;
unsigned char S1p0;
unsigned char S1p1;
if (sx < 0)
{
S0p0 = 0;
S0p1 = S0[0] & 0x0f;
S1p0 = 0;
S1p1 = S1[0] & 0x0f;
}
else if (sx >= srcw - 1)
{
S0p0 = (S0[9] & 0xf0) >> 4;
S0p1 = 0;
S1p0 = (S1[9] & 0xf0) >> 4;
S1p1 = 0;
}
else
{
S0p0 = sx % 2 == 0 ? S0[sx / 2] & 0x0f : (S0[sx / 2] & 0xf0) >> 4;
S0p1 = sx % 2 == 0 ? (S0[sx / 2] & 0xf0) >> 4 : S0[sx / 2 + 1] & 0x0f;
S1p0 = sx % 2 == 0 ? S1[sx / 2] & 0x0f : (S1[sx / 2] & 0xf0) >> 4;
S1p1 = sx % 2 == 0 ? (S1[sx / 2] & 0xf0) >> 4 : S1[sx / 2 + 1] & 0x0f;
}
rows0p[dx] = (S0p0 * a0 + S0p1 * a1) * 17 >> 4;
rows1p[dx] = (S1p0 * a0 + S1p1 * a1) * 17 >> 4;
ialphap += 2;
}
}
}
prev_sy1 = sy;
if (dy + 1 < h && yofs[dy + 1] == sy)
{
// vresize for two rows
short b0 = ibeta[0];
short b1 = ibeta[1];
short b2 = ibeta[2];
short b3 = ibeta[3];
short* rows0p = rows0;
short* rows1p = rows1;
unsigned char* Dp0 = resized_font_bitmap + w * (dy);
unsigned char* Dp1 = resized_font_bitmap + w * (dy + 1);
int dx = 0;
#if __ARM_NEON
int16x8_t _b0 = vdupq_n_s16(b0);
int16x8_t _b1 = vdupq_n_s16(b1);
int16x8_t _b2 = vdupq_n_s16(b2);
int16x8_t _b3 = vdupq_n_s16(b3);
for (; dx + 15 < w; dx += 16)
{
int16x8_t _r00 = vld1q_s16(rows0p);
int16x8_t _r01 = vld1q_s16(rows0p + 8);
int16x8_t _r10 = vld1q_s16(rows1p);
int16x8_t _r11 = vld1q_s16(rows1p + 8);
int16x8_t _acc00 = vaddq_s16(vqdmulhq_s16(_r00, _b0), vqdmulhq_s16(_r10, _b1));
int16x8_t _acc01 = vaddq_s16(vqdmulhq_s16(_r01, _b0), vqdmulhq_s16(_r11, _b1));
int16x8_t _acc10 = vaddq_s16(vqdmulhq_s16(_r00, _b2), vqdmulhq_s16(_r10, _b3));
int16x8_t _acc11 = vaddq_s16(vqdmulhq_s16(_r01, _b2), vqdmulhq_s16(_r11, _b3));
uint8x16_t _Dp0 = vcombine_u8(vqrshrun_n_s16(_acc00, 3), vqrshrun_n_s16(_acc01, 3));
uint8x16_t _Dp1 = vcombine_u8(vqrshrun_n_s16(_acc10, 3), vqrshrun_n_s16(_acc11, 3));
vst1q_u8(Dp0, _Dp0);
vst1q_u8(Dp1, _Dp1);
Dp0 += 16;
Dp1 += 16;
rows0p += 16;
rows1p += 16;
}
for (; dx + 7 < w; dx += 8)
{
int16x8_t _r0 = vld1q_s16(rows0p);
int16x8_t _r1 = vld1q_s16(rows1p);
int16x8_t _acc0 = vaddq_s16(vqdmulhq_s16(_r0, _b0), vqdmulhq_s16(_r1, _b1));
int16x8_t _acc1 = vaddq_s16(vqdmulhq_s16(_r0, _b2), vqdmulhq_s16(_r1, _b3));
uint8x8_t _Dp0 = vqrshrun_n_s16(_acc0, 3);
uint8x8_t _Dp1 = vqrshrun_n_s16(_acc1, 3);
vst1_u8(Dp0, _Dp0);
vst1_u8(Dp1, _Dp1);
Dp0 += 8;
Dp1 += 8;
rows0p += 8;
rows1p += 8;
}
#endif // __ARM_NEON
#if __SSE2__
__m128i _b0 = _mm_set1_epi16(b0);
__m128i _b1 = _mm_set1_epi16(b1);
__m128i _b2 = _mm_set1_epi16(b2);
__m128i _b3 = _mm_set1_epi16(b3);
__m128i _v2 = _mm_set1_epi16(2);
for (; dx + 15 < w; dx += 16)
{
__m128i _r00 = _mm_loadu_si128((const __m128i*)rows0p);
__m128i _r01 = _mm_loadu_si128((const __m128i*)(rows0p + 8));
__m128i _r10 = _mm_loadu_si128((const __m128i*)rows1p);
__m128i _r11 = _mm_loadu_si128((const __m128i*)(rows1p + 8));
__m128i _acc00 = _mm_add_epi16(_mm_mulhi_epi16(_r00, _b0), _mm_mulhi_epi16(_r10, _b1));
__m128i _acc01 = _mm_add_epi16(_mm_mulhi_epi16(_r01, _b0), _mm_mulhi_epi16(_r11, _b1));
__m128i _acc10 = _mm_add_epi16(_mm_mulhi_epi16(_r00, _b2), _mm_mulhi_epi16(_r10, _b3));
__m128i _acc11 = _mm_add_epi16(_mm_mulhi_epi16(_r01, _b2), _mm_mulhi_epi16(_r11, _b3));
_acc00 = _mm_srai_epi16(_mm_add_epi16(_acc00, _v2), 2);
_acc01 = _mm_srai_epi16(_mm_add_epi16(_acc01, _v2), 2);
_acc10 = _mm_srai_epi16(_mm_add_epi16(_acc10, _v2), 2);
_acc11 = _mm_srai_epi16(_mm_add_epi16(_acc11, _v2), 2);
__m128i _Dp0 = _mm_packus_epi16(_acc00, _acc01);
__m128i _Dp1 = _mm_packus_epi16(_acc10, _acc11);
_mm_storeu_si128((__m128i*)Dp0, _Dp0);
_mm_storeu_si128((__m128i*)Dp1, _Dp1);
Dp0 += 16;
Dp1 += 16;
rows0p += 16;
rows1p += 16;
}
for (; dx + 7 < w; dx += 8)
{
__m128i _r0 = _mm_loadu_si128((const __m128i*)rows0p);
__m128i _r1 = _mm_loadu_si128((const __m128i*)rows1p);
__m128i _acc0 = _mm_add_epi16(_mm_mulhi_epi16(_r0, _b0), _mm_mulhi_epi16(_r1, _b1));
__m128i _acc1 = _mm_add_epi16(_mm_mulhi_epi16(_r0, _b2), _mm_mulhi_epi16(_r1, _b3));
_acc0 = _mm_srai_epi16(_mm_add_epi16(_acc0, _v2), 2);
_acc1 = _mm_srai_epi16(_mm_add_epi16(_acc1, _v2), 2);
__m128i _Dp0 = _mm_packus_epi16(_acc0, _acc0);
__m128i _Dp1 = _mm_packus_epi16(_acc1, _acc1);
_mm_storel_epi64((__m128i*)Dp0, _Dp0);
_mm_storel_epi64((__m128i*)Dp1, _Dp1);
Dp0 += 8;
Dp1 += 8;
rows0p += 8;
rows1p += 8;
}
#endif // __SSE2__
for (; dx < w; dx++)
{
short s0 = *rows0p++;
short s1 = *rows1p++;
*Dp0++ = (unsigned char)(((short)((b0 * s0) >> 16) + (short)((b1 * s1) >> 16) + 2) >> 2);
*Dp1++ = (unsigned char)(((short)((b2 * s0) >> 16) + (short)((b3 * s1) >> 16) + 2) >> 2);
}
ibeta += 4;
dy += 1;
}
else
{
// vresize
short b0 = ibeta[0];
short b1 = ibeta[1];
short* rows0p = rows0;
short* rows1p = rows1;
unsigned char* Dp = resized_font_bitmap + w * (dy);
int dx = 0;
#if __ARM_NEON
int16x8_t _b0 = vdupq_n_s16(b0);
int16x8_t _b1 = vdupq_n_s16(b1);
for (; dx + 15 < w; dx += 16)
{
int16x8_t _r00 = vld1q_s16(rows0p);
int16x8_t _r01 = vld1q_s16(rows0p + 8);
int16x8_t _r10 = vld1q_s16(rows1p);
int16x8_t _r11 = vld1q_s16(rows1p + 8);
int16x8_t _acc0 = vaddq_s16(vqdmulhq_s16(_r00, _b0), vqdmulhq_s16(_r10, _b1));
int16x8_t _acc1 = vaddq_s16(vqdmulhq_s16(_r01, _b0), vqdmulhq_s16(_r11, _b1));
uint8x16_t _Dp = vcombine_u8(vqrshrun_n_s16(_acc0, 3), vqrshrun_n_s16(_acc1, 3));
vst1q_u8(Dp, _Dp);
Dp += 16;
rows0p += 16;
rows1p += 16;
}
for (; dx + 7 < w; dx += 8)
{
int16x8_t _r0 = vld1q_s16(rows0p);
int16x8_t _r1 = vld1q_s16(rows1p);
int16x8_t _acc = vaddq_s16(vqdmulhq_s16(_r0, _b0), vqdmulhq_s16(_r1, _b1));
uint8x8_t _Dp = vqrshrun_n_s16(_acc, 3);
vst1_u8(Dp, _Dp);
Dp += 8;
rows0p += 8;
rows1p += 8;
}
#endif // __ARM_NEON
#if __SSE2__
__m128i _b0 = _mm_set1_epi16(b0);
__m128i _b1 = _mm_set1_epi16(b1);
__m128i _v2 = _mm_set1_epi16(2);
for (; dx + 15 < w; dx += 16)
{
__m128i _r00 = _mm_loadu_si128((const __m128i*)rows0p);
__m128i _r01 = _mm_loadu_si128((const __m128i*)(rows0p + 8));
__m128i _r10 = _mm_loadu_si128((const __m128i*)rows1p);
__m128i _r11 = _mm_loadu_si128((const __m128i*)(rows1p + 8));
__m128i _acc0 = _mm_add_epi16(_mm_mulhi_epi16(_r00, _b0), _mm_mulhi_epi16(_r10, _b1));
__m128i _acc1 = _mm_add_epi16(_mm_mulhi_epi16(_r01, _b0), _mm_mulhi_epi16(_r11, _b1));
_acc0 = _mm_srai_epi16(_mm_add_epi16(_acc0, _v2), 2);
_acc1 = _mm_srai_epi16(_mm_add_epi16(_acc1, _v2), 2);
__m128i _Dp = _mm_packus_epi16(_acc0, _acc1);
_mm_storeu_si128((__m128i*)Dp, _Dp);
Dp += 16;
rows0p += 16;
rows1p += 16;
}
for (; dx + 7 < w; dx += 8)
{
__m128i _r0 = _mm_loadu_si128((const __m128i*)rows0p);
__m128i _r1 = _mm_loadu_si128((const __m128i*)rows1p);
__m128i _acc = _mm_add_epi16(_mm_mulhi_epi16(_r0, _b0), _mm_mulhi_epi16(_r1, _b1));
_acc = _mm_srai_epi16(_mm_add_epi16(_acc, _v2), 2);
__m128i _Dp = _mm_packus_epi16(_acc, _acc);
_mm_storel_epi64((__m128i*)Dp, _Dp);
Dp += 8;
rows0p += 8;
rows1p += 8;
}
#endif // __SSE2__
for (; dx < w; dx++)
{
short s0 = *rows0p++;
short s1 = *rows1p++;
*Dp++ = (unsigned char)(((short)((b0 * s0) >> 16) + (short)((b1 * s1) >> 16) + 2) >> 2);
}
ibeta += 2;
}
}
delete[] buf;
}
static void draw_text_c1(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
const unsigned char* pen_color = (const unsigned char*)&color;
unsigned char* resized_font_bitmap = new unsigned char[fontpixelsize * fontpixelsize * 2];
const int n = strlen(text);
int cursor_x = x;
int cursor_y = y;
for (int i = 0; i < n; i++)
{
char ch = text[i];
if (ch == '\n')
{
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}
if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}
if (isprint(ch) != 0)
{
const unsigned char* font_bitmap = mono_font_data[ch - '!'];
// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
const int ystart = std::max(cursor_y, 0);
const int yend = std::min(cursor_y + fontpixelsize * 2, h);
const int xstart = std::max(cursor_x, 0);
const int xend = std::min(cursor_x + fontpixelsize, w);
for (int j = ystart; j < yend; j++)
{
const unsigned char* palpha = resized_font_bitmap + (j - cursor_y) * fontpixelsize + xstart - cursor_x;
unsigned char* p = pixels + stride * j + xstart;
for (int k = xstart; k < xend; k++)
{
unsigned char alpha = *palpha++;
p[0] = (p[0] * (255 - alpha) + pen_color[0] * alpha) / 255;
p += 1;
}
}
cursor_x += fontpixelsize;
}
}
delete[] resized_font_bitmap;
}
static void draw_text_c3(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
const unsigned char* pen_color = (const unsigned char*)&color;
unsigned char* resized_font_bitmap = new unsigned char[fontpixelsize * fontpixelsize * 2];
const int n = strlen(text);
int cursor_x = x;
int cursor_y = y;
for (int i = 0; i < n; i++)
{
char ch = text[i];
if (ch == '\n')
{
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}
if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}
if (isprint(ch) != 0)
{
const unsigned char* font_bitmap = mono_font_data[ch - '!'];
// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
const int ystart = std::max(cursor_y, 0);
const int yend = std::min(cursor_y + fontpixelsize * 2, h);
const int xstart = std::max(cursor_x, 0);
const int xend = std::min(cursor_x + fontpixelsize, w);
for (int j = ystart; j < yend; j++)
{
const unsigned char* palpha = resized_font_bitmap + (j - cursor_y) * fontpixelsize + xstart - cursor_x;
unsigned char* p = pixels + stride * j + xstart * 3;
for (int k = xstart; k < xend; k++)
{
unsigned char alpha = *palpha++;
p[0] = (p[0] * (255 - alpha) + pen_color[0] * alpha) / 255;
p[1] = (p[1] * (255 - alpha) + pen_color[1] * alpha) / 255;
p[2] = (p[2] * (255 - alpha) + pen_color[2] * alpha) / 255;
p += 3;
}
}
cursor_x += fontpixelsize;
}
}
delete[] resized_font_bitmap;
}
static void draw_text_c4(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
const unsigned char* pen_color = (const unsigned char*)&color;
unsigned char* resized_font_bitmap = new unsigned char[fontpixelsize * fontpixelsize * 2];
const int n = strlen(text);
int cursor_x = x;
int cursor_y = y;
for (int i = 0; i < n; i++)
{
char ch = text[i];
if (ch == '\n')
{
// newline
cursor_x = x;
cursor_y += fontpixelsize * 2;
continue;
}
if (ch == ' ')
{
cursor_x += fontpixelsize;
continue;
}
if (isprint(ch) != 0)
{
const unsigned char* font_bitmap = mono_font_data[ch - '!'];
// draw resized character
resize_bilinear_font(font_bitmap, resized_font_bitmap, fontpixelsize);
const int ystart = std::max(cursor_y, 0);
const int yend = std::min(cursor_y + fontpixelsize * 2, h);
const int xstart = std::max(cursor_x, 0);
const int xend = std::min(cursor_x + fontpixelsize, w);
for (int j = ystart; j < yend; j++)
{
const unsigned char* palpha = resized_font_bitmap + (j - cursor_y) * fontpixelsize + xstart - cursor_x;
unsigned char* p = pixels + stride * j + xstart * 4;
for (int k = xstart; k < xend; k++)
{
unsigned char alpha = *palpha++;
p[0] = (p[0] * (255 - alpha) + pen_color[0] * alpha) / 255;
p[1] = (p[1] * (255 - alpha) + pen_color[1] * alpha) / 255;
p[2] = (p[2] * (255 - alpha) + pen_color[2] * alpha) / 255;
p[3] = (p[3] * (255 - alpha) + pen_color[3] * alpha) / 255;
p += 4;
}
}
cursor_x += fontpixelsize;
}
}
delete[] resized_font_bitmap;
}
static void draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
return draw_text_c1(pixels, w, h, w, text, x, y, fontpixelsize, color);
}
static void draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
return draw_text_c3(pixels, w, h, w * 3, text, x, y, fontpixelsize, color);
}
static void draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
{
return draw_text_c4(pixels, w, h, w * 4, text, x, y, fontpixelsize, color);
}
}

3877
patches/mono_font_data.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,120 @@
diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/drawing.cpp opencv-2.4.13.7/modules/core/src/drawing.cpp
--- opencv-2.4.13.7.orig/modules/core/src/drawing.cpp 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/modules/core/src/drawing.cpp 2023-12-09 15:52:28.808104579 +0800
@@ -40,6 +40,8 @@
//M*/
#include "precomp.hpp"
+#include "draw_text.h"
+
namespace cv
{
@@ -1992,6 +1994,7 @@ void polylines( Mat& img, const Point**
}
+#if 0
enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8),
FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8),
FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8),
@@ -2204,12 +2207,41 @@ inline void readCheck(int &c, int &i, co
if(c >= rightBoundary || c < leftBoundary)
c = '?';
}
+#endif
void putText( Mat& img, const string& text, Point org,
int fontFace, double fontScale, Scalar color,
int thickness, int line_type, bool bottomLeftOrigin )
{
+ const int fontpixelsize = 8 * fontScale;
+ const int base_line = 4 * fontScale;
+ const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line;
+
+ unsigned int _color = 0;
+ unsigned char* border_color = (unsigned char*)&_color;
+
+ if (img.channels() == 1)
+ {
+ border_color[0] = color[0];
+ draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 3)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 4)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ border_color[3] = color[3];
+ draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+#if 0
const int* ascii = getFontData(fontFace);
double buf[4];
@@ -2264,10 +2296,21 @@ void putText( Mat& img, const string& te
}
view_x += dx;
}
+#endif
}
Size getTextSize( const string& text, int fontFace, double fontScale, int thickness, int* _base_line)
{
+ const int fontpixelsize = 8 * fontScale;
+
+ int w;
+ int h;
+ get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h);
+
+ *_base_line = 4 * fontScale;
+
+ return Size(w, h);
+#if 0
Size size;
double view_x = 0;
const char **faces = cv::g_HersheyGlyphs;
@@ -2294,6 +2337,7 @@ Size getTextSize( const string& text, in
if( _base_line )
*_base_line = cvRound(base_line*fontScale + thickness*0.5);
return size;
+#endif
}
}
@@ -2679,7 +2723,7 @@ cvInitFont( CvFont *font, int font_face,
{
CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 );
- font->ascii = cv::getFontData(font_face);
+ font->ascii = 0;
font->font_face = font_face;
font->hscale = (float)hscale;
font->vscale = (float)vscale;
diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/tables.cpp opencv-2.4.13.7/modules/core/src/tables.cpp
--- opencv-2.4.13.7.orig/modules/core/src/tables.cpp 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/modules/core/src/tables.cpp 2023-12-09 14:51:50.948704080 +0800
@@ -204,6 +204,7 @@ const uchar g_Saturate8u[] =
255
};
+#if 0
const char* g_HersheyGlyphs[] = {
"",
"MWRMNV RMVV PSTS",
@@ -3506,6 +3507,7 @@ const char* g_HersheyGlyphs[] = {
"",
"",
0 };
+#endif
}

View File

@@ -0,0 +1,137 @@
diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVGenAndroidMK.cmake opencv-2.4.13.7/cmake/OpenCVGenAndroidMK.cmake
--- opencv-2.4.13.7.orig/cmake/OpenCVGenAndroidMK.cmake 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/cmake/OpenCVGenAndroidMK.cmake 2023-12-09 21:14:50.771014374 +0800
@@ -161,5 +161,4 @@ if(ANDROID)
set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../3rdparty/libs/\$(OPENCV_TARGET_ARCH_ABI)")
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY)
- install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
endif(ANDROID)
diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVGenConfig.cmake opencv-2.4.13.7/cmake/OpenCVGenConfig.cmake
--- opencv-2.4.13.7.orig/cmake/OpenCVGenConfig.cmake 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/cmake/OpenCVGenConfig.cmake 2023-12-09 21:10:49.425388446 +0800
@@ -119,10 +119,6 @@ if(UNIX) # ANDROID configuration is crea
endif()
endif()
-if(ANDROID)
- install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
-endif()
-
# --------------------------------------------------------------------------------------------
# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
# --------------------------------------------------------------------------------------------
diff -Nuarp opencv-2.4.13.7.orig/CMakeLists.txt opencv-2.4.13.7/CMakeLists.txt
--- opencv-2.4.13.7.orig/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/CMakeLists.txt 2023-12-10 12:41:39.219962895 +0800
@@ -569,32 +569,13 @@ add_subdirectory(include)
add_subdirectory(modules)
# Generate targets for documentation
-add_subdirectory(doc)
# various data that is used by cv libraries and/or demo applications.
-add_subdirectory(data)
# extra applications
-if(BUILD_opencv_apps)
- add_subdirectory(apps)
-endif()
# examples
-if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES)
- add_subdirectory(samples)
-endif()
-
-if(ANDROID)
- add_subdirectory(platforms/android/service)
-endif()
-
-if(BUILD_ANDROID_PACKAGE)
- add_subdirectory(platforms/android/package)
-endif()
-if (ANDROID)
- add_subdirectory(platforms/android/libinfo)
-endif()
# ----------------------------------------------------------------------------
# Finalization: generate configuration-based files
@@ -605,16 +586,13 @@ ocv_track_build_dependencies()
include(cmake/OpenCVGenHeaders.cmake)
# Generate opencv.pc for pkg-config command
-include(cmake/OpenCVGenPkgconfig.cmake)
# Generate OpenCV.mk for ndk-build (Android build tool)
-include(cmake/OpenCVGenAndroidMK.cmake)
# Generate OpenCVСonfig.cmake and OpenCVConfig-version.cmake for cmake projects
include(cmake/OpenCVGenConfig.cmake)
# Generate Info.plist for the IOS framework
-include(cmake/OpenCVGenInfoPlist.cmake)
# Generate environment setup file
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
@@ -649,12 +627,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA
endif()
endif()
-if(NOT OPENCV_README_FILE)
- if(ANDROID)
- set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android)
- endif()
-endif()
-
if(NOT OPENCV_LICENSE_FILE)
set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
endif()
@@ -664,11 +636,6 @@ if(ANDROID OR NOT UNIX)
install(FILES ${OPENCV_LICENSE_FILE}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
DESTINATION . COMPONENT libs)
- if(OPENCV_README_FILE)
- install(FILES ${OPENCV_README_FILE}
- PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
- DESTINATION . COMPONENT libs)
- endif()
endif()
# ----------------------------------------------------------------------------
diff -Nuarp opencv-2.4.13.7.orig/data/CMakeLists.txt opencv-2.4.13.7/data/CMakeLists.txt
--- opencv-2.4.13.7.orig/data/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/data/CMakeLists.txt 2023-12-09 21:07:33.901501638 +0800
@@ -1,14 +1,6 @@
file(GLOB HAAR_CASCADES haarcascades/*.xml)
file(GLOB LBP_CASCADES lbpcascades/*.xml)
-if(ANDROID)
- install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT libs)
- install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT libs)
-else()
- install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT libs)
- install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs)
-endif()
-
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
if(ANDROID)
install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests)
diff -Nuarp opencv-2.4.13.7.orig/platforms/android/libinfo/CMakeLists.txt opencv-2.4.13.7/platforms/android/libinfo/CMakeLists.txt
--- opencv-2.4.13.7.orig/platforms/android/libinfo/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/platforms/android/libinfo/CMakeLists.txt 2023-12-09 21:02:53.976095360 +0800
@@ -37,4 +37,3 @@ set_target_properties(${the_module} PROP
)
get_filename_component(lib_name "libopencv_info.so" NAME)
-install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs)
diff -Nuarp opencv-2.4.13.7.orig/platforms/android/package/CMakeLists.txt opencv-2.4.13.7/platforms/android/package/CMakeLists.txt
--- opencv-2.4.13.7.orig/platforms/android/package/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800
+++ opencv-2.4.13.7/platforms/android/package/CMakeLists.txt 2023-12-09 21:13:29.379477767 +0800
@@ -89,6 +89,5 @@ add_custom_command(
DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers} opencv_java
)
-install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT libs)
add_custom_target(android_package ALL SOURCES "${APK_NAME}" )
add_dependencies(android_package opencv_java)

View File

@@ -0,0 +1,136 @@
diff -Nuarp opencv-3.4.20.orig/modules/imgproc/src/drawing.cpp opencv-3.4.20/modules/imgproc/src/drawing.cpp
--- opencv-3.4.20.orig/modules/imgproc/src/drawing.cpp 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/modules/imgproc/src/drawing.cpp 2023-12-09 17:09:13.910181866 +0800
@@ -40,6 +40,8 @@
//M*/
#include "precomp.hpp"
+#include "draw_text.h"
+
namespace cv
{
@@ -2051,6 +2053,7 @@ void polylines( Mat& img, const Point* c
}
+#if 0
enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8),
FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8),
FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8),
@@ -2265,6 +2268,7 @@ inline void readCheck(int &c, int &i, co
}
extern const char* g_HersheyGlyphs[];
+#endif
void putText( InputOutputArray _img, const String& text, Point org,
int fontFace, double fontScale, Scalar color,
@@ -2278,6 +2282,35 @@ void putText( InputOutputArray _img, con
return;
}
Mat img = _img.getMat();
+
+ const int fontpixelsize = 8 * fontScale;
+ const int base_line = 4 * fontScale;
+ const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line;
+
+ unsigned int _color = 0;
+ unsigned char* border_color = (unsigned char*)&_color;
+
+ if (img.channels() == 1)
+ {
+ border_color[0] = color[0];
+ draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 3)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 4)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ border_color[3] = color[3];
+ draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+#if 0
const int* ascii = getFontData(fontFace);
double buf[4];
@@ -2332,10 +2365,21 @@ void putText( InputOutputArray _img, con
}
view_x += dx;
}
+#endif
}
Size getTextSize( const String& text, int fontFace, double fontScale, int thickness, int* _base_line)
{
+ const int fontpixelsize = 8 * fontScale;
+
+ int w;
+ int h;
+ get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h);
+
+ *_base_line = 4 * fontScale;
+
+ return Size(w, h);
+#if 0
Size size;
double view_x = 0;
const char **faces = cv::g_HersheyGlyphs;
@@ -2362,10 +2406,13 @@ Size getTextSize( const String& text, in
if( _base_line )
*_base_line = cvRound(base_line*fontScale + thickness*0.5);
return size;
+#endif
}
double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness)
{
+ return pixelHeight / 16.0;
+#if 0
// By https://stackoverflow.com/a/27898487/1531708
const int* ascii = getFontData(fontFace);
@@ -2373,6 +2420,7 @@ double getFontScaleFromHeight(const int
int cap_line = (ascii[0] >> 4) & 15;
return static_cast<double>(pixelHeight - static_cast<double>((thickness + 1)) / 2.0) / static_cast<double>(cap_line + base_line);
+#endif
}
}
@@ -2879,7 +2927,7 @@ cvInitFont( CvFont *font, int font_face,
{
CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 );
- font->ascii = cv::getFontData(font_face);
+ font->ascii = 0;
font->font_face = font_face;
font->hscale = (float)hscale;
font->vscale = (float)vscale;
diff -Nuarp opencv-3.4.20.orig/modules/imgproc/src/hershey_fonts.cpp opencv-3.4.20/modules/imgproc/src/hershey_fonts.cpp
--- opencv-3.4.20.orig/modules/imgproc/src/hershey_fonts.cpp 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/modules/imgproc/src/hershey_fonts.cpp 2023-12-09 17:02:22.175067906 +0800
@@ -51,6 +51,7 @@
namespace cv
{
+#if 0
const char* g_HersheyGlyphs[] = {
"",
"MWRMNV RMVV PSTS",
@@ -3353,6 +3354,7 @@ const char* g_HersheyGlyphs[] = {
"",
"",
0 };
+#endif
}

View File

@@ -0,0 +1,134 @@
diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVGenAndroidMK.cmake opencv-3.4.20/cmake/OpenCVGenAndroidMK.cmake
--- opencv-3.4.20.orig/cmake/OpenCVGenAndroidMK.cmake 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/cmake/OpenCVGenAndroidMK.cmake 2023-12-09 21:22:23.522506093 +0800
@@ -76,6 +76,4 @@ if(ANDROID)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV-abi.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk" @ONLY)
- install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
- install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
endif(ANDROID)
diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake opencv-3.4.20/cmake/OpenCVGenConfig.cmake
--- opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake 2023-12-09 16:58:42.567073866 +0800
+++ opencv-3.4.20/cmake/OpenCVGenConfig.cmake 2023-12-09 21:22:42.614401178 +0800
@@ -119,7 +119,6 @@ endif()
if(ANDROID)
ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in")
- install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev)
endif()
# --------------------------------------------------------------------------------------------
diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVUtils.cmake opencv-3.4.20/cmake/OpenCVUtils.cmake
--- opencv-3.4.20.orig/cmake/OpenCVUtils.cmake 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/cmake/OpenCVUtils.cmake 2023-12-09 21:24:36.516775258 +0800
@@ -976,11 +976,6 @@ macro(ocv_finalize_status)
endif()
endif()
- if(UNIX)
- install(FILES "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind.supp"
- "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind_3rdparty.supp"
- DESTINATION "${OPENCV_OTHER_INSTALL_PATH}" COMPONENT "dev")
- endif()
endmacro()
diff -Nuarp opencv-3.4.20.orig/CMakeLists.txt opencv-3.4.20/CMakeLists.txt
--- opencv-3.4.20.orig/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/CMakeLists.txt 2023-12-10 12:43:21.573441566 +0800
@@ -903,24 +903,13 @@ ocv_add_modules_compiler_options()
add_subdirectory(modules)
# Generate targets for documentation
-add_subdirectory(doc)
# various data that is used by cv libraries and/or demo applications.
-add_subdirectory(data)
# extra applications
-if(BUILD_opencv_apps)
- add_subdirectory(apps)
-endif()
# examples
-if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES)
- add_subdirectory(samples)
-endif()
-if(ANDROID)
- add_subdirectory(platforms/android/service)
-endif()
# ----------------------------------------------------------------------------
# Finalization: generate configuration-based files
@@ -932,22 +921,13 @@ ocv_cmake_hook(PRE_FINALIZE)
include(cmake/OpenCVGenHeaders.cmake)
# Generate opencv.pc for pkg-config command
-if(NOT OPENCV_SKIP_PKGCONFIG_GENERATION
- AND OPENCV_GENERATE_PKGCONFIG
- AND NOT CMAKE_GENERATOR MATCHES "Xcode")
- include(cmake/OpenCVGenPkgconfig.cmake)
-endif()
# Generate OpenCV.mk for ndk-build (Android build tool)
-include(cmake/OpenCVGenAndroidMK.cmake)
# Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects
include(cmake/OpenCVGenConfig.cmake)
# Generate Info.plist for the IOS framework
-if(APPLE_FRAMEWORK)
- include(cmake/OpenCVGenInfoPlist.cmake)
-endif()
# Generate ABI descriptor
include(cmake/OpenCVGenABI.cmake)
@@ -973,12 +953,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA
endif()
endif()
-if(NOT OPENCV_README_FILE)
- if(ANDROID)
- set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android)
- endif()
-endif()
-
if(NOT OPENCV_LICENSE_FILE)
set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
endif()
@@ -988,11 +962,6 @@ if(ANDROID OR NOT UNIX)
install(FILES ${OPENCV_LICENSE_FILE}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
DESTINATION ./ COMPONENT libs)
- if(OPENCV_README_FILE)
- install(FILES ${OPENCV_README_FILE}
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
- DESTINATION ./ COMPONENT libs)
- endif()
endif()
if(COMMAND ocv_pylint_finalize)
diff -Nuarp opencv-3.4.20.orig/data/CMakeLists.txt opencv-3.4.20/data/CMakeLists.txt
--- opencv-3.4.20.orig/data/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/data/CMakeLists.txt 2023-12-09 21:23:02.838290043 +0800
@@ -1,9 +1,6 @@
file(GLOB HAAR_CASCADES haarcascades/*.xml)
file(GLOB LBP_CASCADES lbpcascades/*.xml)
-install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs)
-install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs)
-
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests")
endif()
diff -Nuarp opencv-3.4.20.orig/platforms/android/service/CMakeLists.txt opencv-3.4.20/platforms/android/service/CMakeLists.txt
--- opencv-3.4.20.orig/platforms/android/service/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800
+++ opencv-3.4.20/platforms/android/service/CMakeLists.txt 2023-12-09 21:23:41.098079796 +0800
@@ -1,5 +1,3 @@
if(BUILD_ANDROID_SERVICE)
add_subdirectory(engine)
endif()
-
-install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs)

View File

@@ -0,0 +1,136 @@
diff -Nuarp opencv-4.8.1.orig/modules/imgproc/src/drawing.cpp opencv-4.8.1/modules/imgproc/src/drawing.cpp
--- opencv-4.8.1.orig/modules/imgproc/src/drawing.cpp 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/modules/imgproc/src/drawing.cpp 2023-12-09 17:24:35.811627301 +0800
@@ -40,6 +40,8 @@
//M*/
#include "precomp.hpp"
+#include "draw_text.h"
+
namespace cv
{
@@ -2074,6 +2076,7 @@ void polylines( InputOutputArray _img, c
}
+#if 0
enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8),
FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8),
FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8),
@@ -2288,6 +2291,7 @@ inline void readCheck(int &c, int &i, co
}
extern const char* g_HersheyGlyphs[];
+#endif
void putText( InputOutputArray _img, const String& text, Point org,
int fontFace, double fontScale, Scalar color,
@@ -2301,6 +2305,35 @@ void putText( InputOutputArray _img, con
return;
}
Mat img = _img.getMat();
+
+ const int fontpixelsize = 8 * fontScale;
+ const int base_line = 4 * fontScale;
+ const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line;
+
+ unsigned int _color = 0;
+ unsigned char* border_color = (unsigned char*)&_color;
+
+ if (img.channels() == 1)
+ {
+ border_color[0] = color[0];
+ draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 3)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+ else if (img.channels() == 4)
+ {
+ border_color[0] = color[0];
+ border_color[1] = color[1];
+ border_color[2] = color[2];
+ border_color[3] = color[3];
+ draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color);
+ }
+#if 0
const int* ascii = getFontData(fontFace);
double buf[4];
@@ -2355,10 +2388,21 @@ void putText( InputOutputArray _img, con
}
view_x += dx;
}
+#endif
}
Size getTextSize( const String& text, int fontFace, double fontScale, int thickness, int* _base_line)
{
+ const int fontpixelsize = 8 * fontScale;
+
+ int w;
+ int h;
+ get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h);
+
+ *_base_line = 4 * fontScale;
+
+ return Size(w, h);
+#if 0
Size size;
double view_x = 0;
const char **faces = cv::g_HersheyGlyphs;
@@ -2385,10 +2429,13 @@ Size getTextSize( const String& text, in
if( _base_line )
*_base_line = cvRound(base_line*fontScale + thickness*0.5);
return size;
+#endif
}
double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness)
{
+ return pixelHeight / 16.0;
+#if 0
// By https://stackoverflow.com/a/27898487/1531708
const int* ascii = getFontData(fontFace);
@@ -2396,6 +2443,7 @@ double getFontScaleFromHeight(const int
int cap_line = (ascii[0] >> 4) & 15;
return static_cast<double>(pixelHeight - static_cast<double>((thickness + 1)) / 2.0) / static_cast<double>(cap_line + base_line);
+#endif
}
}
@@ -2897,7 +2945,7 @@ cvInitFont( CvFont *font, int font_face,
{
CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 );
- font->ascii = cv::getFontData(font_face);
+ font->ascii = 0;
font->font_face = font_face;
font->hscale = (float)hscale;
font->vscale = (float)vscale;
diff -Nuarp opencv-4.8.1.orig/modules/imgproc/src/hershey_fonts.cpp opencv-4.8.1/modules/imgproc/src/hershey_fonts.cpp
--- opencv-4.8.1.orig/modules/imgproc/src/hershey_fonts.cpp 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/modules/imgproc/src/hershey_fonts.cpp 2023-12-09 17:22:38.027235607 +0800
@@ -51,6 +51,7 @@
namespace cv
{
+#if 0
const char* g_HersheyGlyphs[] = {
"",
"MWRMNV RMVV PSTS",
@@ -3353,6 +3354,7 @@ const char* g_HersheyGlyphs[] = {
"",
"",
0 };
+#endif
}

View File

@@ -0,0 +1,132 @@
diff -Nuarp opencv-4.8.1.orig/cmake/OpenCVGenAndroidMK.cmake opencv-4.8.1/cmake/OpenCVGenAndroidMK.cmake
--- opencv-4.8.1.orig/cmake/OpenCVGenAndroidMK.cmake 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/cmake/OpenCVGenAndroidMK.cmake 2023-12-09 21:26:00.941311325 +0800
@@ -76,6 +76,4 @@ if(ANDROID)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV-abi.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk" @ONLY)
- install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
- install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev)
endif(ANDROID)
diff -Nuarp opencv-4.8.1.orig/cmake/OpenCVGenConfig.cmake opencv-4.8.1/cmake/OpenCVGenConfig.cmake
--- opencv-4.8.1.orig/cmake/OpenCVGenConfig.cmake 2023-12-09 17:15:45.506366104 +0800
+++ opencv-4.8.1/cmake/OpenCVGenConfig.cmake 2023-12-09 21:26:12.381248460 +0800
@@ -124,7 +124,6 @@ endif()
if(ANDROID)
ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in")
- install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev)
endif()
# --------------------------------------------------------------------------------------------
diff -Nuarp opencv-4.8.1.orig/cmake/OpenCVUtils.cmake opencv-4.8.1/cmake/OpenCVUtils.cmake
--- opencv-4.8.1.orig/cmake/OpenCVUtils.cmake 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/cmake/OpenCVUtils.cmake 2023-12-09 21:26:33.587131928 +0800
@@ -976,11 +976,6 @@ macro(ocv_finalize_status)
endif()
endif()
- if(UNIX)
- install(FILES "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind.supp"
- "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind_3rdparty.supp"
- DESTINATION "${OPENCV_OTHER_INSTALL_PATH}" COMPONENT "dev")
- endif()
endmacro()
diff -Nuarp opencv-4.8.1.orig/CMakeLists.txt opencv-4.8.1/CMakeLists.txt
--- opencv-4.8.1.orig/CMakeLists.txt 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/CMakeLists.txt 2023-12-10 12:43:42.006337472 +0800
@@ -967,24 +967,13 @@ ocv_add_modules_compiler_options()
ocv_register_modules()
# Generate targets for documentation
-add_subdirectory(doc)
# various data that is used by cv libraries and/or demo applications.
-add_subdirectory(data)
# extra applications
-if(BUILD_opencv_apps)
- add_subdirectory(apps)
-endif()
# examples
-if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES)
- add_subdirectory(samples)
-endif()
-if(ANDROID)
- add_subdirectory(platforms/android/service)
-endif()
# ----------------------------------------------------------------------------
# Finalization: generate configuration-based files
@@ -996,20 +985,13 @@ ocv_cmake_hook(PRE_FINALIZE)
include(cmake/OpenCVGenHeaders.cmake)
# Generate opencv.pc for pkg-config command
-if(OPENCV_GENERATE_PKGCONFIG)
- include(cmake/OpenCVGenPkgconfig.cmake)
-endif()
# Generate OpenCV.mk for ndk-build (Android build tool)
-include(cmake/OpenCVGenAndroidMK.cmake)
# Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects
include(cmake/OpenCVGenConfig.cmake)
# Generate Info.plist for the IOS framework
-if(APPLE_FRAMEWORK)
- include(cmake/OpenCVGenInfoPlist.cmake)
-endif()
# Generate ABI descriptor
include(cmake/OpenCVGenABI.cmake)
@@ -1035,12 +1017,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA
endif()
endif()
-if(NOT OPENCV_README_FILE)
- if(ANDROID)
- set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android)
- endif()
-endif()
-
if(NOT OPENCV_LICENSE_FILE)
set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
endif()
@@ -1050,11 +1026,6 @@ if(ANDROID OR NOT UNIX)
install(FILES ${OPENCV_LICENSE_FILE}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
DESTINATION ./ COMPONENT libs)
- if(OPENCV_README_FILE)
- install(FILES ${OPENCV_README_FILE}
- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
- DESTINATION ./ COMPONENT libs)
- endif()
endif()
if(COMMAND ocv_pylint_finalize)
diff -Nuarp opencv-4.8.1.orig/data/CMakeLists.txt opencv-4.8.1/data/CMakeLists.txt
--- opencv-4.8.1.orig/data/CMakeLists.txt 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/data/CMakeLists.txt 2023-12-09 21:26:45.381067118 +0800
@@ -1,9 +1,6 @@
file(GLOB HAAR_CASCADES haarcascades/*.xml)
file(GLOB LBP_CASCADES lbpcascades/*.xml)
-install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs)
-install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs)
-
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests")
endif()
diff -Nuarp opencv-4.8.1.orig/platforms/android/service/CMakeLists.txt opencv-4.8.1/platforms/android/service/CMakeLists.txt
--- opencv-4.8.1.orig/platforms/android/service/CMakeLists.txt 2023-09-27 18:18:31.000000000 +0800
+++ opencv-4.8.1/platforms/android/service/CMakeLists.txt 2023-12-09 21:27:16.220897645 +0800
@@ -6,5 +6,3 @@ endif()
if(BUILD_ANDROID_SERVICE)
add_subdirectory(engine)
endif()
-
-install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs)