├── README.md ├── .gitignore ├── patch_tesseract.diff ├── Build-Windows.ps1 ├── .github └── workflows │ └── build.yml └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # obs-ocr-deps 2 | Dependencies for [OBS OCR Plugin](https://github.com/occ-ai/obs-ocr) 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | !build-linux.sh 2 | !build-macos.sh 3 | !Build-Windows.ps1 4 | !LICENSE 5 | !README.md 6 | !.gitignore 7 | * 8 | !.*/ 9 | !.*/** 10 | !patch_tesseract.diff 11 | -------------------------------------------------------------------------------- /patch_tesseract.diff: -------------------------------------------------------------------------------- 1 | diff --git a/src/arch/simddetect.cpp b/src/arch/simddetect.cpp 2 | index 1afe5a5..eaa76ef 100644 3 | --- a/src/arch/simddetect.cpp 4 | +++ b/src/arch/simddetect.cpp 5 | @@ -254,7 +254,7 @@ SIMDDetect::SIMDDetect() { 6 | // SSE detected. 7 | SetDotProduct(DotProductSSE, &IntSimdMatrix::intSimdMatrixSSE); 8 | #endif 9 | -#if defined(HAVE_NEON) || defined(__aarch64__) 10 | +#if defined(HAVE_NEON) 11 | } else if (neon_available_) { 12 | // NEON detected. 13 | SetDotProduct(DotProductNEON, &IntSimdMatrix::intSimdMatrixNEON); 14 | @@ -311,7 +311,7 @@ void SIMDDetect::Update() { 15 | } else if (dotproduct == "accelerate") { 16 | SetDotProduct(DotProductAccelerate, IntSimdMatrix::intSimdMatrix); 17 | #endif 18 | -#if defined(HAVE_NEON) || defined(__aarch64__) 19 | +#if defined(HAVE_NEON) 20 | } else if (dotproduct == "neon" && neon_available_) { 21 | // NEON selected by config variable. 22 | SetDotProduct(DotProductNEON, &IntSimdMatrix::intSimdMatrixNEON); 23 | -------------------------------------------------------------------------------- /Build-Windows.ps1: -------------------------------------------------------------------------------- 1 | Param($Configuration, $TesseractVersion, $LeptonicaVersion) 2 | 3 | # configure leptonica 4 | cmake leptonica-$LeptonicaVersion -B "leptonica_build_$Configuration" ` 5 | -DCMAKE_INSTALL_PREFIX="release/leptonica/$Configuration" ` 6 | -DCMAKE_BUILD_TYPE="$Configuration" ` 7 | -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 ` 8 | -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ` 9 | -DBUILD_SHARED_LIBS=OFF ` 10 | -DENABLE_ZLIB=OFF ` 11 | -DENABLE_PNG=OFF ` 12 | -DENABLE_GIF=OFF ` 13 | -DENABLE_JPEG=OFF ` 14 | -DENABLE_TIFF=OFF ` 15 | -DENABLE_WEBP=OFF ` 16 | -DENABLE_OPENJPEG=OFF ` 17 | -DSW_BUILD=OFF 18 | 19 | # build leptonica 20 | cmake --build "leptonica_build_$Configuration" --config $Configuration 21 | cmake --install "leptonica_build_$Configuration" --prefix "release/leptonica/$Configuration" --config $Configuration 22 | 23 | # configure tesseract 24 | cmake tesseract-$TesseractVersion -B "tesseract_build_${Configuration}" ` 25 | -DCMAKE_INSTALL_PREFIX="release/tesseract/$Configuration" ` 26 | -DCMAKE_BUILD_TYPE="$Configuration" ` 27 | -DBUILD_SHARED_LIBS=OFF ` 28 | -DLeptonica_DIR="$(Get-Location)/release/leptonica/$Configuration/lib/cmake/leptonica" ` 29 | -DUSE_SYSTEM_ICU=ON ` 30 | -DBUILD_TRAINING_TOOLS=OFF ` 31 | -DBUILD_TESTS=OFF ` 32 | -DDISABLED_LEGACY_ENGINE=ON ` 33 | -DDISABLE_TIFF=ON ` 34 | -DDISABLE_CURL=ON ` 35 | -DSW_BUILD=OFF 36 | 37 | # build 38 | cmake --build "tesseract_build_${Configuration}" --config $Configuration 39 | cmake --install "tesseract_build_${Configuration}" --config $Configuration --prefix release\tesseract\$Configuration 40 | 41 | # copy leptonica static libs to tesseract lib folder 42 | # if config is debug add a "d" to the end of the lib name 43 | if ($Configuration -eq "Debug") { 44 | Copy-Item release\leptonica\$Configuration\lib\leptonica-${LeptonicaVersion}d.lib release\tesseract\$Configuration\lib 45 | } else { 46 | Copy-Item release\leptonica\$Configuration\lib\leptonica-${LeptonicaVersion}.lib release\tesseract\$Configuration\lib 47 | } 48 | 49 | Compress-Archive release\tesseract\$Configuration\* release\tesseract-windows-$TesseractVersion-$Configuration.zip -Verbose 50 | 51 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: "Build" 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" 7 | tags: 8 | - "*" 9 | pull_request: 10 | branches: 11 | - "main" 12 | 13 | jobs: 14 | BuildMac: 15 | runs-on: "macos-13" 16 | env: 17 | LEPTONICA_VERSION: "1.84.1" 18 | TESSERACT_VERSION: "5.3.3" 19 | 20 | strategy: 21 | matrix: 22 | config: 23 | - "Debug" 24 | - "Release" 25 | 26 | defaults: 27 | run: 28 | shell: "bash" 29 | 30 | steps: 31 | - name: "Get version" 32 | run: | 33 | if [[ $GITHUB_REF =~ ^refs/tags/ ]] 34 | then version="${GITHUB_REF#refs/tags/}" 35 | else version=$TESSERACT_VERSION 36 | fi 37 | version="${version%-1}" 38 | 39 | printf "version=%s\n" "$version" > "$GITHUB_OUTPUT" 40 | printf "leptonica_version=%s\n" "$LEPTONICA_VERSION" >> "$GITHUB_OUTPUT" 41 | id: "get-version" 42 | 43 | - uses: "actions/checkout@v4" 44 | 45 | - name: Download Leptonica Source 46 | run: | 47 | wget "https://github.com/DanBloomberg/leptonica/archive/refs/tags/$LEPTONICA_VERSION.tar.gz" 48 | tar -xzf "$LEPTONICA_VERSION.tar.gz" 49 | 50 | - name: Download Tesseract Source 51 | run: | 52 | wget "https://github.com/tesseract-ocr/tesseract/archive/refs/tags/$TESSERACT_VERSION.tar.gz" 53 | tar -xzf "$TESSERACT_VERSION.tar.gz" 54 | 55 | - name: Apply Patch 56 | run: | 57 | cd "tesseract-$TESSERACT_VERSION" 58 | patch < ../patch_tesseract.diff 59 | 60 | - name: Install CMake 61 | run: brew install cmake 62 | 63 | - name: "Run build-macos.sh" 64 | run: "./build-macos.sh ${{ matrix.config }} $TESSERACT_VERSION $LEPTONICA_VERSION" 65 | 66 | - uses: "actions/upload-artifact@v3" 67 | with: 68 | name: "tesseract-macos-${{ matrix.config }}" 69 | path: "release/*.tar.gz" 70 | 71 | BuildLinux: 72 | runs-on: "ubuntu-22.04" 73 | env: 74 | LEPTONICA_VERSION: "1.84.1" 75 | TESSERACT_VERSION: "5.3.3" 76 | 77 | strategy: 78 | matrix: 79 | config: 80 | - "Debug" 81 | - "Release" 82 | 83 | defaults: 84 | run: 85 | shell: "bash" 86 | 87 | steps: 88 | - name: "Get version" 89 | run: | 90 | if [[ $GITHUB_REF =~ ^refs/tags/ ]] 91 | then version="${GITHUB_REF#refs/tags/}" 92 | else version=$TESSERACT_VERSION 93 | fi 94 | version="${version%-1}" 95 | printf "version=%s\n" "$version" > "$GITHUB_OUTPUT" 96 | printf "leptonica_version=%s\n" "$LEPTONICA_VERSION" >> "$GITHUB_OUTPUT" 97 | id: "get-version" 98 | 99 | - uses: "actions/checkout@v4" 100 | 101 | - name: Download Leptonica Source 102 | run: | 103 | wget "https://github.com/DanBloomberg/leptonica/archive/refs/tags/${LEPTONICA_VERSION}.tar.gz" 104 | tar -xzf "$LEPTONICA_VERSION.tar.gz" 105 | 106 | - name: Download Tesseract Source 107 | run: | 108 | wget "https://github.com/tesseract-ocr/tesseract/archive/refs/tags/$TESSERACT_VERSION.tar.gz" 109 | tar -xzf "$TESSERACT_VERSION.tar.gz" 110 | 111 | - name: Install CMake 112 | run: sudo apt-get update && sudo apt-get install -y cmake 113 | 114 | - name: "Run build-linux.sh" 115 | run: "./build-linux.sh ${{ matrix.config }} $TESSERACT_VERSION $LEPTONICA_VERSION" 116 | 117 | - uses: "actions/upload-artifact@v3" 118 | with: 119 | name: "tesseract-linux-${{ matrix.config }}" 120 | path: "release/*.tar.gz" 121 | 122 | BuildWindows: 123 | runs-on: "windows-2022" 124 | env: 125 | LEPTONICA_VERSION: "1.84.1" 126 | TESSERACT_VERSION: "5.3.3" 127 | 128 | strategy: 129 | matrix: 130 | config: 131 | - "Debug" 132 | - "Release" 133 | 134 | steps: 135 | - name: "Get version" 136 | shell: bash 137 | run: | 138 | if [[ $GITHUB_REF =~ ^refs/tags/ ]] 139 | then version="${GITHUB_REF#refs/tags/}" 140 | else version=$TESSERACT_VERSION 141 | fi 142 | version="${version%-1}" 143 | printf "TESSERACT_VERSION=%s\n" "$TESSERACT_VERSION" > "$GITHUB_ENV" 144 | printf "LEPTONICA_VERSION=%s\n" "$LEPTONICA_VERSION" >> "$GITHUB_ENV" 145 | id: "get-version" 146 | 147 | - uses: "actions/checkout@v4" 148 | 149 | - name: Download Leptonica Source 150 | shell: powershell 151 | run: | 152 | Invoke-WebRequest -Uri "https://github.com/DanBloomberg/leptonica/archive/refs/tags/$env:LEPTONICA_VERSION.zip" -OutFile "$env:LEPTONICA_VERSION.zip" 153 | Expand-Archive -Path "$env:LEPTONICA_VERSION.zip" -DestinationPath "." 154 | 155 | - name: Download Tesseract Source 156 | shell: powershell 157 | run: | 158 | Invoke-WebRequest -Uri https://github.com/tesseract-ocr/tesseract/archive/refs/tags/$env:TESSERACT_VERSION.zip -OutFile "$env:TESSERACT_VERSION.zip" 159 | Expand-Archive -Path "$env:TESSERACT_VERSION.zip" -DestinationPath "." 160 | 161 | - name: "Run Build-Windows.ps1" 162 | shell: pwsh 163 | run: "./Build-Windows.ps1 -Configuration ${{ matrix.config }} -TesseractVersion $env:TESSERACT_VERSION -LeptonicaVersion $env:LEPTONICA_VERSION" 164 | 165 | - uses: "actions/upload-artifact@v3" 166 | with: 167 | name: "tesseract-windows-${{ matrix.config }}" 168 | path: "release/*.zip" 169 | 170 | Release: 171 | runs-on: "ubuntu-22.04" 172 | 173 | if: "github.event_name == 'push' && contains(github.ref, 'refs/tags/')" 174 | 175 | needs: 176 | - "BuildMac" 177 | - "BuildLinux" 178 | - "BuildWindows" 179 | 180 | permissions: 181 | contents: "write" 182 | 183 | defaults: 184 | run: 185 | shell: "bash" 186 | 187 | steps: 188 | - name: "Get version" 189 | run: | 190 | if [[ $GITHUB_REF =~ ^refs/tags/ ]] 191 | then version="${GITHUB_REF#refs/tags/}" 192 | else version=main 193 | fi 194 | printf "version=%s" "$version" > "$GITHUB_OUTPUT" 195 | id: "get-version" 196 | 197 | - name: "Download build artifacts" 198 | uses: "actions/download-artifact@v3" 199 | 200 | - name: Generate Checksums 🪪 201 | run: | 202 | : Generate Checksums 🪪 203 | if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi 204 | shopt -s extglob 205 | 206 | echo "### Checksums" > ${{ github.workspace }}/CHECKSUMS.txt 207 | for file in ${{ github.workspace }}/@(*.tar.gz|*.tar.xz|*.zip); do 208 | echo " ${file##*/}: $(sha256sum "${file}" | cut -d " " -f 1)" >> ${{ github.workspace }}/CHECKSUMS.txt 209 | done 210 | 211 | - name: "Create Release" 212 | uses: "softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5" 213 | with: 214 | draft: true 215 | tag_name: "${{ steps.get-version.outputs.version }}" 216 | name: "${{ steps.get-version.outputs.version }}" 217 | body_path: ${{ github.workspace }}/CHECKSUMS.txt 218 | files: | 219 | ${{ github.workspace }}/**/*.tar.gz 220 | ${{ github.workspace }}/**/*.zip 221 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------