├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ └── release.yml ├── .gitignore ├── LICENSE ├── README.md ├── fix-windows-sdk-26100-arm64-wchar.patch ├── highgui ├── CMakeLists.txt ├── include │ └── opencv2 │ │ ├── dnn.hpp │ │ ├── dnn │ │ └── dnn.hpp │ │ ├── highgui.hpp │ │ └── highgui │ │ └── highgui.hpp └── src │ ├── capture_cvi.cpp │ ├── capture_cvi.h │ ├── capture_v4l2.cpp │ ├── capture_v4l2.h │ ├── capture_v4l2_aw_isp.cpp │ ├── capture_v4l2_aw_isp.h │ ├── capture_v4l2_rk_aiq.cpp │ ├── capture_v4l2_rk_aiq.h │ ├── display_fb.cpp │ ├── display_fb.h │ ├── display_win32.cpp │ ├── display_win32.h │ ├── exif.cpp │ ├── exif.hpp │ ├── highgui.cpp │ ├── jpeg_decoder_aw.cpp │ ├── jpeg_decoder_aw.h │ ├── jpeg_decoder_cvi.cpp │ ├── jpeg_decoder_cvi.h │ ├── jpeg_encoder_aw.cpp │ ├── jpeg_encoder_aw.h │ ├── jpeg_encoder_rk_mpp.cpp │ ├── jpeg_encoder_rk_mpp.h │ ├── jpeg_encoder_v4l_cix.cpp │ ├── jpeg_encoder_v4l_cix.h │ ├── jpeg_encoder_v4l_rpi.cpp │ ├── jpeg_encoder_v4l_rpi.h │ ├── kanna_rotate.cpp │ ├── kanna_rotate.h │ ├── nms.cpp │ ├── stb_image.h │ ├── stb_image_write.h │ ├── videocapture.cpp │ ├── videowriter.cpp │ ├── writer_http.cpp │ └── writer_http.h ├── opencv2_cmake_options.txt ├── opencv3_cmake_options.txt ├── opencv4_cmake_options.txt ├── patches ├── Info.plist ├── draw_text.h ├── fontface.html ├── mono_font_data.h ├── opencv-2.4.13.7-drawing-mono-font.patch ├── opencv-2.4.13.7-enable-cxx11.patch ├── opencv-2.4.13.7-fix-highgui-include.patch ├── opencv-2.4.13.7-fix-windows-arm-arch.patch ├── opencv-2.4.13.7-link-openmp.patch ├── opencv-2.4.13.7-minimal-install.patch ├── opencv-2.4.13.7-newer-msvc.patch ├── opencv-2.4.13.7-no-gpu.patch ├── opencv-2.4.13.7-no-link-stdc++.patch ├── opencv-2.4.13.7-no-local-static.patch ├── opencv-2.4.13.7-no-rtti.patch ├── opencv-2.4.13.7-no-zlib.patch ├── opencv-2.4.13.7-unsafe-xadd.patch ├── opencv-3.4.20-drawing-mono-font.patch ├── opencv-3.4.20-fix-emscripten-include.patch ├── opencv-3.4.20-fix-windows-arm-arch.patch ├── opencv-3.4.20-link-openmp.patch ├── opencv-3.4.20-minimal-install.patch ├── opencv-3.4.20-newer-msvc.patch ├── opencv-3.4.20-no-gpu.patch ├── opencv-3.4.20-no-rtti.patch ├── opencv-3.4.20-no-zlib.patch ├── opencv-3.4.20-unsafe-xadd.patch ├── opencv-4.11.0-drawing-mono-font.patch ├── opencv-4.11.0-fix-windows-arm-arch.patch ├── opencv-4.11.0-link-openmp.patch ├── opencv-4.11.0-minimal-install.patch ├── opencv-4.11.0-no-atomic.patch ├── opencv-4.11.0-no-gpu.patch ├── opencv-4.11.0-no-rtti.patch ├── opencv-4.11.0-no-zlib.patch └── opencv-4.11.0-unsafe-xadd.patch ├── test ├── CMakeLists.txt └── main.cpp └── toolchains ├── aarch64-linux-gnu.toolchain.cmake ├── aarch64-openwrt-linux-gnu.toolchain.cmake ├── arm-linux-gnueabi.toolchain.cmake ├── arm-linux-gnueabihf.toolchain.cmake ├── arm-openwrt-linux-gnueabi.toolchain.cmake ├── arm-openwrt-linux-muslgnueabi.toolchain.cmake ├── arm-rockchip830-linux-uclibcgnueabihf.toolchain.cmake ├── c906-v261.toolchain.cmake ├── ios.toolchain.cmake ├── loongarch64-linux-gnu.toolchain.cmake ├── macos-arm64.toolchain.cmake ├── riscv32-linux-musl.toolchain.cmake └── riscv64-unknown-linux-musl.toolchain.cmake /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: paypal.me/shuizhuyuanluo 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE generated directories 2 | .idea/ 3 | cmake-build-debug 4 | cmake-build-release 5 | .vscode 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /fix-windows-sdk-26100-arm64-wchar.patch: -------------------------------------------------------------------------------- 1 | --- "Windows Kits/10/Include/10.0.26100.0/ucrt/wchar.h" 2025-03-21 11:30:49.000000000 +0000 2 | +++ "Windows Kits/10/Include/10.0.26100.0/ucrt/wchar.h" 2025-03-21 11:40:35.766780259 +0000 3 | @@ -228,7 +228,7 @@ typedef wchar_t _Wint_t; 4 | unsigned long Index = 0; 5 | wchar_t const* S = _S; 6 | 7 | - #if defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) 8 | + #if 0//defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) 9 | if (_N >= 4) 10 | { 11 | uint16x8_t V2 = vdupq_n_u16(_C); 12 | @@ -352,7 +352,7 @@ typedef wchar_t _Wint_t; 13 | wchar_t const* S1 = _S1; 14 | wchar_t const* S2 = _S2; 15 | 16 | - #if defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) 17 | + #if 0//defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64) 18 | 19 | while (Count + 8 <= _N) 20 | { 21 | -------------------------------------------------------------------------------- /highgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(the_description "High-level GUI") 2 | ocv_add_module(highgui opencv_imgproc) 3 | 4 | option(WITH_CVI "build with cvi" OFF) 5 | option(WITH_AW "build with aw" OFF) 6 | option(WITH_RK "build with rk" OFF) 7 | option(WITH_RPI "build with rpi" OFF) 8 | option(WITH_CIX "build with cix" OFF) 9 | 10 | set(highgui_srcs 11 | ${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp 12 | ${CMAKE_CURRENT_LIST_DIR}/src/highgui.cpp 13 | ${CMAKE_CURRENT_LIST_DIR}/src/kanna_rotate.cpp 14 | ${CMAKE_CURRENT_LIST_DIR}/src/videocapture.cpp 15 | ${CMAKE_CURRENT_LIST_DIR}/src/videowriter.cpp 16 | 17 | # dnn 18 | ${CMAKE_CURRENT_LIST_DIR}/src/nms.cpp 19 | ) 20 | 21 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 22 | list(APPEND highgui_srcs 23 | ${CMAKE_CURRENT_LIST_DIR}/src/capture_v4l2.cpp 24 | ${CMAKE_CURRENT_LIST_DIR}/src/display_fb.cpp 25 | ${CMAKE_CURRENT_LIST_DIR}/src/writer_http.cpp) 26 | endif() 27 | 28 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 29 | list(APPEND highgui_srcs 30 | ${CMAKE_CURRENT_LIST_DIR}/src/display_win32.cpp) 31 | endif() 32 | 33 | if(WITH_CVI) 34 | list(APPEND highgui_srcs 35 | ${CMAKE_CURRENT_LIST_DIR}/src/capture_cvi.cpp 36 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_decoder_cvi.cpp) 37 | add_definitions(-DCV_WITH_CVI=1) 38 | message(STATUS "highgui cvi enabled") 39 | endif() 40 | 41 | if(WITH_AW) 42 | list(APPEND highgui_srcs 43 | ${CMAKE_CURRENT_LIST_DIR}/src/capture_v4l2_aw_isp.cpp 44 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_decoder_aw.cpp 45 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_aw.cpp) 46 | add_definitions(-DCV_WITH_AW=1) 47 | message(STATUS "highgui aw enabled") 48 | endif() 49 | 50 | if(WITH_RK) 51 | list(APPEND highgui_srcs 52 | ${CMAKE_CURRENT_LIST_DIR}/src/capture_v4l2_rk_aiq.cpp 53 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_rk_mpp.cpp) 54 | add_definitions(-DCV_WITH_RK=1) 55 | message(STATUS "highgui rk enabled") 56 | endif() 57 | 58 | if(WITH_RPI) 59 | list(APPEND highgui_srcs 60 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_v4l_rpi.cpp) 61 | add_definitions(-DCV_WITH_RPI=1) 62 | message(STATUS "highgui rpi enabled") 63 | endif() 64 | 65 | if(WITH_CIX) 66 | list(APPEND highgui_srcs 67 | ${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_v4l_cix.cpp) 68 | add_definitions(-DCV_WITH_CIX=1) 69 | message(STATUS "highgui cix enabled") 70 | endif() 71 | 72 | file(GLOB highgui_ext_hdrs 73 | "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp" 74 | "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp" 75 | "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h" 76 | "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/dnn/*.hpp" 77 | "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/dnn/*.h") 78 | 79 | if(UNIX OR OPENCV_VERSION_MAJOR GREATER_EQUAL 3) 80 | #these variables are set by CHECK_MODULE macro 81 | foreach(P ${HIGHGUI_INCLUDE_DIRS}) 82 | ocv_include_directories(${P}) 83 | endforeach() 84 | 85 | foreach(P ${HIGHGUI_LIBRARY_DIRS}) 86 | link_directories(${P}) 87 | endforeach() 88 | endif() 89 | 90 | source_group("Src" FILES ${highgui_srcs}) 91 | source_group("Include" FILES ${highgui_ext_hdrs}) 92 | ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs}) 93 | ocv_module_include_directories() 94 | 95 | ocv_create_module(${HIGHGUI_LIBRARIES}) 96 | 97 | if(OPENCV_VERSION_MAJOR EQUAL 2) 98 | if(BUILD_SHARED_LIBS) 99 | add_definitions(-DHIGHGUI_EXPORTS) 100 | endif() 101 | 102 | if(MSVC) 103 | set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") 104 | endif() 105 | 106 | ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations -Wno-clobbered) 107 | else() 108 | macro(ocv_highgui_configure_target) 109 | if(APPLE) 110 | add_apple_compiler_options(the_module) 111 | endif() 112 | 113 | if(MSVC) 114 | set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") 115 | endif() 116 | 117 | ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations) 118 | endmacro() 119 | 120 | if(NOT BUILD_opencv_world) 121 | ocv_highgui_configure_target() 122 | endif() 123 | endif() 124 | -------------------------------------------------------------------------------- /highgui/include/opencv2/dnn.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include "opencv2/dnn/dnn.hpp" 18 | -------------------------------------------------------------------------------- /highgui/include/opencv2/dnn/dnn.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef OPENCV_DNN_HPP 18 | #define OPENCV_DNN_HPP 19 | 20 | #include "opencv2/core.hpp" 21 | 22 | namespace cv { 23 | namespace dnn { 24 | 25 | enum SoftNMSMethod 26 | { 27 | SOFTNMS_LINEAR = 1, 28 | SOFTNMS_GAUSSIAN = 2 29 | }; 30 | 31 | CV_EXPORTS void NMSBoxes(const std::vector& bboxes, const std::vector& scores, 32 | const float score_threshold, const float nms_threshold, 33 | CV_OUT std::vector& indices, 34 | const float eta = 1.f, const int top_k = 0); 35 | 36 | CV_EXPORTS void NMSBoxesBatched(const std::vector& bboxes, const std::vector& scores, const std::vector& class_ids, 37 | const float score_threshold, const float nms_threshold, 38 | CV_OUT std::vector& indices, 39 | const float eta = 1.f, const int top_k = 0); 40 | 41 | CV_EXPORTS_W void softNMSBoxes(const std::vector& bboxes, const std::vector& scores, 42 | CV_OUT std::vector& updated_scores, 43 | const float score_threshold, const float nms_threshold, 44 | CV_OUT std::vector& indices, 45 | size_t top_k = 0, const float sigma = 0.5, SoftNMSMethod method = SOFTNMS_GAUSSIAN); 46 | 47 | } // namespace dnn 48 | } // namespace cv 49 | 50 | #endif // OPENCV_DNN_HPP 51 | -------------------------------------------------------------------------------- /highgui/include/opencv2/highgui.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2021 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include "opencv2/highgui/highgui.hpp" 18 | -------------------------------------------------------------------------------- /highgui/include/opencv2/highgui/highgui.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2021 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef OPENCV_HIGHGUI_HPP 18 | #define OPENCV_HIGHGUI_HPP 19 | 20 | #include "opencv2/core.hpp" 21 | 22 | enum 23 | { 24 | CV_LOAD_IMAGE_UNCHANGED = -1, 25 | CV_LOAD_IMAGE_GRAYSCALE = 0, 26 | CV_LOAD_IMAGE_COLOR = 1, 27 | }; 28 | 29 | enum 30 | { 31 | CV_IMWRITE_JPEG_QUALITY = 1 32 | }; 33 | 34 | enum 35 | { 36 | CV_CAP_PROP_FRAME_WIDTH = 3, 37 | CV_CAP_PROP_FRAME_HEIGHT = 4, 38 | CV_CAP_PROP_FPS = 5, 39 | }; 40 | 41 | namespace cv { 42 | 43 | enum ImreadModes 44 | { 45 | IMREAD_UNCHANGED = -1, 46 | IMREAD_GRAYSCALE = 0, 47 | IMREAD_COLOR = 1 48 | }; 49 | 50 | enum ImwriteFlags 51 | { 52 | IMWRITE_JPEG_QUALITY = 1 53 | }; 54 | 55 | enum VideoCaptureProperties 56 | { 57 | CAP_PROP_FRAME_WIDTH = 3, 58 | CAP_PROP_FRAME_HEIGHT = 4, 59 | CAP_PROP_FPS = 5, 60 | }; 61 | 62 | CV_EXPORTS_W Mat imread(const String& filename, int flags = IMREAD_COLOR); 63 | 64 | CV_EXPORTS_W bool imwrite(const String& filename, InputArray img, const std::vector& params = std::vector()); 65 | 66 | CV_EXPORTS_W Mat imdecode(InputArray buf, int flags); 67 | 68 | CV_EXPORTS_W bool imencode(const String& ext, InputArray img, CV_OUT std::vector& buf, const std::vector& params = std::vector()); 69 | 70 | CV_EXPORTS_W void imshow(const String& winname, InputArray mat); 71 | 72 | CV_EXPORTS_W int waitKey(int delay = 0); 73 | 74 | class VideoCaptureImpl; 75 | class CV_EXPORTS_W VideoCapture 76 | { 77 | public: 78 | VideoCapture(); 79 | 80 | ~VideoCapture(); 81 | 82 | bool open(int index); 83 | 84 | bool isOpened() const; 85 | 86 | void release(); 87 | 88 | VideoCapture& operator>>(Mat& bgr_image); 89 | 90 | bool set(int propId, double value); 91 | 92 | double get(int propId) const; 93 | 94 | private: 95 | VideoCaptureImpl* const d; 96 | }; 97 | 98 | class VideoWriterImpl; 99 | class CV_EXPORTS_W VideoWriter 100 | { 101 | public: 102 | VideoWriter(); 103 | 104 | ~VideoWriter(); 105 | 106 | bool open(const String& name, int port); 107 | 108 | bool isOpened() const; 109 | 110 | void release(); 111 | 112 | VideoWriter& operator<<(const Mat& bgr_image); 113 | 114 | void write(const Mat& image); 115 | 116 | protected: 117 | VideoWriterImpl* const d; 118 | }; 119 | 120 | } // namespace cv 121 | 122 | #endif // OPENCV_HIGHGUI_HPP 123 | -------------------------------------------------------------------------------- /highgui/src/capture_cvi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef CAPTURE_CVI_H 18 | #define CAPTURE_CVI_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class capture_cvi_impl; 25 | class capture_cvi 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | capture_cvi(); 31 | ~capture_cvi(); 32 | 33 | int open(int width = 1920, int height = 1080, float fps = 30); 34 | 35 | int get_width() const; 36 | int get_height() const; 37 | float get_fps() const; 38 | 39 | int start_streaming(); 40 | 41 | int read_frame(unsigned char* bgrdata); 42 | 43 | int stop_streaming(); 44 | 45 | int close(); 46 | 47 | private: 48 | capture_cvi_impl* const d; 49 | }; 50 | 51 | } // namespace cv 52 | 53 | #endif // CAPTURE_CVI_H 54 | -------------------------------------------------------------------------------- /highgui/src/capture_v4l2.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef CAPTURE_V4L2_H 18 | #define CAPTURE_V4L2_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class capture_v4l2_impl; 25 | class capture_v4l2 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | capture_v4l2(); 31 | ~capture_v4l2(); 32 | 33 | int open(int index, int width = 640, int height = 480, float fps = 30); 34 | 35 | int get_width() const; 36 | int get_height() const; 37 | float get_fps() const; 38 | 39 | int start_streaming(); 40 | 41 | int read_frame(unsigned char* bgrdata); 42 | 43 | int stop_streaming(); 44 | 45 | int close(); 46 | 47 | private: 48 | capture_v4l2_impl* const d; 49 | }; 50 | 51 | } // namespace cv 52 | 53 | #endif // CAPTURE_V4L2_H 54 | -------------------------------------------------------------------------------- /highgui/src/capture_v4l2_aw_isp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef CAPTURE_V4L2_AW_ISP_H 18 | #define CAPTURE_V4L2_AW_ISP_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class capture_v4l2_aw_isp_impl; 25 | class capture_v4l2_aw_isp 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | capture_v4l2_aw_isp(); 31 | ~capture_v4l2_aw_isp(); 32 | 33 | int open(int width = 640, int height = 480, float fps = 30); 34 | 35 | int get_width() const; 36 | int get_height() const; 37 | float get_fps() const; 38 | 39 | int start_streaming(); 40 | 41 | int read_frame(unsigned char* bgrdata); 42 | 43 | int stop_streaming(); 44 | 45 | int close(); 46 | 47 | private: 48 | capture_v4l2_aw_isp_impl* const d; 49 | }; 50 | 51 | } // namespace cv 52 | 53 | #endif // CAPTURE_V4L2_AW_ISP_H 54 | -------------------------------------------------------------------------------- /highgui/src/capture_v4l2_rk_aiq.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2023 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef CAPTURE_V4L2_RK_AIQ_H 18 | #define CAPTURE_V4L2_RK_AIQ_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class capture_v4l2_rk_aiq_impl; 25 | class capture_v4l2_rk_aiq 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | capture_v4l2_rk_aiq(); 31 | ~capture_v4l2_rk_aiq(); 32 | 33 | int open(int width = 640, int height = 480, float fps = 30); 34 | 35 | int get_width() const; 36 | int get_height() const; 37 | float get_fps() const; 38 | 39 | int start_streaming(); 40 | 41 | int read_frame(unsigned char* bgrdata); 42 | 43 | int stop_streaming(); 44 | 45 | int close(); 46 | 47 | private: 48 | capture_v4l2_rk_aiq_impl* const d; 49 | }; 50 | 51 | } // namespace cv 52 | 53 | #endif // CAPTURE_V4L2_RK_AIQ_H 54 | -------------------------------------------------------------------------------- /highgui/src/display_fb.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef DISPLAY_FB_H 18 | #define DISPLAY_FB_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class display_fb_impl; 25 | class display_fb 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | display_fb(); 31 | ~display_fb(); 32 | 33 | int open(); 34 | 35 | int get_width() const; 36 | int get_height() const; 37 | 38 | int show_bgr(const unsigned char* bgrdata, int width, int height); 39 | int show_gray(const unsigned char* graydata, int width, int height); 40 | 41 | int close(); 42 | 43 | private: 44 | display_fb_impl* const d; 45 | }; 46 | 47 | } // namespace cv 48 | 49 | #endif // DISPLAY_FB_H 50 | -------------------------------------------------------------------------------- /highgui/src/display_win32.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 szx0427&futz12 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | // IMSHOW window for MS Windows 18 | #include "display_win32.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static constexpr auto classNameBase = "OCVMWndClass"; 26 | static char className[100]; // real class name for current process. 27 | // Use this process-specific name to ensure that picture replacement for identical-named windows 28 | // only works for windows in the same process. The windows in other processes, 29 | // even if they have the same name, are ignored by BitmapWindow::show(). 30 | // That's to say, new windows with the same name will be created. 31 | 32 | static std::map g_wndMap; 33 | static std::recursive_mutex g_creationMutex, g_wndMapMutex; 34 | static SimpleWindow* g_wndBeingCreated{}; 35 | static ATOM g_ocvmWndClassAtom{}; 36 | thread_local std::list th_ocvmBmpWndList; 37 | 38 | typedef std::lock_guard defLockGuard; 39 | 40 | template 41 | static inline void safeReleaseArray(T* &array) { 42 | delete[] array; 43 | array = nullptr; 44 | } 45 | 46 | LRESULT CALLBACK __globalWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 47 | { 48 | if (g_wndBeingCreated) { 49 | g_wndBeingCreated->m_hWnd = hWnd; 50 | return g_wndBeingCreated->windowProc(msg, wParam, lParam); 51 | } 52 | 53 | defLockGuard mapLock(g_wndMapMutex); 54 | auto it = g_wndMap.find(hWnd); 55 | if (it != g_wndMap.end()) { 56 | return it->second->windowProc(msg, wParam, lParam); 57 | } 58 | else { 59 | fprintf(stderr, "[WARNING] display_win32: __globalWndProc: Window %p not found\n", hWnd); 60 | return DefWindowProcA(hWnd, msg, wParam, lParam); 61 | } 62 | } 63 | 64 | SimpleWindow::SimpleWindow() 65 | : m_hWnd(nullptr) 66 | { 67 | } 68 | 69 | SimpleWindow::SimpleWindow(SimpleWindow&& right) noexcept 70 | { 71 | *this = std::move(right); 72 | } 73 | 74 | SimpleWindow& SimpleWindow::operator=(SimpleWindow&& right) noexcept 75 | { 76 | detach(); 77 | m_hWnd = right.m_hWnd; 78 | 79 | if (m_hWnd) { 80 | defLockGuard mapLock(g_wndMapMutex); 81 | auto it = g_wndMap.find(m_hWnd); 82 | if (it != g_wndMap.end()) { 83 | it->second = this; 84 | } 85 | else { 86 | fprintf(stderr, "[WARNING] display_win32: move assignment: Window %p not found\n", m_hWnd); 87 | } 88 | 89 | right.m_hWnd = nullptr; 90 | } 91 | 92 | return *this; 93 | } 94 | 95 | HWND SimpleWindow::getHwnd() const 96 | { 97 | return m_hWnd; 98 | } 99 | 100 | bool SimpleWindow::create(LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, DWORD dwExStyle, HMENU hMenu, LPVOID lpParam) 101 | { 102 | assert(!m_hWnd); 103 | 104 | auto hInst = GetModuleHandle(nullptr); 105 | defLockGuard creationLock(g_creationMutex); // use mutex to ensure thread security 106 | 107 | if (!g_ocvmWndClassAtom) { 108 | sprintf(className, "%s:%d", classNameBase, static_cast(GetCurrentProcessId())); 109 | 110 | WNDCLASSA wc; 111 | ZeroMemory(&wc, sizeof(wc)); 112 | wc.style = CS_HREDRAW | CS_VREDRAW; 113 | wc.lpfnWndProc = __globalWndProc; 114 | wc.hInstance = hInst; 115 | wc.lpszClassName = className; 116 | wc.hCursor = LoadCursor(nullptr, IDC_CROSS); 117 | g_ocvmWndClassAtom = RegisterClassA(&wc); 118 | } 119 | 120 | g_wndBeingCreated = this; // storage "this" temporarily to g_wndBeingCreated, which will soon be used by __globalWndProc to process WM_CREATE. 121 | m_hWnd = CreateWindowExA(dwExStyle, className, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInst, lpParam); 122 | g_wndBeingCreated = nullptr; 123 | 124 | if (m_hWnd) { 125 | defLockGuard mapLock(g_wndMapMutex); 126 | g_wndMap.emplace(m_hWnd, this); 127 | return true; 128 | } 129 | return false; 130 | } 131 | 132 | void SimpleWindow::centerWindow() const 133 | { 134 | assert(m_hWnd); 135 | RECT rc; 136 | GetWindowRect(m_hWnd, &rc); 137 | int x = (GetSystemMetrics(SM_CXFULLSCREEN) - (rc.right - rc.left)) / 2; 138 | int y = (GetSystemMetrics(SM_CYFULLSCREEN) - (rc.bottom - rc.top)) / 2; 139 | SetWindowPos(m_hWnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 140 | } 141 | 142 | void SimpleWindow::show(int nCmdShow) 143 | { 144 | assert(m_hWnd); 145 | 146 | ShowWindow(m_hWnd, nCmdShow); 147 | UpdateWindow(m_hWnd); 148 | } 149 | 150 | #if 0 151 | int SimpleWindow::messageLoop() 152 | { 153 | MSG msg; 154 | while (GetMessageA(&msg, getHwnd(), 0, 0) > 0) { 155 | TranslateMessage(&msg); 156 | DispatchMessageA(&msg); 157 | } 158 | 159 | return (int)msg.wParam; 160 | } 161 | #endif 162 | 163 | LRESULT SimpleWindow::windowProc(UINT msg, WPARAM wParam, LPARAM lParam) 164 | { 165 | auto ret = DefWindowProcA(m_hWnd, msg, wParam, lParam); 166 | if (msg == WM_NCDESTROY) { 167 | detach(); 168 | } 169 | return ret; 170 | } 171 | 172 | double SimpleWindow::getDesktopDpiFactor() 173 | { 174 | HDC hDC = GetDC(nullptr); 175 | double ret = GetDeviceCaps(hDC, LOGPIXELSX) / static_cast(USER_DEFAULT_SCREEN_DPI); 176 | ReleaseDC(nullptr, hDC); 177 | return ret; 178 | } 179 | 180 | void SimpleWindow::detach() 181 | { 182 | if (m_hWnd) { 183 | defLockGuard mapLock(g_wndMapMutex); 184 | g_wndMap.erase(m_hWnd); 185 | m_hWnd = nullptr; 186 | } 187 | } 188 | 189 | SimpleWindow::~SimpleWindow() 190 | { 191 | // NOTE: Directly remove mapping when one SimpleWindow object is being destructed. 192 | // Errors will occur if multiple SimpleWindow objects are attached to one HWND. 193 | detach(); 194 | } 195 | 196 | BitmapWindow* BitmapWindow::findOCVMWindowByName(LPCSTR windowName) 197 | { 198 | HWND hWnd = FindWindowA((LPCSTR)(intptr_t)g_ocvmWndClassAtom, windowName); 199 | if (hWnd) { 200 | defLockGuard mapLock(g_wndMapMutex); 201 | auto it = g_wndMap.find(hWnd); 202 | if (it != g_wndMap.end()) { 203 | return reinterpret_cast(it->second); 204 | } 205 | } 206 | return nullptr; 207 | } 208 | 209 | void BitmapWindow::drawBitmap(int horz, int vert) 210 | { 211 | if (horz < 0) { 212 | horz = GetScrollPos(m_hWnd, SB_HORZ); 213 | } 214 | if (vert < 0) { 215 | vert = GetScrollPos(m_hWnd, SB_VERT); 216 | } 217 | 218 | RECT rc; 219 | GetClientRect(m_hWnd, &rc); 220 | if (m_bmpInfo.bmiHeader.biHeight < 0) { 221 | m_xSrc = horz; 222 | m_ySrc = vert; 223 | } 224 | else { 225 | m_xSrc = horz; 226 | m_ySrc = m_bmpInfo.bmiHeader.biHeight - vert - rc.bottom; 227 | } 228 | 229 | InvalidateRect(m_hWnd, nullptr, FALSE); 230 | } 231 | 232 | int BitmapWindow::waitKey(UINT delay) 233 | { 234 | if (th_ocvmBmpWndList.size() == 0) { 235 | return -1; 236 | } 237 | 238 | if (delay > 0) { 239 | for (auto wnd : th_ocvmBmpWndList) { 240 | SetTimer(wnd, waitKeyTimerId, delay, nullptr); 241 | } 242 | } 243 | 244 | MSG msg; 245 | int asciiCode = -1; 246 | while (GetMessageA(&msg, nullptr, 0, 0) > 0) { 247 | if (msg.hwnd) { 248 | if (msg.message == WM_WAITKEYTIMEOUT) { 249 | for (auto wnd : th_ocvmBmpWndList) { 250 | KillTimer(wnd, waitKeyTimerId); 251 | } 252 | // As this thread may have created more than one OCVMWindow, 253 | // we need to clean up remaining messages in the queue 254 | // to avoid receiving many WM_WAITKEYTIMEOUT as soon as 255 | // waitKey() is called next time. 256 | while (PeekMessageA(&msg, nullptr, 0, 0, PM_REMOVE)); 257 | return -1; 258 | } 259 | if (msg.message == WM_CHAR) { 260 | asciiCode = static_cast(msg.wParam); 261 | break; 262 | } 263 | TranslateMessage(&msg); 264 | DispatchMessageA(&msg); 265 | } 266 | } 267 | 268 | return asciiCode; 269 | } 270 | 271 | BitmapWindow::BitmapWindow() 272 | : m_xSrc(0) 273 | , m_ySrc(0) 274 | , m_bits(nullptr) 275 | { 276 | ZeroMemory(&m_bmpInfo, sizeof(m_bmpInfo)); 277 | 278 | int screenWidth = GetSystemMetrics(SM_CXSCREEN); 279 | int screenHeight = GetSystemMetrics(SM_CYSCREEN); 280 | HDC hDesktopDC = GetDC(nullptr); 281 | m_hMemDC = CreateCompatibleDC(hDesktopDC); 282 | m_hMemBitmap = CreateCompatibleBitmap(hDesktopDC, screenWidth, screenHeight); 283 | m_hOldBitmap = SelectObject(m_hMemDC, m_hMemBitmap); 284 | ReleaseDC(nullptr, hDesktopDC); 285 | } 286 | 287 | BitmapWindow::~BitmapWindow() 288 | { 289 | if (m_bits) { 290 | safeReleaseArray(m_bits); 291 | } 292 | 293 | SelectObject(m_hMemDC, m_hOldBitmap); 294 | DeleteObject(m_hMemBitmap); 295 | DeleteDC(m_hMemDC); 296 | } 297 | 298 | void BitmapWindow::show(LPCSTR windowName, const BYTE* bmpFileData) 299 | { 300 | auto formerWindow = findOCVMWindowByName(windowName); 301 | if (formerWindow) { // if a window with this name already exists, just update its image 302 | formerWindow->updateBitmapData(bmpFileData); 303 | RECT rc; 304 | GetWindowRect(formerWindow->getHwnd(), &rc); 305 | SetWindowPos(formerWindow->getHwnd(), nullptr, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE); 306 | formerWindow->updateScrollBarStatus(); 307 | formerWindow->drawBitmap(); 308 | return; 309 | } 310 | 311 | BitmapWindow* newWindow = new BitmapWindow; 312 | newWindow->updateBitmapData(bmpFileData); 313 | 314 | auto dpiFactor = getDesktopDpiFactor(); 315 | newWindow->create(windowName, (WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL) & ~WS_MAXIMIZEBOX, 0, 0, 800 * dpiFactor, 600 * dpiFactor); 316 | newWindow->centerWindow(); 317 | newWindow->drawBitmap(); 318 | newWindow->updateScrollBarStatus(); 319 | newWindow->SimpleWindow::show(SW_SHOWNORMAL); 320 | 321 | th_ocvmBmpWndList.push_back(newWindow->m_hWnd); 322 | } 323 | 324 | void BitmapWindow::updateBitmapData(const BYTE* bmpFileData) 325 | { 326 | if (m_bits) { 327 | safeReleaseArray(m_bits); 328 | } 329 | BITMAPFILEHEADER* fileHeader = (BITMAPFILEHEADER*)bmpFileData; 330 | auto bitsSize = fileHeader->bfSize - fileHeader->bfOffBits; 331 | m_bits = new BYTE[bitsSize]; 332 | memcpy(m_bits, bmpFileData + fileHeader->bfOffBits, bitsSize); 333 | ZeroMemory(&m_bmpInfo, sizeof(m_bmpInfo)); 334 | memcpy(&m_bmpInfo.bmiHeader, bmpFileData + sizeof(BITMAPFILEHEADER), sizeof(BITMAPINFOHEADER)); 335 | } 336 | 337 | void BitmapWindow::updateScrollBarStatus() 338 | { 339 | RECT rc; 340 | GetClientRect(m_hWnd, &rc); 341 | int cx = rc.right; 342 | int cy = rc.bottom; 343 | if (m_bmpInfo.bmiHeader.biWidth > cx) { 344 | EnableScrollBar(m_hWnd, SB_HORZ, ESB_ENABLE_BOTH); 345 | SetScrollRange(m_hWnd, SB_HORZ, 0, m_bmpInfo.bmiHeader.biWidth - cx, TRUE); 346 | } 347 | else { 348 | SetScrollPos(m_hWnd, SB_HORZ, 0, FALSE); 349 | EnableScrollBar(m_hWnd, SB_HORZ, ESB_DISABLE_BOTH); 350 | } 351 | if (abs(m_bmpInfo.bmiHeader.biHeight) > cy) { 352 | EnableScrollBar(m_hWnd, SB_VERT, ESB_ENABLE_BOTH); 353 | SetScrollRange(m_hWnd, SB_VERT, 0, abs(m_bmpInfo.bmiHeader.biHeight) - cy, TRUE); 354 | } 355 | else { 356 | SetScrollPos(m_hWnd, SB_VERT, 0, FALSE); 357 | EnableScrollBar(m_hWnd, SB_VERT, ESB_DISABLE_BOTH); 358 | } 359 | } 360 | 361 | LRESULT BitmapWindow::windowProc(UINT msg, WPARAM wParam, LPARAM lParam) 362 | { 363 | switch (msg) 364 | { 365 | case WM_TIMER: 366 | if (wParam == waitKeyTimerId) { 367 | PostMessageA(m_hWnd, WM_WAITKEYTIMEOUT, 0, 0); 368 | } 369 | return 0; 370 | case WM_PAINT: { 371 | PAINTSTRUCT ps; 372 | HDC hdc = BeginPaint(m_hWnd, &ps); 373 | 374 | int cx = (std::min)(ps.rcPaint.right, m_bmpInfo.bmiHeader.biWidth); 375 | int cy = (std::min)(ps.rcPaint.bottom, m_bmpInfo.bmiHeader.biHeight); 376 | 377 | if (ps.rcPaint.right > m_bmpInfo.bmiHeader.biWidth || ps.rcPaint.bottom > m_bmpInfo.bmiHeader.biHeight) { 378 | HBRUSH hbrBkgnd = CreateSolidBrush(RGB(240, 240, 240)); 379 | FillRect(m_hMemDC, &ps.rcPaint, hbrBkgnd); 380 | DeleteObject(hbrBkgnd); 381 | StretchDIBits(m_hMemDC, 0, 0, cx, cy, m_xSrc, m_ySrc, cx, cy, m_bits, &m_bmpInfo, DIB_RGB_COLORS, SRCCOPY); 382 | BitBlt(hdc, 0, 0, ps.rcPaint.right, ps.rcPaint.bottom, m_hMemDC, 0, 0, SRCCOPY); 383 | } 384 | else { 385 | StretchDIBits(hdc, 0, 0, cx, cy, m_xSrc, m_ySrc, cx, cy, m_bits, &m_bmpInfo, DIB_RGB_COLORS, SRCCOPY); 386 | } 387 | 388 | EndPaint(m_hWnd, &ps); 389 | return 0; 390 | } 391 | case WM_HSCROLL: { 392 | int pos = HIWORD(wParam); 393 | switch (LOWORD(wParam)) { 394 | case SB_THUMBTRACK: 395 | drawBitmap(pos); 396 | break; 397 | case SB_THUMBPOSITION: 398 | SetScrollPos(m_hWnd, SB_HORZ, pos, TRUE); 399 | break; 400 | case SB_LINELEFT: 401 | SetScrollPos(m_hWnd, SB_HORZ, GetScrollPos(m_hWnd, SB_HORZ) - 1, TRUE); 402 | drawBitmap(); 403 | break; 404 | case SB_LINERIGHT: 405 | SetScrollPos(m_hWnd, SB_HORZ, GetScrollPos(m_hWnd, SB_HORZ) + 1, TRUE); 406 | drawBitmap(); 407 | break; 408 | default: 409 | break; 410 | } 411 | return 0; 412 | } 413 | case WM_VSCROLL: { 414 | int pos = HIWORD(wParam); 415 | switch (LOWORD(wParam)) { 416 | case SB_THUMBTRACK: 417 | drawBitmap(-1, pos); 418 | break; 419 | case SB_THUMBPOSITION: 420 | SetScrollPos(m_hWnd, SB_VERT, pos, TRUE); 421 | break; 422 | case SB_LINEDOWN: 423 | SetScrollPos(m_hWnd, SB_VERT, GetScrollPos(m_hWnd, SB_VERT) + 1, TRUE); 424 | drawBitmap(); 425 | break; 426 | case SB_LINEUP: 427 | SetScrollPos(m_hWnd, SB_VERT, GetScrollPos(m_hWnd, SB_VERT) - 1, TRUE); 428 | drawBitmap(); 429 | break; 430 | default: 431 | break; 432 | } 433 | return 0; 434 | } 435 | case WM_GETMINMAXINFO: { 436 | RECT rc; 437 | rc.left = rc.top = 0; 438 | rc.right = m_bmpInfo.bmiHeader.biWidth; 439 | rc.bottom = m_bmpInfo.bmiHeader.biHeight; 440 | AdjustWindowRect(&rc, GetWindowLongPtr(m_hWnd, GWL_STYLE), FALSE); 441 | int cxVertScroll = GetSystemMetrics(SM_CXVSCROLL); 442 | int cyHorzScroll = GetSystemMetrics(SM_CYHSCROLL); 443 | auto mmi = (LPMINMAXINFO)lParam; 444 | mmi->ptMaxTrackSize = { rc.right - rc.left + cxVertScroll,rc.bottom - rc.top + cyHorzScroll }; 445 | return 0; 446 | } 447 | case WM_SIZE: { 448 | if (wParam == SIZE_RESTORED) { 449 | updateScrollBarStatus(); 450 | drawBitmap(); 451 | return 0; 452 | } 453 | break; 454 | } 455 | case WM_NCDESTROY: 456 | th_ocvmBmpWndList.remove(m_hWnd); 457 | if (th_ocvmBmpWndList.size() == 0) { // request to stop the message loop in waitKey() 458 | // when all windows owned by current thread have been closed 459 | PostQuitMessage(0); 460 | } 461 | SimpleWindow::windowProc(msg, wParam, lParam); 462 | delete this; 463 | return 0; 464 | default: 465 | break; 466 | } 467 | 468 | return SimpleWindow::windowProc(msg, wParam, lParam); 469 | } 470 | -------------------------------------------------------------------------------- /highgui/src/display_win32.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 szx0427&futz12 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | class SimpleWindow 22 | { 23 | protected: 24 | HWND m_hWnd; 25 | virtual LRESULT windowProc(UINT msg, WPARAM wParam, LPARAM lParam); 26 | 27 | public: 28 | friend LRESULT CALLBACK __globalWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 29 | 30 | static double getDesktopDpiFactor(); 31 | 32 | // NOTE: a SimpleWindow1 object which is already attached to an HWND should NOT be copied; use pointers instead 33 | SimpleWindow(const SimpleWindow&) = delete; 34 | SimpleWindow& operator=(const SimpleWindow&) = delete; 35 | 36 | SimpleWindow(); 37 | SimpleWindow(SimpleWindow&& right) noexcept; 38 | SimpleWindow& operator=(SimpleWindow&& right) noexcept; 39 | 40 | HWND getHwnd() const; 41 | bool create( 42 | LPCSTR lpWindowName, 43 | DWORD dwStyle, 44 | int X = CW_USEDEFAULT, 45 | int Y = CW_USEDEFAULT, 46 | int nWidth = CW_USEDEFAULT, 47 | int nHeight = CW_USEDEFAULT, 48 | HWND hWndParent = nullptr, 49 | DWORD dwExStyle = 0, 50 | HMENU hMenu = nullptr, 51 | LPVOID lpParam = nullptr 52 | ); 53 | void centerWindow() const; 54 | 55 | void show(int nCmdShow); 56 | 57 | #if 0 58 | // starts message loop ; blocks the thread calling this 59 | // NOT ACTUALLY USED TILL NOW 60 | int messageLoop(); 61 | #endif 62 | 63 | void detach(); 64 | virtual ~SimpleWindow(); 65 | }; 66 | 67 | // 防止那些你用不到的基类函数干扰你,我直接以protected方式继承 68 | class BitmapWindow : protected SimpleWindow 69 | { 70 | protected: 71 | BYTE* m_bits; 72 | BITMAPINFO m_bmpInfo; 73 | int m_xSrc, m_ySrc; 74 | // doubled-buffered painting 75 | // NOTE: this is useful in some cases; don't delete these code 76 | HDC m_hMemDC; 77 | HBITMAP m_hMemBitmap; 78 | HGDIOBJ m_hOldBitmap; 79 | 80 | static constexpr int waitKeyTimerId = 150; 81 | static constexpr int WM_WAITKEYTIMEOUT = WM_USER + 150; 82 | 83 | // only finds identical-named windows in current process 84 | static BitmapWindow* findOCVMWindowByName(LPCSTR windowName); 85 | void drawBitmap(int horz = -1, int vert = -1); 86 | virtual LRESULT windowProc(UINT msg, WPARAM wParam, LPARAM lParam) override; 87 | void updateBitmapData(const BYTE* bmpFileData); 88 | void updateScrollBarStatus(); 89 | 90 | public: 91 | using SimpleWindow::SimpleWindow; 92 | BitmapWindow(); 93 | virtual ~BitmapWindow(); 94 | using SimpleWindow::getHwnd; 95 | 96 | static void show(LPCSTR windowName, const BYTE* bmpFileData); 97 | // NOTE: only manages the windows created by current thread 98 | static int waitKey(UINT delay = 0); 99 | }; 100 | -------------------------------------------------------------------------------- /highgui/src/exif.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | 44 | #ifndef _OPENCV_EXIF_HPP_ 45 | #define _OPENCV_EXIF_HPP_ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | namespace cv 57 | { 58 | /** 59 | * @brief Jpeg markers that can encounter in Jpeg file 60 | */ 61 | enum AppMarkerTypes 62 | { 63 | SOI = 0xD8, SOF0 = 0xC0, SOF2 = 0xC2, DHT = 0xC4, 64 | DQT = 0xDB, DRI = 0xDD, SOS = 0xDA, 65 | 66 | RST0 = 0xD0, RST1 = 0xD1, RST2 = 0xD2, RST3 = 0xD3, 67 | RST4 = 0xD4, RST5 = 0xD5, RST6 = 0xD6, RST7 = 0xD7, 68 | 69 | APP0 = 0xE0, APP1 = 0xE1, APP2 = 0xE2, APP3 = 0xE3, 70 | APP4 = 0xE4, APP5 = 0xE5, APP6 = 0xE6, APP7 = 0xE7, 71 | APP8 = 0xE8, APP9 = 0xE9, APP10 = 0xEA, APP11 = 0xEB, 72 | APP12 = 0xEC, APP13 = 0xED, APP14 = 0xEE, APP15 = 0xEF, 73 | 74 | COM = 0xFE, EOI = 0xD9 75 | }; 76 | 77 | /** 78 | * @brief Base Exif tags used by IFD0 (main image) 79 | */ 80 | enum ExifTagName 81 | { 82 | IMAGE_DESCRIPTION = 0x010E, ///< Image Description: ASCII string 83 | MAKE = 0x010F, ///< Description of manufacturer: ASCII string 84 | MODEL = 0x0110, ///< Description of camera model: ASCII string 85 | ORIENTATION = 0x0112, ///< Orientation of the image: unsigned short 86 | XRESOLUTION = 0x011A, ///< Resolution of the image across X axis: unsigned rational 87 | YRESOLUTION = 0x011B, ///< Resolution of the image across Y axis: unsigned rational 88 | RESOLUTION_UNIT = 0x0128, ///< Resolution units. '1' no-unit, '2' inch, '3' centimeter 89 | SOFTWARE = 0x0131, ///< Shows firmware(internal software of digicam) version number 90 | DATE_TIME = 0x0132, ///< Date/Time of image was last modified 91 | WHITE_POINT = 0x013E, ///< Chromaticity of white point of the image 92 | PRIMARY_CHROMATICIES = 0x013F, ///< Chromaticity of the primaries of the image 93 | Y_CB_CR_COEFFICIENTS = 0x0211, ///< constant to translate an image from YCbCr to RGB format 94 | Y_CB_CR_POSITIONING = 0x0213, ///< Chroma sample point of subsampling pixel array 95 | REFERENCE_BLACK_WHITE = 0x0214, ///< Reference value of black point/white point 96 | COPYRIGHT = 0x8298, ///< Copyright information 97 | EXIF_OFFSET = 0x8769, ///< Offset to Exif Sub IFD 98 | INVALID_TAG = 0xFFFF ///< Shows that the tag was not recognized 99 | }; 100 | 101 | enum Endianess_t 102 | { 103 | INTEL = 0x49, 104 | MOTO = 0x4D, 105 | NONE = 0x00 106 | }; 107 | 108 | typedef std::pair u_rational_t; 109 | 110 | /** 111 | * @brief Entry which contains possible values for different exif tags 112 | */ 113 | struct ExifEntry_t 114 | { 115 | ExifEntry_t(); 116 | 117 | std::vector field_u_rational; ///< vector of rational fields 118 | std::string field_str; ///< any kind of textual information 119 | 120 | float field_float; ///< Currently is not used 121 | double field_double; ///< Currently is not used 122 | 123 | uint32_t field_u32; ///< Unsigned 32-bit value 124 | int32_t field_s32; ///< Signed 32-bit value 125 | 126 | uint16_t tag; ///< Tag number 127 | 128 | uint16_t field_u16; ///< Unsigned 16-bit value 129 | int16_t field_s16; ///< Signed 16-bit value 130 | uint8_t field_u8; ///< Unsigned 8-bit value 131 | int8_t field_s8; ///< Signed 8-bit value 132 | }; 133 | 134 | /** 135 | * @brief Picture orientation which may be taken from EXIF 136 | * Orientation usually matters when the picture is taken by 137 | * smartphone or other camera with orientation sensor support 138 | * Corresponds to EXIF 2.3 Specification 139 | */ 140 | enum ImageOrientation 141 | { 142 | IMAGE_ORIENTATION_TL = 1, ///< Horizontal (normal) 143 | IMAGE_ORIENTATION_TR = 2, ///< Mirrored horizontal 144 | IMAGE_ORIENTATION_BR = 3, ///< Rotate 180 145 | IMAGE_ORIENTATION_BL = 4, ///< Mirrored vertical 146 | IMAGE_ORIENTATION_LT = 5, ///< Mirrored horizontal & rotate 270 CW 147 | IMAGE_ORIENTATION_RT = 6, ///< Rotate 90 CW 148 | IMAGE_ORIENTATION_RB = 7, ///< Mirrored horizontal & rotate 90 CW 149 | IMAGE_ORIENTATION_LB = 8 ///< Rotate 270 CW 150 | }; 151 | 152 | /** 153 | * @brief Reading exif information from Jpeg file 154 | * 155 | * Usage example for getting the orientation of the image: 156 | * 157 | * @code 158 | * std::ifstream stream(filename,std::ios_base::in | std::ios_base::binary); 159 | * ExifReader reader(stream); 160 | * if( reader.parse() ) 161 | * { 162 | * int orientation = reader.getTag(Orientation).field_u16; 163 | * } 164 | * @endcode 165 | * 166 | */ 167 | class ExifReader 168 | { 169 | public: 170 | /** 171 | * @brief ExifReader constructor. Constructs an object of exif reader 172 | * 173 | * @param [in]stream An istream to look for EXIF bytes from 174 | */ 175 | explicit ExifReader( std::istream& stream ); 176 | ~ExifReader(); 177 | 178 | 179 | /** 180 | * @brief Parse the file with exif info 181 | * 182 | * @return true if parsing was successful and exif information exists in JpegReader object 183 | */ 184 | bool parse(); 185 | 186 | /** 187 | * @brief Get tag info by tag number 188 | * 189 | * @param [in] tag The tag number 190 | * @return ExifEntru_t structure. Caller has to know what tag it calls in order to extract proper field from the structure ExifEntry_t 191 | */ 192 | ExifEntry_t getTag( const ExifTagName tag ); 193 | 194 | private: 195 | std::istream& m_stream; 196 | std::vector m_data; 197 | std::map m_exif; 198 | Endianess_t m_format; 199 | 200 | void parseExif(); 201 | bool checkTagMark() const; 202 | 203 | size_t getFieldSize (); 204 | size_t getNumDirEntry( const size_t offsetNumDir ) const; 205 | uint32_t getStartOffset() const; 206 | uint16_t getExifTag( const size_t offset ) const; 207 | uint16_t getU16( const size_t offset ) const; 208 | uint32_t getU32( const size_t offset ) const; 209 | uint16_t getOrientation( const size_t offset ) const; 210 | uint16_t getResolutionUnit( const size_t offset ) const; 211 | uint16_t getYCbCrPos( const size_t offset ) const; 212 | 213 | Endianess_t getFormat() const; 214 | 215 | ExifEntry_t parseExifEntry( const size_t offset ); 216 | 217 | u_rational_t getURational( const size_t offset ) const; 218 | 219 | std::map getExif(); 220 | std::string getString( const size_t offset ) const; 221 | std::vector getResolution( const size_t offset ) const; 222 | std::vector getWhitePoint( const size_t offset ) const; 223 | std::vector getPrimaryChromaticies( const size_t offset ) const; 224 | std::vector getYCbCrCoeffs( const size_t offset ) const; 225 | std::vector getRefBW( const size_t offset ) const; 226 | 227 | private: 228 | static const uint16_t tagMarkRequired = 0x2A; 229 | 230 | //max size of data in tag. 231 | //'DDDDDDDD' contains the value of that Tag. If its size is over 4bytes, 232 | //'DDDDDDDD' contains the offset to data stored address. 233 | static const size_t maxDataSize = 4; 234 | 235 | //bytes per tag field 236 | static const size_t tiffFieldSize = 12; 237 | 238 | //number of primary chromaticies components 239 | static const size_t primaryChromaticiesComponents = 6; 240 | 241 | //number of YCbCr coefficients in field 242 | static const size_t ycbcrCoeffs = 3; 243 | 244 | //number of Reference Black&White components 245 | static const size_t refBWComponents = 6; 246 | }; 247 | 248 | 249 | } 250 | 251 | #endif /* _OPENCV_EXIF_HPP_ */ 252 | -------------------------------------------------------------------------------- /highgui/src/jpeg_decoder_aw.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_DECODER_AW_H 18 | #define JPEG_DECODER_AW_H 19 | 20 | namespace cv { 21 | 22 | class jpeg_decoder_aw_impl; 23 | class jpeg_decoder_aw 24 | { 25 | public: 26 | static bool supported(const unsigned char* jpgdata, int jpgsize); 27 | 28 | jpeg_decoder_aw(); 29 | ~jpeg_decoder_aw(); 30 | 31 | int init(const unsigned char* jpgdata, int jpgsize, int* width, int* height, int* ch); 32 | 33 | int decode(const unsigned char* jpgdata, int jpgsize, unsigned char* outbgr) const; 34 | 35 | int deinit(); 36 | 37 | private: 38 | jpeg_decoder_aw_impl* const d; 39 | }; 40 | 41 | } // namespace cv 42 | 43 | #endif // JPEG_DECODER_AW_H 44 | -------------------------------------------------------------------------------- /highgui/src/jpeg_decoder_cvi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2023 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_DECODER_CVI_H 18 | #define JPEG_DECODER_CVI_H 19 | 20 | namespace cv { 21 | 22 | class jpeg_decoder_cvi_impl; 23 | class jpeg_decoder_cvi 24 | { 25 | public: 26 | static bool supported(const unsigned char* jpgdata, int jpgsize); 27 | 28 | jpeg_decoder_cvi(); 29 | ~jpeg_decoder_cvi(); 30 | 31 | int init(const unsigned char* jpgdata, int jpgsize, int* width, int* height, int* ch); 32 | 33 | int decode(const unsigned char* jpgdata, int jpgsize, unsigned char* outbgr) const; 34 | 35 | int deinit(); 36 | 37 | private: 38 | jpeg_decoder_cvi_impl* const d; 39 | }; 40 | 41 | } // namespace cv 42 | 43 | #endif // JPEG_DECODER_CVI_H 44 | -------------------------------------------------------------------------------- /highgui/src/jpeg_encoder_aw.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_ENCODER_AW_H 18 | #define JPEG_ENCODER_AW_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class jpeg_encoder_aw_impl; 25 | class jpeg_encoder_aw 26 | { 27 | public: 28 | static bool supported(int width, int height, int ch); 29 | 30 | jpeg_encoder_aw(); 31 | ~jpeg_encoder_aw(); 32 | 33 | int init(int width, int height, int ch, int quality); 34 | 35 | int encode(const unsigned char* bgrdata, std::vector& outdata) const; 36 | 37 | int encode(const unsigned char* bgrdata, const char* outfilepath) const; 38 | 39 | int deinit(); 40 | 41 | private: 42 | jpeg_encoder_aw_impl* const d; 43 | }; 44 | 45 | } // namespace cv 46 | 47 | #endif // JPEG_ENCODER_AW_H 48 | -------------------------------------------------------------------------------- /highgui/src/jpeg_encoder_rk_mpp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2023 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_ENCODER_RK_MPP_H 18 | #define JPEG_ENCODER_RK_MPP_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class jpeg_encoder_rk_mpp_impl; 25 | class jpeg_encoder_rk_mpp 26 | { 27 | public: 28 | static bool supported(int width, int height, int ch); 29 | 30 | jpeg_encoder_rk_mpp(); 31 | ~jpeg_encoder_rk_mpp(); 32 | 33 | int init(int width, int height, int ch, int quality); 34 | 35 | int encode(const unsigned char* bgrdata, std::vector& outdata) const; 36 | 37 | int encode(const unsigned char* bgrdata, const char* outfilepath) const; 38 | 39 | int deinit(); 40 | 41 | private: 42 | jpeg_encoder_rk_mpp_impl* const d; 43 | }; 44 | 45 | } // namespace cv 46 | 47 | #endif // JPEG_ENCODER_RK_MPP_H 48 | -------------------------------------------------------------------------------- /highgui/src/jpeg_encoder_v4l_cix.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2025 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_ENCODER_V4L_CIX_H 18 | #define JPEG_ENCODER_V4L_CIX_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class jpeg_encoder_v4l_cix_impl; 25 | class jpeg_encoder_v4l_cix 26 | { 27 | public: 28 | static bool supported(int width, int height, int ch); 29 | 30 | jpeg_encoder_v4l_cix(); 31 | ~jpeg_encoder_v4l_cix(); 32 | 33 | int init(int width, int height, int ch, int quality); 34 | 35 | int encode(const unsigned char* bgrdata, std::vector& outdata) const; 36 | 37 | int encode(const unsigned char* bgrdata, const char* outfilepath) const; 38 | 39 | int deinit(); 40 | 41 | private: 42 | jpeg_encoder_v4l_cix_impl* const d; 43 | }; 44 | 45 | } // namespace cv 46 | 47 | #endif // JPEG_ENCODER_V4L_CIX_H 48 | -------------------------------------------------------------------------------- /highgui/src/jpeg_encoder_v4l_rpi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2025 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef JPEG_ENCODER_V4L_RPI_H 18 | #define JPEG_ENCODER_V4L_RPI_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class jpeg_encoder_v4l_rpi_impl; 25 | class jpeg_encoder_v4l_rpi 26 | { 27 | public: 28 | static bool supported(int width, int height, int ch); 29 | 30 | jpeg_encoder_v4l_rpi(); 31 | ~jpeg_encoder_v4l_rpi(); 32 | 33 | int init(int width, int height, int ch, int quality); 34 | 35 | int encode(const unsigned char* bgrdata, std::vector& outdata) const; 36 | 37 | int encode(const unsigned char* bgrdata, const char* outfilepath) const; 38 | 39 | int deinit(); 40 | 41 | private: 42 | jpeg_encoder_v4l_rpi_impl* const d; 43 | }; 44 | 45 | } // namespace cv 46 | 47 | #endif // JPEG_ENCODER_V4L_RPI_H 48 | -------------------------------------------------------------------------------- /highgui/src/kanna_rotate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef KANNA_ROTATE_H 18 | #define KANNA_ROTATE_H 19 | 20 | namespace cv { 21 | 22 | void kanna_rotate_c1(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type); 23 | 24 | void kanna_rotate_c2(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type); 25 | 26 | void kanna_rotate_c3(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type); 27 | 28 | void kanna_rotate_c4(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type); 29 | 30 | void kanna_rotate_c1(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type); 31 | 32 | void kanna_rotate_c2(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type); 33 | 34 | void kanna_rotate_c3(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type); 35 | 36 | void kanna_rotate_c4(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type); 37 | 38 | } // namespace cv 39 | 40 | #endif // KANNA_ROTATE_H 41 | -------------------------------------------------------------------------------- /highgui/src/nms.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace cv { 25 | namespace dnn { 26 | 27 | static inline bool SortScorePairDescend(const std::pair& pair1, const std::pair& pair2) 28 | { 29 | return pair1.first > pair2.first; 30 | } 31 | 32 | // Get max scores with corresponding indices. 33 | // scores: a set of scores. 34 | // threshold: only consider scores higher than the threshold. 35 | // top_k: if -1, keep all; otherwise, keep at most top_k. 36 | // score_index_vec: store the sorted (score, index) pair. 37 | inline void GetMaxScoreIndex(const std::vector& scores, const float threshold, const int top_k, 38 | std::vector >& score_index_vec) 39 | { 40 | // Generate index score pairs. 41 | for (size_t i = 0; i < scores.size(); ++i) 42 | { 43 | if (scores[i] > threshold) 44 | { 45 | score_index_vec.push_back(std::make_pair(scores[i], i)); 46 | } 47 | } 48 | 49 | // Sort the score pair according to the scores in descending order 50 | std::stable_sort(score_index_vec.begin(), score_index_vec.end(), SortScorePairDescend); 51 | 52 | // Keep top_k scores if needed. 53 | if (top_k > 0 && top_k < (int)score_index_vec.size()) 54 | { 55 | score_index_vec.resize(top_k); 56 | } 57 | } 58 | 59 | // Do non maximum suppression given bboxes and scores. 60 | // Inspired by Piotr Dollar's NMS implementation in EdgeBox. 61 | // https://goo.gl/jV3JYS 62 | // bboxes: a set of bounding boxes. 63 | // scores: a set of corresponding confidences. 64 | // score_threshold: a threshold used to filter detection results. 65 | // nms_threshold: a threshold used in non maximum suppression. 66 | // top_k: if not > 0, keep at most top_k picked indices. 67 | // limit: early terminate once the # of picked indices has reached it. 68 | // indices: the kept indices of bboxes after nms. 69 | template 70 | inline void NMSFast_(const std::vector& bboxes, 71 | const std::vector& scores, const float score_threshold, 72 | const float nms_threshold, const float eta, const int top_k, 73 | std::vector& indices, 74 | float (*computeOverlap)(const BoxType&, const BoxType&), 75 | int limit = std::numeric_limits::max()) 76 | { 77 | // Get top_k scores (with corresponding indices). 78 | std::vector > score_index_vec; 79 | GetMaxScoreIndex(scores, score_threshold, top_k, score_index_vec); 80 | 81 | // Do nms. 82 | float adaptive_threshold = nms_threshold; 83 | indices.clear(); 84 | for (size_t i = 0; i < score_index_vec.size(); ++i) 85 | { 86 | const int idx = score_index_vec[i].second; 87 | bool keep = true; 88 | for (int k = 0; k < (int)indices.size() && keep; ++k) 89 | { 90 | const int kept_idx = indices[k]; 91 | float overlap = computeOverlap(bboxes[idx], bboxes[kept_idx]); 92 | keep = overlap <= adaptive_threshold; 93 | } 94 | if (keep) 95 | { 96 | indices.push_back(idx); 97 | if ((int)indices.size() >= limit) { 98 | break; 99 | } 100 | } 101 | if (keep && eta < 1 && adaptive_threshold > 0.5) { 102 | adaptive_threshold *= eta; 103 | } 104 | } 105 | } 106 | 107 | static inline float rectOverlap(const Rect& a, const Rect& b) 108 | { 109 | int Aa = a.area(); 110 | int Ab = b.area(); 111 | 112 | if (Aa + Ab == 0) 113 | return 0.f; 114 | 115 | int intersect = (a & b).area(); 116 | 117 | return (float)intersect / (Aa + Ab - intersect); 118 | } 119 | 120 | void NMSBoxes(const std::vector& bboxes, const std::vector& scores, 121 | const float score_threshold, const float nms_threshold, 122 | std::vector& indices, const float eta, const int top_k) 123 | { 124 | NMSFast_(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap); 125 | } 126 | 127 | static inline void NMSBoxesBatchedImpl(const std::vector& bboxes, 128 | const std::vector& scores, const std::vector& class_ids, 129 | const float score_threshold, const float nms_threshold, 130 | std::vector& indices, const float eta, const int top_k) 131 | { 132 | int x1, y1, x2, y2, max_coord = 0; 133 | for (size_t i = 0; i < bboxes.size(); i++) 134 | { 135 | x1 = bboxes[i].x; 136 | y1 = bboxes[i].y; 137 | x2 = x1 + bboxes[i].width; 138 | y2 = y1 + bboxes[i].height; 139 | 140 | max_coord = std::max(x1, max_coord); 141 | max_coord = std::max(y1, max_coord); 142 | max_coord = std::max(x2, max_coord); 143 | max_coord = std::max(y2, max_coord); 144 | } 145 | 146 | // calculate offset and add offset to each bbox 147 | std::vector bboxes_offset; 148 | for (size_t i = 0; i < bboxes.size(); i++) 149 | { 150 | int offset = class_ids[i] * (max_coord + 1); 151 | bboxes_offset.push_back(Rect(bboxes[i].x + offset, bboxes[i].y + offset, bboxes[i].width, bboxes[i].height)); 152 | } 153 | 154 | NMSFast_(bboxes_offset, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap); 155 | } 156 | 157 | void NMSBoxesBatched(const std::vector& bboxes, 158 | const std::vector& scores, const std::vector& class_ids, 159 | const float score_threshold, const float nms_threshold, 160 | std::vector& indices, const float eta, const int top_k) 161 | { 162 | NMSBoxesBatchedImpl(bboxes, scores, class_ids, score_threshold, nms_threshold, indices, eta, top_k); 163 | } 164 | 165 | static inline bool score_cmp(const std::pair& a, const std::pair& b) 166 | { 167 | return a.first == b.first ? a.second > b.second : a.first < b.first; 168 | } 169 | 170 | void softNMSBoxes(const std::vector& bboxes, 171 | const std::vector& scores, 172 | std::vector& updated_scores, 173 | const float score_threshold, 174 | const float nms_threshold, 175 | std::vector& indices, 176 | size_t top_k, 177 | const float sigma, 178 | SoftNMSMethod method) 179 | { 180 | indices.clear(); 181 | updated_scores.clear(); 182 | 183 | std::vector > score_index_vec(scores.size()); 184 | for (size_t i = 0; i < scores.size(); i++) 185 | { 186 | score_index_vec[i].first = scores[i]; 187 | score_index_vec[i].second = i; 188 | } 189 | 190 | top_k = top_k == 0 ? scores.size() : std::min(top_k, scores.size()); 191 | ptrdiff_t start = 0; 192 | while (indices.size() < top_k) 193 | { 194 | auto it = std::max_element(score_index_vec.begin() + start, score_index_vec.end(), score_cmp); 195 | 196 | float bscore = it->first; 197 | size_t bidx = it->second; 198 | 199 | if (bscore < score_threshold) 200 | { 201 | break; 202 | } 203 | 204 | indices.push_back(static_cast(bidx)); 205 | updated_scores.push_back(bscore); 206 | std::swap(score_index_vec[start], *it); // first start elements are chosen 207 | 208 | for (size_t i = start + 1; i < scores.size(); ++i) 209 | { 210 | float& bscore_i = score_index_vec[i].first; 211 | const size_t bidx_i = score_index_vec[i].second; 212 | 213 | if (bscore_i < score_threshold) 214 | { 215 | continue; 216 | } 217 | 218 | float overlap = rectOverlap(bboxes[bidx], bboxes[bidx_i]); 219 | 220 | if (method == SOFTNMS_LINEAR) 221 | { 222 | if (overlap > nms_threshold) 223 | { 224 | bscore_i *= 1.f - overlap; 225 | } 226 | } 227 | else // if (method == SOFTNMS_GAUSSIAN) 228 | { 229 | bscore_i *= exp(-(overlap * overlap) / sigma); 230 | } 231 | } 232 | ++start; 233 | } 234 | } 235 | 236 | } // namespace dnn 237 | } // namespace cv 238 | -------------------------------------------------------------------------------- /highgui/src/videocapture.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2023 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #if CV_WITH_CVI 24 | #include "capture_cvi.h" 25 | #endif 26 | #if CV_WITH_AW 27 | #include "capture_v4l2_aw_isp.h" 28 | #endif 29 | #if CV_WITH_RK 30 | #include "capture_v4l2_rk_aiq.h" 31 | #endif 32 | #if defined __linux__ 33 | #include "capture_v4l2.h" 34 | #endif 35 | 36 | namespace cv { 37 | 38 | class VideoCaptureImpl 39 | { 40 | public: 41 | VideoCaptureImpl(); 42 | 43 | public: 44 | bool is_opened; 45 | int width; 46 | int height; 47 | float fps; 48 | 49 | #if CV_WITH_AW 50 | capture_v4l2_aw_isp cap_v4l2_aw_isp; 51 | #endif 52 | #if CV_WITH_RK 53 | capture_v4l2_rk_aiq cap_v4l2_rk_aiq; 54 | #endif 55 | #if CV_WITH_CVI 56 | capture_cvi cap_cvi; 57 | #endif 58 | #if defined __linux__ 59 | capture_v4l2 cap_v4l2; 60 | #endif 61 | }; 62 | 63 | VideoCaptureImpl::VideoCaptureImpl() 64 | { 65 | is_opened = false; 66 | width = 640; 67 | height = 480; 68 | fps = 30; 69 | } 70 | 71 | VideoCapture::VideoCapture() : d(new VideoCaptureImpl) 72 | { 73 | } 74 | 75 | VideoCapture::~VideoCapture() 76 | { 77 | release(); 78 | 79 | delete d; 80 | } 81 | 82 | bool VideoCapture::open(int index) 83 | { 84 | if (d->is_opened) 85 | { 86 | release(); 87 | } 88 | 89 | #if CV_WITH_AW 90 | if (capture_v4l2_aw_isp::supported()) 91 | { 92 | int ret = d->cap_v4l2_aw_isp.open(d->width, d->height, d->fps); 93 | if (ret == 0) 94 | { 95 | d->width = d->cap_v4l2_aw_isp.get_width(); 96 | d->height = d->cap_v4l2_aw_isp.get_height(); 97 | d->fps = d->cap_v4l2_aw_isp.get_fps(); 98 | 99 | ret = d->cap_v4l2_aw_isp.start_streaming(); 100 | if (ret == 0) 101 | { 102 | d->is_opened = true; 103 | } 104 | else 105 | { 106 | d->cap_v4l2_aw_isp.close(); 107 | } 108 | } 109 | } 110 | else 111 | #endif 112 | #if CV_WITH_RK 113 | if (capture_v4l2_rk_aiq::supported()) 114 | { 115 | int ret = d->cap_v4l2_rk_aiq.open(d->width, d->height, d->fps); 116 | if (ret == 0) 117 | { 118 | d->width = d->cap_v4l2_rk_aiq.get_width(); 119 | d->height = d->cap_v4l2_rk_aiq.get_height(); 120 | d->fps = d->cap_v4l2_rk_aiq.get_fps(); 121 | 122 | ret = d->cap_v4l2_rk_aiq.start_streaming(); 123 | if (ret == 0) 124 | { 125 | d->is_opened = true; 126 | } 127 | else 128 | { 129 | d->cap_v4l2_rk_aiq.close(); 130 | } 131 | } 132 | } 133 | else 134 | #endif 135 | #if CV_WITH_CVI 136 | if (capture_cvi::supported()) 137 | { 138 | int ret = d->cap_cvi.open(d->width, d->height, d->fps); 139 | if (ret == 0) 140 | { 141 | d->width = d->cap_cvi.get_width(); 142 | d->height = d->cap_cvi.get_height(); 143 | d->fps = d->cap_cvi.get_fps(); 144 | 145 | ret = d->cap_cvi.start_streaming(); 146 | if (ret == 0) 147 | { 148 | d->is_opened = true; 149 | } 150 | else 151 | { 152 | d->cap_cvi.close(); 153 | } 154 | } 155 | } 156 | else 157 | #endif 158 | #if defined __linux__ 159 | if (capture_v4l2::supported()) 160 | { 161 | int ret = d->cap_v4l2.open(index, d->width, d->height, d->fps); 162 | if (ret == 0) 163 | { 164 | d->width = d->cap_v4l2.get_width(); 165 | d->height = d->cap_v4l2.get_height(); 166 | d->fps = d->cap_v4l2.get_fps(); 167 | 168 | ret = d->cap_v4l2.start_streaming(); 169 | if (ret == 0) 170 | { 171 | d->is_opened = true; 172 | } 173 | else 174 | { 175 | d->cap_v4l2.close(); 176 | } 177 | } 178 | } 179 | else 180 | #endif 181 | { 182 | } 183 | 184 | return d->is_opened; 185 | } 186 | 187 | bool VideoCapture::isOpened() const 188 | { 189 | return d->is_opened; 190 | } 191 | 192 | void VideoCapture::release() 193 | { 194 | if (!d->is_opened) 195 | return; 196 | 197 | #if CV_WITH_AW 198 | if (capture_v4l2_aw_isp::supported()) 199 | { 200 | d->cap_v4l2_aw_isp.stop_streaming(); 201 | 202 | d->cap_v4l2_aw_isp.close(); 203 | } 204 | else 205 | #endif 206 | #if CV_WITH_RK 207 | if (capture_v4l2_rk_aiq::supported()) 208 | { 209 | d->cap_v4l2_rk_aiq.stop_streaming(); 210 | 211 | d->cap_v4l2_rk_aiq.close(); 212 | } 213 | else 214 | #endif 215 | #if CV_WITH_CVI 216 | if (capture_cvi::supported()) 217 | { 218 | d->cap_cvi.stop_streaming(); 219 | 220 | d->cap_cvi.close(); 221 | } 222 | else 223 | #endif 224 | #if defined __linux__ 225 | if (capture_v4l2::supported()) 226 | { 227 | d->cap_v4l2.stop_streaming(); 228 | 229 | d->cap_v4l2.close(); 230 | } 231 | else 232 | #endif 233 | { 234 | } 235 | 236 | d->is_opened = false; 237 | d->width = 640; 238 | d->height = 480; 239 | d->fps = 30; 240 | } 241 | 242 | VideoCapture& VideoCapture::operator>>(Mat& image) 243 | { 244 | if (!d->is_opened) 245 | return *this; 246 | 247 | #if CV_WITH_AW 248 | if (capture_v4l2_aw_isp::supported()) 249 | { 250 | image.create(d->height, d->width, CV_8UC3); 251 | 252 | d->cap_v4l2_aw_isp.read_frame((unsigned char*)image.data); 253 | } 254 | else 255 | #endif 256 | #if CV_WITH_RK 257 | if (capture_v4l2_rk_aiq::supported()) 258 | { 259 | image.create(d->height, d->width, CV_8UC3); 260 | 261 | d->cap_v4l2_rk_aiq.read_frame((unsigned char*)image.data); 262 | } 263 | else 264 | #endif 265 | #if CV_WITH_CVI 266 | if (capture_cvi::supported()) 267 | { 268 | image.create(d->height, d->width, CV_8UC3); 269 | 270 | d->cap_cvi.read_frame((unsigned char*)image.data); 271 | } 272 | else 273 | #endif 274 | #if defined __linux__ 275 | if (capture_v4l2::supported()) 276 | { 277 | image.create(d->height, d->width, CV_8UC3); 278 | 279 | d->cap_v4l2.read_frame((unsigned char*)image.data); 280 | } 281 | else 282 | #endif 283 | { 284 | } 285 | 286 | return *this; 287 | } 288 | 289 | bool VideoCapture::set(int propId, double value) 290 | { 291 | if (propId == CAP_PROP_FRAME_WIDTH) 292 | { 293 | d->width = (int)value; 294 | return true; 295 | } 296 | 297 | if (propId == CAP_PROP_FRAME_HEIGHT) 298 | { 299 | d->height = (int)value; 300 | return true; 301 | } 302 | 303 | if (propId == CAP_PROP_FPS) 304 | { 305 | d->fps = (float)value; 306 | return true; 307 | } 308 | 309 | fprintf(stderr, "ignore unsupported cv cap propId %d = %f\n", propId, value); 310 | return true; 311 | } 312 | 313 | double VideoCapture::get(int propId) const 314 | { 315 | if (propId == CAP_PROP_FRAME_WIDTH) 316 | { 317 | return (double)d->width; 318 | } 319 | 320 | if (propId == CAP_PROP_FRAME_HEIGHT) 321 | { 322 | return (double)d->height; 323 | } 324 | 325 | if (propId == CAP_PROP_FPS) 326 | { 327 | return (double)d->fps; 328 | } 329 | 330 | fprintf(stderr, "ignore unsupported cv cap propId %d\n", propId); 331 | return 0.0; 332 | } 333 | 334 | } // namespace cv 335 | -------------------------------------------------------------------------------- /highgui/src/videowriter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #if defined __linux__ && !__ANDROID__ 24 | #include "writer_http.h" 25 | #endif 26 | 27 | namespace cv { 28 | 29 | class VideoWriterImpl 30 | { 31 | public: 32 | VideoWriterImpl(); 33 | 34 | public: 35 | bool is_opened; 36 | int width; 37 | int height; 38 | float fps; 39 | 40 | #if defined __linux__ && !__ANDROID__ 41 | writer_http wt_http; 42 | #endif 43 | }; 44 | 45 | VideoWriterImpl::VideoWriterImpl() 46 | { 47 | is_opened = false; 48 | width = 0; 49 | height = 0; 50 | fps = 0; 51 | } 52 | 53 | VideoWriter::VideoWriter() : d(new VideoWriterImpl) 54 | { 55 | } 56 | 57 | VideoWriter::~VideoWriter() 58 | { 59 | release(); 60 | 61 | delete d; 62 | } 63 | 64 | bool VideoWriter::open(const String& name, int port) 65 | { 66 | if (d->is_opened) 67 | { 68 | release(); 69 | } 70 | 71 | if (name == "httpjpg") 72 | { 73 | #if defined __linux__ && !__ANDROID__ 74 | if (writer_http::supported()) 75 | { 76 | int ret = d->wt_http.open(port); 77 | if (ret == 0) 78 | { 79 | d->is_opened = true; 80 | } 81 | } 82 | else 83 | #endif 84 | { 85 | } 86 | } 87 | 88 | return d->is_opened; 89 | } 90 | 91 | bool VideoWriter::isOpened() const 92 | { 93 | return d->is_opened; 94 | } 95 | 96 | void VideoWriter::release() 97 | { 98 | if (!d->is_opened) 99 | return; 100 | 101 | #if defined __linux__ && !__ANDROID__ 102 | if (writer_http::supported()) 103 | { 104 | d->wt_http.close(); 105 | } 106 | else 107 | #endif 108 | { 109 | } 110 | 111 | d->is_opened = false; 112 | d->width = 0; 113 | d->height = 0; 114 | d->fps = 0; 115 | } 116 | 117 | VideoWriter& VideoWriter::operator<<(const Mat& image) 118 | { 119 | write(image); 120 | 121 | return *this; 122 | } 123 | 124 | void VideoWriter::write(const Mat& image) 125 | { 126 | if (!d->is_opened) 127 | return; 128 | 129 | #if defined __linux__ && !__ANDROID__ 130 | if (writer_http::supported()) 131 | { 132 | // encode jpg 133 | std::vector buf; 134 | cv::imencode(".JPG", image, buf); 135 | 136 | d->wt_http.write_jpgbuf(buf); 137 | } 138 | else 139 | #endif 140 | { 141 | } 142 | } 143 | 144 | } // namespace cv 145 | -------------------------------------------------------------------------------- /highgui/src/writer_http.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #include "writer_http.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | namespace cv { 35 | 36 | class writer_http_client 37 | { 38 | public: 39 | writer_http_client(int _cfd) : cfd(_cfd) {} 40 | 41 | int cfd; 42 | 43 | public: 44 | bool valid() 45 | { 46 | return cfd >= 0; 47 | } 48 | 49 | void close() 50 | { 51 | ::close(cfd); 52 | cfd = -1; 53 | } 54 | 55 | void wait_for_recv() 56 | { 57 | if (cfd == -1) 58 | return; 59 | 60 | fd_set rfds; 61 | FD_ZERO(&rfds); 62 | FD_SET(cfd, &rfds); 63 | 64 | struct timeval tv; 65 | tv.tv_sec = 5; 66 | tv.tv_usec = 0; 67 | 68 | int ret = select(cfd + 1, &rfds, 0, 0, &tv); 69 | if (ret <= 0) 70 | { 71 | // timeout or error 72 | close(); 73 | } 74 | } 75 | 76 | void wait_for_send() 77 | { 78 | if (cfd == -1) 79 | return; 80 | 81 | fd_set wfds; 82 | FD_ZERO(&wfds); 83 | FD_SET(cfd, &wfds); 84 | 85 | struct timeval tv; 86 | tv.tv_sec = 5; 87 | tv.tv_usec = 0; 88 | 89 | int ret = select(cfd + 1, 0, &wfds, 0, &tv); 90 | if (ret <= 0) 91 | { 92 | // timeout or error 93 | close(); 94 | } 95 | } 96 | 97 | void recv(char* buf, size_t len) 98 | { 99 | wait_for_recv(); 100 | 101 | if (cfd == -1) 102 | return; 103 | 104 | ssize_t nrecv = ::recv(cfd, buf, len, 0); 105 | if (nrecv == -1) 106 | { 107 | buf[0] = '\0'; 108 | // recv break 109 | close(); 110 | } 111 | else 112 | { 113 | buf[nrecv] = '\0'; 114 | } 115 | } 116 | 117 | void send(const char* buf, size_t len) 118 | { 119 | wait_for_send(); 120 | 121 | if (cfd == -1) 122 | return; 123 | 124 | ssize_t nsend = ::send(cfd, buf, len, MSG_NOSIGNAL); 125 | if (nsend != len) 126 | { 127 | // send break 128 | close(); 129 | } 130 | } 131 | }; 132 | 133 | class writer_http_impl 134 | { 135 | public: 136 | writer_http_impl(); 137 | ~writer_http_impl(); 138 | 139 | int open(int port); 140 | 141 | void write_jpgbuf(const std::vector& jpgbuf); 142 | 143 | void close(); 144 | 145 | public: 146 | int sfd; 147 | int port; 148 | 149 | pthread_t looper; 150 | pthread_mutex_t mutex; 151 | pthread_cond_t cond; 152 | 153 | void mainloop(); 154 | 155 | // cv::Mat bgr_to_send; 156 | std::vector jpgbuf; 157 | const unsigned char* jpg_data; 158 | int jpg_size; 159 | int exit_flag; 160 | }; 161 | 162 | static void* server_loop(void* args) 163 | { 164 | ((writer_http_impl*)args)->mainloop(); 165 | return NULL; 166 | } 167 | 168 | writer_http_impl::writer_http_impl() 169 | { 170 | sfd = -1; 171 | port = 7766; 172 | 173 | looper = 0; 174 | 175 | jpg_data = 0; 176 | jpg_size = 0; 177 | exit_flag = 0; 178 | } 179 | 180 | writer_http_impl::~writer_http_impl() 181 | { 182 | close(); 183 | } 184 | 185 | int writer_http_impl::open(int _port) 186 | { 187 | port = _port; 188 | 189 | { 190 | int ret = pthread_mutex_init(&mutex, 0); 191 | if (ret != 0) 192 | { 193 | fprintf(stderr, "pthread_mutex_init failed\n"); 194 | return -1; 195 | } 196 | } 197 | 198 | { 199 | int ret = pthread_cond_init(&cond, 0); 200 | if (ret != 0) 201 | { 202 | fprintf(stderr, "pthread_cond_init failed\n"); 203 | return -1; 204 | } 205 | } 206 | 207 | { 208 | int ret = pthread_create(&looper, 0, server_loop, (void*)this); 209 | if (ret != 0) 210 | { 211 | fprintf(stderr, "pthread_create failed\n"); 212 | return -1; 213 | } 214 | } 215 | 216 | return 0; 217 | } 218 | 219 | void writer_http_impl::write_jpgbuf(const std::vector& _jpgbuf) 220 | { 221 | if (!looper) 222 | return; 223 | 224 | pthread_mutex_lock(&mutex); 225 | { 226 | while (jpg_data) 227 | { 228 | pthread_cond_wait(&cond, &mutex); 229 | } 230 | 231 | jpgbuf = _jpgbuf; 232 | jpg_data = jpgbuf.data(); 233 | jpg_size = jpgbuf.size(); 234 | } 235 | pthread_mutex_unlock(&mutex); 236 | 237 | pthread_cond_signal(&cond); 238 | } 239 | 240 | void writer_http_impl::mainloop() 241 | { 242 | sfd = ::socket(AF_INET, SOCK_STREAM, 0); 243 | if (sfd <= 0) 244 | return; 245 | 246 | { 247 | int on = 1; 248 | setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); 249 | } 250 | 251 | // bind 252 | { 253 | const char* ip = "0.0.0.0"; 254 | 255 | struct sockaddr_in addr; 256 | addr.sin_family = AF_INET; 257 | addr.sin_port = htons(port); 258 | addr.sin_addr.s_addr = inet_addr(ip); 259 | 260 | if (::bind(sfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) 261 | goto OUT; 262 | } 263 | 264 | // listen 265 | { 266 | if (::listen(sfd, 8) != 0) 267 | goto OUT; 268 | } 269 | 270 | // print streaming url 271 | { 272 | struct ifaddrs *ifaddr, *ifa; 273 | 274 | if (getifaddrs(&ifaddr) == -1) 275 | goto OUT; 276 | 277 | for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) 278 | { 279 | if (ifa->ifa_addr == NULL) 280 | continue; 281 | 282 | int family = ifa->ifa_addr->sa_family; 283 | 284 | if (family == AF_INET) 285 | { 286 | void* addr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; 287 | char addressBuffer[INET_ADDRSTRLEN]; 288 | inet_ntop(AF_INET, addr, addressBuffer, INET_ADDRSTRLEN); 289 | 290 | fprintf(stderr, "streaming at http://%s:%d\n", addressBuffer, port); 291 | } 292 | } 293 | 294 | freeifaddrs(ifaddr); 295 | 296 | fprintf(stderr, "streaming at http://127.0.0.1:%d\n", port); 297 | } 298 | 299 | while (1) 300 | { 301 | struct sockaddr_in addr; 302 | memset(&addr, 0, sizeof(addr)); 303 | socklen_t len = sizeof(addr); 304 | 305 | int cfd = ::accept(sfd, (sockaddr*)&addr, &len); 306 | 307 | const char* cip = inet_ntoa(addr.sin_addr); 308 | int cport = ntohs(addr.sin_port); 309 | 310 | fprintf(stderr, "client accepted %s %d\n", cip, cport); 311 | 312 | writer_http_client client(cfd); 313 | 314 | // handle client 315 | while (1) 316 | { 317 | char buf[1024 * 1024]; 318 | client.recv(buf, 1024 * 1024 - 1); 319 | 320 | // fprintf(stderr, "%s", buf); 321 | // fprintf(stderr, "-------------------------\n"); 322 | 323 | if (memcmp(buf, "GET / HTTP/1.1", 14) == 0) 324 | { 325 | const char sbuf[] = "HTTP/1.1 200 OK\r\n" 326 | "Content-Type: multipart/x-mixed-replace;boundary=frame\r\n" 327 | "Connection: keep-alive\r\n" 328 | "Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" 329 | "Pragma: no-cache\r\n" 330 | "\r\n"; 331 | 332 | client.send(sbuf, sizeof(sbuf)); 333 | 334 | client.send("--frame\r\n", 9); 335 | 336 | while (1) 337 | { 338 | // wait for new image 339 | pthread_mutex_lock(&mutex); 340 | { 341 | while (!jpg_data && !exit_flag) 342 | { 343 | pthread_cond_wait(&cond, &mutex); 344 | } 345 | 346 | // block send jpg_data 347 | if (!exit_flag) 348 | { 349 | char sbuf2[1024]; 350 | sprintf(sbuf2, "Content-Type: image/jpeg\r\nContent-Length: %lu\r\n\r\n", jpg_size); 351 | client.send(sbuf2, strlen(sbuf2)); 352 | 353 | client.send((const char*)jpg_data, jpg_size); 354 | 355 | // fprintf(stderr, "[INFO] 4 %4s\n", jpg_data); 356 | 357 | client.send("\r\n--frame\r\n", 11); 358 | } 359 | 360 | jpg_data = 0; 361 | jpg_size = 0; 362 | } 363 | pthread_mutex_unlock(&mutex); 364 | 365 | pthread_cond_signal(&cond); 366 | 367 | if (exit_flag) 368 | { 369 | client.close(); 370 | goto OUT; 371 | } 372 | 373 | if (!client.valid()) 374 | break; 375 | } 376 | 377 | // send error or client timeout 378 | break; 379 | } 380 | else 381 | { 382 | const char sbuf[] = "HTTP/1.1 404 Not Found\r\n" 383 | "Connection: close\r\n" 384 | "\r\n"; 385 | 386 | client.send(sbuf, strlen(sbuf)); 387 | 388 | client.close(); 389 | break; 390 | } 391 | } 392 | 393 | fprintf(stderr, "client closed %s %d\n", cip, cport); 394 | } 395 | 396 | OUT: 397 | ::close(sfd); 398 | sfd = -1; 399 | } 400 | 401 | void writer_http_impl::close() 402 | { 403 | if (!looper) 404 | return; 405 | 406 | // set exit flag 407 | pthread_mutex_lock(&mutex); 408 | { 409 | exit_flag = 1; 410 | 411 | pthread_cond_signal(&cond); 412 | } 413 | pthread_mutex_unlock(&mutex); 414 | 415 | { 416 | int ret = pthread_join(looper, 0); 417 | if (ret != 0) 418 | { 419 | fprintf(stderr, "pthread_join failed\n"); 420 | } 421 | } 422 | 423 | { 424 | int ret = pthread_cond_destroy(&cond); 425 | if (ret != 0) 426 | { 427 | fprintf(stderr, "pthread_cond_destroy failed\n"); 428 | } 429 | } 430 | 431 | { 432 | int ret = pthread_mutex_destroy(&mutex); 433 | if (ret != 0) 434 | { 435 | fprintf(stderr, "pthread_mutex_destroy failed\n"); 436 | } 437 | } 438 | 439 | looper = 0; 440 | 441 | jpg_data = 0; 442 | jpg_size = 0; 443 | exit_flag = 0; 444 | } 445 | 446 | bool writer_http::supported() 447 | { 448 | return true; 449 | } 450 | 451 | writer_http::writer_http() : d(new writer_http_impl) 452 | { 453 | } 454 | 455 | writer_http::~writer_http() 456 | { 457 | delete d; 458 | } 459 | 460 | int writer_http::open(int port) 461 | { 462 | return d->open(port); 463 | } 464 | 465 | void writer_http::write_jpgbuf(const std::vector& jpgbuf) 466 | { 467 | d->write_jpgbuf(jpgbuf); 468 | } 469 | 470 | void writer_http::close() 471 | { 472 | d->close(); 473 | } 474 | 475 | } // namespace cv 476 | -------------------------------------------------------------------------------- /highgui/src/writer_http.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2024 nihui 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | #ifndef WRITER_HTTP_H 18 | #define WRITER_HTTP_H 19 | 20 | #include 21 | 22 | namespace cv { 23 | 24 | class writer_http_impl; 25 | class writer_http 26 | { 27 | public: 28 | static bool supported(); 29 | 30 | writer_http(); 31 | ~writer_http(); 32 | 33 | int open(int port); 34 | 35 | void write_jpgbuf(const std::vector& jpgbuf); 36 | 37 | void close(); 38 | 39 | private: 40 | writer_http_impl* const d; 41 | }; 42 | 43 | } // namespace cv 44 | 45 | #endif // WRITER_HTTP_H 46 | -------------------------------------------------------------------------------- /opencv2_cmake_options.txt: -------------------------------------------------------------------------------- 1 | -DWITH_AVFOUNDATION=OFF 2 | -DWITH_CARBON=OFF 3 | -DWITH_CUDA=OFF 4 | -DWITH_VTK=OFF 5 | -DWITH_CUFFT=OFF 6 | -DWITH_CUBLAS=OFF 7 | -DWITH_EIGEN=OFF 8 | -DWITH_FFMPEG=OFF 9 | -DWITH_GSTREAMER=OFF 10 | -DWITH_GTK=OFF 11 | -DWITH_IMAGEIO=OFF 12 | -DWITH_IPP=OFF 13 | -DWITH_JASPER=OFF 14 | -DWITH_JPEG=OFF 15 | -DWITH_OPENEXR=OFF 16 | -DWITH_PNG=OFF 17 | -DWITH_TIFF=OFF 18 | -DWITH_QUICKTIME=OFF 19 | -DWITH_QTKIT=OFF 20 | -DWITH_TBB=OFF 21 | -DWITH_OPENMP=ON 22 | -DWITH_V4L=OFF 23 | -DWITH_LIBV4L=OFF 24 | -DWITH_OPENCL=OFF 25 | -DBUILD_SHARED_LIBS=OFF 26 | -DBUILD_opencv_apps=OFF 27 | -DBUILD_ANDROID_EXAMPLES=OFF 28 | -DBUILD_DOCS=OFF 29 | -DBUILD_EXAMPLES=OFF 30 | -DBUILD_PACKAGE=OFF 31 | -DBUILD_PERF_TESTS=OFF 32 | -DBUILD_TESTS=OFF 33 | -DBUILD_WITH_DEBUG_INFO=OFF 34 | -DBUILD_WITH_STATIC_CRT=OFF 35 | -DBUILD_FAT_JAVA_LIB=OFF 36 | -DBUILD_ANDROID_SERVICE=OFF 37 | -DBUILD_ANDROID_PACKAGE=OFF 38 | -DBUILD_TINY_GPU_MODULE=OFF 39 | -DBUILD_ZLIB=OFF 40 | -DBUILD_TIFF=OFF 41 | -DBUILD_JASPER=OFF 42 | -DBUILD_JPEG=OFF 43 | -DBUILD_PNG=OFF 44 | -DBUILD_OPENEXR=OFF 45 | -DBUILD_TBB=OFF 46 | -DENABLE_DYNAMIC_CUDA=OFF 47 | -DENABLE_PRECOMPILED_HEADERS=OFF 48 | -DBUILD_opencv_java=OFF 49 | -DBUILD_opencv_androidcamera=OFF 50 | -DBUILD_opencv_ts=OFF 51 | -DBUILD_opencv_python2=OFF 52 | -DBUILD_opencv_python3=OFF 53 | -DBUILD_opencv_gpu=OFF 54 | -DBUILD_opencv_dynamicuda=OFF 55 | -DBUILD_opencv_ocl=OFF 56 | -DBUILD_opencv_imgcodecs=OFF 57 | -DBUILD_opencv_videoio=OFF 58 | -DBUILD_opencv_calib3d=OFF 59 | -DBUILD_opencv_flann=OFF 60 | -DBUILD_opencv_objdetect=OFF 61 | -DBUILD_opencv_stitching=OFF 62 | -DBUILD_opencv_ml=OFF 63 | -DBUILD_opencv_superres=OFF 64 | -DBUILD_opencv_videostab=OFF 65 | -DBUILD_opencv_viz=OFF 66 | -DBUILD_opencv_contrib=OFF 67 | -DBUILD_opencv_features2d=OFF 68 | -DBUILD_opencv_legacy=OFF 69 | -DBUILD_opencv_nonfree=OFF 70 | -------------------------------------------------------------------------------- /opencv3_cmake_options.txt: -------------------------------------------------------------------------------- 1 | -DENABLE_CXX11=OFF 2 | -DBUILD_ZLIB=OFF 3 | -DBUILD_TIFF=OFF 4 | -DBUILD_JASPER=OFF 5 | -DBUILD_JPEG=OFF 6 | -DBUILD_PNG=OFF 7 | -DBUILD_OPENEXR=OFF 8 | -DBUILD_WEBP=OFF 9 | -DBUILD_TBB=OFF 10 | -DBUILD_IPP_IW=OFF 11 | -DBUILD_ITT=OFF 12 | -DWITH_AVFOUNDATION=OFF 13 | -DWITH_CAP_IOS=OFF 14 | -DWITH_CAROTENE=OFF 15 | -DWITH_CPUFEATURES=OFF 16 | -DWITH_EIGEN=OFF 17 | -DWITH_FFMPEG=OFF 18 | -DWITH_GSTREAMER=OFF 19 | -DWITH_GTK=OFF 20 | -DWITH_IPP=OFF 21 | -DWITH_HALIDE=OFF 22 | -DWITH_INF_ENGINE=OFF 23 | -DWITH_NGRAPH=OFF 24 | -DWITH_JASPER=OFF 25 | -DWITH_JPEG=OFF 26 | -DWITH_WEBP=OFF 27 | -DWITH_OPENEXR=OFF 28 | -DWITH_PNG=OFF 29 | -DWITH_TIFF=OFF 30 | -DWITH_OPENVX=OFF 31 | -DWITH_GDCM=OFF 32 | -DWITH_TBB=OFF 33 | -DWITH_HPX=OFF 34 | -DWITH_OPENMP=ON 35 | -DWITH_PTHREADS_PF=OFF 36 | -DWITH_V4L=OFF 37 | -DWITH_CLP=OFF 38 | -DWITH_OPENCL=OFF 39 | -DWITH_OPENCL_SVM=OFF 40 | -DWITH_ITT=OFF 41 | -DWITH_PROTOBUF=OFF 42 | -DWITH_IMGCODEC_HDR=OFF 43 | -DWITH_IMGCODEC_SUNRASTER=OFF 44 | -DWITH_IMGCODEC_PXM=OFF 45 | -DWITH_QUIRC=OFF 46 | -DWITH_TENGINE=OFF 47 | -DBUILD_SHARED_LIBS=OFF 48 | -DBUILD_opencv_apps=OFF 49 | -DBUILD_ANDROID_PROJECTS=OFF 50 | -DBUILD_ANDROID_EXAMPLES=OFF 51 | -DBUILD_DOCS=OFF 52 | -DBUILD_EXAMPLES=OFF 53 | -DBUILD_PACKAGE=OFF 54 | -DBUILD_PERF_TESTS=OFF 55 | -DBUILD_TESTS=OFF 56 | -DBUILD_WITH_STATIC_CRT=OFF 57 | -DBUILD_FAT_JAVA_LIB=OFF 58 | -DBUILD_ANDROID_SERVICE=OFF 59 | -DBUILD_JAVA=OFF 60 | -DENABLE_PRECOMPILED_HEADERS=OFF 61 | -DENABLE_FAST_MATH=ON 62 | -DCV_TRACE=OFF 63 | -DBUILD_opencv_java=OFF 64 | -DBUILD_opencv_js=OFF 65 | -DBUILD_opencv_ts=OFF 66 | -DBUILD_opencv_python2=OFF 67 | -DBUILD_opencv_python3=OFF 68 | -DBUILD_opencv_dnn=OFF 69 | -DBUILD_opencv_imgcodecs=OFF 70 | -DBUILD_opencv_videoio=OFF 71 | -DBUILD_opencv_calib3d=OFF 72 | -DBUILD_opencv_flann=OFF 73 | -DBUILD_opencv_objdetect=OFF 74 | -DBUILD_opencv_stitching=OFF 75 | -DBUILD_opencv_ml=OFF 76 | -DBUILD_opencv_shape=OFF 77 | -DBUILD_opencv_superres=OFF 78 | -DBUILD_opencv_videostab=OFF 79 | -------------------------------------------------------------------------------- /opencv4_cmake_options.txt: -------------------------------------------------------------------------------- 1 | -DBUILD_ZLIB=OFF 2 | -DBUILD_TIFF=OFF 3 | -DBUILD_OPENJPEG=OFF 4 | -DBUILD_JASPER=OFF 5 | -DBUILD_JPEG=OFF 6 | -DBUILD_PNG=OFF 7 | -DBUILD_OPENEXR=OFF 8 | -DBUILD_WEBP=OFF 9 | -DBUILD_TBB=OFF 10 | -DBUILD_IPP_IW=OFF 11 | -DBUILD_ITT=OFF 12 | -DWITH_AVFOUNDATION=OFF 13 | -DWITH_CAP_IOS=OFF 14 | -DWITH_CAROTENE=OFF 15 | -DWITH_CPUFEATURES=OFF 16 | -DWITH_EIGEN=OFF 17 | -DWITH_FFMPEG=OFF 18 | -DWITH_GSTREAMER=OFF 19 | -DWITH_GTK=OFF 20 | -DWITH_IPP=OFF 21 | -DWITH_HALIDE=OFF 22 | -DWITH_VULKAN=OFF 23 | -DWITH_INF_ENGINE=OFF 24 | -DWITH_NGRAPH=OFF 25 | -DWITH_JASPER=OFF 26 | -DWITH_OPENJPEG=OFF 27 | -DWITH_JPEG=OFF 28 | -DWITH_WEBP=OFF 29 | -DWITH_OPENEXR=OFF 30 | -DWITH_PNG=OFF 31 | -DWITH_TIFF=OFF 32 | -DWITH_OPENVX=OFF 33 | -DWITH_GDCM=OFF 34 | -DWITH_TBB=OFF 35 | -DWITH_HPX=OFF 36 | -DWITH_OPENMP=ON 37 | -DWITH_PTHREADS_PF=OFF 38 | -DWITH_V4L=OFF 39 | -DWITH_CLP=OFF 40 | -DWITH_OPENCL=OFF 41 | -DWITH_OPENCL_SVM=OFF 42 | -DWITH_VA=OFF 43 | -DWITH_VA_INTEL=OFF 44 | -DWITH_ITT=OFF 45 | -DWITH_PROTOBUF=OFF 46 | -DWITH_IMGCODEC_HDR=OFF 47 | -DWITH_IMGCODEC_SUNRASTER=OFF 48 | -DWITH_IMGCODEC_PXM=OFF 49 | -DWITH_IMGCODEC_PFM=OFF 50 | -DWITH_QUIRC=OFF 51 | -DWITH_ANDROID_MEDIANDK=OFF 52 | -DWITH_TENGINE=OFF 53 | -DWITH_ONNX=OFF 54 | -DWITH_TIMVX=OFF 55 | -DWITH_OBSENSOR=OFF 56 | -DWITH_CANN=OFF 57 | -DWITH_FLATBUFFERS=OFF 58 | -DBUILD_SHARED_LIBS=OFF 59 | -DBUILD_opencv_apps=OFF 60 | -DBUILD_ANDROID_PROJECTS=OFF 61 | -DBUILD_ANDROID_EXAMPLES=OFF 62 | -DBUILD_DOCS=OFF 63 | -DBUILD_EXAMPLES=OFF 64 | -DBUILD_PACKAGE=OFF 65 | -DBUILD_PERF_TESTS=OFF 66 | -DBUILD_TESTS=OFF 67 | -DBUILD_WITH_STATIC_CRT=OFF 68 | -DBUILD_FAT_JAVA_LIB=OFF 69 | -DBUILD_ANDROID_SERVICE=OFF 70 | -DBUILD_JAVA=OFF 71 | -DBUILD_OBJC=OFF 72 | -DBUILD_KOTLIN_EXTENSIONS=OFF 73 | -DENABLE_PRECOMPILED_HEADERS=OFF 74 | -DENABLE_FAST_MATH=ON 75 | -DCV_TRACE=OFF 76 | -DBUILD_opencv_java=OFF 77 | -DBUILD_opencv_gapi=OFF 78 | -DBUILD_opencv_objc=OFF 79 | -DBUILD_opencv_js=OFF 80 | -DBUILD_opencv_ts=OFF 81 | -DBUILD_opencv_python2=OFF 82 | -DBUILD_opencv_python3=OFF 83 | -DBUILD_opencv_dnn=OFF 84 | -DBUILD_opencv_imgcodecs=OFF 85 | -DBUILD_opencv_videoio=OFF 86 | -DBUILD_opencv_calib3d=OFF 87 | -DBUILD_opencv_flann=OFF 88 | -DBUILD_opencv_objdetect=OFF 89 | -DBUILD_opencv_stitching=OFF 90 | -DBUILD_opencv_ml=OFF 91 | -------------------------------------------------------------------------------- /patches/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | OpenCV 7 | CFBundleIdentifier 8 | org.opencv 9 | CFBundleVersion 10 | __VERSION__ 11 | CFBundleShortVersionString 12 | __VERSION__ 13 | CFBundleSignature 14 | ???? 15 | CFBundlePackageType 16 | FMWK 17 | 18 | 19 | -------------------------------------------------------------------------------- /patches/fontface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Text to Font Header 6 | 28 | 29 | 30 |
32 | 33 | 34 | 35 | 36 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-drawing-mono-font.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/include/opencv2/core/core.hpp opencv-2.4.13.7/modules/core/include/opencv2/core/core.hpp 2 | --- opencv-2.4.13.7.orig/modules/core/include/opencv2/core/core.hpp 2024-08-03 13:33:29.646494334 +0800 3 | +++ opencv-2.4.13.7/modules/core/include/opencv2/core/core.hpp 2024-08-03 13:35:12.013094855 +0800 4 | @@ -2732,6 +2732,37 @@ CV_EXPORTS_W Size getTextSize(const stri 5 | double fontScale, int thickness, 6 | CV_OUT int* baseLine); 7 | 8 | +class FontFaceImpl; 9 | +class CV_EXPORTS_W FontFace 10 | +{ 11 | +public: 12 | + FontFace(); 13 | + FontFace(const String& fontPath); 14 | + 15 | + ~FontFace(); 16 | + 17 | +protected: 18 | + void set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps); 19 | + 20 | +public: 21 | + FontFaceImpl* const d; 22 | +}; 23 | + 24 | +enum PutTextFlags 25 | +{ 26 | + PUT_TEXT_ALIGN_LEFT=0, // put the text to the right from the origin 27 | + PUT_TEXT_ALIGN_CENTER=1,// center the text at the origin; not implemented yet 28 | + PUT_TEXT_ALIGN_RIGHT=2, // put the text to the left of the origin 29 | + PUT_TEXT_ALIGN_MASK=3, // alignment mask 30 | + PUT_TEXT_ORIGIN_TL=0, 31 | + PUT_TEXT_ORIGIN_BL=32, // treat the target image as having bottom-left origin 32 | + PUT_TEXT_WRAP=128 // wrap text to the next line if it does not fit 33 | +}; 34 | + 35 | +CV_EXPORTS_W Point putText(InputOutputArray img, const String &text, Point org, Scalar color, const FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 36 | + 37 | +CV_EXPORTS_W Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 38 | + 39 | ///////////////////////////////// Mat_<_Tp> //////////////////////////////////// 40 | 41 | /*! 42 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/drawing.cpp opencv-2.4.13.7/modules/core/src/drawing.cpp 43 | --- opencv-2.4.13.7.orig/modules/core/src/drawing.cpp 2024-08-03 13:33:29.648494328 +0800 44 | +++ opencv-2.4.13.7/modules/core/src/drawing.cpp 2024-08-03 14:19:07.916992598 +0800 45 | @@ -42,6 +42,25 @@ 46 | 47 | namespace cv 48 | { 49 | +class FontFaceImpl 50 | +{ 51 | +public: 52 | + FontFaceImpl(); 53 | + 54 | +public: 55 | + int glyph_count; 56 | + const unsigned int* glyph_unicode; 57 | + const unsigned char* glyph_bitmaps; 58 | + 59 | +public: 60 | + const unsigned char* get_glyph_bitmap(unsigned int ch) const; 61 | +}; 62 | +} 63 | + 64 | +#include "draw_text.h" 65 | + 66 | +namespace cv 67 | +{ 68 | 69 | enum { XY_SHIFT = 16, XY_ONE = 1 << XY_SHIFT, DRAWING_STORAGE_BLOCK = (1<<12) - 256 }; 70 | 71 | @@ -1992,6 +2011,7 @@ void polylines( Mat& img, const Point** 72 | } 73 | 74 | 75 | +#if 0 76 | enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8), 77 | FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8), 78 | FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8), 79 | @@ -2204,12 +2224,41 @@ inline void readCheck(int &c, int &i, co 80 | if(c >= rightBoundary || c < leftBoundary) 81 | c = '?'; 82 | } 83 | +#endif 84 | 85 | void putText( Mat& img, const string& text, Point org, 86 | int fontFace, double fontScale, Scalar color, 87 | int thickness, int line_type, bool bottomLeftOrigin ) 88 | 89 | { 90 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 91 | + const int base_line = 0; 92 | + const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line; 93 | + 94 | + unsigned int _color = 0; 95 | + unsigned char* border_color = (unsigned char*)&_color; 96 | + 97 | + if (img.channels() == 1) 98 | + { 99 | + border_color[0] = color[0]; 100 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 101 | + } 102 | + else if (img.channels() == 3) 103 | + { 104 | + border_color[0] = color[0]; 105 | + border_color[1] = color[1]; 106 | + border_color[2] = color[2]; 107 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 108 | + } 109 | + else if (img.channels() == 4) 110 | + { 111 | + border_color[0] = color[0]; 112 | + border_color[1] = color[1]; 113 | + border_color[2] = color[2]; 114 | + border_color[3] = color[3]; 115 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 116 | + } 117 | +#if 0 118 | const int* ascii = getFontData(fontFace); 119 | 120 | double buf[4]; 121 | @@ -2264,10 +2313,21 @@ void putText( Mat& img, const string& te 122 | } 123 | view_x += dx; 124 | } 125 | +#endif 126 | } 127 | 128 | Size getTextSize( const string& text, int fontFace, double fontScale, int thickness, int* _base_line) 129 | { 130 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 131 | + 132 | + int w; 133 | + int h; 134 | + get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h); 135 | + 136 | + if(_base_line) *_base_line = 0; 137 | + 138 | + return Size(w, h); 139 | +#if 0 140 | Size size; 141 | double view_x = 0; 142 | const char **faces = cv::g_HersheyGlyphs; 143 | @@ -2294,6 +2354,94 @@ Size getTextSize( const string& text, in 144 | if( _base_line ) 145 | *_base_line = cvRound(base_line*fontScale + thickness*0.5); 146 | return size; 147 | +#endif 148 | +} 149 | + 150 | +FontFaceImpl::FontFaceImpl() 151 | +{ 152 | + glyph_count = 0; 153 | + glyph_unicode = 0; 154 | + glyph_bitmaps = 0; 155 | +} 156 | + 157 | +const unsigned char* FontFaceImpl::get_glyph_bitmap(unsigned int ch) const 158 | +{ 159 | + if (!glyph_count || !glyph_unicode || !glyph_bitmaps) 160 | + return 0; 161 | + 162 | + for (int i = 0; i < glyph_count; i++) 163 | + { 164 | + if (glyph_unicode[i] == ch) 165 | + return glyph_bitmaps + i * 40 * 20; 166 | + } 167 | + 168 | + return 0; 169 | +} 170 | + 171 | +FontFace::FontFace() : d(new FontFaceImpl) 172 | +{ 173 | +} 174 | + 175 | +FontFace::~FontFace() 176 | +{ 177 | + delete d; 178 | +} 179 | + 180 | +void FontFace::set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps) 181 | +{ 182 | + d->glyph_count = count; 183 | + d->glyph_unicode = unicode; 184 | + d->glyph_bitmaps = bitmaps; 185 | +} 186 | + 187 | +Point putText(InputOutputArray _img, const String& text, Point org, Scalar color, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 188 | +{ 189 | + if ( text.empty() ) 190 | + { 191 | + return org; 192 | + } 193 | + Mat img = _img.getMat(); 194 | + 195 | + const int yoffset = org.y - size * 2; 196 | + 197 | + unsigned int _color = 0; 198 | + unsigned char* border_color = (unsigned char*)&_color; 199 | + 200 | + if (img.channels() == 1) 201 | + { 202 | + border_color[0] = color[0]; 203 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 204 | + } 205 | + else if (img.channels() == 3) 206 | + { 207 | + border_color[0] = color[0]; 208 | + border_color[1] = color[1]; 209 | + border_color[2] = color[2]; 210 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 211 | + } 212 | + else if (img.channels() == 4) 213 | + { 214 | + border_color[0] = color[0]; 215 | + border_color[1] = color[1]; 216 | + border_color[2] = color[2]; 217 | + border_color[3] = color[3]; 218 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 219 | + } 220 | + 221 | + int w; 222 | + int h; 223 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 224 | + 225 | + return Point(org.x + w, org.y); 226 | +} 227 | + 228 | +Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 229 | +{ 230 | + int w; 231 | + int h; 232 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 233 | + 234 | + return Rect(org.x, org.y - size * 2, w, h); 235 | } 236 | 237 | } 238 | @@ -2679,7 +2827,7 @@ cvInitFont( CvFont *font, int font_face, 239 | { 240 | CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 ); 241 | 242 | - font->ascii = cv::getFontData(font_face); 243 | + font->ascii = 0; 244 | font->font_face = font_face; 245 | font->hscale = (float)hscale; 246 | font->vscale = (float)vscale; 247 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/tables.cpp opencv-2.4.13.7/modules/core/src/tables.cpp 248 | --- opencv-2.4.13.7.orig/modules/core/src/tables.cpp 2024-08-03 13:33:29.648494328 +0800 249 | +++ opencv-2.4.13.7/modules/core/src/tables.cpp 2024-08-03 13:33:44.160445806 +0800 250 | @@ -204,6 +204,7 @@ const uchar g_Saturate8u[] = 251 | 255 252 | }; 253 | 254 | +#if 0 255 | const char* g_HersheyGlyphs[] = { 256 | "", 257 | "MWRMNV RMVV PSTS", 258 | @@ -3506,6 +3507,7 @@ const char* g_HersheyGlyphs[] = { 259 | "", 260 | "", 261 | 0 }; 262 | +#endif 263 | 264 | } 265 | 266 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-enable-cxx11.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 2 | --- opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake 2018-07-02 20:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 2023-08-06 19:27:16.226755305 +0800 4 | @@ -114,3 +114,7 @@ elseif(MINGW) 5 | set(OpenCV_ARCH x86) 6 | endif() 7 | endif() 8 | + 9 | +set(CMAKE_CXX_STANDARD 11) 10 | +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 11 | +set(CMAKE_CXX_EXTENSIONS OFF) 12 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-fix-highgui-include.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/include/opencv2/opencv.hpp opencv-2.4.13.7/include/opencv2/opencv.hpp 2 | --- opencv-2.4.13.7.orig/include/opencv2/opencv.hpp 2021-03-12 10:34:37.813906930 +0800 3 | +++ opencv-2.4.13.7/include/opencv2/opencv.hpp 2018-07-02 05:41:56.000000000 +0800 4 | @@ -73,7 +73,6 @@ 5 | #include "opencv2/ml/ml.hpp" 6 | #endif 7 | #ifdef HAVE_OPENCV_HIGHGUI 8 | -#include "opencv2/highgui/highgui_c.h" 9 | #include "opencv2/highgui/highgui.hpp" 10 | #endif 11 | #ifdef HAVE_OPENCV_CONTRIB 12 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-fix-windows-arm-arch.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVConfig.cmake opencv-2.4.13.7/cmake/OpenCVConfig.cmake 2 | --- opencv-2.4.13.7.orig/cmake/OpenCVConfig.cmake 2018-07-02 20:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/cmake/OpenCVConfig.cmake 2024-06-10 15:05:13.943493559 +0800 4 | @@ -64,12 +64,17 @@ endif() 5 | if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME) 6 | # custom overrided values 7 | elseif(MSVC) 8 | - if(CMAKE_CL_64) 9 | - set(OpenCV_ARCH x64) 10 | - set(OpenCV_TBB_ARCH intel64) 11 | + # see Modules/CMakeGenericSystem.cmake 12 | + if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 13 | + set(OpenCV_ARCH "x64") 14 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 15 | + set(OpenCV_ARCH "ARM64") 16 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 17 | + set(OpenCV_ARCH "ARM") 18 | + elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 19 | + set(OpenCV_ARCH "x64") 20 | else() 21 | set(OpenCV_ARCH x86) 22 | - set(OpenCV_TBB_ARCH ia32) 23 | endif() 24 | if(MSVC_VERSION EQUAL 1400) 25 | set(OpenCV_RUNTIME vc8) 26 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 27 | --- opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake 2018-07-02 20:41:56.000000000 +0800 28 | +++ opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 2024-06-10 15:05:01.441716441 +0800 29 | @@ -85,11 +85,19 @@ endif() 30 | if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME) 31 | # custom overrided values 32 | elseif(MSVC) 33 | - if(CMAKE_CL_64) 34 | - set(OpenCV_ARCH x64) 35 | + # see Modules/CMakeGenericSystem.cmake 36 | + if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 37 | + set(OpenCV_ARCH "x64") 38 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 39 | + set(OpenCV_ARCH "ARM64") 40 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 41 | + set(OpenCV_ARCH "ARM") 42 | + elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 43 | + set(OpenCV_ARCH "x64") 44 | else() 45 | set(OpenCV_ARCH x86) 46 | endif() 47 | + 48 | if(MSVC_VERSION EQUAL 1400) 49 | set(OpenCV_RUNTIME vc8) 50 | elseif(MSVC_VERSION EQUAL 1500) 51 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-link-openmp.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/cmake/templates/OpenCVConfig.cmake.in opencv-2.4.13.7/cmake/templates/OpenCVConfig.cmake.in 2 | --- opencv-2.4.13.7.orig/cmake/templates/OpenCVConfig.cmake.in 2018-07-02 20:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/cmake/templates/OpenCVConfig.cmake.in 2023-08-30 11:25:24.227478073 +0800 4 | @@ -80,6 +80,7 @@ set(OpenCV_CUDA_VERSION @OpenCV_CUDA_VER 5 | set(OpenCV_USE_CUBLAS @HAVE_CUBLAS@) 6 | set(OpenCV_USE_CUFFT @HAVE_CUFFT@) 7 | set(OpenCV_USE_NVCUVID @HAVE_NVCUVID@) 8 | +set(OpenCV_USE_OPENMP @HAVE_OPENMP@) 9 | 10 | # Android API level from which OpenCV has been compiled is remembered 11 | if(ANDROID) 12 | @@ -291,6 +292,10 @@ if(OpenCV_CUDA_VERSION) 13 | endforeach() 14 | endif() 15 | 16 | +if(OpenCV_USE_OPENMP) 17 | + find_package(OpenMP) 18 | +endif() 19 | + 20 | # ============================================================== 21 | # Android camera helper macro 22 | # ============================================================== 23 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/CMakeLists.txt opencv-2.4.13.7/modules/core/CMakeLists.txt 24 | --- opencv-2.4.13.7.orig/modules/core/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800 25 | +++ opencv-2.4.13.7/modules/core/CMakeLists.txt 2023-08-30 11:41:25.374790126 +0800 26 | @@ -52,7 +52,17 @@ else() 27 | HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail}) 28 | endif() 29 | 30 | -ocv_create_module() 31 | +if(HAVE_OPENMP) 32 | + if(ANDROID_NDK_MAJOR AND (ANDROID_NDK_MAJOR GREATER 20)) 33 | + ocv_create_module(-fopenmp -static-openmp) 34 | + elseif(OpenMP_CXX_FOUND) 35 | + ocv_create_module(OpenMP::OpenMP_CXX) 36 | + else() 37 | + ocv_create_module(${OpenMP_CXX_FLAGS}) 38 | + endif() 39 | +else() 40 | + ocv_create_module() 41 | +endif() 42 | ocv_add_precompiled_headers(${the_module}) 43 | 44 | ocv_add_accuracy_tests() 45 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-minimal-install.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVGenAndroidMK.cmake opencv-2.4.13.7/cmake/OpenCVGenAndroidMK.cmake 2 | --- opencv-2.4.13.7.orig/cmake/OpenCVGenAndroidMK.cmake 2018-07-02 20:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/cmake/OpenCVGenAndroidMK.cmake 2023-12-09 21:14:50.771014374 +0800 4 | @@ -161,5 +161,4 @@ if(ANDROID) 5 | set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../3rdparty/libs/\$(OPENCV_TARGET_ARCH_ABI)") 6 | 7 | configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY) 8 | - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) 9 | endif(ANDROID) 10 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVGenConfig.cmake opencv-2.4.13.7/cmake/OpenCVGenConfig.cmake 11 | --- opencv-2.4.13.7.orig/cmake/OpenCVGenConfig.cmake 2018-07-02 20:41:56.000000000 +0800 12 | +++ opencv-2.4.13.7/cmake/OpenCVGenConfig.cmake 2023-12-09 21:10:49.425388446 +0800 13 | @@ -119,10 +119,6 @@ if(UNIX) # ANDROID configuration is crea 14 | endif() 15 | endif() 16 | 17 | -if(ANDROID) 18 | - install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) 19 | -endif() 20 | - 21 | # -------------------------------------------------------------------------------------------- 22 | # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages 23 | # -------------------------------------------------------------------------------------------- 24 | diff -Nuarp opencv-2.4.13.7.orig/CMakeLists.txt opencv-2.4.13.7/CMakeLists.txt 25 | --- opencv-2.4.13.7.orig/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800 26 | +++ opencv-2.4.13.7/CMakeLists.txt 2023-12-10 12:41:39.219962895 +0800 27 | @@ -569,32 +569,13 @@ add_subdirectory(include) 28 | add_subdirectory(modules) 29 | 30 | # Generate targets for documentation 31 | -add_subdirectory(doc) 32 | 33 | # various data that is used by cv libraries and/or demo applications. 34 | -add_subdirectory(data) 35 | 36 | # extra applications 37 | -if(BUILD_opencv_apps) 38 | - add_subdirectory(apps) 39 | -endif() 40 | 41 | # examples 42 | -if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES) 43 | - add_subdirectory(samples) 44 | -endif() 45 | - 46 | -if(ANDROID) 47 | - add_subdirectory(platforms/android/service) 48 | -endif() 49 | - 50 | -if(BUILD_ANDROID_PACKAGE) 51 | - add_subdirectory(platforms/android/package) 52 | -endif() 53 | 54 | -if (ANDROID) 55 | - add_subdirectory(platforms/android/libinfo) 56 | -endif() 57 | 58 | # ---------------------------------------------------------------------------- 59 | # Finalization: generate configuration-based files 60 | @@ -605,16 +586,13 @@ ocv_track_build_dependencies() 61 | include(cmake/OpenCVGenHeaders.cmake) 62 | 63 | # Generate opencv.pc for pkg-config command 64 | -include(cmake/OpenCVGenPkgconfig.cmake) 65 | 66 | # Generate OpenCV.mk for ndk-build (Android build tool) 67 | -include(cmake/OpenCVGenAndroidMK.cmake) 68 | 69 | # Generate OpenCVСonfig.cmake and OpenCVConfig-version.cmake for cmake projects 70 | include(cmake/OpenCVGenConfig.cmake) 71 | 72 | # Generate Info.plist for the IOS framework 73 | -include(cmake/OpenCVGenInfoPlist.cmake) 74 | 75 | # Generate environment setup file 76 | if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) 77 | @@ -649,12 +627,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA 78 | endif() 79 | endif() 80 | 81 | -if(NOT OPENCV_README_FILE) 82 | - if(ANDROID) 83 | - set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android) 84 | - endif() 85 | -endif() 86 | - 87 | if(NOT OPENCV_LICENSE_FILE) 88 | set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) 89 | endif() 90 | @@ -664,11 +636,6 @@ if(ANDROID OR NOT UNIX) 91 | install(FILES ${OPENCV_LICENSE_FILE} 92 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ 93 | DESTINATION . COMPONENT libs) 94 | - if(OPENCV_README_FILE) 95 | - install(FILES ${OPENCV_README_FILE} 96 | - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ 97 | - DESTINATION . COMPONENT libs) 98 | - endif() 99 | endif() 100 | 101 | # ---------------------------------------------------------------------------- 102 | diff -Nuarp opencv-2.4.13.7.orig/data/CMakeLists.txt opencv-2.4.13.7/data/CMakeLists.txt 103 | --- opencv-2.4.13.7.orig/data/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800 104 | +++ opencv-2.4.13.7/data/CMakeLists.txt 2023-12-09 21:07:33.901501638 +0800 105 | @@ -1,14 +1,6 @@ 106 | file(GLOB HAAR_CASCADES haarcascades/*.xml) 107 | file(GLOB LBP_CASCADES lbpcascades/*.xml) 108 | 109 | -if(ANDROID) 110 | - install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT libs) 111 | - install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT libs) 112 | -else() 113 | - install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT libs) 114 | - install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs) 115 | -endif() 116 | - 117 | if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) 118 | if(ANDROID) 119 | install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests) 120 | diff -Nuarp opencv-2.4.13.7.orig/platforms/android/libinfo/CMakeLists.txt opencv-2.4.13.7/platforms/android/libinfo/CMakeLists.txt 121 | --- opencv-2.4.13.7.orig/platforms/android/libinfo/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800 122 | +++ opencv-2.4.13.7/platforms/android/libinfo/CMakeLists.txt 2023-12-09 21:02:53.976095360 +0800 123 | @@ -37,4 +37,3 @@ set_target_properties(${the_module} PROP 124 | ) 125 | 126 | get_filename_component(lib_name "libopencv_info.so" NAME) 127 | -install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs) 128 | diff -Nuarp opencv-2.4.13.7.orig/platforms/android/package/CMakeLists.txt opencv-2.4.13.7/platforms/android/package/CMakeLists.txt 129 | --- opencv-2.4.13.7.orig/platforms/android/package/CMakeLists.txt 2018-07-02 20:41:56.000000000 +0800 130 | +++ opencv-2.4.13.7/platforms/android/package/CMakeLists.txt 2023-12-09 21:13:29.379477767 +0800 131 | @@ -89,6 +89,5 @@ add_custom_command( 132 | DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers} opencv_java 133 | ) 134 | 135 | -install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT libs) 136 | add_custom_target(android_package ALL SOURCES "${APK_NAME}" ) 137 | add_dependencies(android_package opencv_java) 138 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-newer-msvc.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVConfig.cmake opencv-2.4.13.7/cmake/OpenCVConfig.cmake 2 | --- opencv-2.4.13.7.orig/cmake/OpenCVConfig.cmake 2018-07-02 20:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/cmake/OpenCVConfig.cmake 2023-08-13 22:11:10.193931771 +0800 4 | @@ -85,6 +85,10 @@ elseif(MSVC) 5 | set(OpenCV_RUNTIME vc14) 6 | elseif(MSVC_VERSION MATCHES "^191[0-9]$") 7 | set(OpenCV_RUNTIME vc15) 8 | + elseif(MSVC_VERSION MATCHES "^192[0-9]$") 9 | + set(OpenCV_RUNTIME vc16) 10 | + elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") 11 | + set(OpenCV_RUNTIME vc17) 12 | endif() 13 | elseif(MINGW) 14 | set(OpenCV_RUNTIME mingw) 15 | diff -Nuarp opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 16 | --- opencv-2.4.13.7.orig/cmake/OpenCVDetectCXXCompiler.cmake 2018-07-02 20:41:56.000000000 +0800 17 | +++ opencv-2.4.13.7/cmake/OpenCVDetectCXXCompiler.cmake 2023-08-13 22:11:03.358965110 +0800 18 | @@ -104,6 +104,10 @@ elseif(MSVC) 19 | set(OpenCV_RUNTIME vc14) 20 | elseif(MSVC_VERSION MATCHES "^191[0-9]$") 21 | set(OpenCV_RUNTIME vc15) 22 | + elseif(MSVC_VERSION MATCHES "^192[0-9]$") 23 | + set(OpenCV_RUNTIME vc16) 24 | + elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") 25 | + set(OpenCV_RUNTIME vc17) 26 | endif() 27 | elseif(MINGW) 28 | set(OpenCV_RUNTIME mingw) 29 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-no-link-stdc++.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7/cmake/OpenCVCompilerOptions.cmake opencv-2.4.13.7.no-link-stdc++/cmake/OpenCVCompilerOptions.cmake 2 | --- opencv-2.4.13.7/cmake/OpenCVCompilerOptions.cmake 2018-07-02 05:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7.no-link-stdc++/cmake/OpenCVCompilerOptions.cmake 2021-05-11 15:57:17.159970391 +0800 4 | @@ -313,7 +313,6 @@ endif() 5 | # Extra link libs if the user selects building static libs: 6 | if(NOT BUILD_SHARED_LIBS AND ((CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID) OR QNX)) 7 | # Android does not need these settings because they are already set by toolchain file 8 | - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++) 9 | set(OPENCV_EXTRA_FLAGS "-fPIC ${OPENCV_EXTRA_FLAGS}") 10 | endif() 11 | 12 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-no-local-static.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/gpumat.cpp opencv-2.4.13.7/modules/core/src/gpumat.cpp 2 | --- opencv-2.4.13.7.orig/modules/core/src/gpumat.cpp 2018-07-02 05:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/modules/core/src/gpumat.cpp 2021-05-12 13:05:39.939811441 +0800 4 | @@ -222,40 +222,40 @@ static bool loadCudaSupportLib() 5 | 6 | #endif 7 | 8 | -static GpuFuncTable* gpuFuncTable() 9 | -{ 10 | #ifdef DYNAMIC_CUDA_SUPPORT 11 | - static EmptyFuncTable stub; 12 | - static GpuFuncTable* libFuncTable = loadCudaSupportLib() ? gpuFactory(): (GpuFuncTable*)&stub; 13 | - static GpuFuncTable *funcTable = libFuncTable ? libFuncTable : (GpuFuncTable*)&stub; 14 | +static EmptyFuncTable g_GpuFuncTable_stub; 15 | +static GpuFuncTable* g_GpuFuncTable_libFuncTable = loadCudaSupportLib() ? gpuFactory(): (GpuFuncTable*)&g_GpuFuncTable_stub; 16 | +static GpuFuncTable *g_GpuFuncTable_funcTable = g_GpuFuncTable_libFuncTable ? g_GpuFuncTable_libFuncTable : (GpuFuncTable*)&g_GpuFuncTable_stub; 17 | #else 18 | # ifdef USE_CUDA 19 | - static CudaFuncTable impl; 20 | - static GpuFuncTable* funcTable = &impl; 21 | +static CudaFuncTable g_GpuFuncTable_impl; 22 | +static GpuFuncTable* g_GpuFuncTable_funcTable = &g_GpuFuncTable_impl; 23 | #else 24 | - static EmptyFuncTable stub; 25 | - static GpuFuncTable* funcTable = &stub; 26 | +static EmptyFuncTable g_GpuFuncTable_stub; 27 | +static GpuFuncTable* g_GpuFuncTable_funcTable = &g_GpuFuncTable_stub; 28 | #endif 29 | #endif 30 | - return funcTable; 31 | +static GpuFuncTable* gpuFuncTable() 32 | +{ 33 | + return g_GpuFuncTable_funcTable; 34 | } 35 | 36 | -static DeviceInfoFuncTable* deviceInfoFuncTable() 37 | -{ 38 | #ifdef DYNAMIC_CUDA_SUPPORT 39 | - static EmptyDeviceInfoFuncTable stub; 40 | - static DeviceInfoFuncTable* libFuncTable = loadCudaSupportLib() ? deviceInfoFactory(): (DeviceInfoFuncTable*)&stub; 41 | - static DeviceInfoFuncTable* funcTable = libFuncTable ? libFuncTable : (DeviceInfoFuncTable*)&stub; 42 | +static EmptyDeviceInfoFuncTable g_DeviceInfoFuncTable_stub; 43 | +static DeviceInfoFuncTable* g_DeviceInfoFuncTable_libFuncTable = loadCudaSupportLib() ? deviceInfoFactory(): (DeviceInfoFuncTable*)&g_DeviceInfoFuncTable_stub; 44 | +static DeviceInfoFuncTable* g_DeviceInfoFuncTable_funcTable = g_DeviceInfoFuncTable_libFuncTable ? g_DeviceInfoFuncTable_libFuncTable : (DeviceInfoFuncTable*)&g_DeviceInfoFuncTable_stub; 45 | #else 46 | # ifdef USE_CUDA 47 | - static CudaDeviceInfoFuncTable impl; 48 | - static DeviceInfoFuncTable* funcTable = &impl; 49 | +static CudaDeviceInfoFuncTable g_DeviceInfoFuncTable_impl; 50 | +static DeviceInfoFuncTable* g_DeviceInfoFuncTable_funcTable = &g_DeviceInfoFuncTable_impl; 51 | #else 52 | - static EmptyDeviceInfoFuncTable stub; 53 | - static DeviceInfoFuncTable* funcTable = &stub; 54 | +static EmptyDeviceInfoFuncTable g_DeviceInfoFuncTable_stub; 55 | +static DeviceInfoFuncTable* g_DeviceInfoFuncTable_funcTable = &g_DeviceInfoFuncTable_stub; 56 | #endif 57 | #endif 58 | - return funcTable; 59 | +static DeviceInfoFuncTable* deviceInfoFuncTable() 60 | +{ 61 | + return g_DeviceInfoFuncTable_funcTable; 62 | } 63 | 64 | 65 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/matop.cpp opencv-2.4.13.7/modules/core/src/matop.cpp 66 | --- opencv-2.4.13.7.orig/modules/core/src/matop.cpp 2018-07-02 05:41:56.000000000 +0800 67 | +++ opencv-2.4.13.7/modules/core/src/matop.cpp 2021-05-12 14:09:01.821745993 +0800 68 | @@ -203,10 +203,10 @@ public: 69 | static void makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha=1); 70 | }; 71 | 72 | +static MatOp_Initializer g_MatOp_initializer; 73 | static MatOp_Initializer* getGlobalMatOpInitializer() 74 | { 75 | - static MatOp_Initializer initializer; 76 | - return &initializer; 77 | + return &g_MatOp_initializer; 78 | } 79 | 80 | static inline bool isIdentity(const MatExpr& e) { return e.op == &g_MatOp_Identity; } 81 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-no-rtti.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7/modules/core/src/glob.cpp opencv-2.4.13.7.nortti/modules/core/src/glob.cpp 2 | --- opencv-2.4.13.7/modules/core/src/glob.cpp 2018-07-02 05:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7.nortti/modules/core/src/glob.cpp 2021-01-08 23:24:46.371298637 +0800 4 | @@ -225,7 +225,6 @@ static void glob_rec(const cv::String& d 5 | if ((dir = opendir (directory.c_str())) != 0) 6 | { 7 | /* find all the files and directories within directory */ 8 | - try 9 | { 10 | while ((ent = readdir (dir)) != 0) 11 | { 12 | @@ -247,11 +246,6 @@ static void glob_rec(const cv::String& d 13 | } 14 | } 15 | } 16 | - catch (...) 17 | - { 18 | - closedir(dir); 19 | - throw; 20 | - } 21 | closedir(dir); 22 | } 23 | else CV_Error(CV_StsObjectNotFound, cv::format("could not open directory: %s", directory.c_str())); 24 | diff -Nuarp opencv-2.4.13.7/modules/core/src/matrix.cpp opencv-2.4.13.7.nortti/modules/core/src/matrix.cpp 25 | --- opencv-2.4.13.7/modules/core/src/matrix.cpp 2018-07-02 05:41:56.000000000 +0800 26 | +++ opencv-2.4.13.7.nortti/modules/core/src/matrix.cpp 2021-01-08 23:24:59.991085589 +0800 27 | @@ -279,7 +279,6 @@ Mat::Mat(const Mat& m, const Range& _row 28 | } 29 | 30 | *this = m; 31 | - try 32 | { 33 | if( _rowRange != Range::all() && _rowRange != Range(0,rows) ) 34 | { 35 | @@ -300,11 +299,6 @@ Mat::Mat(const Mat& m, const Range& _row 36 | flags |= SUBMATRIX_FLAG; 37 | } 38 | } 39 | - catch(...) 40 | - { 41 | - release(); 42 | - throw; 43 | - } 44 | 45 | if( rows == 1 ) 46 | flags |= CONTINUOUS_FLAG; 47 | diff -Nuarp opencv-2.4.13.7/modules/core/src/persistence.cpp opencv-2.4.13.7.nortti/modules/core/src/persistence.cpp 48 | --- opencv-2.4.13.7/modules/core/src/persistence.cpp 2018-07-02 05:41:56.000000000 +0800 49 | +++ opencv-2.4.13.7.nortti/modules/core/src/persistence.cpp 2021-01-08 23:25:39.470468027 +0800 50 | @@ -2918,18 +2918,12 @@ cvOpenFileStorage( const char* filename, 51 | 52 | //mode = cvGetErrMode(); 53 | //cvSetErrMode( CV_ErrModeSilent ); 54 | - try 55 | { 56 | if( fs->fmt == CV_STORAGE_FORMAT_XML ) 57 | icvXMLParse( fs ); 58 | else 59 | icvYMLParse( fs ); 60 | } 61 | - catch (...) 62 | - { 63 | - cvReleaseFileStorage( &fs ); 64 | - throw; 65 | - } 66 | //cvSetErrMode( mode ); 67 | 68 | // release resources that we do not need anymore 69 | @@ -4285,13 +4279,9 @@ icvReadSeq( CvFileStorage* fs, CvFileNod 70 | flags |= CV_SEQ_FLAG_HOLE; 71 | if( !strstr(flags_str, "untyped") ) 72 | { 73 | - try 74 | { 75 | flags |= icvDecodeSimpleFormat(dt); 76 | } 77 | - catch(...) 78 | - { 79 | - } 80 | } 81 | } 82 | 83 | diff -Nuarp opencv-2.4.13.7/modules/core/src/system.cpp opencv-2.4.13.7.nortti/modules/core/src/system.cpp 84 | --- opencv-2.4.13.7/modules/core/src/system.cpp 2018-07-02 05:41:56.000000000 +0800 85 | +++ opencv-2.4.13.7.nortti/modules/core/src/system.cpp 2021-01-08 23:25:56.543200966 +0800 86 | @@ -571,8 +571,6 @@ void error( const Exception& exc ) 87 | static volatile int* p = 0; 88 | *p = 0; 89 | } 90 | - 91 | - throw exc; 92 | } 93 | 94 | CvErrorCallback 95 | @@ -1160,14 +1158,9 @@ public: 96 | TLSDataContainer* k = tlsContainers_[key]; 97 | if (!k) 98 | return; 99 | - try 100 | { 101 | k->deleteDataInstance(data); 102 | } 103 | - catch (...) 104 | - { 105 | - CV_DbgAssert(k == NULL); // Debug this! 106 | - } 107 | } 108 | }; 109 | 110 | diff -Nuarp opencv-2.4.13.7/modules/imgproc/src/contours.cpp opencv-2.4.13.7.nortti/modules/imgproc/src/contours.cpp 111 | --- opencv-2.4.13.7/modules/imgproc/src/contours.cpp 2018-07-02 05:41:56.000000000 +0800 112 | +++ opencv-2.4.13.7.nortti/modules/imgproc/src/contours.cpp 2021-01-08 23:26:22.223799256 +0800 113 | @@ -1681,7 +1681,6 @@ cvFindContours( void* img, CvMemStorag 114 | } 115 | else 116 | { 117 | - try 118 | { 119 | scanner = cvStartFindContours( img, storage, cntHeaderSize, mode, method, offset ); 120 | 121 | @@ -1692,12 +1691,6 @@ cvFindContours( void* img, CvMemStorag 122 | } 123 | while( contour != 0 ); 124 | } 125 | - catch(...) 126 | - { 127 | - if( scanner ) 128 | - cvEndFindContours(&scanner); 129 | - throw; 130 | - } 131 | 132 | *firstContour = cvEndFindContours( &scanner ); 133 | } 134 | diff -Nuarp opencv-2.4.13.7/modules/photo/src/arrays.hpp opencv-2.4.13.7.nortti/modules/photo/src/arrays.hpp 135 | --- opencv-2.4.13.7/modules/photo/src/arrays.hpp 2018-07-02 05:41:56.000000000 +0800 136 | +++ opencv-2.4.13.7.nortti/modules/photo/src/arrays.hpp 2021-01-08 23:26:50.440357875 +0800 137 | @@ -52,7 +52,6 @@ template struct Array2d { 138 | { 139 | if (array2d.needToDeallocArray) { 140 | // copy constructor for self allocating arrays not supported 141 | - throw new exception(); 142 | } 143 | } 144 | 145 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-no-zlib.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/persistence.cpp opencv-2.4.13.7/modules/core/src/persistence.cpp 2 | --- opencv-2.4.13.7.orig/modules/core/src/persistence.cpp 2018-07-02 05:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7/modules/core/src/persistence.cpp 2021-02-25 00:07:23.031002590 +0800 4 | @@ -47,17 +47,7 @@ 5 | #include 6 | #include 7 | 8 | -#define USE_ZLIB 1 9 | - 10 | -#ifdef __APPLE__ 11 | -# include "TargetConditionals.h" 12 | -# if (defined TARGET_OS_IPHONE && TARGET_OS_IPHONE) || (defined TARGET_IPHONE_SIMULATOR && TARGET_IPHONE_SIMULATOR) 13 | -# undef USE_ZLIB 14 | -# define USE_ZLIB 0 15 | - typedef void* gzFile; 16 | -# endif 17 | -#endif 18 | - 19 | +#define USE_ZLIB 0 20 | #if USE_ZLIB 21 | # ifndef _LFS64_LARGEFILE 22 | # define _LFS64_LARGEFILE 0 23 | @@ -66,6 +56,8 @@ 24 | # define _FILE_OFFSET_BITS 0 25 | # endif 26 | # include 27 | +#else 28 | +typedef void* gzFile; 29 | #endif 30 | 31 | /****************************************************************************************\ 32 | -------------------------------------------------------------------------------- /patches/opencv-2.4.13.7-unsafe-xadd.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-2.4.13.7/modules/core/include/opencv2/core/operations.hpp opencv-2.4.13.7.unsafe_xadd/modules/core/include/opencv2/core/operations.hpp 2 | --- opencv-2.4.13.7/modules/core/include/opencv2/core/operations.hpp 2018-07-02 05:41:56.000000000 +0800 3 | +++ opencv-2.4.13.7.unsafe_xadd/modules/core/include/opencv2/core/operations.hpp 2021-05-11 15:43:01.953963662 +0800 4 | @@ -52,46 +52,8 @@ 5 | #ifdef __cplusplus 6 | 7 | /////// exchange-add operation for atomic operations on reference counters /////// 8 | -#ifdef CV_XADD 9 | - // allow to use user-defined macro 10 | -#elif defined __GNUC__ 11 | - 12 | - #if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) 13 | - #ifdef __ATOMIC_SEQ_CST 14 | - #define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), (delta), __ATOMIC_SEQ_CST) 15 | - #else 16 | - #define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), (delta), 5) 17 | - #endif 18 | - #elif __GNUC__*10 + __GNUC_MINOR__ >= 42 19 | - 20 | - #if !(defined WIN32 || defined _WIN32) && (defined __i486__ || defined __i586__ || \ 21 | - defined __i686__ || defined __MMX__ || defined __SSE__ || defined __ppc__) || \ 22 | - defined _STLPORT_MAJOR || defined _LIBCPP_VERSION || \ 23 | - defined __EMSCRIPTEN__ 24 | - 25 | - #define CV_XADD __sync_fetch_and_add 26 | - #else 27 | - #include 28 | - #define CV_XADD __gnu_cxx::__exchange_and_add 29 | - #endif 30 | - 31 | - #else 32 | - #include 33 | - #if __GNUC__*10 + __GNUC_MINOR__ >= 34 34 | - #define CV_XADD __gnu_cxx::__exchange_and_add 35 | - #else 36 | - #define CV_XADD __exchange_and_add 37 | - #endif 38 | - #endif 39 | - 40 | -#elif defined WIN32 || defined _WIN32 || defined WINCE 41 | - namespace cv { CV_EXPORTS int _interlockedExchangeAdd(int* addr, int delta); } 42 | - #define CV_XADD cv::_interlockedExchangeAdd 43 | - 44 | -#else 45 | - static inline int CV_XADD(int* addr, int delta) 46 | - { int tmp = *addr; *addr += delta; return tmp; } 47 | -#endif 48 | +static inline int CV_XADD(int* addr, int delta) 49 | +{ int tmp = *addr; *addr += delta; return tmp; } 50 | 51 | #include 52 | 53 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-drawing-mono-font.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/modules/imgproc/include/opencv2/imgproc.hpp opencv-3.4.20/modules/imgproc/include/opencv2/imgproc.hpp 2 | --- opencv-3.4.20.orig/modules/imgproc/include/opencv2/imgproc.hpp 2024-08-03 13:22:07.649774626 +0800 3 | +++ opencv-3.4.20/modules/imgproc/include/opencv2/imgproc.hpp 2024-08-03 13:23:14.297551785 +0800 4 | @@ -4912,6 +4912,37 @@ CV_EXPORTS_W double getFontScaleFromHeig 5 | const int pixelHeight, 6 | const int thickness = 1); 7 | 8 | +class FontFaceImpl; 9 | +class CV_EXPORTS_W FontFace 10 | +{ 11 | +public: 12 | + FontFace(); 13 | + FontFace(const String& fontPath); 14 | + 15 | + ~FontFace(); 16 | + 17 | +protected: 18 | + void set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps); 19 | + 20 | +public: 21 | + FontFaceImpl* const d; 22 | +}; 23 | + 24 | +enum PutTextFlags 25 | +{ 26 | + PUT_TEXT_ALIGN_LEFT=0, // put the text to the right from the origin 27 | + PUT_TEXT_ALIGN_CENTER=1,// center the text at the origin; not implemented yet 28 | + PUT_TEXT_ALIGN_RIGHT=2, // put the text to the left of the origin 29 | + PUT_TEXT_ALIGN_MASK=3, // alignment mask 30 | + PUT_TEXT_ORIGIN_TL=0, 31 | + PUT_TEXT_ORIGIN_BL=32, // treat the target image as having bottom-left origin 32 | + PUT_TEXT_WRAP=128 // wrap text to the next line if it does not fit 33 | +}; 34 | + 35 | +CV_EXPORTS_W Point putText(InputOutputArray img, const String &text, Point org, Scalar color, const FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 36 | + 37 | +CV_EXPORTS_W Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 38 | + 39 | /** @brief Class for iterating over all pixels on a raster line segment. 40 | 41 | The class LineIterator is used to get each pixel of a raster line connecting 42 | diff -Nuarp opencv-3.4.20.orig/modules/imgproc/src/drawing.cpp opencv-3.4.20/modules/imgproc/src/drawing.cpp 43 | --- opencv-3.4.20.orig/modules/imgproc/src/drawing.cpp 2024-08-03 13:22:07.653774613 +0800 44 | +++ opencv-3.4.20/modules/imgproc/src/drawing.cpp 2024-08-03 13:30:01.392190643 +0800 45 | @@ -42,6 +42,25 @@ 46 | 47 | namespace cv 48 | { 49 | +class FontFaceImpl 50 | +{ 51 | +public: 52 | + FontFaceImpl(); 53 | + 54 | +public: 55 | + int glyph_count; 56 | + const unsigned int* glyph_unicode; 57 | + const unsigned char* glyph_bitmaps; 58 | + 59 | +public: 60 | + const unsigned char* get_glyph_bitmap(unsigned int ch) const; 61 | +}; 62 | +} 63 | + 64 | +#include "draw_text.h" 65 | + 66 | +namespace cv 67 | +{ 68 | 69 | enum { XY_SHIFT = 16, XY_ONE = 1 << XY_SHIFT, DRAWING_STORAGE_BLOCK = (1<<12) - 256 }; 70 | 71 | @@ -2051,6 +2070,7 @@ void polylines( Mat& img, const Point* c 72 | } 73 | 74 | 75 | +#if 0 76 | enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8), 77 | FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8), 78 | FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8), 79 | @@ -2265,6 +2285,7 @@ inline void readCheck(int &c, int &i, co 80 | } 81 | 82 | extern const char* g_HersheyGlyphs[]; 83 | +#endif 84 | 85 | void putText( InputOutputArray _img, const String& text, Point org, 86 | int fontFace, double fontScale, Scalar color, 87 | @@ -2278,6 +2299,35 @@ void putText( InputOutputArray _img, con 88 | return; 89 | } 90 | Mat img = _img.getMat(); 91 | + 92 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 93 | + const int base_line = 0; 94 | + const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line; 95 | + 96 | + unsigned int _color = 0; 97 | + unsigned char* border_color = (unsigned char*)&_color; 98 | + 99 | + if (img.channels() == 1) 100 | + { 101 | + border_color[0] = color[0]; 102 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 103 | + } 104 | + else if (img.channels() == 3) 105 | + { 106 | + border_color[0] = color[0]; 107 | + border_color[1] = color[1]; 108 | + border_color[2] = color[2]; 109 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 110 | + } 111 | + else if (img.channels() == 4) 112 | + { 113 | + border_color[0] = color[0]; 114 | + border_color[1] = color[1]; 115 | + border_color[2] = color[2]; 116 | + border_color[3] = color[3]; 117 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 118 | + } 119 | +#if 0 120 | const int* ascii = getFontData(fontFace); 121 | 122 | double buf[4]; 123 | @@ -2332,10 +2382,21 @@ void putText( InputOutputArray _img, con 124 | } 125 | view_x += dx; 126 | } 127 | +#endif 128 | } 129 | 130 | Size getTextSize( const String& text, int fontFace, double fontScale, int thickness, int* _base_line) 131 | { 132 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 133 | + 134 | + int w; 135 | + int h; 136 | + get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h); 137 | + 138 | + if(_base_line) *_base_line = 0; 139 | + 140 | + return Size(w, h); 141 | +#if 0 142 | Size size; 143 | double view_x = 0; 144 | const char **faces = cv::g_HersheyGlyphs; 145 | @@ -2362,10 +2423,13 @@ Size getTextSize( const String& text, in 146 | if( _base_line ) 147 | *_base_line = cvRound(base_line*fontScale + thickness*0.5); 148 | return size; 149 | +#endif 150 | } 151 | 152 | double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness) 153 | { 154 | + return pixelHeight / (fontFace == 1 ? 16 : (fontFace == 5 ? 24 : 40)); 155 | +#if 0 156 | // By https://stackoverflow.com/a/27898487/1531708 157 | const int* ascii = getFontData(fontFace); 158 | 159 | @@ -2373,6 +2437,96 @@ double getFontScaleFromHeight(const int 160 | int cap_line = (ascii[0] >> 4) & 15; 161 | 162 | return static_cast(pixelHeight - static_cast((thickness + 1)) / 2.0) / static_cast(cap_line + base_line); 163 | +#endif 164 | +} 165 | + 166 | +FontFaceImpl::FontFaceImpl() 167 | +{ 168 | + glyph_count = 0; 169 | + glyph_unicode = 0; 170 | + glyph_bitmaps = 0; 171 | +} 172 | + 173 | +const unsigned char* FontFaceImpl::get_glyph_bitmap(unsigned int ch) const 174 | +{ 175 | + if (!glyph_count || !glyph_unicode || !glyph_bitmaps) 176 | + return 0; 177 | + 178 | + for (int i = 0; i < glyph_count; i++) 179 | + { 180 | + if (glyph_unicode[i] == ch) 181 | + return glyph_bitmaps + i * 40 * 20; 182 | + } 183 | + 184 | + return 0; 185 | +} 186 | + 187 | +FontFace::FontFace() : d(new FontFaceImpl) 188 | +{ 189 | +} 190 | + 191 | +FontFace::~FontFace() 192 | +{ 193 | + delete d; 194 | +} 195 | + 196 | +void FontFace::set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps) 197 | +{ 198 | + d->glyph_count = count; 199 | + d->glyph_unicode = unicode; 200 | + d->glyph_bitmaps = bitmaps; 201 | +} 202 | + 203 | +Point putText(InputOutputArray _img, const String& text, Point org, Scalar color, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 204 | +{ 205 | + CV_INSTRUMENT_REGION(); 206 | + 207 | + if ( text.empty() ) 208 | + { 209 | + return org; 210 | + } 211 | + Mat img = _img.getMat(); 212 | + 213 | + const int yoffset = org.y - size * 2; 214 | + 215 | + unsigned int _color = 0; 216 | + unsigned char* border_color = (unsigned char*)&_color; 217 | + 218 | + if (img.channels() == 1) 219 | + { 220 | + border_color[0] = color[0]; 221 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 222 | + } 223 | + else if (img.channels() == 3) 224 | + { 225 | + border_color[0] = color[0]; 226 | + border_color[1] = color[1]; 227 | + border_color[2] = color[2]; 228 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 229 | + } 230 | + else if (img.channels() == 4) 231 | + { 232 | + border_color[0] = color[0]; 233 | + border_color[1] = color[1]; 234 | + border_color[2] = color[2]; 235 | + border_color[3] = color[3]; 236 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 237 | + } 238 | + 239 | + int w; 240 | + int h; 241 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 242 | + 243 | + return Point(org.x + w, org.y); 244 | +} 245 | + 246 | +Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 247 | +{ 248 | + int w; 249 | + int h; 250 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 251 | + 252 | + return Rect(org.x, org.y - size * 2, w, h); 253 | } 254 | 255 | } 256 | @@ -2879,7 +3033,7 @@ cvInitFont( CvFont *font, int font_face, 257 | { 258 | CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 ); 259 | 260 | - font->ascii = cv::getFontData(font_face); 261 | + font->ascii = 0; 262 | font->font_face = font_face; 263 | font->hscale = (float)hscale; 264 | font->vscale = (float)vscale; 265 | diff -Nuarp opencv-3.4.20.orig/modules/imgproc/src/hershey_fonts.cpp opencv-3.4.20/modules/imgproc/src/hershey_fonts.cpp 266 | --- opencv-3.4.20.orig/modules/imgproc/src/hershey_fonts.cpp 2024-08-03 13:22:07.654774610 +0800 267 | +++ opencv-3.4.20/modules/imgproc/src/hershey_fonts.cpp 2024-08-03 13:22:25.006716593 +0800 268 | @@ -51,6 +51,7 @@ 269 | namespace cv 270 | { 271 | 272 | +#if 0 273 | const char* g_HersheyGlyphs[] = { 274 | "", 275 | "MWRMNV RMVV PSTS", 276 | @@ -3353,6 +3354,7 @@ const char* g_HersheyGlyphs[] = { 277 | "", 278 | "", 279 | 0 }; 280 | +#endif 281 | 282 | } 283 | 284 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-fix-emscripten-include.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/modules/core/include/opencv2/core/hal/intrin_wasm.hpp opencv-3.4.20/modules/core/include/opencv2/core/hal/intrin_wasm.hpp 2 | --- opencv-3.4.20.orig/modules/core/include/opencv2/core/hal/intrin_wasm.hpp 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/modules/core/include/opencv2/core/hal/intrin_wasm.hpp 2023-08-06 19:09:44.971191540 +0800 4 | @@ -8,6 +8,7 @@ 5 | #include 6 | #include 7 | #include 8 | +#include 9 | #include "opencv2/core/saturate.hpp" 10 | 11 | #define CV_SIMD128 1 12 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-fix-windows-arm-arch.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-3.4.20/cmake/OpenCVDetectCXXCompiler.cmake 2 | --- opencv-3.4.20.orig/cmake/OpenCVDetectCXXCompiler.cmake 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/cmake/OpenCVDetectCXXCompiler.cmake 2024-06-10 14:54:29.392187073 +0800 4 | @@ -143,9 +143,9 @@ elseif(MSVC) 5 | # see Modules/CMakeGenericSystem.cmake 6 | if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 7 | set(OpenCV_ARCH "x64") 8 | - elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") 9 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 10 | set(OpenCV_ARCH "ARM64") 11 | - elseif("${CMAKE_GENERATOR}" MATCHES "ARM") 12 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 13 | set(OpenCV_ARCH "ARM") 14 | elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 15 | set(OpenCV_ARCH "x64") 16 | diff -Nuarp opencv-3.4.20.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in opencv-3.4.20/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 17 | --- opencv-3.4.20.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2023-06-27 19:29:13.000000000 +0800 18 | +++ opencv-3.4.20/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2024-06-10 14:54:43.583157025 +0800 19 | @@ -99,9 +99,9 @@ elseif(MSVC) 20 | # see Modules/CMakeGenericSystem.cmake 21 | if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 22 | set(OpenCV_ARCH "x64") 23 | - elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") 24 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 25 | set(OpenCV_ARCH "ARM64") 26 | - elseif("${CMAKE_GENERATOR}" MATCHES "ARM") 27 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 28 | set(OpenCV_ARCH "ARM") 29 | elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 30 | set(OpenCV_ARCH "x64") 31 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-link-openmp.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake opencv-3.4.20/cmake/OpenCVGenConfig.cmake 2 | --- opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/cmake/OpenCVGenConfig.cmake 2023-08-30 11:59:03.095856713 +0800 4 | @@ -15,6 +15,10 @@ if(HAVE_CUDA) 5 | ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-CUDA.cmake.in" CUDA_CONFIGCMAKE @ONLY) 6 | endif() 7 | 8 | +if(HAVE_OPENMP) 9 | + ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-OPENMP.cmake.in" OPENMP_CONFIGCMAKE @ONLY) 10 | +endif() 11 | + 12 | if(ANDROID) 13 | if(NOT ANDROID_NATIVE_API_LEVEL) 14 | set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0) 15 | diff -Nuarp opencv-3.4.20.orig/cmake/templates/OpenCVConfig.cmake.in opencv-3.4.20/cmake/templates/OpenCVConfig.cmake.in 16 | --- opencv-3.4.20.orig/cmake/templates/OpenCVConfig.cmake.in 2023-06-27 19:29:13.000000000 +0800 17 | +++ opencv-3.4.20/cmake/templates/OpenCVConfig.cmake.in 2023-08-30 11:59:19.223817499 +0800 18 | @@ -94,6 +94,7 @@ endif() 19 | 20 | 21 | @CUDA_CONFIGCMAKE@ 22 | +@OPENMP_CONFIGCMAKE@ 23 | @ANDROID_CONFIGCMAKE@ 24 | 25 | @IPPICV_CONFIGCMAKE@ 26 | diff -Nuarp opencv-3.4.20.orig/cmake/templates/OpenCVConfig-OPENMP.cmake.in opencv-3.4.20/cmake/templates/OpenCVConfig-OPENMP.cmake.in 27 | --- opencv-3.4.20.orig/cmake/templates/OpenCVConfig-OPENMP.cmake.in 1970-01-01 08:00:00.000000000 +0800 28 | +++ opencv-3.4.20/cmake/templates/OpenCVConfig-OPENMP.cmake.in 2023-08-30 11:58:12.298980226 +0800 29 | @@ -0,0 +1,5 @@ 30 | +set(OpenCV_USE_OPENMP "@HAVE_OPENMP@") 31 | + 32 | +if(OpenCV_USE_OPENMP) 33 | + find_package(OpenMP) 34 | +endif() 35 | diff -Nuarp opencv-3.4.20.orig/modules/core/CMakeLists.txt opencv-3.4.20/modules/core/CMakeLists.txt 36 | --- opencv-3.4.20.orig/modules/core/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800 37 | +++ opencv-3.4.20/modules/core/CMakeLists.txt 2023-08-30 12:13:56.534064133 +0800 38 | @@ -113,6 +113,16 @@ ocv_target_link_libraries(${the_module} 39 | "${OPENCV_HAL_LINKER_LIBS}" 40 | ) 41 | 42 | +if(HAVE_OPENMP) 43 | + if(ANDROID_NDK_MAJOR AND (ANDROID_NDK_MAJOR GREATER 20)) 44 | + ocv_target_link_libraries(${the_module} PUBLIC "-fopenmp" "-static-openmp") 45 | + elseif(OpenMP_CXX_FOUND) 46 | + ocv_target_link_libraries(${the_module} PUBLIC OpenMP::OpenMP_CXX) 47 | + else() 48 | + ocv_target_link_libraries(${the_module} PUBLIC "${OpenMP_CXX_FLAGS}") 49 | + endif() 50 | +endif() 51 | + 52 | if(OPENCV_CORE_EXCLUDE_C_API) 53 | ocv_target_compile_definitions(${the_module} PRIVATE "OPENCV_EXCLUDE_C_API=1") 54 | endif() 55 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-minimal-install.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVGenAndroidMK.cmake opencv-3.4.20/cmake/OpenCVGenAndroidMK.cmake 2 | --- opencv-3.4.20.orig/cmake/OpenCVGenAndroidMK.cmake 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/cmake/OpenCVGenAndroidMK.cmake 2023-12-09 21:22:23.522506093 +0800 4 | @@ -76,6 +76,4 @@ if(ANDROID) 5 | 6 | configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY) 7 | configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV-abi.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk" @ONLY) 8 | - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) 9 | - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) 10 | endif(ANDROID) 11 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake opencv-3.4.20/cmake/OpenCVGenConfig.cmake 12 | --- opencv-3.4.20.orig/cmake/OpenCVGenConfig.cmake 2023-12-09 16:58:42.567073866 +0800 13 | +++ opencv-3.4.20/cmake/OpenCVGenConfig.cmake 2023-12-09 21:22:42.614401178 +0800 14 | @@ -119,7 +119,6 @@ endif() 15 | 16 | if(ANDROID) 17 | ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in") 18 | - install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev) 19 | endif() 20 | 21 | # -------------------------------------------------------------------------------------------- 22 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVUtils.cmake opencv-3.4.20/cmake/OpenCVUtils.cmake 23 | --- opencv-3.4.20.orig/cmake/OpenCVUtils.cmake 2023-06-27 19:29:13.000000000 +0800 24 | +++ opencv-3.4.20/cmake/OpenCVUtils.cmake 2023-12-09 21:24:36.516775258 +0800 25 | @@ -976,11 +976,6 @@ macro(ocv_finalize_status) 26 | endif() 27 | endif() 28 | 29 | - if(UNIX) 30 | - install(FILES "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind.supp" 31 | - "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind_3rdparty.supp" 32 | - DESTINATION "${OPENCV_OTHER_INSTALL_PATH}" COMPONENT "dev") 33 | - endif() 34 | endmacro() 35 | 36 | 37 | diff -Nuarp opencv-3.4.20.orig/CMakeLists.txt opencv-3.4.20/CMakeLists.txt 38 | --- opencv-3.4.20.orig/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800 39 | +++ opencv-3.4.20/CMakeLists.txt 2023-12-10 12:43:21.573441566 +0800 40 | @@ -903,24 +903,13 @@ ocv_add_modules_compiler_options() 41 | add_subdirectory(modules) 42 | 43 | # Generate targets for documentation 44 | -add_subdirectory(doc) 45 | 46 | # various data that is used by cv libraries and/or demo applications. 47 | -add_subdirectory(data) 48 | 49 | # extra applications 50 | -if(BUILD_opencv_apps) 51 | - add_subdirectory(apps) 52 | -endif() 53 | 54 | # examples 55 | -if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES) 56 | - add_subdirectory(samples) 57 | -endif() 58 | 59 | -if(ANDROID) 60 | - add_subdirectory(platforms/android/service) 61 | -endif() 62 | 63 | # ---------------------------------------------------------------------------- 64 | # Finalization: generate configuration-based files 65 | @@ -932,22 +921,13 @@ ocv_cmake_hook(PRE_FINALIZE) 66 | include(cmake/OpenCVGenHeaders.cmake) 67 | 68 | # Generate opencv.pc for pkg-config command 69 | -if(NOT OPENCV_SKIP_PKGCONFIG_GENERATION 70 | - AND OPENCV_GENERATE_PKGCONFIG 71 | - AND NOT CMAKE_GENERATOR MATCHES "Xcode") 72 | - include(cmake/OpenCVGenPkgconfig.cmake) 73 | -endif() 74 | 75 | # Generate OpenCV.mk for ndk-build (Android build tool) 76 | -include(cmake/OpenCVGenAndroidMK.cmake) 77 | 78 | # Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects 79 | include(cmake/OpenCVGenConfig.cmake) 80 | 81 | # Generate Info.plist for the IOS framework 82 | -if(APPLE_FRAMEWORK) 83 | - include(cmake/OpenCVGenInfoPlist.cmake) 84 | -endif() 85 | 86 | # Generate ABI descriptor 87 | include(cmake/OpenCVGenABI.cmake) 88 | @@ -973,12 +953,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA 89 | endif() 90 | endif() 91 | 92 | -if(NOT OPENCV_README_FILE) 93 | - if(ANDROID) 94 | - set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android) 95 | - endif() 96 | -endif() 97 | - 98 | if(NOT OPENCV_LICENSE_FILE) 99 | set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) 100 | endif() 101 | @@ -988,11 +962,6 @@ if(ANDROID OR NOT UNIX) 102 | install(FILES ${OPENCV_LICENSE_FILE} 103 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 104 | DESTINATION ./ COMPONENT libs) 105 | - if(OPENCV_README_FILE) 106 | - install(FILES ${OPENCV_README_FILE} 107 | - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 108 | - DESTINATION ./ COMPONENT libs) 109 | - endif() 110 | endif() 111 | 112 | if(COMMAND ocv_pylint_finalize) 113 | diff -Nuarp opencv-3.4.20.orig/data/CMakeLists.txt opencv-3.4.20/data/CMakeLists.txt 114 | --- opencv-3.4.20.orig/data/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800 115 | +++ opencv-3.4.20/data/CMakeLists.txt 2023-12-09 21:23:02.838290043 +0800 116 | @@ -1,9 +1,6 @@ 117 | file(GLOB HAAR_CASCADES haarcascades/*.xml) 118 | file(GLOB LBP_CASCADES lbpcascades/*.xml) 119 | 120 | -install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs) 121 | -install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs) 122 | - 123 | if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) 124 | install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests") 125 | endif() 126 | diff -Nuarp opencv-3.4.20.orig/platforms/android/service/CMakeLists.txt opencv-3.4.20/platforms/android/service/CMakeLists.txt 127 | --- opencv-3.4.20.orig/platforms/android/service/CMakeLists.txt 2023-06-27 19:29:13.000000000 +0800 128 | +++ opencv-3.4.20/platforms/android/service/CMakeLists.txt 2023-12-09 21:23:41.098079796 +0800 129 | @@ -1,5 +1,3 @@ 130 | if(BUILD_ANDROID_SERVICE) 131 | add_subdirectory(engine) 132 | endif() 133 | - 134 | -install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs) 135 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-newer-msvc.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-3.4.20/cmake/OpenCVDetectCXXCompiler.cmake 2 | --- opencv-3.4.20.orig/cmake/OpenCVDetectCXXCompiler.cmake 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/cmake/OpenCVDetectCXXCompiler.cmake 2024-06-10 14:47:05.286016469 +0800 4 | @@ -169,7 +169,7 @@ elseif(MSVC) 5 | set(OpenCV_RUNTIME vc15) 6 | elseif(MSVC_VERSION MATCHES "^192[0-9]$") 7 | set(OpenCV_RUNTIME vc16) 8 | - elseif(MSVC_VERSION MATCHES "^193[0-9]$") 9 | + elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") 10 | set(OpenCV_RUNTIME vc17) 11 | else() 12 | message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME") 13 | diff -Nuarp opencv-3.4.20.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in opencv-3.4.20/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 14 | --- opencv-3.4.20.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2023-06-27 19:29:13.000000000 +0800 15 | +++ opencv-3.4.20/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2024-06-10 14:46:17.345712729 +0800 16 | @@ -137,7 +137,7 @@ elseif(MSVC) 17 | set(OpenCV_RUNTIME vc14) # selecting previous compatible runtime version 18 | endif() 19 | endif() 20 | - elseif(MSVC_VERSION MATCHES "^193[0-9]$") 21 | + elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") 22 | set(OpenCV_RUNTIME vc17) 23 | check_one_config(has_VS2022) 24 | if(NOT has_VS2022) 25 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-no-zlib.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/modules/core/src/persistence.hpp opencv-3.4.20/modules/core/src/persistence.hpp 2 | --- opencv-3.4.20.orig/modules/core/src/persistence.hpp 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/modules/core/src/persistence.hpp 2023-08-06 11:09:02.718289684 +0800 4 | @@ -12,7 +12,7 @@ 5 | #include 6 | #include 7 | 8 | -#define USE_ZLIB 1 9 | +#define USE_ZLIB 0 10 | #if USE_ZLIB 11 | # ifndef _LFS64_LARGEFILE 12 | # define _LFS64_LARGEFILE 0 13 | -------------------------------------------------------------------------------- /patches/opencv-3.4.20-unsafe-xadd.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-3.4.20.orig/modules/core/include/opencv2/core/cvdef.h opencv-3.4.20/modules/core/include/opencv2/core/cvdef.h 2 | --- opencv-3.4.20.orig/modules/core/include/opencv2/core/cvdef.h 2023-06-27 19:29:13.000000000 +0800 3 | +++ opencv-3.4.20/modules/core/include/opencv2/core/cvdef.h 2023-08-06 11:12:38.619404492 +0800 4 | @@ -534,33 +534,7 @@ Cv64suf; 5 | * exchange-add operation for atomic operations on reference counters * 6 | \****************************************************************************************/ 7 | 8 | -#ifdef CV_XADD 9 | - // allow to use user-defined macro 10 | -#elif defined __GNUC__ || defined __clang__ 11 | -# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER 12 | -# ifdef __ATOMIC_ACQ_REL 13 | -# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) 14 | -# else 15 | -# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4) 16 | -# endif 17 | -# else 18 | -# if defined __ATOMIC_ACQ_REL && !defined __clang__ 19 | - // version for gcc >= 4.7 20 | -# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL) 21 | -# else 22 | -# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) 23 | -# endif 24 | -# endif 25 | -#elif defined _MSC_VER && !defined RC_INVOKED 26 | -# include 27 | -# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) 28 | -#else 29 | - #ifdef OPENCV_FORCE_UNSAFE_XADD 30 | - CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } 31 | - #else 32 | - #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)" 33 | - #endif 34 | -#endif 35 | +CV_INLINE int CV_XADD(void* addr, int delta) { int tmp = *(int*)addr; *(int*)addr += delta; return tmp; } 36 | 37 | 38 | /****************************************************************************************\ 39 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-drawing-mono-font.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/modules/imgproc/include/opencv2/imgproc.hpp opencv-4.11.0/modules/imgproc/include/opencv2/imgproc.hpp 2 | --- opencv-4.11.0.orig/modules/imgproc/include/opencv2/imgproc.hpp 2025-01-19 00:07:25.706895750 +0800 3 | +++ opencv-4.11.0/modules/imgproc/include/opencv2/imgproc.hpp 2025-01-19 00:19:27.955301521 +0800 4 | @@ -4929,6 +4929,37 @@ CV_EXPORTS_W double getFontScaleFromHeig 5 | const int pixelHeight, 6 | const int thickness = 1); 7 | 8 | +class FontFaceImpl; 9 | +class CV_EXPORTS_W FontFace 10 | +{ 11 | +public: 12 | + FontFace(); 13 | + FontFace(const String& fontPath); 14 | + 15 | + ~FontFace(); 16 | + 17 | +protected: 18 | + void set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps); 19 | + 20 | +public: 21 | + FontFaceImpl* const d; 22 | +}; 23 | + 24 | +enum PutTextFlags 25 | +{ 26 | + PUT_TEXT_ALIGN_LEFT=0, // put the text to the right from the origin 27 | + PUT_TEXT_ALIGN_CENTER=1,// center the text at the origin; not implemented yet 28 | + PUT_TEXT_ALIGN_RIGHT=2, // put the text to the left of the origin 29 | + PUT_TEXT_ALIGN_MASK=3, // alignment mask 30 | + PUT_TEXT_ORIGIN_TL=0, 31 | + PUT_TEXT_ORIGIN_BL=32, // treat the target image as having bottom-left origin 32 | + PUT_TEXT_WRAP=128 // wrap text to the next line if it does not fit 33 | +}; 34 | + 35 | +CV_EXPORTS_W Point putText(InputOutputArray img, const String &text, Point org, Scalar color, const FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 36 | + 37 | +CV_EXPORTS_W Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range()); 38 | + 39 | /** @brief Class for iterating over all pixels on a raster line segment. 40 | 41 | The class LineIterator is used to get each pixel of a raster line connecting 42 | diff -Nuarp opencv-4.11.0.orig/modules/imgproc/src/drawing.cpp opencv-4.11.0/modules/imgproc/src/drawing.cpp 43 | --- opencv-4.11.0.orig/modules/imgproc/src/drawing.cpp 2025-01-19 00:07:25.768896509 +0800 44 | +++ opencv-4.11.0/modules/imgproc/src/drawing.cpp 2025-01-19 00:24:39.379680129 +0800 45 | @@ -43,6 +43,25 @@ using namespace cv; 46 | 47 | namespace cv 48 | { 49 | +class FontFaceImpl 50 | +{ 51 | +public: 52 | + FontFaceImpl(); 53 | + 54 | +public: 55 | + int glyph_count; 56 | + const unsigned int* glyph_unicode; 57 | + const unsigned char* glyph_bitmaps; 58 | + 59 | +public: 60 | + const unsigned char* get_glyph_bitmap(unsigned int ch) const; 61 | +}; 62 | +} 63 | + 64 | +#include "draw_text.h" 65 | + 66 | +namespace cv 67 | +{ 68 | enum { XY_SHIFT = 16, XY_ONE = 1 << XY_SHIFT, DRAWING_STORAGE_BLOCK = (1<<12) - 256 }; 69 | 70 | static const int MAX_THICKNESS = 32767; 71 | @@ -2069,6 +2088,7 @@ void polylines( InputOutputArray _img, c 72 | } 73 | 74 | 75 | +#if 0 76 | enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8), 77 | FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8), 78 | FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8), 79 | @@ -2283,6 +2303,7 @@ inline void readCheck(int &c, int &i, co 80 | } 81 | 82 | extern const char* g_HersheyGlyphs[]; 83 | +#endif 84 | 85 | void putText( InputOutputArray _img, const String& text, Point org, 86 | int fontFace, double fontScale, Scalar color, 87 | @@ -2296,6 +2317,35 @@ void putText( InputOutputArray _img, con 88 | return; 89 | } 90 | Mat img = _img.getMat(); 91 | + 92 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 93 | + const int base_line = 0; 94 | + const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line; 95 | + 96 | + unsigned int _color = 0; 97 | + unsigned char* border_color = (unsigned char*)&_color; 98 | + 99 | + if (img.channels() == 1) 100 | + { 101 | + border_color[0] = color[0]; 102 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 103 | + } 104 | + else if (img.channels() == 3) 105 | + { 106 | + border_color[0] = color[0]; 107 | + border_color[1] = color[1]; 108 | + border_color[2] = color[2]; 109 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 110 | + } 111 | + else if (img.channels() == 4) 112 | + { 113 | + border_color[0] = color[0]; 114 | + border_color[1] = color[1]; 115 | + border_color[2] = color[2]; 116 | + border_color[3] = color[3]; 117 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); 118 | + } 119 | +#if 0 120 | const int* ascii = getFontData(fontFace); 121 | 122 | double buf[4]; 123 | @@ -2350,10 +2400,21 @@ void putText( InputOutputArray _img, con 124 | } 125 | view_x += dx; 126 | } 127 | +#endif 128 | } 129 | 130 | Size getTextSize( const String& text, int fontFace, double fontScale, int thickness, int* _base_line) 131 | { 132 | + const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale; 133 | + 134 | + int w; 135 | + int h; 136 | + get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h); 137 | + 138 | + if(_base_line) *_base_line = 0; 139 | + 140 | + return Size(w, h); 141 | +#if 0 142 | Size size; 143 | double view_x = 0; 144 | const char **faces = cv::g_HersheyGlyphs; 145 | @@ -2380,10 +2441,13 @@ Size getTextSize( const String& text, in 146 | if( _base_line ) 147 | *_base_line = cvRound(base_line*fontScale + thickness*0.5); 148 | return size; 149 | +#endif 150 | } 151 | 152 | double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness) 153 | { 154 | + return pixelHeight / (fontFace == 1 ? 16 : (fontFace == 5 ? 24 : 40)); 155 | +#if 0 156 | // By https://stackoverflow.com/a/27898487/1531708 157 | const int* ascii = getFontData(fontFace); 158 | 159 | @@ -2391,6 +2455,96 @@ double getFontScaleFromHeight(const int 160 | int cap_line = (ascii[0] >> 4) & 15; 161 | 162 | return static_cast(pixelHeight - static_cast((thickness + 1)) / 2.0) / static_cast(cap_line + base_line); 163 | +#endif 164 | +} 165 | + 166 | +FontFaceImpl::FontFaceImpl() 167 | +{ 168 | + glyph_count = 0; 169 | + glyph_unicode = 0; 170 | + glyph_bitmaps = 0; 171 | +} 172 | + 173 | +const unsigned char* FontFaceImpl::get_glyph_bitmap(unsigned int ch) const 174 | +{ 175 | + if (!glyph_count || !glyph_unicode || !glyph_bitmaps) 176 | + return 0; 177 | + 178 | + for (int i = 0; i < glyph_count; i++) 179 | + { 180 | + if (glyph_unicode[i] == ch) 181 | + return glyph_bitmaps + i * 40 * 20; 182 | + } 183 | + 184 | + return 0; 185 | +} 186 | + 187 | +FontFace::FontFace() : d(new FontFaceImpl) 188 | +{ 189 | +} 190 | + 191 | +FontFace::~FontFace() 192 | +{ 193 | + delete d; 194 | +} 195 | + 196 | +void FontFace::set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps) 197 | +{ 198 | + d->glyph_count = count; 199 | + d->glyph_unicode = unicode; 200 | + d->glyph_bitmaps = bitmaps; 201 | +} 202 | + 203 | +Point putText(InputOutputArray _img, const String& text, Point org, Scalar color, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 204 | +{ 205 | + CV_INSTRUMENT_REGION(); 206 | + 207 | + if ( text.empty() ) 208 | + { 209 | + return org; 210 | + } 211 | + Mat img = _img.getMat(); 212 | + 213 | + const int yoffset = org.y - size * 2; 214 | + 215 | + unsigned int _color = 0; 216 | + unsigned char* border_color = (unsigned char*)&_color; 217 | + 218 | + if (img.channels() == 1) 219 | + { 220 | + border_color[0] = color[0]; 221 | + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 222 | + } 223 | + else if (img.channels() == 3) 224 | + { 225 | + border_color[0] = color[0]; 226 | + border_color[1] = color[1]; 227 | + border_color[2] = color[2]; 228 | + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 229 | + } 230 | + else if (img.channels() == 4) 231 | + { 232 | + border_color[0] = color[0]; 233 | + border_color[1] = color[1]; 234 | + border_color[2] = color[2]; 235 | + border_color[3] = color[3]; 236 | + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, size, _color, fontface); 237 | + } 238 | + 239 | + int w; 240 | + int h; 241 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 242 | + 243 | + return Point(org.x + w, org.y); 244 | +} 245 | + 246 | +Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap) 247 | +{ 248 | + int w; 249 | + int h; 250 | + get_text_drawing_size(text.c_str(), size, &w, &h, fontface); 251 | + 252 | + return Rect(org.x, org.y - size * 2, w, h); 253 | } 254 | 255 | } 256 | @@ -2870,7 +3024,7 @@ cvInitFont( CvFont *font, int font_face, 257 | { 258 | CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 ); 259 | 260 | - font->ascii = cv::getFontData(font_face); 261 | + font->ascii = 0; 262 | font->font_face = font_face; 263 | font->hscale = (float)hscale; 264 | font->vscale = (float)vscale; 265 | diff -Nuarp opencv-4.11.0.orig/modules/imgproc/src/hershey_fonts.cpp opencv-4.11.0/modules/imgproc/src/hershey_fonts.cpp 266 | --- opencv-4.11.0.orig/modules/imgproc/src/hershey_fonts.cpp 2025-01-19 00:07:25.781896668 +0800 267 | +++ opencv-4.11.0/modules/imgproc/src/hershey_fonts.cpp 2025-01-19 00:19:27.956301532 +0800 268 | @@ -51,6 +51,7 @@ 269 | namespace cv 270 | { 271 | 272 | +#if 0 273 | const char* g_HersheyGlyphs[] = { 274 | "", 275 | "MWRMNV RMVV PSTS", 276 | @@ -3353,6 +3354,7 @@ const char* g_HersheyGlyphs[] = { 277 | "", 278 | "", 279 | 0 }; 280 | +#endif 281 | 282 | } 283 | 284 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-fix-windows-arm-arch.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/cmake/OpenCVDetectCXXCompiler.cmake opencv-4.11.0/cmake/OpenCVDetectCXXCompiler.cmake 2 | --- opencv-4.11.0.orig/cmake/OpenCVDetectCXXCompiler.cmake 2025-01-18 23:31:52.784608127 +0800 3 | +++ opencv-4.11.0/cmake/OpenCVDetectCXXCompiler.cmake 2025-01-18 23:48:03.298849297 +0800 4 | @@ -154,9 +154,9 @@ elseif(MSVC) 5 | # see Modules/CMakeGenericSystem.cmake 6 | if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 7 | set(OpenCV_ARCH "x64") 8 | - elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") 9 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 10 | set(OpenCV_ARCH "ARM64") 11 | - elseif("${CMAKE_GENERATOR}" MATCHES "ARM") 12 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 13 | set(OpenCV_ARCH "ARM") 14 | elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 15 | set(OpenCV_ARCH "x64") 16 | diff -Nuarp opencv-4.11.0.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in opencv-4.11.0/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 17 | --- opencv-4.11.0.orig/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2025-01-18 23:31:52.785608139 +0800 18 | +++ opencv-4.11.0/cmake/templates/OpenCVConfig.root-WIN32.cmake.in 2025-01-18 23:48:03.298849297 +0800 19 | @@ -99,9 +99,9 @@ elseif(MSVC) 20 | # see Modules/CMakeGenericSystem.cmake 21 | if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)") 22 | set(OpenCV_ARCH "x64") 23 | - elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") 24 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM64|arm64)") 25 | set(OpenCV_ARCH "ARM64") 26 | - elseif("${CMAKE_GENERATOR}" MATCHES "ARM") 27 | + elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(ARM|arm)") 28 | set(OpenCV_ARCH "ARM") 29 | elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") 30 | set(OpenCV_ARCH "x64") 31 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-link-openmp.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/cmake/OpenCVGenConfig.cmake opencv-4.11.0/cmake/OpenCVGenConfig.cmake 2 | --- opencv-4.11.0.orig/cmake/OpenCVGenConfig.cmake 2025-01-18 23:31:52.784608127 +0800 3 | +++ opencv-4.11.0/cmake/OpenCVGenConfig.cmake 2025-01-18 23:46:35.410724844 +0800 4 | @@ -19,6 +19,10 @@ if(HAVE_CUDA) 5 | endif() 6 | endif() 7 | 8 | +if(HAVE_OPENMP) 9 | + ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-OPENMP.cmake.in" OPENMP_CONFIGCMAKE @ONLY) 10 | +endif() 11 | + 12 | if(ANDROID) 13 | if(NOT ANDROID_NATIVE_API_LEVEL) 14 | set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0) 15 | diff -Nuarp opencv-4.11.0.orig/cmake/templates/OpenCVConfig.cmake.in opencv-4.11.0/cmake/templates/OpenCVConfig.cmake.in 16 | --- opencv-4.11.0.orig/cmake/templates/OpenCVConfig.cmake.in 2025-01-18 23:31:52.785608139 +0800 17 | +++ opencv-4.11.0/cmake/templates/OpenCVConfig.cmake.in 2025-01-18 23:46:35.410724844 +0800 18 | @@ -94,6 +94,7 @@ endif() 19 | 20 | 21 | @CUDA_CONFIGCMAKE@ 22 | +@OPENMP_CONFIGCMAKE@ 23 | @ANDROID_CONFIGCMAKE@ 24 | 25 | @IPPICV_CONFIGCMAKE@ 26 | diff -Nuarp opencv-4.11.0.orig/cmake/templates/OpenCVConfig-OPENMP.cmake.in opencv-4.11.0/cmake/templates/OpenCVConfig-OPENMP.cmake.in 27 | --- opencv-4.11.0.orig/cmake/templates/OpenCVConfig-OPENMP.cmake.in 1970-01-01 08:00:00.000000000 +0800 28 | +++ opencv-4.11.0/cmake/templates/OpenCVConfig-OPENMP.cmake.in 2025-01-18 23:46:35.410724844 +0800 29 | @@ -0,0 +1,5 @@ 30 | +set(OpenCV_USE_OPENMP "@HAVE_OPENMP@") 31 | + 32 | +if(OpenCV_USE_OPENMP) 33 | + find_package(OpenMP) 34 | +endif() 35 | diff -Nuarp opencv-4.11.0.orig/modules/core/CMakeLists.txt opencv-4.11.0/modules/core/CMakeLists.txt 36 | --- opencv-4.11.0.orig/modules/core/CMakeLists.txt 2025-01-18 23:31:52.823608595 +0800 37 | +++ opencv-4.11.0/modules/core/CMakeLists.txt 2025-01-18 23:46:35.410724844 +0800 38 | @@ -198,8 +198,14 @@ if(HAVE_HPX) 39 | ocv_target_link_libraries(${the_module} LINK_PRIVATE "${HPX_LIBRARIES}") 40 | endif() 41 | 42 | -if(HAVE_OPENMP AND DEFINED OpenMP_CXX_LIBRARIES AND OpenMP_CXX_LIBRARIES) 43 | - ocv_target_link_libraries(${the_module} LINK_PRIVATE "${OpenMP_CXX_LIBRARIES}") 44 | +if(HAVE_OPENMP) 45 | + if(ANDROID_NDK_MAJOR AND (ANDROID_NDK_MAJOR GREATER 20)) 46 | + ocv_target_link_libraries(${the_module} PUBLIC "-fopenmp" "-static-openmp") 47 | + elseif(OpenMP_CXX_FOUND) 48 | + ocv_target_link_libraries(${the_module} PUBLIC OpenMP::OpenMP_CXX) 49 | + else() 50 | + ocv_target_link_libraries(${the_module} PUBLIC "${OpenMP_CXX_FLAGS}") 51 | + endif() 52 | endif() 53 | 54 | ocv_add_accuracy_tests() 55 | diff -Nuarp opencv-4.11.0.orig/modules/video/CMakeLists.txt opencv-4.11.0/modules/video/CMakeLists.txt 56 | --- opencv-4.11.0.orig/modules/video/CMakeLists.txt 2025-01-18 23:31:52.852608943 +0800 57 | +++ opencv-4.11.0/modules/video/CMakeLists.txt 2025-01-18 23:46:35.410724844 +0800 58 | @@ -10,7 +10,3 @@ ocv_define_module(video 59 | python 60 | js 61 | ) 62 | - 63 | -if(HAVE_OPENMP AND DEFINED OpenMP_CXX_LIBRARIES AND OpenMP_CXX_LIBRARIES) 64 | - ocv_target_link_libraries(${the_module} LINK_PRIVATE "${OpenMP_CXX_LIBRARIES}") 65 | -endif() 66 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-minimal-install.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/cmake/OpenCVGenAndroidMK.cmake opencv-4.11.0/cmake/OpenCVGenAndroidMK.cmake 2 | --- opencv-4.11.0.orig/cmake/OpenCVGenAndroidMK.cmake 2025-01-18 23:31:52.784608127 +0800 3 | +++ opencv-4.11.0/cmake/OpenCVGenAndroidMK.cmake 2025-01-18 23:49:42.727186205 +0800 4 | @@ -76,6 +76,4 @@ if(ANDROID) 5 | 6 | configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" @ONLY) 7 | configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV-abi.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk" @ONLY) 8 | - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) 9 | - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV-${ANDROID_NDK_ABI_NAME}.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) 10 | endif(ANDROID) 11 | diff -Nuarp opencv-4.11.0.orig/cmake/OpenCVUtils.cmake opencv-4.11.0/cmake/OpenCVUtils.cmake 12 | --- opencv-4.11.0.orig/cmake/OpenCVUtils.cmake 2025-01-18 23:31:52.785608139 +0800 13 | +++ opencv-4.11.0/cmake/OpenCVUtils.cmake 2025-01-18 23:49:42.727186205 +0800 14 | @@ -980,11 +980,6 @@ macro(ocv_finalize_status) 15 | endif() 16 | endif() 17 | 18 | - if(UNIX) 19 | - install(FILES "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind.supp" 20 | - "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind_3rdparty.supp" 21 | - DESTINATION "${OPENCV_OTHER_INSTALL_PATH}" COMPONENT "dev") 22 | - endif() 23 | endmacro() 24 | 25 | 26 | diff -Nuarp opencv-4.11.0.orig/CMakeLists.txt opencv-4.11.0/CMakeLists.txt 27 | --- opencv-4.11.0.orig/CMakeLists.txt 2025-01-18 23:31:52.783608115 +0800 28 | +++ opencv-4.11.0/CMakeLists.txt 2025-01-18 23:49:42.727186205 +0800 29 | @@ -1068,20 +1068,12 @@ ocv_add_modules_compiler_options() 30 | ocv_register_modules() 31 | 32 | # Generate targets for documentation 33 | -add_subdirectory(doc) 34 | 35 | # various data that is used by cv libraries and/or demo applications. 36 | -add_subdirectory(data) 37 | 38 | # extra applications 39 | -if(BUILD_opencv_apps) 40 | - add_subdirectory(apps) 41 | -endif() 42 | 43 | # examples 44 | -if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES) 45 | - add_subdirectory(samples) 46 | -endif() 47 | 48 | # ---------------------------------------------------------------------------- 49 | # Finalization: generate configuration-based files 50 | @@ -1093,20 +1085,13 @@ ocv_cmake_hook(PRE_FINALIZE) 51 | include(cmake/OpenCVGenHeaders.cmake) 52 | 53 | # Generate opencv.pc for pkg-config command 54 | -if(OPENCV_GENERATE_PKGCONFIG) 55 | - include(cmake/OpenCVGenPkgconfig.cmake) 56 | -endif() 57 | 58 | # Generate OpenCV.mk for ndk-build (Android build tool) 59 | -include(cmake/OpenCVGenAndroidMK.cmake) 60 | 61 | # Generate OpenCVConfig.cmake and OpenCVConfig-version.cmake for cmake projects 62 | include(cmake/OpenCVGenConfig.cmake) 63 | 64 | # Generate Info.plist for the iOS/visionOS framework 65 | -if(APPLE_FRAMEWORK) 66 | - include(cmake/OpenCVGenInfoPlist.cmake) 67 | -endif() 68 | 69 | # Generate ABI descriptor 70 | include(cmake/OpenCVGenABI.cmake) 71 | @@ -1132,12 +1117,6 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PA 72 | endif() 73 | endif() 74 | 75 | -if(NOT OPENCV_README_FILE) 76 | - if(ANDROID) 77 | - set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android) 78 | - endif() 79 | -endif() 80 | - 81 | if(NOT OPENCV_LICENSE_FILE) 82 | set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) 83 | endif() 84 | @@ -1147,11 +1126,6 @@ if(ANDROID OR NOT UNIX) 85 | install(FILES ${OPENCV_LICENSE_FILE} 86 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 87 | DESTINATION ./ COMPONENT libs) 88 | - if(OPENCV_README_FILE) 89 | - install(FILES ${OPENCV_README_FILE} 90 | - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 91 | - DESTINATION ./ COMPONENT libs) 92 | - endif() 93 | endif() 94 | 95 | if(COMMAND ocv_pylint_finalize) 96 | diff -Nuarp opencv-4.11.0.orig/data/CMakeLists.txt opencv-4.11.0/data/CMakeLists.txt 97 | --- opencv-4.11.0.orig/data/CMakeLists.txt 2025-01-18 23:31:52.786608151 +0800 98 | +++ opencv-4.11.0/data/CMakeLists.txt 2025-01-18 23:49:42.727186205 +0800 99 | @@ -1,9 +1,6 @@ 100 | file(GLOB HAAR_CASCADES haarcascades/*.xml) 101 | file(GLOB LBP_CASCADES lbpcascades/*.xml) 102 | 103 | -install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs) 104 | -install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs) 105 | - 106 | if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) 107 | install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests") 108 | endif() 109 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-no-atomic.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/modules/core/src/mathfuncs.cpp opencv-4.11.0/modules/core/src/mathfuncs.cpp 2 | --- opencv-4.11.0.orig/modules/core/src/mathfuncs.cpp 2025-01-18 23:31:52.827608643 +0800 3 | +++ opencv-4.11.0/modules/core/src/mathfuncs.cpp 2025-01-18 23:55:21.143734178 +0800 4 | @@ -2170,8 +2170,13 @@ const double* getExpTab64f() 5 | const float* getExpTab32f() 6 | { 7 | static float CV_DECL_ALIGNED(64) expTab_f[EXPTAB_MASK+1]; 8 | +#ifndef OPENCV_DISABLE_THREAD_SUPPORT 9 | static std::atomic expTab_f_initialized(false); 10 | if (!expTab_f_initialized.load()) 11 | +#else 12 | + static bool expTab_f_initialized = false; 13 | + if (!expTab_f_initialized) 14 | +#endif 15 | { 16 | for( int j = 0; j <= EXPTAB_MASK; j++ ) 17 | expTab_f[j] = (float)expTab[j]; 18 | diff -Nuarp opencv-4.11.0.orig/modules/core/src/parallel.cpp opencv-4.11.0/modules/core/src/parallel.cpp 19 | --- opencv-4.11.0.orig/modules/core/src/parallel.cpp 2025-01-18 23:43:48.356574419 +0800 20 | +++ opencv-4.11.0/modules/core/src/parallel.cpp 2025-01-18 23:55:21.143734178 +0800 21 | @@ -497,6 +497,7 @@ void parallel_for_(const cv::Range& rang 22 | if (range.empty()) 23 | return; 24 | 25 | +#ifndef OPENCV_DISABLE_THREAD_SUPPORT 26 | static std::atomic flagNestedParallelFor(false); 27 | bool isNotNestedRegion = !flagNestedParallelFor.load(); 28 | if (isNotNestedRegion) 29 | @@ -509,6 +510,7 @@ void parallel_for_(const cv::Range& rang 30 | } 31 | } 32 | else // nested parallel_for_() calls are not parallelized 33 | +#endif 34 | { 35 | CV_UNUSED(nstripes); 36 | body(range); 37 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-no-zlib.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/modules/core/src/persistence.hpp opencv-4.11.0/modules/core/src/persistence.hpp 2 | --- opencv-4.11.0.orig/modules/core/src/persistence.hpp 2025-01-18 23:31:52.826608631 +0800 3 | +++ opencv-4.11.0/modules/core/src/persistence.hpp 2025-01-18 23:46:02.204299996 +0800 4 | @@ -12,7 +12,7 @@ 5 | #include 6 | #include 7 | 8 | -#define USE_ZLIB 1 9 | +#define USE_ZLIB 0 10 | #if USE_ZLIB 11 | # ifndef _LFS64_LARGEFILE 12 | # define _LFS64_LARGEFILE 0 13 | -------------------------------------------------------------------------------- /patches/opencv-4.11.0-unsafe-xadd.patch: -------------------------------------------------------------------------------- 1 | diff -Nuarp opencv-4.11.0.orig/modules/core/include/opencv2/core/cvdef.h opencv-4.11.0/modules/core/include/opencv2/core/cvdef.h 2 | --- opencv-4.11.0.orig/modules/core/include/opencv2/core/cvdef.h 2025-01-18 23:41:09.776469917 +0800 3 | +++ opencv-4.11.0/modules/core/include/opencv2/core/cvdef.h 2025-01-18 23:56:07.110333645 +0800 4 | @@ -694,33 +694,7 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumTy 5 | * exchange-add operation for atomic operations on reference counters * 6 | \****************************************************************************************/ 7 | 8 | -#ifdef CV_XADD 9 | - // allow to use user-defined macro 10 | -#elif defined __GNUC__ || defined __clang__ 11 | -# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER 12 | -# ifdef __ATOMIC_ACQ_REL 13 | -# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) 14 | -# else 15 | -# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4) 16 | -# endif 17 | -# else 18 | -# if defined __ATOMIC_ACQ_REL && !defined __clang__ 19 | - // version for gcc >= 4.7 20 | -# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL) 21 | -# else 22 | -# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) 23 | -# endif 24 | -# endif 25 | -#elif defined _MSC_VER && !defined RC_INVOKED 26 | -# include 27 | -# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) 28 | -#else 29 | - #ifdef OPENCV_FORCE_UNSAFE_XADD 30 | - CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } 31 | - #else 32 | - #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)" 33 | - #endif 34 | -#endif 35 | +CV_INLINE int CV_XADD(void* addr, int delta) { int tmp = *(int*)addr; *(int*)addr += delta; return tmp; } 36 | 37 | 38 | /****************************************************************************************\ 39 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(opencv-mobile-test) 2 | cmake_minimum_required(VERSION 3.5) 3 | 4 | # opencv4 requires c++11 5 | set(CMAKE_CXX_STANDARD 11) 6 | 7 | if(APPLE OR IOS) 8 | # set OpenCV_DIR to where opencv2.framework resides 9 | find_library(OpenCV_LIBS NAMES opencv2 PATHS ${OpenCV_DIR}) 10 | else() 11 | # set OpenCV_DIR to where OpenCVConfig.cmake resides 12 | find_package(OpenCV REQUIRED) 13 | endif() 14 | 15 | add_executable(opencv-mobile-test main.cpp) 16 | 17 | target_link_libraries(opencv-mobile-test ${OpenCV_LIBS}) 18 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | cv::Mat bgr = cv::imread("in.jpg", 1); 8 | 9 | cv::resize(bgr, bgr, cv::Size(200, 200)); 10 | 11 | cv::imwrite("out.jpg", bgr); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /toolchains/aarch64-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | 4 | set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-march=armv8-a") 12 | set(CMAKE_CXX_FLAGS "-march=armv8-a") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/aarch64-openwrt-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | 4 | if(DEFINED ENV{TOOLCHAIN_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{TOOLCHAIN_ROOT_PATH} TOOLCHAIN_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "TOOLCHAIN_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(TOOLCHAIN_ROOT_PATH ${TOOLCHAIN_ROOT_PATH} CACHE STRING "root path to toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/aarch64-openwrt-linux-gnu-gcc") 13 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/aarch64-openwrt-linux-gnu-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | 19 | set(CMAKE_C_FLAGS "-march=armv8-a") 20 | set(CMAKE_CXX_FLAGS "-march=armv8-a") 21 | 22 | # cache flags 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 25 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabi.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabi-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabi-g++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4") 12 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 12 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/arm-openwrt-linux-gnueabi.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | if(DEFINED ENV{TOOLCHAIN_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{TOOLCHAIN_ROOT_PATH} TOOLCHAIN_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "TOOLCHAIN_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(TOOLCHAIN_ROOT_PATH ${TOOLCHAIN_ROOT_PATH} CACHE STRING "root path to toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-openwrt-linux-gnueabi-gcc") 13 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-openwrt-linux-gnueabi-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | 19 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 20 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 21 | 22 | # cache flags 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 25 | -------------------------------------------------------------------------------- /toolchains/arm-openwrt-linux-muslgnueabi.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | if(DEFINED ENV{TOOLCHAIN_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{TOOLCHAIN_ROOT_PATH} TOOLCHAIN_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "TOOLCHAIN_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(TOOLCHAIN_ROOT_PATH ${TOOLCHAIN_ROOT_PATH} CACHE STRING "root path to toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-openwrt-linux-muslgnueabi-gcc") 13 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-openwrt-linux-muslgnueabi-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | 19 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 20 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 21 | 22 | # cache flags 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 25 | -------------------------------------------------------------------------------- /toolchains/arm-rockchip830-linux-uclibcgnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | if(DEFINED ENV{TOOLCHAIN_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{TOOLCHAIN_ROOT_PATH} TOOLCHAIN_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "TOOLCHAIN_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(TOOLCHAIN_ROOT_PATH ${TOOLCHAIN_ROOT_PATH} CACHE STRING "root path to toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc") 13 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT_PATH}/bin/arm-rockchip830-linux-uclibcgnueabihf-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | 19 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 20 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 21 | 22 | # cache flags 23 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 25 | -------------------------------------------------------------------------------- /toolchains/c906-v261.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv64) 3 | set(C906 True) 4 | 5 | if(DEFINED ENV{RISCV_ROOT_PATH}) 6 | file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) 7 | else() 8 | message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") 9 | endif() 10 | 11 | set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") 12 | 13 | set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-gcc") 14 | set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-g++") 15 | 16 | set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-linux-gnu") 17 | 18 | set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot") 19 | 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 24 | 25 | set(CMAKE_C_FLAGS "-march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d -mtune=c906") 26 | set(CMAKE_CXX_FLAGS "-march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d -mtune=c906") 27 | 28 | # cache flags 29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 31 | 32 | # export RISCV_ROOT_PATH=/home/nihui/osd/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1 33 | 34 | # cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchains/c906-v261.toolchain.cmake -DCMAKE_C_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_CXX_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release `cat ../../opencv4_cmake_options.txt` -DBUILD_opencv_world=OFF -DOPENCV_DISABLE_FILESYSTEM_SUPPORT=ON .. 35 | 36 | # /home/nihui/osd/xuantie-qemu-x86_64-Ubuntu-18.04-20230825-0120/bin/qemu-riscv64 -cpu c906fdv -L /home/nihui/osd/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1/sysroot ./opencv-mobile-test 37 | -------------------------------------------------------------------------------- /toolchains/loongarch64-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR loongarch64) 3 | 4 | if(DEFINED ENV{LOONGARCH64_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{LOONGARCH64_ROOT_PATH} LOONGARCH64_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "LOONGARCH64_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(LOONGARCH64_ROOT_PATH ${LOONGARCH64_ROOT_PATH} CACHE STRING "root path to loongarch64 toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${LOONGARCH64_ROOT_PATH}/bin/loongarch64-linux-gnu-gcc") 13 | set(CMAKE_CXX_COMPILER "${LOONGARCH64_ROOT_PATH}/bin/loongarch64-linux-gnu-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH "${LOONGARCH64_ROOT_PATH}/loongarch64-linux-gnu") 16 | 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 21 | 22 | set(CMAKE_C_FLAGS "-march=loongarch64") 23 | set(CMAKE_CXX_FLAGS "-march=loongarch64") 24 | 25 | # cache flags 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 28 | -------------------------------------------------------------------------------- /toolchains/macos-arm64.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Darwin) 2 | set(CMAKE_SYSTEM_PROCESSOR arm64) 3 | set(UNIX TRUE) 4 | set(APPLE TRUE) 5 | 6 | set(CMAKE_AR ar CACHE FILEPATH "" FORCE) 7 | set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) 8 | 9 | set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architecture") 10 | 11 | # query xcodebuild for SDK root 12 | execute_process(COMMAND xcodebuild -version -sdk macosx Path 13 | OUTPUT_VARIABLE CMAKE_OSX_SYSROOT 14 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 15 | 16 | message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT}") 17 | 18 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT} CACHE STRING "find search path root" FORCE) 19 | 20 | set(CMAKE_FIND_FRAMEWORK FIRST) 21 | set(CMAKE_SYSTEM_FRAMEWORK_PATH 22 | ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks 23 | ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks 24 | ${CMAKE_OSX_SYSROOT}/Developer/Library/Frameworks 25 | ) 26 | 27 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 28 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 29 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 30 | -------------------------------------------------------------------------------- /toolchains/riscv32-linux-musl.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv32) 3 | 4 | if(DEFINED ENV{RISCV_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv32-linux-musl-gcc") 13 | set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv32-linux-musl-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv32-linux-musl") 16 | 17 | set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot") 18 | 19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 23 | 24 | set(CMAKE_C_FLAGS "-march=rv32imafdc") 25 | set(CMAKE_CXX_FLAGS "-march=rv32imafdc") 26 | 27 | # cache flags 28 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 30 | 31 | # export RISCV_ROOT_PATH=/home/nihui/osd/nds32le-linux-musl-v5d 32 | 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchains/riscv32-linux-musl.toolchain.cmake -DCMAKE_C_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_CXX_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release `cat ../../opencv4_cmake_options.txt` -DBUILD_opencv_world=OFF -DOPENCV_DISABLE_FILESYSTEM_SUPPORT=ON .. 34 | -------------------------------------------------------------------------------- /toolchains/riscv64-unknown-linux-musl.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv64) 3 | set(C906 True) 4 | 5 | if(DEFINED ENV{RISCV_ROOT_PATH}) 6 | file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) 7 | else() 8 | message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") 9 | endif() 10 | 11 | set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") 12 | 13 | set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-musl-gcc") 14 | set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-musl-g++") 15 | 16 | set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-linux-musl") 17 | 18 | set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot") 19 | 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 24 | 25 | set(CMAKE_C_FLAGS "-march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d -mtune=c906") 26 | set(CMAKE_CXX_FLAGS "-march=rv64gcv0p7_zfh_xtheadc -mabi=lp64d -mtune=c906") 27 | 28 | # cache flags 29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 31 | 32 | # export RISCV_ROOT_PATH=/home/nihui/osd/host-tools/gcc/riscv64-linux-musl-x86_64 33 | 34 | # cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchains/riscv64-unknown-linux-musl.toolchain.cmake -DCMAKE_C_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_CXX_FLAGS="-fno-rtti -fno-exceptions" -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release `cat ../../opencv4_cmake_options.txt` -DBUILD_opencv_world=OFF -DOPENCV_DISABLE_FILESYSTEM_SUPPORT=ON .. 35 | --------------------------------------------------------------------------------