react-native-executorch 0.4.7 → 0.5.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1021) hide show
  1. package/android/CMakeLists.txt +17 -0
  2. package/android/build.gradle +76 -13
  3. package/android/libs/classes.jar +0 -0
  4. package/android/src/main/cpp/CMakeLists.txt +73 -0
  5. package/android/src/main/cpp/ETInstallerModule.cpp +76 -0
  6. package/android/src/main/cpp/ETInstallerModule.h +43 -0
  7. package/android/src/main/java/com/swmansion/rnexecutorch/ETInstaller.kt +66 -0
  8. package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +3 -3
  9. package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +7 -113
  10. package/common/ada/ada.cpp +17406 -0
  11. package/common/ada/ada.h +10274 -0
  12. package/common/pfft/pfft.c +2205 -0
  13. package/common/pfft/pfft.h +185 -0
  14. package/common/rnexecutorch/Log.h +489 -0
  15. package/common/rnexecutorch/RnExecutorchInstaller.cpp +78 -0
  16. package/common/rnexecutorch/RnExecutorchInstaller.h +112 -0
  17. package/common/rnexecutorch/TokenizerModule.cpp +52 -0
  18. package/common/rnexecutorch/TokenizerModule.h +26 -0
  19. package/common/rnexecutorch/data_processing/FFT.cpp +21 -0
  20. package/common/rnexecutorch/data_processing/FFT.h +23 -0
  21. package/common/rnexecutorch/data_processing/FileUtils.h +30 -0
  22. package/common/rnexecutorch/data_processing/ImageProcessing.cpp +240 -0
  23. package/common/rnexecutorch/data_processing/ImageProcessing.h +55 -0
  24. package/common/rnexecutorch/data_processing/Numerical.cpp +82 -0
  25. package/common/rnexecutorch/data_processing/Numerical.h +23 -0
  26. package/common/rnexecutorch/data_processing/base64.cpp +110 -0
  27. package/common/rnexecutorch/data_processing/base64.h +46 -0
  28. package/common/rnexecutorch/data_processing/dsp.cpp +65 -0
  29. package/common/rnexecutorch/data_processing/dsp.h +12 -0
  30. package/common/rnexecutorch/host_objects/JSTensorViewIn.h +12 -0
  31. package/common/rnexecutorch/host_objects/JSTensorViewOut.h +22 -0
  32. package/common/rnexecutorch/host_objects/JsiConversions.h +410 -0
  33. package/common/rnexecutorch/host_objects/ModelHostObject.h +239 -0
  34. package/common/rnexecutorch/jsi/JsiHostObject.cpp +108 -0
  35. package/common/rnexecutorch/jsi/JsiHostObject.h +87 -0
  36. package/common/rnexecutorch/jsi/OwningArrayBuffer.h +40 -0
  37. package/common/rnexecutorch/jsi/Promise.cpp +20 -0
  38. package/common/rnexecutorch/jsi/Promise.h +69 -0
  39. package/common/rnexecutorch/jsi/RuntimeAwareCache.h +58 -0
  40. package/common/rnexecutorch/jsi/RuntimeLifecycleMonitor.cpp +53 -0
  41. package/common/rnexecutorch/jsi/RuntimeLifecycleMonitor.h +35 -0
  42. package/common/rnexecutorch/metaprogramming/ConstructorHelpers.h +131 -0
  43. package/common/rnexecutorch/metaprogramming/FunctionHelpers.h +50 -0
  44. package/common/rnexecutorch/metaprogramming/TypeConcepts.h +37 -0
  45. package/common/rnexecutorch/models/BaseModel.cpp +181 -0
  46. package/common/rnexecutorch/models/BaseModel.h +47 -0
  47. package/common/rnexecutorch/models/EncoderDecoderBase.cpp +21 -0
  48. package/common/rnexecutorch/models/EncoderDecoderBase.h +31 -0
  49. package/common/rnexecutorch/models/classification/Classification.cpp +72 -0
  50. package/common/rnexecutorch/models/classification/Classification.h +26 -0
  51. package/{ios/RnExecutorch/models/classification/Constants.mm → common/rnexecutorch/models/classification/Constants.h} +7 -2
  52. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.cpp +27 -0
  53. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.h +17 -0
  54. package/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.cpp +45 -0
  55. package/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h +23 -0
  56. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.cpp +61 -0
  57. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h +26 -0
  58. package/{ios/RnExecutorch/models/image_segmentation/Constants.mm → common/rnexecutorch/models/image_segmentation/Constants.h} +7 -2
  59. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp +173 -0
  60. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h +43 -0
  61. package/{ios/RnExecutorch/utils/Constants.mm → common/rnexecutorch/models/object_detection/Constants.h} +9 -2
  62. package/common/rnexecutorch/models/object_detection/ObjectDetection.cpp +82 -0
  63. package/common/rnexecutorch/models/object_detection/ObjectDetection.h +31 -0
  64. package/{ios/RnExecutorch/utils/ObjectDetectionUtils.mm → common/rnexecutorch/models/object_detection/Utils.cpp} +10 -30
  65. package/common/rnexecutorch/models/object_detection/Utils.h +17 -0
  66. package/common/rnexecutorch/models/ocr/CTCLabelConverter.cpp +88 -0
  67. package/common/rnexecutorch/models/ocr/CTCLabelConverter.h +29 -0
  68. package/common/rnexecutorch/models/ocr/Constants.h +34 -0
  69. package/common/rnexecutorch/models/ocr/Detector.cpp +102 -0
  70. package/common/rnexecutorch/models/ocr/Detector.h +30 -0
  71. package/common/rnexecutorch/models/ocr/DetectorUtils.cpp +703 -0
  72. package/common/rnexecutorch/models/ocr/DetectorUtils.h +80 -0
  73. package/common/rnexecutorch/models/ocr/OCR.cpp +52 -0
  74. package/common/rnexecutorch/models/ocr/OCR.h +36 -0
  75. package/common/rnexecutorch/models/ocr/RecognitionHandler.cpp +107 -0
  76. package/common/rnexecutorch/models/ocr/RecognitionHandler.h +40 -0
  77. package/common/rnexecutorch/models/ocr/RecognitionHandlerUtils.cpp +153 -0
  78. package/common/rnexecutorch/models/ocr/RecognitionHandlerUtils.h +72 -0
  79. package/common/rnexecutorch/models/ocr/Recognizer.cpp +80 -0
  80. package/common/rnexecutorch/models/ocr/Recognizer.h +36 -0
  81. package/common/rnexecutorch/models/ocr/RecognizerUtils.cpp +202 -0
  82. package/common/rnexecutorch/models/ocr/RecognizerUtils.h +70 -0
  83. package/common/rnexecutorch/models/ocr/Types.h +37 -0
  84. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.cpp +31 -0
  85. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.h +21 -0
  86. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +70 -0
  87. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +31 -0
  88. package/common/rnexecutorch/models/speech_to_text/SpeechToTextStrategy.h +26 -0
  89. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.cpp +38 -0
  90. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.h +25 -0
  91. package/common/rnexecutorch/models/style_transfer/StyleTransfer.cpp +55 -0
  92. package/common/rnexecutorch/models/style_transfer/StyleTransfer.h +29 -0
  93. package/common/rnexecutorch/models/vertical_ocr/VerticalDetector.cpp +92 -0
  94. package/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h +49 -0
  95. package/common/rnexecutorch/models/vertical_ocr/VerticalOCR.cpp +180 -0
  96. package/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h +78 -0
  97. package/common/rnexecutorch/tests/LogTest.cpp +530 -0
  98. package/common/rnexecutorch/tests/README.md +20 -0
  99. package/common/rnexecutorch/tests/run_all_tests.sh +14 -0
  100. package/common/rnexecutorch/tests/run_test.sh +18 -0
  101. package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
  102. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  103. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  104. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  105. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  106. package/ios/RnExecutorch/ETInstaller.h +8 -0
  107. package/ios/RnExecutorch/ETInstaller.mm +56 -0
  108. package/ios/RnExecutorch/utils/Conversions.h +8 -9
  109. package/ios/RnExecutorch/utils/Numerical.h +2 -0
  110. package/ios/RnExecutorch.xcodeproj/project.pbxproj +73 -0
  111. package/lib/common/Logger.d.ts +8 -0
  112. package/lib/common/Logger.js +19 -0
  113. package/lib/constants/modelUrls.d.ts +89 -0
  114. package/lib/constants/modelUrls.js +116 -0
  115. package/lib/constants/sttDefaults.js +66 -0
  116. package/lib/controllers/LLMController.js +210 -0
  117. package/lib/controllers/OCRController.js +65 -0
  118. package/lib/controllers/SpeechToTextController.d.ts +52 -0
  119. package/lib/controllers/SpeechToTextController.js +343 -0
  120. package/lib/hooks/natural_language_processing/useSpeechToText.js +44 -0
  121. package/lib/index.d.ts +50 -0
  122. package/{src/index.tsx → lib/index.js} +22 -10
  123. package/lib/module/Error.js +8 -6
  124. package/lib/module/Error.js.map +1 -1
  125. package/lib/module/common/Logger.js +23 -0
  126. package/lib/module/common/Logger.js.map +1 -0
  127. package/lib/module/constants/llmDefaults.js +8 -0
  128. package/lib/module/constants/llmDefaults.js.map +1 -1
  129. package/lib/module/constants/modelUrls.js +300 -84
  130. package/lib/module/constants/modelUrls.js.map +1 -1
  131. package/lib/module/constants/ocr/models.js +181 -286
  132. package/lib/module/constants/ocr/models.js.map +1 -1
  133. package/lib/module/constants/ocr/symbols.js +63 -63
  134. package/lib/module/constants/sttDefaults.js +12 -10
  135. package/lib/module/constants/sttDefaults.js.map +1 -1
  136. package/lib/module/controllers/LLMController.js +17 -11
  137. package/lib/module/controllers/LLMController.js.map +1 -1
  138. package/lib/module/controllers/OCRController.js +16 -9
  139. package/lib/module/controllers/OCRController.js.map +1 -1
  140. package/lib/module/controllers/SpeechToTextController.js +32 -19
  141. package/lib/module/controllers/SpeechToTextController.js.map +1 -1
  142. package/lib/module/controllers/VerticalOCRController.js +16 -9
  143. package/lib/module/controllers/VerticalOCRController.js.map +1 -1
  144. package/lib/module/hooks/computer_vision/useClassification.js +5 -5
  145. package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
  146. package/lib/module/hooks/computer_vision/useImageEmbeddings.js +13 -0
  147. package/lib/module/hooks/computer_vision/useImageEmbeddings.js.map +1 -0
  148. package/lib/module/hooks/computer_vision/useImageSegmentation.js +4 -4
  149. package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -1
  150. package/lib/module/hooks/computer_vision/useOCR.js +14 -15
  151. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  152. package/lib/module/hooks/computer_vision/useObjectDetection.js +5 -5
  153. package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
  154. package/lib/module/hooks/computer_vision/useStyleTransfer.js +5 -5
  155. package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
  156. package/lib/module/hooks/computer_vision/useVerticalOCR.js +16 -17
  157. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  158. package/lib/module/hooks/general/useExecutorchModule.js +5 -3
  159. package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
  160. package/lib/module/hooks/natural_language_processing/useLLM.js +22 -25
  161. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  162. package/lib/module/hooks/natural_language_processing/useSpeechToText.js +16 -14
  163. package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
  164. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +4 -5
  165. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -1
  166. package/lib/module/hooks/natural_language_processing/useTokenizer.js +20 -19
  167. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
  168. package/lib/module/hooks/useNonStaticModule.js +52 -0
  169. package/lib/module/hooks/useNonStaticModule.js.map +1 -0
  170. package/lib/module/index.js +16 -2
  171. package/lib/module/index.js.map +1 -1
  172. package/lib/module/modules/BaseModule.js +6 -3
  173. package/lib/module/modules/BaseModule.js.map +1 -1
  174. package/lib/module/modules/BaseNonStaticModule.js +17 -0
  175. package/lib/module/modules/BaseNonStaticModule.js.map +1 -0
  176. package/lib/module/modules/computer_vision/ClassificationModule.js +13 -8
  177. package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
  178. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js +19 -0
  179. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js.map +1 -0
  180. package/lib/module/modules/computer_vision/ImageSegmentationModule.js +21 -19
  181. package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -1
  182. package/lib/module/modules/computer_vision/OCRModule.js +13 -10
  183. package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
  184. package/lib/module/modules/computer_vision/ObjectDetectionModule.js +13 -8
  185. package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
  186. package/lib/module/modules/computer_vision/StyleTransferModule.js +13 -8
  187. package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
  188. package/lib/module/modules/computer_vision/VerticalOCRModule.js +15 -10
  189. package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
  190. package/lib/module/modules/general/ExecutorchModule.js +10 -36
  191. package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
  192. package/lib/module/modules/natural_language_processing/LLMModule.js +18 -22
  193. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  194. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +27 -16
  195. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  196. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +15 -8
  197. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -1
  198. package/lib/module/modules/natural_language_processing/TokenizerModule.js +20 -14
  199. package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -1
  200. package/lib/module/native/NativeETInstaller.js +5 -0
  201. package/lib/module/native/NativeETInstaller.js.map +1 -0
  202. package/lib/module/native/RnExecutorchModules.js +2 -11
  203. package/lib/module/native/RnExecutorchModules.js.map +1 -1
  204. package/lib/module/types/common.js +25 -8
  205. package/lib/module/types/common.js.map +1 -1
  206. package/lib/module/types/stt.js +6 -0
  207. package/lib/module/types/stt.js.map +1 -1
  208. package/lib/module/utils/ResourceFetcher.js +276 -114
  209. package/lib/module/utils/ResourceFetcher.js.map +1 -1
  210. package/lib/module/utils/ResourceFetcherUtils.js +155 -0
  211. package/lib/module/utils/ResourceFetcherUtils.js.map +1 -0
  212. package/lib/module/utils/llm.js +41 -1
  213. package/lib/module/utils/llm.js.map +1 -1
  214. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +14 -0
  215. package/lib/modules/natural_language_processing/SpeechToTextModule.js +30 -0
  216. package/lib/modules/natural_language_processing/TokenizerModule.js +29 -0
  217. package/lib/native/RnExecutorchModules.d.ts +3 -0
  218. package/lib/native/RnExecutorchModules.js +16 -0
  219. package/lib/typescript/Error.d.ts +2 -0
  220. package/lib/typescript/Error.d.ts.map +1 -1
  221. package/lib/typescript/common/Logger.d.ts +9 -0
  222. package/lib/typescript/common/Logger.d.ts.map +1 -0
  223. package/lib/typescript/constants/llmDefaults.d.ts +1 -0
  224. package/lib/typescript/constants/llmDefaults.d.ts.map +1 -1
  225. package/lib/typescript/constants/modelUrls.d.ts +223 -79
  226. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  227. package/lib/typescript/constants/ocr/models.d.ts +882 -284
  228. package/lib/typescript/constants/ocr/models.d.ts.map +1 -1
  229. package/lib/typescript/constants/sttDefaults.d.ts +1 -0
  230. package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
  231. package/lib/typescript/controllers/LLMController.d.ts +3 -4
  232. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  233. package/lib/typescript/controllers/OCRController.d.ts +5 -6
  234. package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
  235. package/lib/typescript/controllers/SpeechToTextController.d.ts +11 -6
  236. package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
  237. package/lib/typescript/controllers/VerticalOCRController.d.ts +5 -6
  238. package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
  239. package/lib/typescript/hooks/computer_vision/useClassification.d.ts +8 -6
  240. package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
  241. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts +16 -0
  242. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts.map +1 -0
  243. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +5 -3
  244. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -1
  245. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +4 -4
  246. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  247. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -3
  248. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
  249. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +5 -3
  250. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
  251. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +3 -5
  252. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  253. package/lib/typescript/hooks/general/useExecutorchModule.d.ts +1 -1
  254. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -4
  255. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  256. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -5
  257. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
  258. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +9 -5
  259. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -1
  260. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +6 -4
  261. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -1
  262. package/lib/typescript/hooks/useNonStaticModule.d.ts +21 -0
  263. package/lib/typescript/hooks/useNonStaticModule.d.ts.map +1 -0
  264. package/lib/typescript/index.d.ts +18 -2
  265. package/lib/typescript/index.d.ts.map +1 -1
  266. package/lib/typescript/modules/BaseModule.d.ts +1 -1
  267. package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
  268. package/lib/typescript/modules/BaseNonStaticModule.d.ts +10 -0
  269. package/lib/typescript/modules/BaseNonStaticModule.d.ts.map +1 -0
  270. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +6 -6
  271. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
  272. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts +9 -0
  273. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts.map +1 -0
  274. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +8 -28
  275. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -1
  276. package/lib/typescript/modules/computer_vision/OCRModule.d.ts +8 -7
  277. package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
  278. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +7 -5
  279. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
  280. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
  281. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
  282. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +7 -8
  283. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
  284. package/lib/typescript/modules/general/ExecutorchModule.d.ts +5 -8
  285. package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
  286. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +16 -16
  287. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  288. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +19 -9
  289. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  290. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +7 -5
  291. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -1
  292. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +10 -9
  293. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -1
  294. package/lib/typescript/native/{NativeStyleTransfer.d.ts → NativeETInstaller.d.ts} +2 -3
  295. package/lib/typescript/native/NativeETInstaller.d.ts.map +1 -0
  296. package/lib/typescript/native/RnExecutorchModules.d.ts +3 -21
  297. package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
  298. package/lib/typescript/types/common.d.ts +30 -2
  299. package/lib/typescript/types/common.d.ts.map +1 -1
  300. package/lib/typescript/types/stt.d.ts +5 -1
  301. package/lib/typescript/types/stt.d.ts.map +1 -1
  302. package/lib/typescript/utils/ResourceFetcher.d.ts +18 -10
  303. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
  304. package/lib/typescript/utils/ResourceFetcherUtils.d.ts +55 -0
  305. package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -0
  306. package/lib/typescript/utils/llm.d.ts +4 -0
  307. package/lib/typescript/utils/llm.d.ts.map +1 -1
  308. package/lib/utils/ResourceFetcherUtils.js +119 -0
  309. package/lib/utils/llm.js +72 -0
  310. package/package.json +22 -64
  311. package/react-native-executorch.podspec +75 -3
  312. package/src/Error.ts +8 -10
  313. package/src/common/Logger.ts +25 -0
  314. package/src/constants/llmDefaults.ts +11 -0
  315. package/src/constants/modelUrls.ts +365 -168
  316. package/src/constants/ocr/models.ts +826 -395
  317. package/src/constants/ocr/symbols.ts +63 -63
  318. package/src/constants/sttDefaults.ts +14 -18
  319. package/src/controllers/LLMController.ts +28 -18
  320. package/src/controllers/OCRController.ts +24 -15
  321. package/src/controllers/SpeechToTextController.ts +53 -40
  322. package/src/controllers/VerticalOCRController.ts +24 -14
  323. package/src/hooks/computer_vision/useClassification.ts +10 -11
  324. package/src/hooks/computer_vision/useImageEmbeddings.ts +15 -0
  325. package/src/hooks/computer_vision/useImageSegmentation.ts +5 -8
  326. package/src/hooks/computer_vision/useOCR.ts +29 -21
  327. package/src/hooks/computer_vision/useObjectDetection.ts +6 -9
  328. package/src/hooks/computer_vision/useStyleTransfer.ts +6 -6
  329. package/src/hooks/computer_vision/useVerticalOCR.ts +30 -27
  330. package/src/hooks/general/useExecutorchModule.ts +3 -3
  331. package/src/hooks/natural_language_processing/useLLM.ts +38 -28
  332. package/src/hooks/natural_language_processing/useSpeechToText.ts +34 -26
  333. package/src/hooks/natural_language_processing/useTextEmbeddings.ts +11 -11
  334. package/src/hooks/natural_language_processing/useTokenizer.ts +22 -22
  335. package/src/hooks/useNonStaticModule.ts +74 -0
  336. package/src/index.ts +108 -0
  337. package/src/modules/BaseModule.ts +9 -3
  338. package/src/modules/BaseNonStaticModule.ts +26 -0
  339. package/src/modules/computer_vision/ClassificationModule.ts +20 -11
  340. package/src/modules/computer_vision/ImageEmbeddingsModule.ts +26 -0
  341. package/src/modules/computer_vision/ImageSegmentationModule.ts +35 -27
  342. package/src/modules/computer_vision/OCRModule.ts +23 -15
  343. package/src/modules/computer_vision/ObjectDetectionModule.ts +24 -11
  344. package/src/modules/computer_vision/StyleTransferModule.ts +20 -11
  345. package/src/modules/computer_vision/VerticalOCRModule.ts +25 -21
  346. package/src/modules/general/ExecutorchModule.ts +18 -48
  347. package/src/modules/natural_language_processing/LLMModule.ts +27 -30
  348. package/src/modules/natural_language_processing/SpeechToTextModule.ts +42 -37
  349. package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +27 -12
  350. package/src/modules/natural_language_processing/TokenizerModule.ts +27 -17
  351. package/src/native/NativeETInstaller.ts +8 -0
  352. package/src/native/RnExecutorchModules.ts +4 -46
  353. package/src/types/common.ts +40 -12
  354. package/src/types/stt.ts +5 -1
  355. package/src/utils/ResourceFetcher.ts +338 -119
  356. package/src/utils/ResourceFetcherUtils.ts +186 -0
  357. package/src/utils/llm.ts +65 -1
  358. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  359. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  360. package/third-party/android/libs/opencv/arm64-v8a/libopencv_core.a +0 -0
  361. package/third-party/android/libs/opencv/arm64-v8a/libopencv_features2d.a +0 -0
  362. package/third-party/android/libs/opencv/arm64-v8a/libopencv_highgui.a +0 -0
  363. package/third-party/android/libs/opencv/arm64-v8a/libopencv_imgproc.a +0 -0
  364. package/third-party/android/libs/opencv/arm64-v8a/libopencv_photo.a +0 -0
  365. package/third-party/android/libs/opencv/arm64-v8a/libopencv_video.a +0 -0
  366. package/third-party/android/libs/opencv/x86_64/libopencv_core.a +0 -0
  367. package/third-party/android/libs/opencv/x86_64/libopencv_features2d.a +0 -0
  368. package/third-party/android/libs/opencv/x86_64/libopencv_highgui.a +0 -0
  369. package/third-party/android/libs/opencv/x86_64/libopencv_imgproc.a +0 -0
  370. package/third-party/android/libs/opencv/x86_64/libopencv_photo.a +0 -0
  371. package/third-party/android/libs/opencv/x86_64/libopencv_video.a +0 -0
  372. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv.a +0 -0
  373. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv_hal.a +0 -0
  374. package/third-party/android/libs/opencv-third-party/arm64-v8a/libkleidicv_thread.a +0 -0
  375. package/third-party/include/c10/macros/Export.h +163 -0
  376. package/third-party/include/c10/macros/Macros.h +497 -0
  377. package/third-party/include/c10/util/BFloat16-inl.h +342 -0
  378. package/third-party/include/c10/util/BFloat16-math.h +266 -0
  379. package/third-party/include/c10/util/BFloat16.h +125 -0
  380. package/third-party/include/c10/util/Half-inl.h +347 -0
  381. package/third-party/include/c10/util/Half.h +416 -0
  382. package/third-party/include/c10/util/TypeSafeSignMath.h +133 -0
  383. package/third-party/include/c10/util/bit_cast.h +43 -0
  384. package/third-party/include/c10/util/floating_point_utils.h +33 -0
  385. package/third-party/include/c10/util/irange.h +107 -0
  386. package/third-party/include/executorch/ExecuTorch.h +13 -0
  387. package/third-party/include/executorch/ExecuTorchError.h +16 -0
  388. package/third-party/include/executorch/ExecuTorchLog.h +76 -0
  389. package/third-party/include/executorch/ExecuTorchModule.h +286 -0
  390. package/third-party/include/executorch/ExecuTorchTensor.h +742 -0
  391. package/third-party/include/executorch/ExecuTorchValue.h +219 -0
  392. package/third-party/include/executorch/extension/module/module.h +492 -0
  393. package/third-party/include/executorch/extension/tensor/tensor.h +13 -0
  394. package/third-party/include/executorch/extension/tensor/tensor_accessor.h +190 -0
  395. package/third-party/include/executorch/extension/tensor/tensor_ptr.h +347 -0
  396. package/third-party/include/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  397. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +71 -0
  398. package/third-party/include/executorch/runtime/backend/backend_init_context.h +72 -0
  399. package/third-party/include/executorch/runtime/backend/interface.h +166 -0
  400. package/third-party/include/executorch/runtime/core/array_ref.h +235 -0
  401. package/third-party/include/executorch/runtime/core/data_loader.h +136 -0
  402. package/third-party/include/executorch/runtime/core/defines.h +20 -0
  403. package/third-party/include/executorch/runtime/core/error.h +229 -0
  404. package/third-party/include/executorch/runtime/core/evalue.h +521 -0
  405. package/third-party/include/executorch/runtime/core/event_tracer.h +565 -0
  406. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +323 -0
  407. package/third-party/include/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  408. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  409. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  410. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  411. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  412. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  413. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  414. package/third-party/include/executorch/runtime/core/freeable_buffer.h +107 -0
  415. package/third-party/include/executorch/runtime/core/hierarchical_allocator.h +107 -0
  416. package/third-party/include/executorch/runtime/core/memory_allocator.h +198 -0
  417. package/third-party/include/executorch/runtime/core/named_data_map.h +86 -0
  418. package/third-party/include/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  419. package/third-party/include/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  420. package/third-party/include/executorch/runtime/core/portable_type/bits_types.h +83 -0
  421. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  422. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  423. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  424. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  425. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  426. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  427. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  428. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  429. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  430. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  431. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  432. package/third-party/include/executorch/runtime/core/portable_type/complex.h +44 -0
  433. package/third-party/include/executorch/runtime/core/portable_type/device.h +70 -0
  434. package/third-party/include/executorch/runtime/core/portable_type/half.h +27 -0
  435. package/third-party/include/executorch/runtime/core/portable_type/optional.h +36 -0
  436. package/third-party/include/executorch/runtime/core/portable_type/qint_types.h +83 -0
  437. package/third-party/include/executorch/runtime/core/portable_type/scalar.h +110 -0
  438. package/third-party/include/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  439. package/third-party/include/executorch/runtime/core/portable_type/string_view.h +29 -0
  440. package/third-party/include/executorch/runtime/core/portable_type/tensor.h +142 -0
  441. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  442. package/third-party/include/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  443. package/third-party/include/executorch/runtime/core/result.h +258 -0
  444. package/third-party/include/executorch/runtime/core/span.h +93 -0
  445. package/third-party/include/executorch/runtime/core/tag.h +71 -0
  446. package/third-party/include/executorch/runtime/core/tensor_layout.h +79 -0
  447. package/third-party/include/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  448. package/third-party/include/executorch/runtime/executor/memory_manager.h +113 -0
  449. package/third-party/include/executorch/runtime/executor/method.h +387 -0
  450. package/third-party/include/executorch/runtime/executor/method_meta.h +251 -0
  451. package/third-party/include/executorch/runtime/executor/program.h +320 -0
  452. package/third-party/include/executorch/runtime/executor/pte_data_map.h +144 -0
  453. package/third-party/include/executorch/runtime/executor/tensor_parser.h +156 -0
  454. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  455. package/third-party/include/executorch/runtime/kernel/operator_registry.h +278 -0
  456. package/third-party/include/executorch/runtime/platform/abort.h +36 -0
  457. package/third-party/include/executorch/runtime/platform/assert.h +119 -0
  458. package/third-party/include/executorch/runtime/platform/clock.h +43 -0
  459. package/third-party/include/executorch/runtime/platform/compat_unistd.h +75 -0
  460. package/third-party/include/executorch/runtime/platform/compiler.h +191 -0
  461. package/third-party/include/executorch/runtime/platform/log.h +177 -0
  462. package/third-party/include/executorch/runtime/platform/platform.h +133 -0
  463. package/third-party/include/executorch/runtime/platform/profiler.h +292 -0
  464. package/third-party/include/executorch/runtime/platform/runtime.h +35 -0
  465. package/third-party/include/executorch/runtime/platform/system.h +49 -0
  466. package/third-party/include/executorch/runtime/platform/types.h +24 -0
  467. package/third-party/include/executorch/schema/extended_header.h +76 -0
  468. package/third-party/include/opencv2/core/affine.hpp +676 -0
  469. package/third-party/include/opencv2/core/async.hpp +107 -0
  470. package/third-party/include/opencv2/core/base.hpp +735 -0
  471. package/third-party/include/opencv2/core/bindings_utils.hpp +279 -0
  472. package/third-party/include/opencv2/core/bufferpool.hpp +39 -0
  473. package/third-party/include/opencv2/core/check.hpp +231 -0
  474. package/third-party/include/opencv2/core/core.hpp +55 -0
  475. package/third-party/include/opencv2/core/core_c.h +3261 -0
  476. package/third-party/include/opencv2/core/cv_cpu_dispatch.h +404 -0
  477. package/third-party/include/opencv2/core/cv_cpu_helper.h +856 -0
  478. package/third-party/include/opencv2/core/cvdef.h +1003 -0
  479. package/third-party/include/opencv2/core/cvstd.hpp +196 -0
  480. package/third-party/include/opencv2/core/cvstd.inl.hpp +188 -0
  481. package/third-party/include/opencv2/core/cvstd_wrapper.hpp +187 -0
  482. package/third-party/include/opencv2/core/detail/async_promise.hpp +73 -0
  483. package/third-party/include/opencv2/core/detail/dispatch_helper.impl.hpp +48 -0
  484. package/third-party/include/opencv2/core/detail/exception_ptr.hpp +24 -0
  485. package/third-party/include/opencv2/core/dualquaternion.hpp +1054 -0
  486. package/third-party/include/opencv2/core/dualquaternion.inl.hpp +464 -0
  487. package/third-party/include/opencv2/core/eigen.hpp +405 -0
  488. package/third-party/include/opencv2/core/fast_math.hpp +433 -0
  489. package/third-party/include/opencv2/core/hal/hal.hpp +451 -0
  490. package/third-party/include/opencv2/core/hal/interface.h +191 -0
  491. package/third-party/include/opencv2/core/hal/intrin.hpp +1222 -0
  492. package/third-party/include/opencv2/core/hal/intrin_avx.hpp +3378 -0
  493. package/third-party/include/opencv2/core/hal/intrin_avx512.hpp +3688 -0
  494. package/third-party/include/opencv2/core/hal/intrin_cpp.hpp +3446 -0
  495. package/third-party/include/opencv2/core/hal/intrin_forward.hpp +195 -0
  496. package/third-party/include/opencv2/core/hal/intrin_lasx.hpp +3243 -0
  497. package/third-party/include/opencv2/core/hal/intrin_lsx.hpp +2671 -0
  498. package/third-party/include/opencv2/core/hal/intrin_math.hpp +772 -0
  499. package/third-party/include/opencv2/core/hal/intrin_msa.hpp +1973 -0
  500. package/third-party/include/opencv2/core/hal/intrin_neon.hpp +2710 -0
  501. package/third-party/include/opencv2/core/hal/intrin_rvv071.hpp +3452 -0
  502. package/third-party/include/opencv2/core/hal/intrin_rvv_scalable.hpp +2559 -0
  503. package/third-party/include/opencv2/core/hal/intrin_sse.hpp +3528 -0
  504. package/third-party/include/opencv2/core/hal/intrin_sse_em.hpp +175 -0
  505. package/third-party/include/opencv2/core/hal/intrin_vsx.hpp +1756 -0
  506. package/third-party/include/opencv2/core/hal/intrin_wasm.hpp +2911 -0
  507. package/third-party/include/opencv2/core/hal/msa_macros.h +2079 -0
  508. package/third-party/include/opencv2/core/hal/simd_utils.impl.hpp +313 -0
  509. package/third-party/include/opencv2/core/mat.hpp +3842 -0
  510. package/third-party/include/opencv2/core/mat.inl.hpp +2753 -0
  511. package/third-party/include/opencv2/core/matx.hpp +603 -0
  512. package/third-party/include/opencv2/core/matx.inl.hpp +1132 -0
  513. package/third-party/include/opencv2/core/neon_utils.hpp +127 -0
  514. package/third-party/include/opencv2/core/operations.hpp +610 -0
  515. package/third-party/include/opencv2/core/optim.hpp +362 -0
  516. package/third-party/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +66 -0
  517. package/third-party/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +148 -0
  518. package/third-party/include/opencv2/core/parallel/parallel_backend.hpp +108 -0
  519. package/third-party/include/opencv2/core/persistence.hpp +1321 -0
  520. package/third-party/include/opencv2/core/quaternion.hpp +1889 -0
  521. package/third-party/include/opencv2/core/quaternion.inl.hpp +907 -0
  522. package/third-party/include/opencv2/core/saturate.hpp +347 -0
  523. package/third-party/include/opencv2/core/simd_intrinsics.hpp +90 -0
  524. package/third-party/include/opencv2/core/softfloat.hpp +657 -0
  525. package/third-party/include/opencv2/core/sse_utils.hpp +861 -0
  526. package/third-party/include/opencv2/core/traits.hpp +417 -0
  527. package/third-party/include/opencv2/core/types.hpp +2368 -0
  528. package/third-party/include/opencv2/core/types_c.h +2064 -0
  529. package/third-party/include/opencv2/core/utility.hpp +1296 -0
  530. package/third-party/include/opencv2/core/utils/allocator_stats.hpp +31 -0
  531. package/third-party/include/opencv2/core/utils/allocator_stats.impl.hpp +111 -0
  532. package/third-party/include/opencv2/core/utils/filesystem.hpp +91 -0
  533. package/third-party/include/opencv2/core/utils/fp_control_utils.hpp +70 -0
  534. package/third-party/include/opencv2/core/utils/instrumentation.hpp +127 -0
  535. package/third-party/include/opencv2/core/utils/logger.defines.hpp +50 -0
  536. package/third-party/include/opencv2/core/utils/logger.hpp +258 -0
  537. package/third-party/include/opencv2/core/utils/logtag.hpp +27 -0
  538. package/third-party/include/opencv2/core/utils/tls.hpp +230 -0
  539. package/third-party/include/opencv2/core/utils/trace.hpp +281 -0
  540. package/third-party/include/opencv2/core/version.hpp +29 -0
  541. package/third-party/include/opencv2/core/vsx_utils.hpp +1115 -0
  542. package/third-party/include/opencv2/core.hpp +3699 -0
  543. package/third-party/include/opencv2/cvconfig.h +155 -0
  544. package/third-party/include/opencv2/dnn/dnn.hpp +51 -0
  545. package/third-party/include/opencv2/dnn.hpp +17 -0
  546. package/third-party/include/opencv2/features2d/features2d.hpp +55 -0
  547. package/third-party/include/opencv2/features2d/hal/interface.h +32 -0
  548. package/third-party/include/opencv2/features2d.hpp +1756 -0
  549. package/third-party/include/opencv2/highgui/highgui.hpp +113 -0
  550. package/third-party/include/opencv2/highgui.hpp +17 -0
  551. package/third-party/include/opencv2/imgproc/bindings.hpp +34 -0
  552. package/third-party/include/opencv2/imgproc/detail/gcgraph.hpp +355 -0
  553. package/third-party/include/opencv2/imgproc/detail/legacy.hpp +35 -0
  554. package/third-party/include/opencv2/imgproc/hal/hal.hpp +246 -0
  555. package/third-party/include/opencv2/imgproc/hal/interface.h +52 -0
  556. package/third-party/include/opencv2/imgproc/imgproc.hpp +55 -0
  557. package/third-party/include/opencv2/imgproc/imgproc_c.h +1261 -0
  558. package/third-party/include/opencv2/imgproc/segmentation.hpp +168 -0
  559. package/third-party/include/opencv2/imgproc/types_c.h +632 -0
  560. package/third-party/include/opencv2/imgproc.hpp +5956 -0
  561. package/third-party/include/opencv2/opencv.hpp +102 -0
  562. package/third-party/include/opencv2/opencv_modules.hpp +19 -0
  563. package/third-party/include/opencv2/photo/legacy/constants_c.h +10 -0
  564. package/third-party/include/opencv2/photo/photo.hpp +55 -0
  565. package/third-party/include/opencv2/photo.hpp +975 -0
  566. package/third-party/include/opencv2/video/background_segm.hpp +341 -0
  567. package/third-party/include/opencv2/video/detail/tracking.detail.hpp +435 -0
  568. package/third-party/include/opencv2/video/legacy/constants_c.h +15 -0
  569. package/third-party/include/opencv2/video/tracking.hpp +1014 -0
  570. package/third-party/include/opencv2/video/video.hpp +55 -0
  571. package/third-party/include/opencv2/video.hpp +65 -0
  572. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  573. package/third-party/include/tokenizers-cpp/tokenizers_cpp.h +118 -0
  574. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.h +27 -0
  575. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/ETModel.mm +249 -0
  576. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/HuggingFaceTokenizer.h +14 -0
  577. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/HuggingFaceTokenizer.mm +80 -0
  578. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.h +32 -0
  579. package/third-party/ios/ExecutorchLib/ExecutorchLib/Exported/LLaMARunner.mm +95 -0
  580. package/third-party/ios/ExecutorchLib/ExecutorchLib/InputType.h +12 -0
  581. package/third-party/ios/ExecutorchLib/ExecutorchLib/Utils.hpp +217 -0
  582. package/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.cpp +11 -0
  583. package/third-party/ios/ExecutorchLib/ExecutorchLib/model/Model.h +11 -0
  584. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/irunner.h +48 -0
  585. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.cpp +278 -0
  586. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/runner.h +67 -0
  587. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/stats.h +164 -0
  588. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.cpp +65 -0
  589. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_decoder_runner.h +105 -0
  590. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.cpp +91 -0
  591. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_prefiller.h +51 -0
  592. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/text_token_generator.h +162 -0
  593. package/third-party/ios/ExecutorchLib/ExecutorchLib/runner/util.h +108 -0
  594. package/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.cpp +193 -0
  595. package/third-party/ios/ExecutorchLib/ExecutorchLib/sampler/sampler.h +64 -0
  596. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/base64.h +202 -0
  597. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.cpp +313 -0
  598. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/bpe_tokenizer.h +57 -0
  599. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.cpp +78 -0
  600. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/llama_tiktoken.h +23 -0
  601. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.cpp +427 -0
  602. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tiktoken.h +87 -0
  603. package/third-party/ios/ExecutorchLib/ExecutorchLib/tokenizer/tokenizer.h +76 -0
  604. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.pbxproj +683 -0
  605. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  606. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/xcuserdata/norbertklockiewicz.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  607. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/xcuserdata/norbertklockiewicz.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  608. package/third-party/ios/ExecutorchLib/build.sh +44 -0
  609. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/Info.plist +43 -0
  610. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/ios-arm64/libbackend_coreml_ios.a +0 -0
  611. package/third-party/ios/ExecutorchLib/frameworks/backend_coreml.xcframework/ios-arm64-simulator/libbackend_coreml_simulator.a +0 -0
  612. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/Info.plist +43 -0
  613. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/ios-arm64/libbackend_mps_ios.a +0 -0
  614. package/third-party/ios/ExecutorchLib/frameworks/backend_mps.xcframework/ios-arm64-simulator/libbackend_mps_simulator.a +0 -0
  615. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/Info.plist +43 -0
  616. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/ios-arm64/libbackend_xnnpack_ios.a +0 -0
  617. package/third-party/ios/ExecutorchLib/frameworks/backend_xnnpack.xcframework/ios-arm64-simulator/libbackend_xnnpack_simulator.a +0 -0
  618. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/Info.plist +47 -0
  619. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/macros/Export.h +163 -0
  620. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/macros/Macros.h +497 -0
  621. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16-inl.h +342 -0
  622. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16-math.h +266 -0
  623. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/BFloat16.h +125 -0
  624. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/Half-inl.h +347 -0
  625. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/Half.h +416 -0
  626. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/TypeSafeSignMath.h +133 -0
  627. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/bit_cast.h +43 -0
  628. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/floating_point_utils.h +33 -0
  629. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/c10/util/irange.h +107 -0
  630. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorch.h +13 -0
  631. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchError.h +16 -0
  632. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchLog.h +76 -0
  633. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchModule.h +286 -0
  634. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchTensor.h +742 -0
  635. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/ExecuTorchValue.h +219 -0
  636. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/module/module.h +492 -0
  637. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor.h +13 -0
  638. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_accessor.h +190 -0
  639. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr.h +347 -0
  640. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  641. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_execution_context.h +71 -0
  642. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/backend_init_context.h +72 -0
  643. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/backend/interface.h +166 -0
  644. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/array_ref.h +235 -0
  645. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/data_loader.h +136 -0
  646. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/defines.h +20 -0
  647. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/error.h +229 -0
  648. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/evalue.h +521 -0
  649. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer.h +565 -0
  650. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks.h +323 -0
  651. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  652. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  653. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  654. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  655. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  656. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  657. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  658. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/freeable_buffer.h +107 -0
  659. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/hierarchical_allocator.h +107 -0
  660. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/memory_allocator.h +198 -0
  661. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/named_data_map.h +86 -0
  662. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  663. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  664. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/bits_types.h +83 -0
  665. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  666. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  667. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  668. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  669. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  670. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  671. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  672. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  673. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  674. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  675. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  676. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/complex.h +44 -0
  677. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/device.h +70 -0
  678. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/half.h +27 -0
  679. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/optional.h +36 -0
  680. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/qint_types.h +83 -0
  681. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar.h +110 -0
  682. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  683. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/string_view.h +29 -0
  684. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor.h +142 -0
  685. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  686. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  687. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/result.h +258 -0
  688. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/span.h +93 -0
  689. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tag.h +71 -0
  690. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tensor_layout.h +79 -0
  691. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  692. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/memory_manager.h +113 -0
  693. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method.h +387 -0
  694. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/method_meta.h +251 -0
  695. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/program.h +320 -0
  696. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/pte_data_map.h +144 -0
  697. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/executor/tensor_parser.h +156 -0
  698. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  699. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/kernel/operator_registry.h +278 -0
  700. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/abort.h +36 -0
  701. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/assert.h +119 -0
  702. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/clock.h +43 -0
  703. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compat_unistd.h +75 -0
  704. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/compiler.h +191 -0
  705. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/log.h +177 -0
  706. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/platform.h +133 -0
  707. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/profiler.h +292 -0
  708. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/runtime.h +35 -0
  709. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/system.h +49 -0
  710. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/runtime/platform/types.h +24 -0
  711. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/executorch/schema/extended_header.h +76 -0
  712. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/Headers/module.modulemap +5 -0
  713. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64/libexecutorch_ios.a +0 -0
  714. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/macros/Export.h +163 -0
  715. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/macros/Macros.h +497 -0
  716. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16-inl.h +342 -0
  717. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16-math.h +266 -0
  718. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/BFloat16.h +125 -0
  719. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/Half-inl.h +347 -0
  720. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/Half.h +416 -0
  721. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/TypeSafeSignMath.h +133 -0
  722. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/bit_cast.h +43 -0
  723. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/floating_point_utils.h +33 -0
  724. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/c10/util/irange.h +107 -0
  725. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorch.h +13 -0
  726. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchError.h +16 -0
  727. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchLog.h +76 -0
  728. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchModule.h +286 -0
  729. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchTensor.h +742 -0
  730. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/ExecuTorchValue.h +219 -0
  731. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/module/module.h +492 -0
  732. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor.h +13 -0
  733. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_accessor.h +190 -0
  734. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr.h +347 -0
  735. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/extension/tensor/tensor_ptr_maker.h +653 -0
  736. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_execution_context.h +71 -0
  737. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/backend_init_context.h +72 -0
  738. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/backend/interface.h +166 -0
  739. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/array_ref.h +235 -0
  740. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/data_loader.h +136 -0
  741. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/defines.h +20 -0
  742. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/error.h +229 -0
  743. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/evalue.h +521 -0
  744. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer.h +565 -0
  745. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks.h +323 -0
  746. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/event_tracer_hooks_delegate.h +197 -0
  747. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/exec_aten.h +147 -0
  748. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/dim_order_util.h +263 -0
  749. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1331 -0
  750. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  751. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +69 -0
  752. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/exec_aten/util/tensor_util.h +1250 -0
  753. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/freeable_buffer.h +107 -0
  754. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/hierarchical_allocator.h +107 -0
  755. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/memory_allocator.h +198 -0
  756. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/named_data_map.h +86 -0
  757. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  758. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  759. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/bits_types.h +83 -0
  760. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +163 -0
  761. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +497 -0
  762. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +342 -0
  763. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +266 -0
  764. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +125 -0
  765. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +347 -0
  766. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/Half.h +416 -0
  767. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +133 -0
  768. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +43 -0
  769. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +33 -0
  770. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/c10/c10/util/irange.h +107 -0
  771. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/complex.h +44 -0
  772. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/device.h +70 -0
  773. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/half.h +27 -0
  774. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/optional.h +36 -0
  775. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/qint_types.h +83 -0
  776. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar.h +110 -0
  777. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  778. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/string_view.h +29 -0
  779. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor.h +142 -0
  780. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_impl.h +261 -0
  781. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  782. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/result.h +258 -0
  783. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/span.h +93 -0
  784. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tag.h +71 -0
  785. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tensor_layout.h +79 -0
  786. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  787. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/memory_manager.h +113 -0
  788. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method.h +387 -0
  789. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/method_meta.h +251 -0
  790. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/program.h +320 -0
  791. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/pte_data_map.h +144 -0
  792. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/executor/tensor_parser.h +156 -0
  793. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/kernel_runtime_context.h +122 -0
  794. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/kernel/operator_registry.h +278 -0
  795. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/abort.h +36 -0
  796. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/assert.h +119 -0
  797. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/clock.h +43 -0
  798. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compat_unistd.h +75 -0
  799. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/compiler.h +191 -0
  800. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/log.h +177 -0
  801. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/platform.h +133 -0
  802. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/profiler.h +292 -0
  803. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/runtime.h +35 -0
  804. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/system.h +49 -0
  805. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/runtime/platform/types.h +24 -0
  806. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/executorch/schema/extended_header.h +76 -0
  807. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/Headers/module.modulemap +5 -0
  808. package/third-party/ios/ExecutorchLib/frameworks/executorch.xcframework/ios-arm64-simulator/libexecutorch_simulator.a +0 -0
  809. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/Info.plist +43 -0
  810. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/ios-arm64/libkernels_custom_ios.a +0 -0
  811. package/third-party/ios/ExecutorchLib/frameworks/kernels_custom.xcframework/ios-arm64-simulator/libkernels_custom_simulator.a +0 -0
  812. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/Info.plist +43 -0
  813. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/ios-arm64/libkernels_optimized_ios.a +0 -0
  814. package/third-party/ios/ExecutorchLib/frameworks/kernels_optimized.xcframework/ios-arm64-simulator/libkernels_optimized_simulator.a +0 -0
  815. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/Info.plist +43 -0
  816. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/ios-arm64/libkernels_portable_ios.a +0 -0
  817. package/third-party/ios/ExecutorchLib/frameworks/kernels_portable.xcframework/ios-arm64-simulator/libkernels_portable_simulator.a +0 -0
  818. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/Info.plist +43 -0
  819. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/ios-arm64/libkernels_quantized_ios.a +0 -0
  820. package/third-party/ios/ExecutorchLib/frameworks/kernels_quantized.xcframework/ios-arm64-simulator/libkernels_quantized_simulator.a +0 -0
  821. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/Info.plist +43 -0
  822. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/bitmap256.h +82 -0
  823. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/filtered_re2.h +111 -0
  824. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/pod_array.h +43 -0
  825. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter.h +130 -0
  826. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prefilter_tree.h +139 -0
  827. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/prog.h +483 -0
  828. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/re2.h +994 -0
  829. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/regexp.h +692 -0
  830. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/set.h +85 -0
  831. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_array.h +367 -0
  832. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/sparse_set.h +241 -0
  833. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/stringpiece.h +205 -0
  834. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_casefold.h +78 -0
  835. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/unicode_groups.h +64 -0
  836. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Headers/walker-inl.h +235 -0
  837. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/Info.plist +26 -0
  838. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64/re2.framework/re2 +0 -0
  839. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/bitmap256.h +82 -0
  840. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/filtered_re2.h +111 -0
  841. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/pod_array.h +43 -0
  842. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter.h +130 -0
  843. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prefilter_tree.h +139 -0
  844. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/prog.h +483 -0
  845. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/re2.h +994 -0
  846. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/regexp.h +692 -0
  847. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/set.h +85 -0
  848. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_array.h +367 -0
  849. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/sparse_set.h +241 -0
  850. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/stringpiece.h +205 -0
  851. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_casefold.h +78 -0
  852. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/unicode_groups.h +64 -0
  853. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Headers/walker-inl.h +235 -0
  854. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/Info.plist +26 -0
  855. package/third-party/ios/ExecutorchLib/frameworks/re2.xcframework/ios-arm64-simulator/re2.framework/re2 +0 -0
  856. package/third-party/ios/ios.toolchain.cmake +1122 -0
  857. package/LICENSE +0 -79
  858. package/README.md +0 -148
  859. package/android/src/main/java/com/swmansion/rnexecutorch/Classification.kt +0 -64
  860. package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +0 -90
  861. package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +0 -58
  862. package/android/src/main/java/com/swmansion/rnexecutorch/OCR.kt +0 -90
  863. package/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt +0 -64
  864. package/android/src/main/java/com/swmansion/rnexecutorch/SpeechToText.kt +0 -91
  865. package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +0 -54
  866. package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +0 -51
  867. package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +0 -86
  868. package/android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt +0 -179
  869. package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +0 -54
  870. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +0 -48
  871. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +0 -37
  872. package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +0 -46
  873. package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/Constants.kt +0 -1005
  874. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +0 -26
  875. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +0 -142
  876. package/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt +0 -74
  877. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Detector.kt +0 -82
  878. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt +0 -117
  879. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/Recognizer.kt +0 -51
  880. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/VerticalDetector.kt +0 -89
  881. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/CTCLabelConverter.kt +0 -58
  882. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/Constants.kt +0 -31
  883. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/DetectorUtils.kt +0 -608
  884. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +0 -430
  885. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TDecoder.kt +0 -39
  886. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/BaseS2TModule.kt +0 -43
  887. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Moonshine.kt +0 -16
  888. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineDecoder.kt +0 -23
  889. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/MoonshineEncoder.kt +0 -20
  890. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/Whisper.kt +0 -16
  891. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperDecoder.kt +0 -22
  892. package/android/src/main/java/com/swmansion/rnexecutorch/models/speechToText/WhisperEncoder.kt +0 -29
  893. package/android/src/main/java/com/swmansion/rnexecutorch/models/styleTransfer/StyleTransferModel.kt +0 -43
  894. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -87
  895. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt +0 -34
  896. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ImageProcessor.kt +0 -237
  897. package/android/src/main/java/com/swmansion/rnexecutorch/utils/Numerical.kt +0 -8
  898. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt +0 -201
  899. package/android/src/main/java/com/swmansion/rnexecutorch/utils/STFT.kt +0 -50
  900. package/android/src/main/java/com/swmansion/rnexecutorch/utils/TensorUtils.kt +0 -103
  901. package/ios/RnExecutorch/Classification.h +0 -5
  902. package/ios/RnExecutorch/Classification.mm +0 -54
  903. package/ios/RnExecutorch/ETModule.h +0 -5
  904. package/ios/RnExecutorch/ETModule.mm +0 -75
  905. package/ios/RnExecutorch/ImageSegmentation.h +0 -5
  906. package/ios/RnExecutorch/ImageSegmentation.mm +0 -60
  907. package/ios/RnExecutorch/OCR.h +0 -5
  908. package/ios/RnExecutorch/OCR.mm +0 -96
  909. package/ios/RnExecutorch/ObjectDetection.h +0 -5
  910. package/ios/RnExecutorch/ObjectDetection.mm +0 -56
  911. package/ios/RnExecutorch/SpeechToText.h +0 -5
  912. package/ios/RnExecutorch/SpeechToText.mm +0 -125
  913. package/ios/RnExecutorch/StyleTransfer.h +0 -5
  914. package/ios/RnExecutorch/StyleTransfer.mm +0 -55
  915. package/ios/RnExecutorch/TextEmbeddings.h +0 -5
  916. package/ios/RnExecutorch/TextEmbeddings.mm +0 -62
  917. package/ios/RnExecutorch/Tokenizer.h +0 -5
  918. package/ios/RnExecutorch/Tokenizer.mm +0 -83
  919. package/ios/RnExecutorch/VerticalOCR.h +0 -5
  920. package/ios/RnExecutorch/VerticalOCR.mm +0 -183
  921. package/ios/RnExecutorch/models/BaseModel.h +0 -21
  922. package/ios/RnExecutorch/models/BaseModel.mm +0 -43
  923. package/ios/RnExecutorch/models/classification/ClassificationModel.h +0 -10
  924. package/ios/RnExecutorch/models/classification/ClassificationModel.mm +0 -53
  925. package/ios/RnExecutorch/models/classification/Constants.h +0 -3
  926. package/ios/RnExecutorch/models/image_segmentation/Constants.h +0 -4
  927. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +0 -10
  928. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +0 -146
  929. package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.hpp +0 -11
  930. package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +0 -64
  931. package/ios/RnExecutorch/models/ocr/Detector.h +0 -9
  932. package/ios/RnExecutorch/models/ocr/Detector.mm +0 -101
  933. package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +0 -16
  934. package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +0 -135
  935. package/ios/RnExecutorch/models/ocr/Recognizer.h +0 -8
  936. package/ios/RnExecutorch/models/ocr/Recognizer.mm +0 -77
  937. package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -10
  938. package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +0 -118
  939. package/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.h +0 -16
  940. package/ios/RnExecutorch/models/ocr/utils/CTCLabelConverter.mm +0 -80
  941. package/ios/RnExecutorch/models/ocr/utils/Constants.h +0 -26
  942. package/ios/RnExecutorch/models/ocr/utils/DetectorUtils.h +0 -31
  943. package/ios/RnExecutorch/models/ocr/utils/DetectorUtils.mm +0 -754
  944. package/ios/RnExecutorch/models/ocr/utils/OCRUtils.h +0 -10
  945. package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -67
  946. package/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.h +0 -35
  947. package/ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm +0 -331
  948. package/ios/RnExecutorch/models/stt/Moonshine.hpp +0 -13
  949. package/ios/RnExecutorch/models/stt/Moonshine.mm +0 -64
  950. package/ios/RnExecutorch/models/stt/MoonshineDecoder.hpp +0 -16
  951. package/ios/RnExecutorch/models/stt/MoonshineDecoder.mm +0 -24
  952. package/ios/RnExecutorch/models/stt/MoonshineEncoder.hpp +0 -15
  953. package/ios/RnExecutorch/models/stt/MoonshineEncoder.mm +0 -18
  954. package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.hpp +0 -26
  955. package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +0 -19
  956. package/ios/RnExecutorch/models/stt/Whisper.hpp +0 -12
  957. package/ios/RnExecutorch/models/stt/Whisper.mm +0 -68
  958. package/ios/RnExecutorch/models/stt/WhisperDecoder.hpp +0 -16
  959. package/ios/RnExecutorch/models/stt/WhisperDecoder.mm +0 -22
  960. package/ios/RnExecutorch/models/stt/WhisperEncoder.hpp +0 -15
  961. package/ios/RnExecutorch/models/stt/WhisperEncoder.mm +0 -21
  962. package/ios/RnExecutorch/models/style_transfer/StyleTransferModel.h +0 -11
  963. package/ios/RnExecutorch/models/style_transfer/StyleTransferModel.mm +0 -50
  964. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +0 -15
  965. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +0 -45
  966. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +0 -8
  967. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +0 -49
  968. package/ios/RnExecutorch/utils/Constants.h +0 -8
  969. package/ios/RnExecutorch/utils/ObjectDetectionUtils.hpp +0 -23
  970. package/ios/RnExecutorch/utils/SFFT.hpp +0 -13
  971. package/ios/RnExecutorch/utils/SFFT.mm +0 -71
  972. package/lib/module/native/NativeClassification.js +0 -5
  973. package/lib/module/native/NativeClassification.js.map +0 -1
  974. package/lib/module/native/NativeETModule.js +0 -5
  975. package/lib/module/native/NativeETModule.js.map +0 -1
  976. package/lib/module/native/NativeImageSegmentation.js +0 -5
  977. package/lib/module/native/NativeImageSegmentation.js.map +0 -1
  978. package/lib/module/native/NativeOCR.js +0 -5
  979. package/lib/module/native/NativeOCR.js.map +0 -1
  980. package/lib/module/native/NativeObjectDetection.js +0 -5
  981. package/lib/module/native/NativeObjectDetection.js.map +0 -1
  982. package/lib/module/native/NativeSpeechToText.js +0 -5
  983. package/lib/module/native/NativeSpeechToText.js.map +0 -1
  984. package/lib/module/native/NativeStyleTransfer.js +0 -5
  985. package/lib/module/native/NativeStyleTransfer.js.map +0 -1
  986. package/lib/module/native/NativeTextEmbeddings.js +0 -5
  987. package/lib/module/native/NativeTextEmbeddings.js.map +0 -1
  988. package/lib/module/native/NativeTokenizer.js +0 -5
  989. package/lib/module/native/NativeTokenizer.js.map +0 -1
  990. package/lib/module/native/NativeVerticalOCR.js +0 -5
  991. package/lib/module/native/NativeVerticalOCR.js.map +0 -1
  992. package/lib/module/package.json +0 -1
  993. package/lib/typescript/native/NativeClassification.d.ts +0 -10
  994. package/lib/typescript/native/NativeClassification.d.ts.map +0 -1
  995. package/lib/typescript/native/NativeETModule.d.ts +0 -9
  996. package/lib/typescript/native/NativeETModule.d.ts.map +0 -1
  997. package/lib/typescript/native/NativeImageSegmentation.d.ts +0 -10
  998. package/lib/typescript/native/NativeImageSegmentation.d.ts.map +0 -1
  999. package/lib/typescript/native/NativeOCR.d.ts +0 -9
  1000. package/lib/typescript/native/NativeOCR.d.ts.map +0 -1
  1001. package/lib/typescript/native/NativeObjectDetection.d.ts +0 -9
  1002. package/lib/typescript/native/NativeObjectDetection.d.ts.map +0 -1
  1003. package/lib/typescript/native/NativeSpeechToText.d.ts +0 -12
  1004. package/lib/typescript/native/NativeSpeechToText.d.ts.map +0 -1
  1005. package/lib/typescript/native/NativeStyleTransfer.d.ts.map +0 -1
  1006. package/lib/typescript/native/NativeTextEmbeddings.d.ts +0 -8
  1007. package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +0 -1
  1008. package/lib/typescript/native/NativeTokenizer.d.ts +0 -12
  1009. package/lib/typescript/native/NativeTokenizer.d.ts.map +0 -1
  1010. package/lib/typescript/native/NativeVerticalOCR.d.ts +0 -9
  1011. package/lib/typescript/native/NativeVerticalOCR.d.ts.map +0 -1
  1012. package/src/native/NativeClassification.ts +0 -9
  1013. package/src/native/NativeETModule.ts +0 -14
  1014. package/src/native/NativeImageSegmentation.ts +0 -14
  1015. package/src/native/NativeOCR.ts +0 -16
  1016. package/src/native/NativeObjectDetection.ts +0 -10
  1017. package/src/native/NativeSpeechToText.ts +0 -17
  1018. package/src/native/NativeStyleTransfer.ts +0 -10
  1019. package/src/native/NativeTextEmbeddings.ts +0 -9
  1020. package/src/native/NativeTokenizer.ts +0 -13
  1021. package/src/native/NativeVerticalOCR.ts +0 -16
@@ -0,0 +1,3842 @@
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
6
+ license.
7
+ // If you do not agree to this license, do not download, install,
8
+ // copy or use the software.
9
+ //
10
+ //
11
+ // License Agreement
12
+ // For Open Source Computer Vision Library
13
+ //
14
+ // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
15
+ // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
16
+ // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
17
+ // Third party copyrights are property of their respective owners.
18
+ //
19
+ // Redistribution and use in source and binary forms, with or without
20
+ modification,
21
+ // are permitted provided that the following conditions are met:
22
+ //
23
+ // * Redistribution's of source code must retain the above copyright notice,
24
+ // this list of conditions and the following disclaimer.
25
+ //
26
+ // * Redistribution's in binary form must reproduce the above copyright
27
+ notice,
28
+ // this list of conditions and the following disclaimer in the documentation
29
+ // and/or other materials provided with the distribution.
30
+ //
31
+ // * The name of the copyright holders may not be used to endorse or promote
32
+ products
33
+ // derived from this software without specific prior written permission.
34
+ //
35
+ // This software is provided by the copyright holders and contributors "as is"
36
+ and
37
+ // any express or implied warranties, including, but not limited to, the implied
38
+ // warranties of merchantability and fitness for a particular purpose are
39
+ disclaimed.
40
+ // In no event shall the Intel Corporation or contributors be liable for any
41
+ direct,
42
+ // indirect, incidental, special, exemplary, or consequential damages
43
+ // (including, but not limited to, procurement of substitute goods or services;
44
+ // loss of use, data, or profits; or business interruption) however caused
45
+ // and on any theory of liability, whether in contract, strict liability,
46
+ // or tort (including negligence or otherwise) arising in any way out of
47
+ // the use of this software, even if advised of the possibility of such damage.
48
+ //
49
+ //M*/
50
+
51
+ #ifndef OPENCV_CORE_MAT_HPP
52
+ #define OPENCV_CORE_MAT_HPP
53
+
54
+ #ifndef __cplusplus
55
+ #error mat.hpp header must be compiled as C++
56
+ #endif
57
+
58
+ #include "opencv2/core/matx.hpp"
59
+ #include "opencv2/core/types.hpp"
60
+
61
+ #include "opencv2/core/bufferpool.hpp"
62
+
63
+ #include <array>
64
+ #include <type_traits>
65
+
66
+ namespace cv {
67
+
68
+ //! @addtogroup core_basic
69
+ //! @{
70
+
71
+ enum AccessFlag {
72
+ ACCESS_READ = 1 << 24,
73
+ ACCESS_WRITE = 1 << 25,
74
+ ACCESS_RW = 3 << 24,
75
+ ACCESS_MASK = ACCESS_RW,
76
+ ACCESS_FAST = 1 << 26
77
+ };
78
+ CV_ENUM_FLAGS(AccessFlag)
79
+ __CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag)
80
+
81
+ CV__DEBUG_NS_BEGIN
82
+
83
+ class CV_EXPORTS _OutputArray;
84
+
85
+ //////////////////////// Input/Output Array Arguments
86
+ ////////////////////////////////////
87
+
88
+ /** @brief This is the proxy class for passing read-only input arrays into
89
+ OpenCV functions.
90
+
91
+ It is defined as:
92
+ @code
93
+ typedef const _InputArray& InputArray;
94
+ @endcode
95
+ where \ref cv::_InputArray is a class that can be constructed from \ref cv::Mat,
96
+ \ref cv::Mat_<T>,
97
+ \ref cv::Matx<T, m, n>, std::vector<T>, std::vector<std::vector<T>>,
98
+ std::vector<Mat>, std::vector<Mat_<T>>, \ref cv::UMat, std::vector<UMat> or
99
+ `double`. It can also be constructed from a matrix expression.
100
+
101
+ Since this is mostly implementation-level class, and its interface may change in
102
+ future versions, we do not describe it in details. There are a few key things,
103
+ though, that should be kept in mind:
104
+
105
+ - When you see in the reference manual or in OpenCV source code a function
106
+ that takes InputArray, it means that you can actually pass `Mat`, `Matx`,
107
+ `vector<T>` etc. (see above the complete list).
108
+ - Optional input arguments: If some of the input arrays may be empty, pass
109
+ cv::noArray() (or simply cv::Mat() as you probably did before).
110
+ - The class is designed solely for passing parameters. That is, normally you
111
+ *should not* declare class members, local and global variables of this type.
112
+ - If you want to design your own function or a class method that can operate
113
+ of arrays of multiple types, you can use InputArray (or OutputArray) for the
114
+ respective parameters. Inside a function you should use _InputArray::getMat()
115
+ method to construct a matrix header for the array (without copying data).
116
+ _InputArray::kind() can be used to distinguish Mat from `vector<>` etc., but
117
+ normally it is not needed.
118
+
119
+ Here is how you can use a function that takes InputArray :
120
+ @code
121
+ std::vector<Point2f> vec;
122
+ // points or a circle
123
+ for( int i = 0; i < 30; i++ )
124
+ vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)),
125
+ (float)(100 - 30*sin(i*CV_PI*2/5))));
126
+ cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20));
127
+ @endcode
128
+ That is, we form an STL vector containing points, and apply in-place affine
129
+ transformation to the vector using the 2x3 matrix created inline as `Matx<float,
130
+ 2, 3>` instance.
131
+
132
+ Here is how such a function can be implemented (for simplicity, we implement a
133
+ very specific case of it, according to the assertion statement inside) :
134
+ @code
135
+ void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m)
136
+ {
137
+ // get Mat headers for input arrays. This is O(1) operation,
138
+ // unless _src and/or _m are matrix expressions.
139
+ Mat src = _src.getMat(), m = _m.getMat();
140
+ CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() ==
141
+ Size(3, 2) );
142
+
143
+ // [re]create the output array so that it has the proper size and type.
144
+ // In case of Mat it calls Mat::create, in case of STL vector it calls
145
+ vector::resize. _dst.create(src.size(), src.type()); Mat dst = _dst.getMat();
146
+
147
+ for( int i = 0; i < src.rows; i++ )
148
+ for( int j = 0; j < src.cols; j++ )
149
+ {
150
+ Point2f pt = src.at<Point2f>(i, j);
151
+ dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x +
152
+ m.at<float>(0, 1)*pt.y +
153
+ m.at<float>(0, 2),
154
+ m.at<float>(1, 0)*pt.x +
155
+ m.at<float>(1, 1)*pt.y +
156
+ m.at<float>(1, 2));
157
+ }
158
+ }
159
+ @endcode
160
+ There is another related type, InputArrayOfArrays, which is currently defined as
161
+ a synonym for InputArray:
162
+ @code
163
+ typedef InputArray InputArrayOfArrays;
164
+ @endcode
165
+ It denotes function arguments that are either vectors of vectors or vectors of
166
+ matrices. A separate synonym is needed to generate Python/Java etc. wrappers
167
+ properly. At the function implementation level their use is similar, but
168
+ _InputArray::getMat(idx) should be used to get header for the idx-th component
169
+ of the outer vector and _InputArray::size().area() should be used to find the
170
+ number of components (vectors/matrices) of the outer vector.
171
+
172
+ In general, type support is limited to cv::Mat types. Other types are forbidden.
173
+ But in some cases we need to support passing of custom non-general Mat types,
174
+ like arrays of cv::KeyPoint, cv::DMatch, etc. This data is not intended to be
175
+ interpreted as an image data, or processed somehow like regular cv::Mat. To pass
176
+ such custom type use rawIn() / rawOut() / rawInOut() wrappers. Custom type is
177
+ wrapped as Mat-compatible `CV_8UC<N>` values (N = sizeof(T), N <= CV_CN_MAX).
178
+ */
179
+ class CV_EXPORTS _InputArray {
180
+ public:
181
+ enum KindFlag {
182
+ KIND_SHIFT = 16,
183
+ FIXED_TYPE = 0x8000 << KIND_SHIFT,
184
+ FIXED_SIZE = 0x4000 << KIND_SHIFT,
185
+ KIND_MASK = 31 << KIND_SHIFT,
186
+
187
+ NONE = 0 << KIND_SHIFT,
188
+ MAT = 1 << KIND_SHIFT,
189
+ MATX = 2 << KIND_SHIFT,
190
+ STD_VECTOR = 3 << KIND_SHIFT,
191
+ STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
192
+ STD_VECTOR_MAT = 5 << KIND_SHIFT,
193
+ #if OPENCV_ABI_COMPATIBILITY < 500
194
+ EXPR =
195
+ 6
196
+ << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/pull/17046
197
+ #endif
198
+ STD_BOOL_VECTOR = 12 << KIND_SHIFT,
199
+ #if OPENCV_ABI_COMPATIBILITY < 500
200
+ STD_ARRAY =
201
+ 14 << KIND_SHIFT, //!< removed:
202
+ //!< https://github.com/opencv/opencv/issues/18897
203
+ #endif
204
+ STD_ARRAY_MAT = 15 << KIND_SHIFT
205
+ };
206
+
207
+ _InputArray();
208
+ _InputArray(int _flags, void *_obj);
209
+ _InputArray(const Mat &m);
210
+ _InputArray(const MatExpr &expr);
211
+ _InputArray(const std::vector<Mat> &vec);
212
+ template <typename _Tp> _InputArray(const Mat_<_Tp> &m);
213
+ template <typename _Tp> _InputArray(const std::vector<_Tp> &vec);
214
+ _InputArray(const std::vector<bool> &vec);
215
+ template <typename _Tp> _InputArray(const std::vector<std::vector<_Tp>> &vec);
216
+ _InputArray(const std::vector<std::vector<bool>> &) = delete; // not supported
217
+ template <typename _Tp> _InputArray(const std::vector<Mat_<_Tp>> &vec);
218
+ template <typename _Tp> _InputArray(const _Tp *vec, int n);
219
+ template <typename _Tp, int m, int n>
220
+ _InputArray(const Matx<_Tp, m, n> &matx);
221
+ _InputArray(const double &val);
222
+
223
+ template <typename _Tp, std::size_t _Nm>
224
+ _InputArray(const std::array<_Tp, _Nm> &arr);
225
+ template <std::size_t _Nm> _InputArray(const std::array<Mat, _Nm> &arr);
226
+
227
+ template <typename _Tp> static _InputArray rawIn(const std::vector<_Tp> &vec);
228
+ template <typename _Tp, std::size_t _Nm>
229
+ static _InputArray rawIn(const std::array<_Tp, _Nm> &arr);
230
+
231
+ Mat getMat(int idx = -1) const;
232
+ Mat getMat_(int idx = -1) const;
233
+ void getMatVector(std::vector<Mat> &mv) const;
234
+
235
+ int getFlags() const;
236
+ void *getObj() const;
237
+ Size getSz() const;
238
+
239
+ _InputArray::KindFlag kind() const;
240
+ int dims(int i = -1) const;
241
+ int cols(int i = -1) const;
242
+ int rows(int i = -1) const;
243
+ Size size(int i = -1) const;
244
+ int sizend(int *sz, int i = -1) const;
245
+ bool sameSize(const _InputArray &arr) const;
246
+ size_t total(int i = -1) const;
247
+ int type(int i = -1) const;
248
+ int depth(int i = -1) const;
249
+ int channels(int i = -1) const;
250
+ bool isContinuous(int i = -1) const;
251
+ bool isSubmatrix(int i = -1) const;
252
+ bool empty() const;
253
+ void copyTo(const _OutputArray &arr) const;
254
+ void copyTo(const _OutputArray &arr, const _InputArray &mask) const;
255
+ size_t offset(int i = -1) const;
256
+ size_t step(int i = -1) const;
257
+ bool isMat() const;
258
+ bool isMatVector() const;
259
+ bool isMatx() const;
260
+ bool isVector() const;
261
+ ~_InputArray();
262
+
263
+ protected:
264
+ int flags;
265
+ void *obj;
266
+ Size sz;
267
+
268
+ void init(int _flags, const void *_obj);
269
+ void init(int _flags, const void *_obj, Size _sz);
270
+ };
271
+ CV_ENUM_FLAGS(_InputArray::KindFlag)
272
+ __CV_ENUM_FLAGS_BITWISE_AND(_InputArray::KindFlag, int, _InputArray::KindFlag)
273
+
274
+ /** @brief This type is very similar to InputArray except that it is used for
275
+ input/output and output function parameters.
276
+
277
+ Just like with InputArray, OpenCV users should not care about OutputArray, they
278
+ just pass `Mat`, `vector<T>` etc. to the functions. The same limitation as for
279
+ `InputArray`: *Do not explicitly create OutputArray instances* applies here too.
280
+
281
+ If you want to make your function polymorphic (i.e. accept different arrays as
282
+ output parameters), it is also not very difficult. Take the sample above as the
283
+ reference. Note that _OutputArray::create() needs to be called before
284
+ _OutputArray::getMat(). This way you guarantee that the output array is properly
285
+ allocated.
286
+
287
+ Optional output parameters. If you do not need certain output array to be
288
+ computed and returned to you, pass cv::noArray(), just like you would in the
289
+ case of optional input array. At the implementation level, use
290
+ _OutputArray::needed() to check if certain output array needs to be computed or
291
+ not.
292
+
293
+ There are several synonyms for OutputArray that are used to assist automatic
294
+ Python/Java/... wrapper generators:
295
+ @code
296
+ typedef OutputArray OutputArrayOfArrays;
297
+ typedef OutputArray InputOutputArray;
298
+ typedef OutputArray InputOutputArrayOfArrays;
299
+ @endcode
300
+ */
301
+ class CV_EXPORTS _OutputArray : public _InputArray {
302
+ public:
303
+ enum DepthMask {
304
+ DEPTH_MASK_8U = 1 << CV_8U,
305
+ DEPTH_MASK_8S = 1 << CV_8S,
306
+ DEPTH_MASK_16U = 1 << CV_16U,
307
+ DEPTH_MASK_16S = 1 << CV_16S,
308
+ DEPTH_MASK_32S = 1 << CV_32S,
309
+ DEPTH_MASK_32F = 1 << CV_32F,
310
+ DEPTH_MASK_64F = 1 << CV_64F,
311
+ DEPTH_MASK_16F = 1 << CV_16F,
312
+ DEPTH_MASK_ALL = (DEPTH_MASK_64F << 1) - 1,
313
+ DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
314
+ DEPTH_MASK_ALL_16F = (DEPTH_MASK_16F << 1) - 1,
315
+ DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
316
+ };
317
+
318
+ _OutputArray();
319
+ _OutputArray(int _flags, void *_obj);
320
+ _OutputArray(Mat &m);
321
+ _OutputArray(std::vector<Mat> &vec);
322
+ template <typename _Tp> _OutputArray(std::vector<_Tp> &vec);
323
+ _OutputArray(std::vector<bool> &vec) = delete; // not supported
324
+ template <typename _Tp> _OutputArray(std::vector<std::vector<_Tp>> &vec);
325
+ _OutputArray(std::vector<std::vector<bool>> &) = delete; // not supported
326
+ template <typename _Tp> _OutputArray(std::vector<Mat_<_Tp>> &vec);
327
+ template <typename _Tp> _OutputArray(Mat_<_Tp> &m);
328
+ template <typename _Tp> _OutputArray(_Tp *vec, int n);
329
+ template <typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n> &matx);
330
+
331
+ _OutputArray(const Mat &m);
332
+ _OutputArray(const std::vector<Mat> &vec);
333
+ template <typename _Tp> _OutputArray(const std::vector<_Tp> &vec);
334
+ template <typename _Tp>
335
+ _OutputArray(const std::vector<std::vector<_Tp>> &vec);
336
+ template <typename _Tp> _OutputArray(const std::vector<Mat_<_Tp>> &vec);
337
+ template <typename _Tp> _OutputArray(const Mat_<_Tp> &m);
338
+ template <typename _Tp> _OutputArray(const _Tp *vec, int n);
339
+ template <typename _Tp, int m, int n>
340
+ _OutputArray(const Matx<_Tp, m, n> &matx);
341
+
342
+ template <typename _Tp, std::size_t _Nm>
343
+ _OutputArray(std::array<_Tp, _Nm> &arr);
344
+ template <typename _Tp, std::size_t _Nm>
345
+ _OutputArray(const std::array<_Tp, _Nm> &arr);
346
+ template <std::size_t _Nm> _OutputArray(std::array<Mat, _Nm> &arr);
347
+ template <std::size_t _Nm> _OutputArray(const std::array<Mat, _Nm> &arr);
348
+
349
+ template <typename _Tp> static _OutputArray rawOut(std::vector<_Tp> &vec);
350
+ template <typename _Tp, std::size_t _Nm>
351
+ static _OutputArray rawOut(std::array<_Tp, _Nm> &arr);
352
+
353
+ bool fixedSize() const;
354
+ bool fixedType() const;
355
+ bool needed() const;
356
+ Mat &getMatRef(int i = -1) const;
357
+ void create(Size sz, int type, int i = -1, bool allowTransposed = false,
358
+ _OutputArray::DepthMask fixedDepthMask =
359
+ static_cast<_OutputArray::DepthMask>(0)) const;
360
+ void create(int rows, int cols, int type, int i = -1,
361
+ bool allowTransposed = false,
362
+ _OutputArray::DepthMask fixedDepthMask =
363
+ static_cast<_OutputArray::DepthMask>(0)) const;
364
+ void create(int dims, const int *size, int type, int i = -1,
365
+ bool allowTransposed = false,
366
+ _OutputArray::DepthMask fixedDepthMask =
367
+ static_cast<_OutputArray::DepthMask>(0)) const;
368
+ void createSameSize(const _InputArray &arr, int mtype) const;
369
+ void release() const;
370
+ void clear() const;
371
+ void setTo(const _InputArray &value,
372
+ const _InputArray &mask = _InputArray()) const;
373
+
374
+ void assign(const Mat &m) const;
375
+
376
+ void assign(const std::vector<Mat> &v) const;
377
+
378
+ void move(Mat &m) const;
379
+ };
380
+
381
+ class CV_EXPORTS _InputOutputArray : public _OutputArray {
382
+ public:
383
+ _InputOutputArray();
384
+ _InputOutputArray(int _flags, void *_obj);
385
+ _InputOutputArray(Mat &m);
386
+ _InputOutputArray(std::vector<Mat> &vec);
387
+ template <typename _Tp> _InputOutputArray(std::vector<_Tp> &vec);
388
+ _InputOutputArray(std::vector<bool> &vec) = delete; // not supported
389
+ template <typename _Tp> _InputOutputArray(std::vector<std::vector<_Tp>> &vec);
390
+ template <typename _Tp> _InputOutputArray(std::vector<Mat_<_Tp>> &vec);
391
+ template <typename _Tp> _InputOutputArray(Mat_<_Tp> &m);
392
+ template <typename _Tp> _InputOutputArray(_Tp *vec, int n);
393
+ template <typename _Tp, int m, int n>
394
+ _InputOutputArray(Matx<_Tp, m, n> &matx);
395
+
396
+ _InputOutputArray(const Mat &m);
397
+ _InputOutputArray(const std::vector<Mat> &vec);
398
+ template <typename _Tp> _InputOutputArray(const std::vector<_Tp> &vec);
399
+ template <typename _Tp>
400
+ _InputOutputArray(const std::vector<std::vector<_Tp>> &vec);
401
+ template <typename _Tp> _InputOutputArray(const std::vector<Mat_<_Tp>> &vec);
402
+ template <typename _Tp> _InputOutputArray(const Mat_<_Tp> &m);
403
+ template <typename _Tp> _InputOutputArray(const _Tp *vec, int n);
404
+ template <typename _Tp, int m, int n>
405
+ _InputOutputArray(const Matx<_Tp, m, n> &matx);
406
+
407
+ template <typename _Tp, std::size_t _Nm>
408
+ _InputOutputArray(std::array<_Tp, _Nm> &arr);
409
+ template <typename _Tp, std::size_t _Nm>
410
+ _InputOutputArray(const std::array<_Tp, _Nm> &arr);
411
+ template <std::size_t _Nm> _InputOutputArray(std::array<Mat, _Nm> &arr);
412
+ template <std::size_t _Nm> _InputOutputArray(const std::array<Mat, _Nm> &arr);
413
+
414
+ template <typename _Tp>
415
+ static _InputOutputArray rawInOut(std::vector<_Tp> &vec);
416
+ template <typename _Tp, std::size_t _Nm>
417
+ _InputOutputArray rawInOut(std::array<_Tp, _Nm> &arr);
418
+ };
419
+
420
+ /** Helper to wrap custom types. @see InputArray */
421
+ template <typename _Tp> static inline _InputArray rawIn(_Tp &v);
422
+ /** Helper to wrap custom types. @see InputArray */
423
+ template <typename _Tp> static inline _OutputArray rawOut(_Tp &v);
424
+ /** Helper to wrap custom types. @see InputArray */
425
+ template <typename _Tp> static inline _InputOutputArray rawInOut(_Tp &v);
426
+
427
+ CV__DEBUG_NS_END
428
+
429
+ typedef const _InputArray &InputArray;
430
+ typedef InputArray InputArrayOfArrays;
431
+ typedef const _OutputArray &OutputArray;
432
+ typedef OutputArray OutputArrayOfArrays;
433
+ typedef const _InputOutputArray &InputOutputArray;
434
+ typedef InputOutputArray InputOutputArrayOfArrays;
435
+
436
+ /** @brief Returns an empty InputArray or OutputArray.
437
+
438
+ This function is used to provide an "empty" or "null" array when certain
439
+ functions take optional input or output arrays that you don't want to provide.
440
+
441
+ Many OpenCV functions accept optional arguments as `cv::InputArray` or
442
+ `cv::OutputArray`. When you don't want to pass any data for these optional
443
+ parameters, you can use `cv::noArray()` to indicate that you are omitting them.
444
+
445
+ @return An empty `cv::InputArray` or `cv::OutputArray` that can be used as a
446
+ placeholder.
447
+
448
+ @note This is often used when a function has optional arrays, and you do not
449
+ want to provide a specific input or output array.
450
+
451
+ @see cv::InputArray, cv::OutputArray
452
+ */
453
+ CV_EXPORTS InputOutputArray noArray();
454
+
455
+ /////////////////////////////////// MatAllocator
456
+ /////////////////////////////////////////
457
+
458
+ /** @brief Usage flags for allocator
459
+
460
+ @warning All flags except `USAGE_DEFAULT` are experimental.
461
+
462
+ @warning For the OpenCL allocator, `USAGE_ALLOCATE_SHARED_MEMORY` depends on
463
+ OpenCV's optional, experimental integration with OpenCL SVM. To enable this
464
+ integration, build OpenCV using the `WITH_OPENCL_SVM=ON` CMake option and, at
465
+ runtime, call `cv::ocl::Context::getDefault().setUseSVM(true);` or similar
466
+ code. Note that SVM is incompatible with OpenCL 1.x.
467
+ */
468
+ enum UMatUsageFlags {
469
+ USAGE_DEFAULT = 0,
470
+
471
+ // buffer allocation policy is platform and usage specific
472
+ USAGE_ALLOCATE_HOST_MEMORY = 1 << 0,
473
+ USAGE_ALLOCATE_DEVICE_MEMORY = 1 << 1,
474
+ USAGE_ALLOCATE_SHARED_MEMORY =
475
+ 1 << 2, // It is not equal to: USAGE_ALLOCATE_HOST_MEMORY |
476
+ // USAGE_ALLOCATE_DEVICE_MEMORY
477
+
478
+ __UMAT_USAGE_FLAGS_32BIT = 0x7fffffff // Binary compatibility hint
479
+ };
480
+
481
+ struct CV_EXPORTS UMatData;
482
+
483
+ /** @brief Custom array allocator
484
+ */
485
+ class CV_EXPORTS MatAllocator {
486
+ public:
487
+ MatAllocator() {}
488
+ virtual ~MatAllocator() {}
489
+
490
+ // let's comment it off for now to detect and fix all the uses of allocator
491
+ // virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
492
+ // uchar*& datastart, uchar*& data, size_t* step) = 0;
493
+ // virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
494
+ virtual UMatData *allocate(int dims, const int *sizes, int type, void *data,
495
+ size_t *step, AccessFlag flags,
496
+ UMatUsageFlags usageFlags) const = 0;
497
+ virtual bool allocate(UMatData *data, AccessFlag accessflags,
498
+ UMatUsageFlags usageFlags) const = 0;
499
+ virtual void deallocate(UMatData *data) const = 0;
500
+ virtual void map(UMatData *data, AccessFlag accessflags) const;
501
+ virtual void unmap(UMatData *data) const;
502
+ virtual void download(UMatData *data, void *dst, int dims, const size_t sz[],
503
+ const size_t srcofs[], const size_t srcstep[],
504
+ const size_t dststep[]) const;
505
+ virtual void upload(UMatData *data, const void *src, int dims,
506
+ const size_t sz[], const size_t dstofs[],
507
+ const size_t dststep[], const size_t srcstep[]) const;
508
+ virtual void copy(UMatData *srcdata, UMatData *dstdata, int dims,
509
+ const size_t sz[], const size_t srcofs[],
510
+ const size_t srcstep[], const size_t dstofs[],
511
+ const size_t dststep[], bool sync) const;
512
+
513
+ // default implementation returns DummyBufferPoolController
514
+ virtual BufferPoolController *
515
+ getBufferPoolController(const char *id = NULL) const;
516
+ };
517
+
518
+ //////////////////////////////// MatCommaInitializer
519
+ /////////////////////////////////////
520
+
521
+ /** @brief Comma-separated Matrix Initializer
522
+
523
+ The class instances are usually not created explicitly.
524
+ Instead, they are created on "matrix << firstValue" operator.
525
+
526
+ The sample below initializes 2x2 rotation matrix:
527
+
528
+ \code
529
+ double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
530
+ Mat R = (Mat_<double>(2,2) << a, -b, b, a);
531
+ \endcode
532
+ */
533
+ template <typename _Tp> class MatCommaInitializer_ {
534
+ public:
535
+ //! the constructor, created by "matrix << firstValue" operator, where matrix
536
+ //! is cv::Mat
537
+ MatCommaInitializer_(Mat_<_Tp> *_m);
538
+ //! the operator that takes the next value and put it to the matrix
539
+ template <typename T2> MatCommaInitializer_<_Tp> &operator,(T2 v);
540
+ //! another form of conversion operator
541
+ operator Mat_<_Tp>() const;
542
+
543
+ protected:
544
+ MatIterator_<_Tp> it;
545
+ };
546
+
547
+ /////////////////////////////////////// Mat
548
+ //////////////////////////////////////////////
549
+
550
+ // note that umatdata might be allocated together
551
+ // with the matrix data, not as a separate object.
552
+ // therefore, it does not have constructor or destructor;
553
+ // it should be explicitly initialized using init().
554
+ struct CV_EXPORTS UMatData {
555
+ enum MemoryFlag {
556
+ COPY_ON_MAP = 1,
557
+ HOST_COPY_OBSOLETE = 2,
558
+ DEVICE_COPY_OBSOLETE = 4,
559
+ TEMP_UMAT = 8,
560
+ TEMP_COPIED_UMAT = 24,
561
+ USER_ALLOCATED = 32,
562
+ DEVICE_MEM_MAPPED = 64,
563
+ ASYNC_CLEANUP = 128
564
+ };
565
+ UMatData(const MatAllocator *allocator);
566
+ ~UMatData();
567
+
568
+ // provide atomic access to the structure
569
+ void lock();
570
+ void unlock();
571
+
572
+ bool hostCopyObsolete() const;
573
+ bool deviceCopyObsolete() const;
574
+ bool deviceMemMapped() const;
575
+ bool copyOnMap() const;
576
+ bool tempUMat() const;
577
+ bool tempCopiedUMat() const;
578
+ void markHostCopyObsolete(bool flag);
579
+ void markDeviceCopyObsolete(bool flag);
580
+ void markDeviceMemMapped(bool flag);
581
+
582
+ const MatAllocator *prevAllocator;
583
+ const MatAllocator *currAllocator;
584
+ int urefcount;
585
+ int refcount;
586
+ uchar *data;
587
+ uchar *origdata;
588
+ size_t size;
589
+
590
+ UMatData::MemoryFlag flags;
591
+ void *handle;
592
+ void *userdata;
593
+ int allocatorFlags_;
594
+ int mapcount;
595
+ UMatData *originalUMatData;
596
+ std::shared_ptr<void> allocatorContext;
597
+ };
598
+ CV_ENUM_FLAGS(UMatData::MemoryFlag)
599
+
600
+ struct CV_EXPORTS MatSize {
601
+ explicit MatSize(int *_p) CV_NOEXCEPT;
602
+ int dims() const CV_NOEXCEPT;
603
+ Size operator()() const;
604
+ const int &operator[](int i) const;
605
+ int &operator[](int i);
606
+ operator const int *() const CV_NOEXCEPT; // TODO OpenCV 4.0: drop this
607
+ bool operator==(const MatSize &sz) const CV_NOEXCEPT;
608
+ bool operator!=(const MatSize &sz) const CV_NOEXCEPT;
609
+
610
+ int *p;
611
+ };
612
+
613
+ struct CV_EXPORTS MatStep {
614
+ MatStep() CV_NOEXCEPT;
615
+ explicit MatStep(size_t s) CV_NOEXCEPT;
616
+ const size_t &operator[](int i) const CV_NOEXCEPT;
617
+ size_t &operator[](int i) CV_NOEXCEPT;
618
+ operator size_t() const;
619
+ MatStep &operator=(size_t s);
620
+
621
+ size_t *p;
622
+ size_t buf[2];
623
+
624
+ protected:
625
+ MatStep &operator=(const MatStep &);
626
+ };
627
+
628
+ /** @example samples/cpp/cout_mat.cpp
629
+ An example demonstrating the serial out capabilities of cv::Mat
630
+ */
631
+
632
+ /** @brief n-dimensional dense array class \anchor CVMat_Details
633
+
634
+ The class Mat represents an n-dimensional dense numerical single-channel or
635
+ multi-channel array. It can be used to store real or complex-valued vectors and
636
+ matrices, grayscale or color images, voxel volumes, vector fields, point clouds,
637
+ tensors, histograms (though, very high-dimensional histograms may be better
638
+ stored in a SparseMat ). The data layout of the array `M` is defined by the
639
+ array `M.step[]`, so that the address of element \f$(i_0,...,i_{M.dims-1})\f$,
640
+ where \f$0\leq i_k<M.size[k]\f$, is computed as:
641
+ \f[addr(M_{i_0,...,i_{M.dims-1}}) = M.data + M.step[0]*i_0 + M.step[1]*i_1 + ...
642
+ + M.step[M.dims-1]*i_{M.dims-1}\f] In case of a 2-dimensional array, the above
643
+ formula is reduced to:
644
+ \f[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\f]
645
+ Note that `M.step[i] >= M.step[i+1]` (in fact, `M.step[i] >=
646
+ M.step[i+1]*M.size[i+1]` ). This means that 2-dimensional matrices are stored
647
+ row-by-row, 3-dimensional matrices are stored plane-by-plane, and so on.
648
+ M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() .
649
+
650
+ So, the data layout in Mat is compatible with the majority of dense array types
651
+ from the standard toolkits and SDKs, such as Numpy (ndarray), Win32 (independent
652
+ device bitmaps), and others, that is, with any array that uses *steps* (or
653
+ *strides*) to compute the position of a pixel. Due to this compatibility, it is
654
+ possible to make a Mat header for user-allocated data and process it in-place
655
+ using OpenCV functions.
656
+
657
+ There are many different ways to create a Mat object. The most popular options
658
+ are listed below:
659
+
660
+ - Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols,
661
+ type[, fillValue]) constructor. A new array of the specified size and type is
662
+ allocated. type has the same meaning as in the cvCreateMat method. For example,
663
+ CV_8UC1 means a 8-bit single-channel array, CV_32FC2 means a 2-channel (complex)
664
+ floating-point array, and so on.
665
+ @code
666
+ // make a 7x7 complex matrix filled with 1+3j.
667
+ Mat M(7,7,CV_32FC2,Scalar(1,3));
668
+ // and now turn M to a 100x60 15-channel 8-bit matrix.
669
+ // The old content will be deallocated
670
+ M.create(100,60,CV_8UC(15));
671
+ @endcode
672
+ As noted in the introduction to this chapter, create() allocates only a new
673
+ array when the shape or type of the current array are different from the
674
+ specified ones.
675
+
676
+ - Create a multi-dimensional array:
677
+ @code
678
+ // create a 100x100x100 8-bit array
679
+ int sz[] = {100, 100, 100};
680
+ Mat bigCube(3, sz, CV_8U, Scalar::all(0));
681
+ @endcode
682
+ It passes the number of dimensions =1 to the Mat constructor but the created
683
+ array will be 2-dimensional with the number of columns set to 1. So, Mat::dims
684
+ is always \>= 2 (can also be 0 when the array is empty).
685
+
686
+ - Use a copy constructor or assignment operator where there can be an array or
687
+ expression on the right side (see below). As noted in the introduction, the
688
+ array assignment is an O(1) operation because it only copies the header and
689
+ increases the reference counter. The Mat::clone() method can be used to get a
690
+ full (deep) copy of the array when you need it.
691
+
692
+ - Construct a header for a part of another array. It can be a single row, single
693
+ column, several rows, several columns, rectangular region in the array (called a
694
+ *minor* in algebra) or a diagonal. Such operations are also O(1) because the new
695
+ header references the same data. You can actually modify a part of the array
696
+ using this feature, for example:
697
+ @code
698
+ // add the 5-th row, multiplied by 3 to the 3rd row
699
+ M.row(3) = M.row(3) + M.row(5)*3;
700
+ // now copy the 7-th column to the 1-st column
701
+ // M.col(1) = M.col(7); // this will not work
702
+ Mat M1 = M.col(1);
703
+ M.col(7).copyTo(M1);
704
+ // create a new 320x240 image
705
+ Mat img(Size(320,240),CV_8UC3);
706
+ // select a ROI
707
+ Mat roi(img, Rect(10,10,100,100));
708
+ // fill the ROI with (0,255,0) (which is green in RGB space);
709
+ // the original 320x240 image will be modified
710
+ roi = Scalar(0,255,0);
711
+ @endcode
712
+ Due to the additional datastart and dataend members, it is possible to compute a
713
+ relative sub-array position in the main *container* array using locateROI():
714
+ @code
715
+ Mat A = Mat::eye(10, 10, CV_32S);
716
+ // extracts A columns, 1 (inclusive) to 3 (exclusive).
717
+ Mat B = A(Range::all(), Range(1, 3));
718
+ // extracts B rows, 5 (inclusive) to 9 (exclusive).
719
+ // that is, C \~ A(Range(5, 9), Range(1, 3))
720
+ Mat C = B(Range(5, 9), Range::all());
721
+ Size size; Point ofs;
722
+ C.locateROI(size, ofs);
723
+ // size will be (width=10,height=10) and the ofs will be (x=1, y=5)
724
+ @endcode
725
+ As in case of whole matrices, if you need a deep copy, use the `clone()` method
726
+ of the extracted sub-matrices.
727
+
728
+ - Make a header for user-allocated data. It can be useful to do the following:
729
+ -# Process "foreign" data using OpenCV (for example, when you implement a
730
+ DirectShow\* filter or a processing module for gstreamer, and so on). For
731
+ example:
732
+ @code
733
+ Mat process_video_frame(const unsigned char* pixels,
734
+ int width, int height, int step)
735
+ {
736
+ // wrap input buffer
737
+ Mat img(height, width, CV_8UC3, (unsigned char*)pixels, step);
738
+
739
+ Mat result;
740
+ GaussianBlur(img, result, Size(7, 7), 1.5, 1.5);
741
+
742
+ return result;
743
+ }
744
+ @endcode
745
+ -# Quickly initialize small matrices and/or get a super-fast element access.
746
+ @code
747
+ double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}};
748
+ Mat M = Mat(3, 3, CV_64F, m).inv();
749
+ @endcode
750
+ .
751
+
752
+ - Use MATLAB-style array initializers, zeros(), ones(), eye(), for example:
753
+ @code
754
+ // create a double-precision identity matrix and add it to M.
755
+ M += Mat::eye(M.rows, M.cols, CV_64F);
756
+ @endcode
757
+
758
+ - Use a comma-separated initializer:
759
+ @code
760
+ // create a 3x3 double-precision identity matrix
761
+ Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
762
+ @endcode
763
+ With this approach, you first call a constructor of the Mat class with the
764
+ proper parameters, and then you just put `<< operator` followed by
765
+ comma-separated values that can be constants, variables, expressions, and so on.
766
+ Also, note the extra parentheses required to avoid compilation errors.
767
+
768
+ Once the array is created, it is automatically managed via a reference-counting
769
+ mechanism. If the array header is built on top of user-allocated data, you
770
+ should handle the data by yourself. The array data is deallocated when no one
771
+ points to it. If you want to release the data pointed by a array header before
772
+ the array destructor is called, use Mat::release().
773
+
774
+ The next important thing to learn about the array class is element access. This
775
+ manual already described how to compute an address of each array element.
776
+ Normally, you are not required to use the formula directly in the code. If you
777
+ know the array element type (which can be retrieved using the method Mat::type()
778
+ ), you can access the element \f$M_{ij}\f$ of a 2-dimensional array as:
779
+ @code
780
+ M.at<double>(i,j) += 1.f;
781
+ @endcode
782
+ assuming that `M` is a double-precision floating-point array. There are several
783
+ variants of the method at for a different number of dimensions.
784
+
785
+ If you need to process a whole row of a 2D array, the most efficient way is to
786
+ get the pointer to the row first, and then just use the plain C operator [] :
787
+ @code
788
+ // compute sum of positive matrix elements
789
+ // (assuming that M is a double-precision matrix)
790
+ double sum=0;
791
+ for(int i = 0; i < M.rows; i++)
792
+ {
793
+ const double* Mi = M.ptr<double>(i);
794
+ for(int j = 0; j < M.cols; j++)
795
+ sum += std::max(Mi[j], 0.);
796
+ }
797
+ @endcode
798
+ Some operations, like the one above, do not actually depend on the array shape.
799
+ They just process elements of an array one by one (or elements from multiple
800
+ arrays that have the same coordinates, for example, array addition). Such
801
+ operations are called *element-wise*. It makes sense to check whether all the
802
+ input/output arrays are continuous, namely, have no gaps at the end of each row.
803
+ If yes, process them as a long single row:
804
+ @code
805
+ // compute the sum of positive matrix elements, optimized variant
806
+ double sum=0;
807
+ int cols = M.cols, rows = M.rows;
808
+ if(M.isContinuous())
809
+ {
810
+ cols *= rows;
811
+ rows = 1;
812
+ }
813
+ for(int i = 0; i < rows; i++)
814
+ {
815
+ const double* Mi = M.ptr<double>(i);
816
+ for(int j = 0; j < cols; j++)
817
+ sum += std::max(Mi[j], 0.);
818
+ }
819
+ @endcode
820
+ In case of the continuous matrix, the outer loop body is executed just once. So,
821
+ the overhead is smaller, which is especially noticeable in case of small
822
+ matrices.
823
+
824
+ Finally, there are STL-style iterators that are smart enough to skip gaps
825
+ between successive rows:
826
+ @code
827
+ // compute sum of positive matrix elements, iterator-based variant
828
+ double sum=0;
829
+ MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>();
830
+ for(; it != it_end; ++it)
831
+ sum += std::max(*it, 0.);
832
+ @endcode
833
+ The matrix iterators are random-access iterators, so they can be passed to any
834
+ STL algorithm, including std::sort().
835
+
836
+ @note Matrix Expressions and arithmetic see MatExpr
837
+ */
838
+ class CV_EXPORTS Mat {
839
+ public:
840
+ /**
841
+ These are various constructors that form a matrix. As noted in the
842
+ AutomaticAllocation, often the default constructor is enough, and the proper
843
+ matrix will be allocated by an OpenCV function. The constructed matrix can
844
+ further be assigned to another matrix or matrix expression or can be allocated
845
+ with Mat::create . In the former case, the old content is de-referenced.
846
+ */
847
+ Mat() CV_NOEXCEPT;
848
+
849
+ /** @overload
850
+ @param rows Number of rows in a 2D array.
851
+ @param cols Number of columns in a 2D array.
852
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
853
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
854
+ CV_CN_MAX channels) matrices.
855
+ */
856
+ Mat(int rows, int cols, int type);
857
+
858
+ /** @overload
859
+ @param size 2D array size: Size(cols, rows) . In the Size() constructor, the
860
+ number of rows and the number of columns go in the reverse order.
861
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
862
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
863
+ CV_CN_MAX channels) matrices.
864
+ */
865
+ Mat(Size size, int type);
866
+
867
+ /** @overload
868
+ @param rows Number of rows in a 2D array.
869
+ @param cols Number of columns in a 2D array.
870
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
871
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
872
+ CV_CN_MAX channels) matrices.
873
+ @param s An optional value to initialize each matrix element with. To set all
874
+ the matrix elements to the particular value after the construction, use the
875
+ assignment operator Mat::operator=(const Scalar& value) .
876
+ */
877
+ Mat(int rows, int cols, int type, const Scalar &s);
878
+
879
+ /** @overload
880
+ @param size 2D array size: Size(cols, rows) . In the Size() constructor, the
881
+ number of rows and the number of columns go in the reverse order.
882
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
883
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
884
+ CV_CN_MAX channels) matrices.
885
+ @param s An optional value to initialize each matrix element with. To set all
886
+ the matrix elements to the particular value after the construction, use the
887
+ assignment operator Mat::operator=(const Scalar& value) .
888
+ */
889
+ Mat(Size size, int type, const Scalar &s);
890
+
891
+ /** @overload
892
+ @param ndims Array dimensionality.
893
+ @param sizes Array of integers specifying an n-dimensional array shape.
894
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
895
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
896
+ CV_CN_MAX channels) matrices.
897
+ */
898
+ Mat(int ndims, const int *sizes, int type);
899
+
900
+ /** @overload
901
+ @param sizes Array of integers specifying an n-dimensional array shape.
902
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
903
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
904
+ CV_CN_MAX channels) matrices.
905
+ */
906
+ Mat(const std::vector<int> &sizes, int type);
907
+
908
+ /** @overload
909
+ @param ndims Array dimensionality.
910
+ @param sizes Array of integers specifying an n-dimensional array shape.
911
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
912
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
913
+ CV_CN_MAX channels) matrices.
914
+ @param s An optional value to initialize each matrix element with. To set all
915
+ the matrix elements to the particular value after the construction, use the
916
+ assignment operator Mat::operator=(const Scalar& value) .
917
+ */
918
+ Mat(int ndims, const int *sizes, int type, const Scalar &s);
919
+
920
+ /** @overload
921
+ @param sizes Array of integers specifying an n-dimensional array shape.
922
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
923
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
924
+ CV_CN_MAX channels) matrices.
925
+ @param s An optional value to initialize each matrix element with. To set all
926
+ the matrix elements to the particular value after the construction, use the
927
+ assignment operator Mat::operator=(const Scalar& value) .
928
+ */
929
+ Mat(const std::vector<int> &sizes, int type, const Scalar &s);
930
+
931
+ /** @overload
932
+ @param m Array that (as a whole or partly) is assigned to the constructed
933
+ matrix. No data is copied by these constructors. Instead, the header pointing
934
+ to m data or its sub-array is constructed and associated with it. The
935
+ reference counter, if any, is incremented. So, when you modify the matrix
936
+ formed using such a constructor, you also modify the corresponding elements of
937
+ m . If you want to have an independent copy of the sub-array, use Mat::clone()
938
+ .
939
+ */
940
+ Mat(const Mat &m);
941
+
942
+ /** @overload
943
+ @param rows Number of rows in a 2D array.
944
+ @param cols Number of columns in a 2D array.
945
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
946
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
947
+ CV_CN_MAX channels) matrices.
948
+ @param data Pointer to the user data. Matrix constructors that take data and
949
+ step parameters do not allocate matrix data. Instead, they just initialize the
950
+ matrix header that points to the specified data, which means that no data is
951
+ copied. This operation is very efficient and can be used to process external
952
+ data using OpenCV functions. The external data is not automatically
953
+ deallocated, so you should take care of it.
954
+ @param step Number of bytes each matrix row occupies. The value should include
955
+ the padding bytes at the end of each row, if any. If the parameter is missing
956
+ (set to AUTO_STEP ), no padding is assumed and the actual step is calculated
957
+ as cols*elemSize(). See Mat::elemSize.
958
+ */
959
+ Mat(int rows, int cols, int type, void *data, size_t step = AUTO_STEP);
960
+
961
+ /** @overload
962
+ @param size 2D array size: Size(cols, rows) . In the Size() constructor, the
963
+ number of rows and the number of columns go in the reverse order.
964
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
965
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
966
+ CV_CN_MAX channels) matrices.
967
+ @param data Pointer to the user data. Matrix constructors that take data and
968
+ step parameters do not allocate matrix data. Instead, they just initialize the
969
+ matrix header that points to the specified data, which means that no data is
970
+ copied. This operation is very efficient and can be used to process external
971
+ data using OpenCV functions. The external data is not automatically
972
+ deallocated, so you should take care of it.
973
+ @param step Number of bytes each matrix row occupies. The value should include
974
+ the padding bytes at the end of each row, if any. If the parameter is missing
975
+ (set to AUTO_STEP ), no padding is assumed and the actual step is calculated
976
+ as cols*elemSize(). See Mat::elemSize.
977
+ */
978
+ Mat(Size size, int type, void *data, size_t step = AUTO_STEP);
979
+
980
+ /** @overload
981
+ @param ndims Array dimensionality.
982
+ @param sizes Array of integers specifying an n-dimensional array shape.
983
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
984
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
985
+ CV_CN_MAX channels) matrices.
986
+ @param data Pointer to the user data. Matrix constructors that take data and
987
+ step parameters do not allocate matrix data. Instead, they just initialize the
988
+ matrix header that points to the specified data, which means that no data is
989
+ copied. This operation is very efficient and can be used to process external
990
+ data using OpenCV functions. The external data is not automatically
991
+ deallocated, so you should take care of it.
992
+ @param steps Array of ndims-1 steps in case of a multi-dimensional array (the
993
+ last step is always set to the element size). If not specified, the matrix is
994
+ assumed to be continuous.
995
+ */
996
+ Mat(int ndims, const int *sizes, int type, void *data,
997
+ const size_t *steps = 0);
998
+
999
+ /** @overload
1000
+ @param sizes Array of integers specifying an n-dimensional array shape.
1001
+ @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel
1002
+ matrices, or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to
1003
+ CV_CN_MAX channels) matrices.
1004
+ @param data Pointer to the user data. Matrix constructors that take data and
1005
+ step parameters do not allocate matrix data. Instead, they just initialize the
1006
+ matrix header that points to the specified data, which means that no data is
1007
+ copied. This operation is very efficient and can be used to process external
1008
+ data using OpenCV functions. The external data is not automatically
1009
+ deallocated, so you should take care of it.
1010
+ @param steps Array of ndims-1 steps in case of a multi-dimensional array (the
1011
+ last step is always set to the element size). If not specified, the matrix is
1012
+ assumed to be continuous.
1013
+ */
1014
+ Mat(const std::vector<int> &sizes, int type, void *data,
1015
+ const size_t *steps = 0);
1016
+
1017
+ /** @overload
1018
+ @param m Array that (as a whole or partly) is assigned to the constructed
1019
+ matrix. No data is copied by these constructors. Instead, the header pointing
1020
+ to m data or its sub-array is constructed and associated with it. The
1021
+ reference counter, if any, is incremented. So, when you modify the matrix
1022
+ formed using such a constructor, you also modify the corresponding elements of
1023
+ m . If you want to have an independent copy of the sub-array, use Mat::clone()
1024
+ .
1025
+ @param rowRange Range of the m rows to take. As usual, the range start is
1026
+ inclusive and the range end is exclusive. Use Range::all() to take all the
1027
+ rows.
1028
+ @param colRange Range of the m columns to take. Use Range::all() to take all
1029
+ the columns.
1030
+ */
1031
+ Mat(const Mat &m, const Range &rowRange,
1032
+ const Range &colRange = Range::all());
1033
+
1034
+ /** @overload
1035
+ @param m Array that (as a whole or partly) is assigned to the constructed
1036
+ matrix. No data is copied by these constructors. Instead, the header pointing
1037
+ to m data or its sub-array is constructed and associated with it. The
1038
+ reference counter, if any, is incremented. So, when you modify the matrix
1039
+ formed using such a constructor, you also modify the corresponding elements of
1040
+ m . If you want to have an independent copy of the sub-array, use Mat::clone()
1041
+ .
1042
+ @param roi Region of interest.
1043
+ */
1044
+ Mat(const Mat &m, const Rect &roi);
1045
+
1046
+ /** @overload
1047
+ @param m Array that (as a whole or partly) is assigned to the constructed
1048
+ matrix. No data is copied by these constructors. Instead, the header pointing
1049
+ to m data or its sub-array is constructed and associated with it. The
1050
+ reference counter, if any, is incremented. So, when you modify the matrix
1051
+ formed using such a constructor, you also modify the corresponding elements of
1052
+ m . If you want to have an independent copy of the sub-array, use Mat::clone()
1053
+ .
1054
+ @param ranges Array of selected ranges of m along each dimensionality.
1055
+ */
1056
+ Mat(const Mat &m, const Range *ranges);
1057
+
1058
+ /** @overload
1059
+ @param m Array that (as a whole or partly) is assigned to the constructed
1060
+ matrix. No data is copied by these constructors. Instead, the header pointing
1061
+ to m data or its sub-array is constructed and associated with it. The
1062
+ reference counter, if any, is incremented. So, when you modify the matrix
1063
+ formed using such a constructor, you also modify the corresponding elements of
1064
+ m . If you want to have an independent copy of the sub-array, use Mat::clone()
1065
+ .
1066
+ @param ranges Array of selected ranges of m along each dimensionality.
1067
+ */
1068
+ Mat(const Mat &m, const std::vector<Range> &ranges);
1069
+
1070
+ /** @overload
1071
+ @param vec STL vector whose elements form the matrix. The matrix has a single
1072
+ column and the number of rows equal to the number of vector elements. Type of
1073
+ the matrix matches the type of vector elements. The constructor can handle
1074
+ arbitrary types, for which there is a properly declared DataType . This means
1075
+ that the vector elements must be primitive numbers or uni-type numerical
1076
+ tuples of numbers. Mixed-type structures are not supported. The corresponding
1077
+ constructor is explicit. Since STL vectors are not automatically converted to
1078
+ Mat instances, you should write Mat(vec) explicitly. Unless you copy the data
1079
+ into the matrix ( copyData=true ), no new elements will be added to the vector
1080
+ because it can potentially yield vector data reallocation, and, thus, the
1081
+ matrix data pointer will be invalid.
1082
+ @param copyData Flag to specify whether the underlying data of the STL vector
1083
+ should be copied to (true) or shared with (false) the newly constructed
1084
+ matrix. When the data is copied, the allocated buffer is managed using Mat
1085
+ reference counting mechanism. While the data is shared, the reference counter
1086
+ is NULL, and you should not deallocate the data until the matrix is
1087
+ destructed.
1088
+ */
1089
+ template <typename _Tp>
1090
+ explicit Mat(const std::vector<_Tp> &vec, bool copyData = false);
1091
+
1092
+ /** @overload
1093
+ */
1094
+ template <typename _Tp, typename = typename std::enable_if<
1095
+ std::is_arithmetic<_Tp>::value>::type>
1096
+ explicit Mat(const std::initializer_list<_Tp> list);
1097
+
1098
+ /** @overload
1099
+ */
1100
+ template <typename _Tp>
1101
+ explicit Mat(const std::initializer_list<int> sizes,
1102
+ const std::initializer_list<_Tp> list);
1103
+
1104
+ /** @overload
1105
+ */
1106
+ template <typename _Tp, size_t _Nm>
1107
+ explicit Mat(const std::array<_Tp, _Nm> &arr, bool copyData = false);
1108
+
1109
+ /** @overload
1110
+ */
1111
+ template <typename _Tp, int n>
1112
+ explicit Mat(const Vec<_Tp, n> &vec, bool copyData = true);
1113
+
1114
+ /** @overload
1115
+ */
1116
+ template <typename _Tp, int m, int n>
1117
+ explicit Mat(const Matx<_Tp, m, n> &mtx, bool copyData = true);
1118
+
1119
+ /** @overload
1120
+ */
1121
+ template <typename _Tp>
1122
+ explicit Mat(const Point_<_Tp> &pt, bool copyData = true);
1123
+
1124
+ /** @overload
1125
+ */
1126
+ template <typename _Tp>
1127
+ explicit Mat(const Point3_<_Tp> &pt, bool copyData = true);
1128
+
1129
+ /** @overload
1130
+ */
1131
+ template <typename _Tp>
1132
+ explicit Mat(const MatCommaInitializer_<_Tp> &commaInitializer);
1133
+
1134
+ //! destructor - calls release()
1135
+ ~Mat();
1136
+
1137
+ /** @brief assignment operators
1138
+
1139
+ These are available assignment operators. Since they all are very different,
1140
+ make sure to read the operator parameters description.
1141
+ @param m Assigned, right-hand-side matrix. Matrix assignment is an O(1)
1142
+ operation. This means that no data is copied but the data is shared and the
1143
+ reference counter, if any, is incremented. Before assigning new data, the old
1144
+ data is de-referenced via Mat::release .
1145
+ */
1146
+ Mat &operator=(const Mat &m);
1147
+
1148
+ /** @overload
1149
+ @param expr Assigned matrix expression object. As opposite to the first form
1150
+ of the assignment operation, the second form can reuse already allocated
1151
+ matrix if it has the right size and type to fit the matrix expression result.
1152
+ It is automatically handled by the real function that the matrix expressions
1153
+ is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes
1154
+ care of automatic C reallocation.
1155
+ */
1156
+ Mat &operator=(const MatExpr &expr);
1157
+
1158
+ /** @brief Creates a matrix header for the specified matrix row.
1159
+
1160
+ The method makes a new header for the specified matrix row and returns it.
1161
+ This is an O(1) operation, regardless of the matrix size. The underlying data
1162
+ of the new matrix is shared with the original matrix. Here is the example of
1163
+ one of the classical basic matrix processing operations, axpy, used by LU and
1164
+ many other algorithms:
1165
+ @code
1166
+ inline void matrix_axpy(Mat& A, int i, int j, double alpha)
1167
+ {
1168
+ A.row(i) += A.row(j)*alpha;
1169
+ }
1170
+ @endcode
1171
+ @note In the current implementation, the following code does not work as
1172
+ expected:
1173
+ @code
1174
+ Mat A;
1175
+ ...
1176
+ A.row(i) = A.row(j); // will not work
1177
+ @endcode
1178
+ This happens because A.row(i) forms a temporary header that is further
1179
+ assigned to another header. Remember that each of these operations is O(1),
1180
+ that is, no data is copied. Thus, the above assignment is not true if you may
1181
+ have expected the j-th row to be copied to the i-th row. To achieve that, you
1182
+ should either turn this simple assignment into an expression or use the
1183
+ Mat::copyTo method:
1184
+ @code
1185
+ Mat A;
1186
+ ...
1187
+ // works, but looks a bit obscure.
1188
+ A.row(i) = A.row(j) + 0;
1189
+ // this is a bit longer, but the recommended method.
1190
+ A.row(j).copyTo(A.row(i));
1191
+ @endcode
1192
+ @param y A 0-based row index.
1193
+ */
1194
+ Mat row(int y) const;
1195
+
1196
+ /** @brief Creates a matrix header for the specified matrix column.
1197
+
1198
+ The method makes a new header for the specified matrix column and returns it.
1199
+ This is an O(1) operation, regardless of the matrix size. The underlying data
1200
+ of the new matrix is shared with the original matrix. See also the Mat::row
1201
+ description.
1202
+ @param x A 0-based column index.
1203
+ */
1204
+ Mat col(int x) const;
1205
+
1206
+ /** @brief Creates a matrix header for the specified row span.
1207
+
1208
+ The method makes a new header for the specified row span of the matrix.
1209
+ Similarly to Mat::row and Mat::col , this is an O(1) operation.
1210
+ @param startrow An inclusive 0-based start index of the row span.
1211
+ @param endrow An exclusive 0-based ending index of the row span.
1212
+ */
1213
+ Mat rowRange(int startrow, int endrow) const;
1214
+
1215
+ /** @overload
1216
+ @param r Range structure containing both the start and the end indices.
1217
+ */
1218
+ Mat rowRange(const Range &r) const;
1219
+
1220
+ /** @brief Creates a matrix header for the specified column span.
1221
+
1222
+ The method makes a new header for the specified column span of the matrix.
1223
+ Similarly to Mat::row and Mat::col , this is an O(1) operation.
1224
+ @param startcol An inclusive 0-based start index of the column span.
1225
+ @param endcol An exclusive 0-based ending index of the column span.
1226
+ */
1227
+ Mat colRange(int startcol, int endcol) const;
1228
+
1229
+ /** @overload
1230
+ @param r Range structure containing both the start and the end indices.
1231
+ */
1232
+ Mat colRange(const Range &r) const;
1233
+
1234
+ /** @brief Extracts a diagonal from a matrix
1235
+
1236
+ The method makes a new header for the specified matrix diagonal. The new
1237
+ matrix is represented as a single-column matrix. Similarly to Mat::row and
1238
+ Mat::col, this is an O(1) operation.
1239
+ @param d index of the diagonal, with the following values:
1240
+ - `d=0` is the main diagonal.
1241
+ - `d<0` is a diagonal from the lower half. For example, d=-1 means the
1242
+ diagonal is set immediately below the main one.
1243
+ - `d>0` is a diagonal from the upper half. For example, d=1 means the diagonal
1244
+ is set immediately above the main one. For example:
1245
+ @code
1246
+ Mat m = (Mat_<int>(3,3) <<
1247
+ 1,2,3,
1248
+ 4,5,6,
1249
+ 7,8,9);
1250
+ Mat d0 = m.diag(0);
1251
+ Mat d1 = m.diag(1);
1252
+ Mat d_1 = m.diag(-1);
1253
+ @endcode
1254
+ The resulting matrices are
1255
+ @code
1256
+ d0 =
1257
+ [1;
1258
+ 5;
1259
+ 9]
1260
+ d1 =
1261
+ [2;
1262
+ 6]
1263
+ d_1 =
1264
+ [4;
1265
+ 8]
1266
+ @endcode
1267
+ */
1268
+ Mat diag(int d = 0) const;
1269
+
1270
+ /** @brief creates a diagonal matrix
1271
+
1272
+ The method creates a square diagonal matrix from specified main diagonal.
1273
+ @param d One-dimensional matrix that represents the main diagonal.
1274
+ */
1275
+ CV_NODISCARD_STD static Mat diag(const Mat &d);
1276
+
1277
+ /** @brief Creates a full copy of the array and the underlying data.
1278
+
1279
+ The method creates a full copy of the array. The original step[] is not taken
1280
+ into account. So, the array copy is a continuous array occupying
1281
+ total()*elemSize() bytes.
1282
+ */
1283
+ CV_NODISCARD_STD Mat clone() const;
1284
+
1285
+ /** @brief Copies the matrix to another one.
1286
+
1287
+ The method copies the matrix data to another matrix. Before copying the data,
1288
+ the method invokes :
1289
+ @code
1290
+ m.create(this->size(), this->type());
1291
+ @endcode
1292
+ so that the destination matrix is reallocated if needed. While m.copyTo(m);
1293
+ works flawlessly, the function does not handle the case of a partial overlap
1294
+ between the source and the destination matrices.
1295
+
1296
+ When the operation mask is specified, if the Mat::create call shown above
1297
+ reallocates the matrix, the newly allocated matrix is initialized with all
1298
+ zeros before copying the data.
1299
+ @param m Destination matrix. If it does not have a proper size or type before
1300
+ the operation, it is reallocated.
1301
+ */
1302
+ void copyTo(OutputArray m) const;
1303
+
1304
+ /** @overload
1305
+ @param m Destination matrix. If it does not have a proper size or type before
1306
+ the operation, it is reallocated.
1307
+ @param mask Operation mask of the same size as \*this. Its non-zero elements
1308
+ indicate which matrix elements need to be copied. The mask has to be of type
1309
+ CV_8U and can have 1 or multiple channels.
1310
+ */
1311
+ void copyTo(OutputArray m, InputArray mask) const;
1312
+
1313
+ /** @brief Converts an array to another data type with optional scaling.
1314
+
1315
+ The method converts source pixel values to the target data type.
1316
+ saturate_cast\<\> is applied at the end to avoid possible overflows:
1317
+
1318
+ \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f]
1319
+ @param m output matrix; if it does not have a proper size or type before the
1320
+ operation, it is reallocated.
1321
+ @param rtype desired output matrix type or, rather, the depth since the number
1322
+ of channels are the same as the input has; if rtype is negative, the output
1323
+ matrix will have the same type as the input.
1324
+ @param alpha optional scale factor.
1325
+ @param beta optional delta added to the scaled values.
1326
+ */
1327
+ void convertTo(OutputArray m, int rtype, double alpha = 1,
1328
+ double beta = 0) const;
1329
+
1330
+ /** @brief Provides a functional form of convertTo.
1331
+
1332
+ This is an internally used method called by the @ref MatrixExpressions engine.
1333
+ @param m Destination array.
1334
+ @param type Desired destination array depth (or -1 if it should be the same as
1335
+ the source type).
1336
+ */
1337
+ void assignTo(Mat &m, int type = -1) const;
1338
+
1339
+ /** @brief Sets all or some of the array elements to the specified value.
1340
+ @param s Assigned scalar converted to the actual array type.
1341
+ */
1342
+ Mat &operator=(const Scalar &s);
1343
+
1344
+ /** @brief Sets all or some of the array elements to the specified value.
1345
+
1346
+ This is an advanced variant of the Mat::operator=(const Scalar& s) operator.
1347
+ @param value Assigned scalar converted to the actual array type.
1348
+ @param mask Operation mask of the same size as \*this. Its non-zero elements
1349
+ indicate which matrix elements need to be copied. The mask has to be of type
1350
+ CV_8U and can have 1 or multiple channels
1351
+ */
1352
+ Mat &setTo(InputArray value, InputArray mask = noArray());
1353
+
1354
+ /** @brief Changes the shape and/or the number of channels of a 2D matrix
1355
+ without copying the data.
1356
+
1357
+ The method makes a new matrix header for \*this elements. The new matrix may
1358
+ have a different size and/or different number of channels. Any combination is
1359
+ possible if:
1360
+ - No extra elements are included into the new matrix and no elements are
1361
+ excluded. Consequently, the product rows\*cols\*channels() must stay the same
1362
+ after the transformation.
1363
+ - No data is copied. That is, this is an O(1) operation. Consequently, if
1364
+ you change the number of rows, or the operation changes the indices of
1365
+ elements row in some other way, the matrix must be continuous. See
1366
+ Mat::isContinuous .
1367
+
1368
+ For example, if there is a set of 3D points stored as an STL vector, and you
1369
+ want to represent the points as a 3xN matrix, do the following:
1370
+ @code
1371
+ std::vector<Point3f> vec;
1372
+ ...
1373
+ Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation
1374
+ reshape(1). // make Nx3 1-channel matrix out of Nx1
1375
+ 3-channel.
1376
+ // Also, an O(1) operation
1377
+ t(); // finally, transpose the Nx3 matrix.
1378
+ // This involves copying all the elements
1379
+ @endcode
1380
+ 3-channel 2x2 matrix reshaped to 1-channel 4x3 matrix, each column has values
1381
+ from one of original channels:
1382
+ @code
1383
+ Mat m(Size(2, 2), CV_8UC3, Scalar(1, 2, 3));
1384
+ vector<int> new_shape {4, 3};
1385
+ m = m.reshape(1, new_shape);
1386
+ @endcode
1387
+ or:
1388
+ @code
1389
+ Mat m(Size(2, 2), CV_8UC3, Scalar(1, 2, 3));
1390
+ const int new_shape[] = {4, 3};
1391
+ m = m.reshape(1, 2, new_shape);
1392
+ @endcode
1393
+ @param cn New number of channels. If the parameter is 0, the number of
1394
+ channels remains the same.
1395
+ @param rows New number of rows. If the parameter is 0, the number of rows
1396
+ remains the same.
1397
+ */
1398
+ Mat reshape(int cn, int rows = 0) const;
1399
+
1400
+ /** @overload
1401
+ * @param cn New number of channels. If the parameter is 0, the number of
1402
+ * channels remains the same.
1403
+ * @param newndims New number of dimentions.
1404
+ * @param newsz Array with new matrix size by all dimentions. If some sizes
1405
+ * are zero, the original sizes in those dimensions are presumed.
1406
+ */
1407
+ Mat reshape(int cn, int newndims, const int *newsz) const;
1408
+
1409
+ /** @overload
1410
+ * @param cn New number of channels. If the parameter is 0, the number of
1411
+ * channels remains the same.
1412
+ * @param newshape Vector with new matrix size by all dimentions. If some
1413
+ * sizes are zero, the original sizes in those dimensions are presumed.
1414
+ */
1415
+ Mat reshape(int cn, const std::vector<int> &newshape) const;
1416
+
1417
+ /** @brief Transposes a matrix.
1418
+
1419
+ The method performs matrix transposition by means of matrix expressions. It
1420
+ does not perform the actual transposition but returns a temporary matrix
1421
+ transposition object that can be further used as a part of more complex matrix
1422
+ expressions or can be assigned to a matrix:
1423
+ @code
1424
+ Mat A1 = A + Mat::eye(A.size(), A.type())*lambda;
1425
+ Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I)
1426
+ @endcode
1427
+ */
1428
+ MatExpr t() const;
1429
+
1430
+ /** @brief Inverses a matrix.
1431
+
1432
+ The method performs a matrix inversion by means of matrix expressions. This
1433
+ means that a temporary matrix inversion object is returned by the method and
1434
+ can be used further as a part of more complex matrix expressions or can be
1435
+ assigned to a matrix.
1436
+ @param method Matrix inversion method. One of cv::DecompTypes
1437
+ */
1438
+ MatExpr inv(int method = DECOMP_LU) const;
1439
+
1440
+ /** @brief Performs an element-wise multiplication or division of the two
1441
+ matrices.
1442
+
1443
+ The method returns a temporary object encoding per-element array
1444
+ multiplication, with optional scale. Note that this is not a matrix
1445
+ multiplication that corresponds to a simpler "\*" operator.
1446
+
1447
+ Example:
1448
+ @code
1449
+ Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5)
1450
+ @endcode
1451
+ @param m Another array of the same type and the same size as \*this, or a
1452
+ matrix expression.
1453
+ @param scale Optional scale factor.
1454
+ */
1455
+ MatExpr mul(InputArray m, double scale = 1) const;
1456
+
1457
+ /** @brief Computes a cross-product of two 3-element vectors.
1458
+
1459
+ The method computes a cross-product of two 3-element vectors. The vectors must
1460
+ be 3-element floating-point vectors of the same shape and size. The result is
1461
+ another 3-element vector of the same shape and type as operands.
1462
+ @param m Another cross-product operand.
1463
+ */
1464
+ Mat cross(InputArray m) const;
1465
+
1466
+ /** @brief Computes a dot-product of two vectors.
1467
+
1468
+ The method computes a dot-product of two matrices. If the matrices are not
1469
+ single-column or single-row vectors, the top-to-bottom left-to-right scan
1470
+ ordering is used to treat them as 1D vectors. The vectors must have the same
1471
+ size and type. If the matrices have more than one channel, the dot products
1472
+ from all the channels are summed together.
1473
+ @param m another dot-product operand.
1474
+ */
1475
+ double dot(InputArray m) const;
1476
+
1477
+ /** @brief Returns a zero array of the specified size and type.
1478
+
1479
+ The method returns a Matlab-style zero array initializer. It can be used to
1480
+ quickly form a constant array as a function parameter, part of a matrix
1481
+ expression, or as a matrix initializer:
1482
+ @code
1483
+ Mat A;
1484
+ A = Mat::zeros(3, 3, CV_32F);
1485
+ @endcode
1486
+ In the example above, a new matrix is allocated only if A is not a 3x3
1487
+ floating-point matrix. Otherwise, the existing matrix A is filled with zeros.
1488
+ @param rows Number of rows.
1489
+ @param cols Number of columns.
1490
+ @param type Created matrix type.
1491
+ */
1492
+ CV_NODISCARD_STD static MatExpr zeros(int rows, int cols, int type);
1493
+
1494
+ /** @overload
1495
+ @param size Alternative to the matrix size specification Size(cols, rows) .
1496
+ @param type Created matrix type.
1497
+ */
1498
+ CV_NODISCARD_STD static MatExpr zeros(Size size, int type);
1499
+
1500
+ /** @overload
1501
+ @param ndims Array dimensionality.
1502
+ @param sz Array of integers specifying the array shape.
1503
+ @param type Created matrix type.
1504
+ */
1505
+ CV_NODISCARD_STD static MatExpr zeros(int ndims, const int *sz, int type);
1506
+
1507
+ /** @brief Returns an array of all 1's of the specified size and type.
1508
+
1509
+ The method returns a Matlab-style 1's array initializer, similarly to
1510
+ Mat::zeros. Note that using this method you can initialize an array with an
1511
+ arbitrary value, using the following Matlab idiom:
1512
+ @code
1513
+ Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled
1514
+ with 3.
1515
+ @endcode
1516
+ The above operation does not form a 100x100 matrix of 1's and then multiply it
1517
+ by 3. Instead, it just remembers the scale factor (3 in this case) and use it
1518
+ when actually invoking the matrix initializer.
1519
+ @note In case of multi-channels type, only the first channel will be
1520
+ initialized with 1's, the others will be set to 0's.
1521
+ @param rows Number of rows.
1522
+ @param cols Number of columns.
1523
+ @param type Created matrix type.
1524
+ */
1525
+ CV_NODISCARD_STD static MatExpr ones(int rows, int cols, int type);
1526
+
1527
+ /** @overload
1528
+ @param size Alternative to the matrix size specification Size(cols, rows) .
1529
+ @param type Created matrix type.
1530
+ */
1531
+ CV_NODISCARD_STD static MatExpr ones(Size size, int type);
1532
+
1533
+ /** @overload
1534
+ @param ndims Array dimensionality.
1535
+ @param sz Array of integers specifying the array shape.
1536
+ @param type Created matrix type.
1537
+ */
1538
+ CV_NODISCARD_STD static MatExpr ones(int ndims, const int *sz, int type);
1539
+
1540
+ /** @brief Returns an identity matrix of the specified size and type.
1541
+
1542
+ The method returns a Matlab-style identity matrix initializer, similarly to
1543
+ Mat::zeros. Similarly to Mat::ones, you can use a scale operation to create a
1544
+ scaled identity matrix efficiently:
1545
+ @code
1546
+ // make a 4x4 diagonal matrix with 0.1's on the diagonal.
1547
+ Mat A = Mat::eye(4, 4, CV_32F)*0.1;
1548
+ @endcode
1549
+ @note In case of multi-channels type, identity matrix will be initialized only
1550
+ for the first channel, the others will be set to 0's
1551
+ @param rows Number of rows.
1552
+ @param cols Number of columns.
1553
+ @param type Created matrix type.
1554
+ */
1555
+ CV_NODISCARD_STD static MatExpr eye(int rows, int cols, int type);
1556
+
1557
+ /** @overload
1558
+ @param size Alternative matrix size specification as Size(cols, rows) .
1559
+ @param type Created matrix type.
1560
+ */
1561
+ CV_NODISCARD_STD static MatExpr eye(Size size, int type);
1562
+
1563
+ /** @brief Allocates new array data if needed.
1564
+
1565
+ This is one of the key Mat methods. Most new-style OpenCV functions and
1566
+ methods that produce arrays call this method for each output array. The method
1567
+ uses the following algorithm:
1568
+
1569
+ -# If the current array shape and the type match the new ones, return
1570
+ immediately. Otherwise, de-reference the previous data by calling
1571
+ Mat::release.
1572
+ -# Initialize the new header.
1573
+ -# Allocate the new data of total()\*elemSize() bytes.
1574
+ -# Allocate the new, associated with the data, reference counter and set it
1575
+ to 1.
1576
+
1577
+ Such a scheme makes the memory management robust and efficient at the same
1578
+ time and helps avoid extra typing for you. This means that usually there is no
1579
+ need to explicitly allocate output arrays. That is, instead of writing:
1580
+ @code
1581
+ Mat color;
1582
+ ...
1583
+ Mat gray(color.rows, color.cols, color.depth());
1584
+ cvtColor(color, gray, COLOR_BGR2GRAY);
1585
+ @endcode
1586
+ you can simply write:
1587
+ @code
1588
+ Mat color;
1589
+ ...
1590
+ Mat gray;
1591
+ cvtColor(color, gray, COLOR_BGR2GRAY);
1592
+ @endcode
1593
+ because cvtColor, as well as the most of OpenCV functions, calls Mat::create()
1594
+ for the output array internally.
1595
+ @param rows New number of rows.
1596
+ @param cols New number of columns.
1597
+ @param type New matrix type.
1598
+ */
1599
+ void create(int rows, int cols, int type);
1600
+
1601
+ /** @overload
1602
+ @param size Alternative new matrix size specification: Size(cols, rows)
1603
+ @param type New matrix type.
1604
+ */
1605
+ void create(Size size, int type);
1606
+
1607
+ /** @overload
1608
+ @param ndims New array dimensionality.
1609
+ @param sizes Array of integers specifying a new array shape.
1610
+ @param type New matrix type.
1611
+ */
1612
+ void create(int ndims, const int *sizes, int type);
1613
+
1614
+ /** @overload
1615
+ @param sizes Array of integers specifying a new array shape.
1616
+ @param type New matrix type.
1617
+ */
1618
+ void create(const std::vector<int> &sizes, int type);
1619
+
1620
+ /** @brief Increments the reference counter.
1621
+
1622
+ The method increments the reference counter associated with the matrix data.
1623
+ If the matrix header points to an external data set (see Mat::Mat ), the
1624
+ reference counter is NULL, and the method has no effect in this case.
1625
+ Normally, to avoid memory leaks, the method should not be called explicitly.
1626
+ It is called implicitly by the matrix assignment operator. The reference
1627
+ counter increment is an atomic operation on the platforms that support it.
1628
+ Thus, it is safe to operate on the same matrices asynchronously in different
1629
+ threads.
1630
+ */
1631
+ void addref();
1632
+
1633
+ /** @brief Decrements the reference counter and deallocates the matrix if
1634
+ needed.
1635
+
1636
+ The method decrements the reference counter associated with the matrix data.
1637
+ When the reference counter reaches 0, the matrix data is deallocated and the
1638
+ data and the reference counter pointers are set to NULL's. If the matrix
1639
+ header points to an external data set (see Mat::Mat ), the reference counter
1640
+ is NULL, and the method has no effect in this case.
1641
+
1642
+ This method can be called manually to force the matrix data deallocation. But
1643
+ since this method is automatically called in the destructor, or by any other
1644
+ method that changes the data pointer, it is usually not needed. The reference
1645
+ counter decrement and check for 0 is an atomic operation on the platforms that
1646
+ support it. Thus, it is safe to operate on the same matrices asynchronously in
1647
+ different threads.
1648
+ */
1649
+ void release();
1650
+
1651
+ //! internal use function, consider to use 'release' method instead;
1652
+ //! deallocates the matrix data
1653
+ void deallocate();
1654
+ //! internal use function; properly re-allocates _size, _step arrays
1655
+ void copySize(const Mat &m);
1656
+
1657
+ /** @brief Reserves space for the certain number of rows.
1658
+
1659
+ The method reserves space for sz rows. If the matrix already has enough space
1660
+ to store sz rows, nothing happens. If the matrix is reallocated, the first
1661
+ Mat::rows rows are preserved. The method emulates the corresponding method of
1662
+ the STL vector class.
1663
+ @param sz Number of rows.
1664
+ */
1665
+ void reserve(size_t sz);
1666
+
1667
+ /** @brief Reserves space for the certain number of bytes.
1668
+
1669
+ The method reserves space for sz bytes. If the matrix already has enough space
1670
+ to store sz bytes, nothing happens. If matrix has to be reallocated its
1671
+ previous content could be lost.
1672
+ @param sz Number of bytes.
1673
+ */
1674
+ void reserveBuffer(size_t sz);
1675
+
1676
+ /** @brief Changes the number of matrix rows.
1677
+
1678
+ The methods change the number of matrix rows. If the matrix is reallocated,
1679
+ the first min(Mat::rows, sz) rows are preserved. The methods emulate the
1680
+ corresponding methods of the STL vector class.
1681
+ @param sz New number of rows.
1682
+ */
1683
+ void resize(size_t sz);
1684
+
1685
+ /** @overload
1686
+ @param sz New number of rows.
1687
+ @param s Value assigned to the newly added elements.
1688
+ */
1689
+ void resize(size_t sz, const Scalar &s);
1690
+
1691
+ //! internal function
1692
+ void push_back_(const void *elem);
1693
+
1694
+ /** @brief Adds elements to the bottom of the matrix.
1695
+
1696
+ The methods add one or more elements to the bottom of the matrix. They emulate
1697
+ the corresponding method of the STL vector class. When elem is Mat , its type
1698
+ and the number of columns must be the same as in the container matrix.
1699
+ @param elem Added element(s).
1700
+ */
1701
+ template <typename _Tp> void push_back(const _Tp &elem);
1702
+
1703
+ /** @overload
1704
+ @param elem Added element(s).
1705
+ */
1706
+ template <typename _Tp> void push_back(const Mat_<_Tp> &elem);
1707
+
1708
+ /** @overload
1709
+ @param elem Added element(s).
1710
+ */
1711
+ template <typename _Tp> void push_back(const std::vector<_Tp> &elem);
1712
+
1713
+ /** @overload
1714
+ @param m Added line(s).
1715
+ */
1716
+ void push_back(const Mat &m);
1717
+
1718
+ /** @brief Removes elements from the bottom of the matrix.
1719
+
1720
+ The method removes one or more rows from the bottom of the matrix.
1721
+ @param nelems Number of removed rows. If it is greater than the total number
1722
+ of rows, an exception is thrown.
1723
+ */
1724
+ void pop_back(size_t nelems = 1);
1725
+
1726
+ /** @brief Locates the matrix header within a parent matrix.
1727
+
1728
+ After you extracted a submatrix from a matrix using Mat::row, Mat::col,
1729
+ Mat::rowRange, Mat::colRange, and others, the resultant submatrix points just
1730
+ to the part of the original big matrix. However, each submatrix contains
1731
+ information (represented by datastart and dataend fields) that helps
1732
+ reconstruct the original matrix size and the position of the extracted
1733
+ submatrix within the original matrix. The method locateROI does exactly that.
1734
+ @param wholeSize Output parameter that contains the size of the whole matrix
1735
+ containing *this* as a part.
1736
+ @param ofs Output parameter that contains an offset of *this* inside the whole
1737
+ matrix.
1738
+ */
1739
+ void locateROI(Size &wholeSize, Point &ofs) const;
1740
+
1741
+ /** @brief Adjusts a submatrix size and position within the parent matrix.
1742
+
1743
+ The method is complimentary to Mat::locateROI . The typical use of these
1744
+ functions is to determine the submatrix position within the parent matrix and
1745
+ then shift the position somehow. Typically, it can be required for filtering
1746
+ operations when pixels outside of the ROI should be taken into account. When
1747
+ all the method parameters are positive, the ROI needs to grow in all
1748
+ directions by the specified amount, for example:
1749
+ @code
1750
+ A.adjustROI(2, 2, 2, 2);
1751
+ @endcode
1752
+ In this example, the matrix size is increased by 4 elements in each direction.
1753
+ The matrix is shifted by 2 elements to the left and 2 elements up, which
1754
+ brings in all the necessary pixels for the filtering with the 5x5 kernel.
1755
+
1756
+ adjustROI forces the adjusted ROI to be inside of the parent matrix that is
1757
+ boundaries of the adjusted ROI are constrained by boundaries of the parent
1758
+ matrix. For example, if the submatrix A is located in the first row of a
1759
+ parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not be
1760
+ increased in the upward direction.
1761
+
1762
+ The function is used internally by the OpenCV filtering functions, like
1763
+ filter2D , morphological operations, and so on.
1764
+ @param dtop Shift of the top submatrix boundary upwards.
1765
+ @param dbottom Shift of the bottom submatrix boundary downwards.
1766
+ @param dleft Shift of the left submatrix boundary to the left.
1767
+ @param dright Shift of the right submatrix boundary to the right.
1768
+ @sa copyMakeBorder
1769
+ */
1770
+ Mat &adjustROI(int dtop, int dbottom, int dleft, int dright);
1771
+
1772
+ /** @brief Extracts a rectangular submatrix.
1773
+
1774
+ The operators make a new header for the specified sub-array of \*this . They
1775
+ are the most generalized forms of Mat::row, Mat::col, Mat::rowRange, and
1776
+ Mat::colRange . For example, `A(Range(0, 10), Range::all())` is equivalent to
1777
+ `A.rowRange(0, 10)`. Similarly to all of the above, the operators are O(1)
1778
+ operations, that is, no matrix data is copied.
1779
+ @param rowRange Start and end row of the extracted submatrix. The upper
1780
+ boundary is not included. To select all the rows, use Range::all().
1781
+ @param colRange Start and end column of the extracted submatrix. The upper
1782
+ boundary is not included. To select all the columns, use Range::all().
1783
+ */
1784
+ Mat operator()(Range rowRange, Range colRange) const;
1785
+
1786
+ /** @overload
1787
+ @param roi Extracted submatrix specified as a rectangle.
1788
+ */
1789
+ Mat operator()(const Rect &roi) const;
1790
+
1791
+ /** @overload
1792
+ @param ranges Array of selected ranges along each array dimension.
1793
+ */
1794
+ Mat operator()(const Range *ranges) const;
1795
+
1796
+ /** @overload
1797
+ @param ranges Array of selected ranges along each array dimension.
1798
+ */
1799
+ Mat operator()(const std::vector<Range> &ranges) const;
1800
+
1801
+ template <typename _Tp> operator std::vector<_Tp>() const;
1802
+ template <typename _Tp, int n> operator Vec<_Tp, n>() const;
1803
+ template <typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
1804
+
1805
+ template <typename _Tp, std::size_t _Nm>
1806
+ operator std::array<_Tp, _Nm>() const;
1807
+
1808
+ /** @brief Reports whether the matrix is continuous or not.
1809
+
1810
+ The method returns true if the matrix elements are stored continuously without
1811
+ gaps at the end of each row. Otherwise, it returns false. Obviously, 1x1 or
1812
+ 1xN matrices are always continuous. Matrices created with Mat::create are
1813
+ always continuous. But if you extract a part of the matrix using Mat::col,
1814
+ Mat::diag, and so on, or constructed a matrix header for externally allocated
1815
+ data, such matrices may no longer have this property.
1816
+
1817
+ The continuity flag is stored as a bit in the Mat::flags field and is computed
1818
+ automatically when you construct a matrix header. Thus, the continuity check
1819
+ is a very fast operation, though theoretically it could be done as follows:
1820
+ @code
1821
+ // alternative implementation of Mat::isContinuous()
1822
+ bool myCheckMatContinuity(const Mat& m)
1823
+ {
1824
+ //return (m.flags & Mat::CONTINUOUS_FLAG) != 0;
1825
+ return m.rows == 1 || m.step == m.cols*m.elemSize();
1826
+ }
1827
+ @endcode
1828
+ The method is used in quite a few of OpenCV functions. The point is that
1829
+ element-wise operations (such as arithmetic and logical operations, math
1830
+ functions, alpha blending, color space transformations, and others) do not
1831
+ depend on the image geometry. Thus, if all the input and output arrays are
1832
+ continuous, the functions can process them as very long single-row vectors.
1833
+ The example below illustrates how an alpha-blending function can be
1834
+ implemented:
1835
+ @code
1836
+ template<typename T>
1837
+ void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
1838
+ {
1839
+ const float alpha_scale = (float)std::numeric_limits<T>::max(),
1840
+ inv_scale = 1.f/alpha_scale;
1841
+
1842
+ CV_Assert( src1.type() == src2.type() &&
1843
+ src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) &&
1844
+ src1.size() == src2.size());
1845
+ Size size = src1.size();
1846
+ dst.create(size, src1.type());
1847
+
1848
+ // here is the idiom: check the arrays for continuity and,
1849
+ // if this is the case,
1850
+ // treat the arrays as 1D vectors
1851
+ if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() )
1852
+ {
1853
+ size.width *= size.height;
1854
+ size.height = 1;
1855
+ }
1856
+ size.width *= 4;
1857
+
1858
+ for( int i = 0; i < size.height; i++ )
1859
+ {
1860
+ // when the arrays are continuous,
1861
+ // the outer loop is executed only once
1862
+ const T* ptr1 = src1.ptr<T>(i);
1863
+ const T* ptr2 = src2.ptr<T>(i);
1864
+ T* dptr = dst.ptr<T>(i);
1865
+
1866
+ for( int j = 0; j < size.width; j += 4 )
1867
+ {
1868
+ float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale;
1869
+ dptr[j] = saturate_cast<T>(ptr1[j]*alpha + ptr2[j]*beta);
1870
+ dptr[j+1] = saturate_cast<T>(ptr1[j+1]*alpha +
1871
+ ptr2[j+1]*beta); dptr[j+2] = saturate_cast<T>(ptr1[j+2]*alpha +
1872
+ ptr2[j+2]*beta); dptr[j+3] = saturate_cast<T>((1 -
1873
+ (1-alpha)*(1-beta))*alpha_scale);
1874
+ }
1875
+ }
1876
+ }
1877
+ @endcode
1878
+ This approach, while being very simple, can boost the performance of a simple
1879
+ element-operation by 10-20 percents, especially if the image is rather small
1880
+ and the operation is quite simple.
1881
+
1882
+ Another OpenCV idiom in this function, a call of Mat::create for the
1883
+ destination array, that allocates the destination array unless it already has
1884
+ the proper size and type. And while the newly allocated arrays are always
1885
+ continuous, you still need to check the destination array because Mat::create
1886
+ does not always allocate a new matrix.
1887
+ */
1888
+ bool isContinuous() const;
1889
+
1890
+ //! returns true if the matrix is a submatrix of another matrix
1891
+ bool isSubmatrix() const;
1892
+
1893
+ /** @brief Returns the matrix element size in bytes.
1894
+
1895
+ The method returns the matrix element size in bytes. For example, if the
1896
+ matrix type is CV_16SC3 , the method returns 3\*sizeof(short) or 6.
1897
+ */
1898
+ size_t elemSize() const;
1899
+
1900
+ /** @brief Returns the size of each matrix element channel in bytes.
1901
+
1902
+ The method returns the matrix element channel size in bytes, that is, it
1903
+ ignores the number of channels. For example, if the matrix type is CV_16SC3 ,
1904
+ the method returns sizeof(short) or 2.
1905
+ */
1906
+ size_t elemSize1() const;
1907
+
1908
+ /** @brief Returns the type of a matrix element.
1909
+
1910
+ The method returns a matrix element type. This is an identifier compatible
1911
+ with the CvMat type system, like CV_16SC3 or 16-bit signed 3-channel array,
1912
+ and so on.
1913
+ */
1914
+ int type() const;
1915
+
1916
+ /** @brief Returns the depth of a matrix element.
1917
+
1918
+ The method returns the identifier of the matrix element depth (the type of
1919
+ each individual channel). For example, for a 16-bit signed element array, the
1920
+ method returns CV_16S . A complete list of matrix types contains the following
1921
+ values:
1922
+ - CV_8U - 8-bit unsigned integers ( 0..255 )
1923
+ - CV_8S - 8-bit signed integers ( -128..127 )
1924
+ - CV_16U - 16-bit unsigned integers ( 0..65535 )
1925
+ - CV_16S - 16-bit signed integers ( -32768..32767 )
1926
+ - CV_32S - 32-bit signed integers ( -2147483648..2147483647 )
1927
+ - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
1928
+ - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )
1929
+ */
1930
+ int depth() const;
1931
+
1932
+ /** @brief Returns the number of matrix channels.
1933
+
1934
+ The method returns the number of matrix channels.
1935
+ */
1936
+ int channels() const;
1937
+
1938
+ /** @brief Returns a normalized step.
1939
+
1940
+ The method returns a matrix step divided by Mat::elemSize1() . It can be
1941
+ useful to quickly access an arbitrary matrix element.
1942
+ */
1943
+ size_t step1(int i = 0) const;
1944
+
1945
+ /** @brief Returns true if the array has no elements.
1946
+
1947
+ The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because
1948
+ of pop_back() and resize() methods `M.total() == 0` does not imply that
1949
+ `M.data == NULL`.
1950
+ */
1951
+ bool empty() const;
1952
+
1953
+ /** @brief Returns the total number of array elements.
1954
+
1955
+ The method returns the number of array elements (a number of pixels if the
1956
+ array represents an image).
1957
+ */
1958
+ size_t total() const;
1959
+
1960
+ /** @brief Returns the total number of array elements.
1961
+
1962
+ The method returns the number of elements within a certain sub-array slice
1963
+ with startDim <= dim < endDim
1964
+ */
1965
+ size_t total(int startDim, int endDim = INT_MAX) const;
1966
+
1967
+ /**
1968
+ * @param elemChannels Number of channels or number of columns the matrix
1969
+ * should have. For a 2-D matrix, when the matrix has only 1 column, then it
1970
+ * should have elemChannels channels; When the matrix has only 1 channel, then
1971
+ * it should have elemChannels columns. For a 3-D matrix, it should have only
1972
+ * one channel. Furthermore, if the number of planes is not one, then the
1973
+ * number of rows within every plane has to be 1; if the number of rows within
1974
+ * every plane is not 1, then the number of planes has to
1975
+ * be 1.
1976
+ * @param depth The depth the matrix should have. Set it to -1 when any depth
1977
+ * is fine.
1978
+ * @param requireContinuous Set it to true to require the matrix to be
1979
+ * continuous
1980
+ * @return -1 if the requirement is not satisfied.
1981
+ * Otherwise, it returns the number of elements in the matrix. Note
1982
+ * that an element may have multiple channels.
1983
+ *
1984
+ * The following code demonstrates its usage for a 2-d matrix:
1985
+ * @snippet snippets/core_mat_checkVector.cpp example-2d
1986
+ *
1987
+ * The following code demonstrates its usage for a 3-d matrix:
1988
+ * @snippet snippets/core_mat_checkVector.cpp example-3d
1989
+ */
1990
+ int checkVector(int elemChannels, int depth = -1,
1991
+ bool requireContinuous = true) const;
1992
+
1993
+ /** @brief Returns a pointer to the specified matrix row.
1994
+
1995
+ The methods return `uchar*` or typed pointer to the specified matrix row. See
1996
+ the sample in Mat::isContinuous to know how to use these methods.
1997
+ @param i0 A 0-based row index.
1998
+ */
1999
+ uchar *ptr(int i0 = 0);
2000
+ /** @overload */
2001
+ const uchar *ptr(int i0 = 0) const;
2002
+
2003
+ /** @overload
2004
+ @param row Index along the dimension 0
2005
+ @param col Index along the dimension 1
2006
+ */
2007
+ uchar *ptr(int row, int col);
2008
+ /** @overload
2009
+ @param row Index along the dimension 0
2010
+ @param col Index along the dimension 1
2011
+ */
2012
+ const uchar *ptr(int row, int col) const;
2013
+
2014
+ /** @overload */
2015
+ uchar *ptr(int i0, int i1, int i2);
2016
+ /** @overload */
2017
+ const uchar *ptr(int i0, int i1, int i2) const;
2018
+
2019
+ /** @overload */
2020
+ uchar *ptr(const int *idx);
2021
+ /** @overload */
2022
+ const uchar *ptr(const int *idx) const;
2023
+ /** @overload */
2024
+ template <int n> uchar *ptr(const Vec<int, n> &idx);
2025
+ /** @overload */
2026
+ template <int n> const uchar *ptr(const Vec<int, n> &idx) const;
2027
+
2028
+ /** @overload */
2029
+ template <typename _Tp> _Tp *ptr(int i0 = 0);
2030
+ /** @overload */
2031
+ template <typename _Tp> const _Tp *ptr(int i0 = 0) const;
2032
+ /** @overload
2033
+ @param row Index along the dimension 0
2034
+ @param col Index along the dimension 1
2035
+ */
2036
+ template <typename _Tp> _Tp *ptr(int row, int col);
2037
+ /** @overload
2038
+ @param row Index along the dimension 0
2039
+ @param col Index along the dimension 1
2040
+ */
2041
+ template <typename _Tp> const _Tp *ptr(int row, int col) const;
2042
+ /** @overload */
2043
+ template <typename _Tp> _Tp *ptr(int i0, int i1, int i2);
2044
+ /** @overload */
2045
+ template <typename _Tp> const _Tp *ptr(int i0, int i1, int i2) const;
2046
+ /** @overload */
2047
+ template <typename _Tp> _Tp *ptr(const int *idx);
2048
+ /** @overload */
2049
+ template <typename _Tp> const _Tp *ptr(const int *idx) const;
2050
+ /** @overload */
2051
+ template <typename _Tp, int n> _Tp *ptr(const Vec<int, n> &idx);
2052
+ /** @overload */
2053
+ template <typename _Tp, int n> const _Tp *ptr(const Vec<int, n> &idx) const;
2054
+
2055
+ /** @brief Returns a reference to the specified array element.
2056
+
2057
+ The template methods return a reference to the specified array element. For
2058
+ the sake of higher performance, the index range checks are only performed in
2059
+ the Debug configuration.
2060
+
2061
+ Note that the variants with a single index (i) can be used to access elements
2062
+ of single-row or single-column 2-dimensional arrays. That is, if, for example,
2063
+ A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can
2064
+ simply write `A.at<float>(k+4)` and `B.at<int>(2*i+1)` instead of
2065
+ `A.at<float>(0,k+4)` and `B.at<int>(2*i+1,0)`, respectively.
2066
+
2067
+ The example below initializes a Hilbert matrix:
2068
+ @code
2069
+ Mat H(100, 100, CV_64F);
2070
+ for(int i = 0; i < H.rows; i++)
2071
+ for(int j = 0; j < H.cols; j++)
2072
+ H.at<double>(i,j)=1./(i+j+1);
2073
+ @endcode
2074
+
2075
+ Keep in mind that the size identifier used in the at operator cannot be chosen
2076
+ at random. It depends on the image from which you are trying to retrieve the
2077
+ data. The table below gives a better insight in this:
2078
+ - If matrix is of type `CV_8U` then use `Mat.at<uchar>(y,x)`.
2079
+ - If matrix is of type `CV_8S` then use `Mat.at<schar>(y,x)`.
2080
+ - If matrix is of type `CV_16U` then use `Mat.at<ushort>(y,x)`.
2081
+ - If matrix is of type `CV_16S` then use `Mat.at<short>(y,x)`.
2082
+ - If matrix is of type `CV_32S` then use `Mat.at<int>(y,x)`.
2083
+ - If matrix is of type `CV_32F` then use `Mat.at<float>(y,x)`.
2084
+ - If matrix is of type `CV_64F` then use `Mat.at<double>(y,x)`.
2085
+
2086
+ @param i0 Index along the dimension 0
2087
+ */
2088
+ template <typename _Tp> _Tp &at(int i0 = 0);
2089
+ /** @overload
2090
+ @param i0 Index along the dimension 0
2091
+ */
2092
+ template <typename _Tp> const _Tp &at(int i0 = 0) const;
2093
+ /** @overload
2094
+ @param row Index along the dimension 0
2095
+ @param col Index along the dimension 1
2096
+ */
2097
+ template <typename _Tp> _Tp &at(int row, int col);
2098
+ /** @overload
2099
+ @param row Index along the dimension 0
2100
+ @param col Index along the dimension 1
2101
+ */
2102
+ template <typename _Tp> const _Tp &at(int row, int col) const;
2103
+
2104
+ /** @overload
2105
+ @param i0 Index along the dimension 0
2106
+ @param i1 Index along the dimension 1
2107
+ @param i2 Index along the dimension 2
2108
+ */
2109
+ template <typename _Tp> _Tp &at(int i0, int i1, int i2);
2110
+ /** @overload
2111
+ @param i0 Index along the dimension 0
2112
+ @param i1 Index along the dimension 1
2113
+ @param i2 Index along the dimension 2
2114
+ */
2115
+ template <typename _Tp> const _Tp &at(int i0, int i1, int i2) const;
2116
+
2117
+ /** @overload
2118
+ @param idx Array of Mat::dims indices.
2119
+ */
2120
+ template <typename _Tp> _Tp &at(const int *idx);
2121
+ /** @overload
2122
+ @param idx Array of Mat::dims indices.
2123
+ */
2124
+ template <typename _Tp> const _Tp &at(const int *idx) const;
2125
+
2126
+ /** @overload */
2127
+ template <typename _Tp, int n> _Tp &at(const Vec<int, n> &idx);
2128
+ /** @overload */
2129
+ template <typename _Tp, int n> const _Tp &at(const Vec<int, n> &idx) const;
2130
+
2131
+ /** @overload
2132
+ special versions for 2D arrays (especially convenient for referencing image
2133
+ pixels)
2134
+ @param pt Element position specified as Point(j,i) .
2135
+ */
2136
+ template <typename _Tp> _Tp &at(Point pt);
2137
+ /** @overload
2138
+ special versions for 2D arrays (especially convenient for referencing image
2139
+ pixels)
2140
+ @param pt Element position specified as Point(j,i) .
2141
+ */
2142
+ template <typename _Tp> const _Tp &at(Point pt) const;
2143
+
2144
+ /** @brief Returns the matrix iterator and sets it to the first matrix
2145
+ element.
2146
+
2147
+ The methods return the matrix read-only or read-write iterators. The use of
2148
+ matrix iterators is very similar to the use of bi-directional STL iterators.
2149
+ In the example below, the alpha blending function is rewritten using the
2150
+ matrix iterators:
2151
+ @code
2152
+ template<typename T>
2153
+ void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
2154
+ {
2155
+ typedef Vec<T, 4> VT;
2156
+
2157
+ const float alpha_scale = (float)std::numeric_limits<T>::max(),
2158
+ inv_scale = 1.f/alpha_scale;
2159
+
2160
+ CV_Assert( src1.type() == src2.type() &&
2161
+ src1.type() == traits::Type<VT>::value &&
2162
+ src1.size() == src2.size());
2163
+ Size size = src1.size();
2164
+ dst.create(size, src1.type());
2165
+
2166
+ MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end =
2167
+ src1.end<VT>(); MatConstIterator_<VT> it2 = src2.begin<VT>(); MatIterator_<VT>
2168
+ dst_it = dst.begin<VT>();
2169
+
2170
+ for( ; it1 != it1_end; ++it1, ++it2, ++dst_it )
2171
+ {
2172
+ VT pix1 = *it1, pix2 = *it2;
2173
+ float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale;
2174
+ *dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta),
2175
+ saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta),
2176
+ saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta),
2177
+ saturate_cast<T>((1 -
2178
+ (1-alpha)*(1-beta))*alpha_scale));
2179
+ }
2180
+ }
2181
+ @endcode
2182
+ */
2183
+ template <typename _Tp> MatIterator_<_Tp> begin();
2184
+ template <typename _Tp> MatConstIterator_<_Tp> begin() const;
2185
+
2186
+ /** @brief Same as begin() but for inverse traversal
2187
+ */
2188
+ template <typename _Tp> std::reverse_iterator<MatIterator_<_Tp>> rbegin();
2189
+ template <typename _Tp>
2190
+ std::reverse_iterator<MatConstIterator_<_Tp>> rbegin() const;
2191
+
2192
+ /** @brief Returns the matrix iterator and sets it to the after-last matrix
2193
+ element.
2194
+
2195
+ The methods return the matrix read-only or read-write iterators, set to the
2196
+ point following the last matrix element.
2197
+ */
2198
+ template <typename _Tp> MatIterator_<_Tp> end();
2199
+ template <typename _Tp> MatConstIterator_<_Tp> end() const;
2200
+
2201
+ /** @brief Same as end() but for inverse traversal
2202
+ */
2203
+ template <typename _Tp> std::reverse_iterator<MatIterator_<_Tp>> rend();
2204
+ template <typename _Tp>
2205
+ std::reverse_iterator<MatConstIterator_<_Tp>> rend() const;
2206
+
2207
+ /** @brief Runs the given functor over all matrix elements in parallel.
2208
+
2209
+ The operation passed as argument has to be a function pointer, a function
2210
+ object or a lambda(C++11).
2211
+
2212
+ Example 1. All of the operations below put 0xFF the first channel of all
2213
+ matrix elements:
2214
+ @code
2215
+ Mat image(1920, 1080, CV_8UC3);
2216
+ typedef cv::Point3_<uint8_t> Pixel;
2217
+
2218
+ // first. raw pointer access.
2219
+ for (int r = 0; r < image.rows; ++r) {
2220
+ Pixel* ptr = image.ptr<Pixel>(r, 0);
2221
+ const Pixel* ptr_end = ptr + image.cols;
2222
+ for (; ptr != ptr_end; ++ptr) {
2223
+ ptr->x = 255;
2224
+ }
2225
+ }
2226
+
2227
+ // Using MatIterator. (Simple but there are a Iterator's overhead)
2228
+ for (Pixel &p : cv::Mat_<Pixel>(image)) {
2229
+ p.x = 255;
2230
+ }
2231
+
2232
+ // Parallel execution with function object.
2233
+ struct Operator {
2234
+ void operator ()(Pixel &pixel, const int * position) {
2235
+ pixel.x = 255;
2236
+ }
2237
+ };
2238
+ image.forEach<Pixel>(Operator());
2239
+
2240
+ // Parallel execution using C++11 lambda.
2241
+ image.forEach<Pixel>([](Pixel &p, const int * position) -> void {
2242
+ p.x = 255;
2243
+ });
2244
+ @endcode
2245
+ Example 2. Using the pixel's position:
2246
+ @code
2247
+ // Creating 3D matrix (255 x 255 x 255) typed uint8_t
2248
+ // and initialize all elements by the value which equals elements
2249
+ position.
2250
+ // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3).
2251
+
2252
+ int sizes[] = { 255, 255, 255 };
2253
+ typedef cv::Point3_<uint8_t> Pixel;
2254
+
2255
+ Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3);
2256
+
2257
+ image.forEach<Pixel>([](Pixel& pixel, const int position[]) -> void {
2258
+ pixel.x = position[0];
2259
+ pixel.y = position[1];
2260
+ pixel.z = position[2];
2261
+ });
2262
+ @endcode
2263
+ */
2264
+ template <typename _Tp, typename Functor>
2265
+ void forEach(const Functor &operation);
2266
+ /** @overload */
2267
+ template <typename _Tp, typename Functor>
2268
+ void forEach(const Functor &operation) const;
2269
+
2270
+ Mat(Mat &&m) CV_NOEXCEPT;
2271
+ Mat &operator=(Mat &&m);
2272
+
2273
+ enum {
2274
+ MAGIC_VAL = 0x42FF0000,
2275
+ AUTO_STEP = 0,
2276
+ CONTINUOUS_FLAG = CV_MAT_CONT_FLAG,
2277
+ SUBMATRIX_FLAG = CV_SUBMAT_FLAG
2278
+ };
2279
+ enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
2280
+
2281
+ /*! includes several bit-fields:
2282
+ - the magic signature
2283
+ - continuity flag
2284
+ - depth
2285
+ - number of channels
2286
+ */
2287
+ int flags;
2288
+ //! the matrix dimensionality, >= 2
2289
+ int dims;
2290
+ //! the number of rows and columns or (-1, -1) when the matrix has more than 2
2291
+ //! dimensions
2292
+ int rows, cols;
2293
+ //! pointer to the data
2294
+ uchar *data;
2295
+
2296
+ //! helper fields used in locateROI and adjustROI
2297
+ const uchar *datastart;
2298
+ const uchar *dataend;
2299
+ const uchar *datalimit;
2300
+
2301
+ //! custom allocator
2302
+ MatAllocator *allocator;
2303
+ //! and the standard allocator
2304
+ static MatAllocator *getStdAllocator();
2305
+ static MatAllocator *getDefaultAllocator();
2306
+ static void setDefaultAllocator(MatAllocator *allocator);
2307
+
2308
+ //! internal use method: updates the continuity flag
2309
+ void updateContinuityFlag();
2310
+
2311
+ //! interaction with UMat
2312
+ UMatData *u;
2313
+
2314
+ MatSize size;
2315
+ MatStep step;
2316
+
2317
+ protected:
2318
+ template <typename _Tp, typename Functor>
2319
+ void forEach_impl(const Functor &operation);
2320
+ };
2321
+
2322
+ ///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
2323
+
2324
+ /** @brief Template matrix class derived from Mat
2325
+
2326
+ @code{.cpp}
2327
+ template<typename _Tp> class Mat_ : public Mat
2328
+ {
2329
+ public:
2330
+ // ... some specific methods
2331
+ // and
2332
+ // no new extra fields
2333
+ };
2334
+ @endcode
2335
+ The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It
2336
+ does not have any extra data fields. Nor this class nor Mat has any virtual
2337
+ methods. Thus, references or pointers to these two classes can be freely but
2338
+ carefully converted one to another. For example:
2339
+ @code{.cpp}
2340
+ // create a 100x100 8-bit matrix
2341
+ Mat M(100,100,CV_8U);
2342
+ // this will be compiled fine. no any data conversion will be done.
2343
+ Mat_<float>& M1 = (Mat_<float>&)M;
2344
+ // the program is likely to crash at the statement below
2345
+ M1(99,99) = 1.f;
2346
+ @endcode
2347
+ While Mat is sufficient in most cases, Mat_ can be more convenient if you use a
2348
+ lot of element access operations and if you know matrix type at the compilation
2349
+ time. Note that `Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do
2350
+ absolutely the same and run at the same speed, but the latter is certainly
2351
+ shorter:
2352
+ @code{.cpp}
2353
+ Mat_<double> M(20,20);
2354
+ for(int i = 0; i < M.rows; i++)
2355
+ for(int j = 0; j < M.cols; j++)
2356
+ M(i,j) = 1./(i+j+1);
2357
+ Mat E, V;
2358
+ eigen(M,E,V);
2359
+ cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0);
2360
+ @endcode
2361
+ To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter:
2362
+ @code{.cpp}
2363
+ // allocate a 320x240 color image and fill it with green (in RGB space)
2364
+ Mat_<Vec3b> img(240, 320, Vec3b(0,255,0));
2365
+ // now draw a diagonal white line
2366
+ for(int i = 0; i < 100; i++)
2367
+ img(i,i)=Vec3b(255,255,255);
2368
+ // and now scramble the 2nd (red) channel of each pixel
2369
+ for(int i = 0; i < img.rows; i++)
2370
+ for(int j = 0; j < img.cols; j++)
2371
+ img(i,j)[2] ^= (uchar)(i ^ j);
2372
+ @endcode
2373
+ Mat_ is fully compatible with C++11 range-based for loop. For example such loop
2374
+ can be used to safely apply look-up table:
2375
+ @code{.cpp}
2376
+ void applyTable(Mat_<uchar>& I, const uchar* const table)
2377
+ {
2378
+ for(auto& pixel : I)
2379
+ {
2380
+ pixel = table[pixel];
2381
+ }
2382
+ }
2383
+ @endcode
2384
+ */
2385
+ template <typename _Tp> class Mat_ : public Mat {
2386
+ public:
2387
+ typedef _Tp value_type;
2388
+ typedef typename DataType<_Tp>::channel_type channel_type;
2389
+ typedef MatIterator_<_Tp> iterator;
2390
+ typedef MatConstIterator_<_Tp> const_iterator;
2391
+
2392
+ //! default constructor
2393
+ Mat_() CV_NOEXCEPT;
2394
+ //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
2395
+ Mat_(int _rows, int _cols);
2396
+ //! constructor that sets each matrix element to specified value
2397
+ Mat_(int _rows, int _cols, const _Tp &value);
2398
+ //! equivalent to Mat(_size, DataType<_Tp>::type)
2399
+ explicit Mat_(Size _size);
2400
+ //! constructor that sets each matrix element to specified value
2401
+ Mat_(Size _size, const _Tp &value);
2402
+ //! n-dim array constructor
2403
+ Mat_(int _ndims, const int *_sizes);
2404
+ //! n-dim array constructor that sets each matrix element to specified value
2405
+ Mat_(int _ndims, const int *_sizes, const _Tp &value);
2406
+ //! copy/conversion constructor. If m is of different type, it's converted
2407
+ Mat_(const Mat &m);
2408
+ //! copy constructor
2409
+ Mat_(const Mat_ &m);
2410
+ //! constructs a matrix on top of user-allocated data. step is in bytes(!!!),
2411
+ //! regardless of the type
2412
+ Mat_(int _rows, int _cols, _Tp *_data, size_t _step = AUTO_STEP);
2413
+ //! constructs n-dim matrix on top of user-allocated data. steps are in
2414
+ //! bytes(!!!), regardless of the type
2415
+ Mat_(int _ndims, const int *_sizes, _Tp *_data, const size_t *_steps = 0);
2416
+ //! selects a submatrix
2417
+ Mat_(const Mat_ &m, const Range &rowRange,
2418
+ const Range &colRange = Range::all());
2419
+ //! selects a submatrix
2420
+ Mat_(const Mat_ &m, const Rect &roi);
2421
+ //! selects a submatrix, n-dim version
2422
+ Mat_(const Mat_ &m, const Range *ranges);
2423
+ //! selects a submatrix, n-dim version
2424
+ Mat_(const Mat_ &m, const std::vector<Range> &ranges);
2425
+ //! from a matrix expression
2426
+ explicit Mat_(const MatExpr &e);
2427
+ //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will
2428
+ //! have a single column
2429
+ explicit Mat_(const std::vector<_Tp> &vec, bool copyData = false);
2430
+ template <int n>
2431
+ explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n> &vec,
2432
+ bool copyData = true);
2433
+ template <int m, int n>
2434
+ explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n> &mtx,
2435
+ bool copyData = true);
2436
+ explicit Mat_(const Point_<typename DataType<_Tp>::channel_type> &pt,
2437
+ bool copyData = true);
2438
+ explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type> &pt,
2439
+ bool copyData = true);
2440
+ explicit Mat_(const MatCommaInitializer_<_Tp> &commaInitializer);
2441
+
2442
+ Mat_(std::initializer_list<_Tp> values);
2443
+ explicit Mat_(const std::initializer_list<int> sizes,
2444
+ const std::initializer_list<_Tp> values);
2445
+
2446
+ template <std::size_t _Nm>
2447
+ explicit Mat_(const std::array<_Tp, _Nm> &arr, bool copyData = false);
2448
+
2449
+ Mat_ &operator=(const Mat &m);
2450
+ Mat_ &operator=(const Mat_ &m);
2451
+ //! set all the elements to s.
2452
+ Mat_ &operator=(const _Tp &s);
2453
+ //! assign a matrix expression
2454
+ Mat_ &operator=(const MatExpr &e);
2455
+
2456
+ //! iterators; they are smart enough to skip gaps in the end of rows
2457
+ iterator begin();
2458
+ iterator end();
2459
+ const_iterator begin() const;
2460
+ const_iterator end() const;
2461
+
2462
+ // reverse iterators
2463
+ std::reverse_iterator<iterator> rbegin();
2464
+ std::reverse_iterator<iterator> rend();
2465
+ std::reverse_iterator<const_iterator> rbegin() const;
2466
+ std::reverse_iterator<const_iterator> rend() const;
2467
+
2468
+ //! template methods for operation over all matrix elements.
2469
+ // the operations take care of skipping gaps in the end of rows (if any)
2470
+ template <typename Functor> void forEach(const Functor &operation);
2471
+ template <typename Functor> void forEach(const Functor &operation) const;
2472
+
2473
+ //! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
2474
+ void create(int _rows, int _cols);
2475
+ //! equivalent to Mat::create(_size, DataType<_Tp>::type)
2476
+ void create(Size _size);
2477
+ //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
2478
+ void create(int _ndims, const int *_sizes);
2479
+ //! equivalent to Mat::release()
2480
+ void release();
2481
+ //! cross-product
2482
+ Mat_ cross(const Mat_ &m) const;
2483
+ //! data type conversion
2484
+ template <typename T2> operator Mat_<T2>() const;
2485
+ //! overridden forms of Mat::row() etc.
2486
+ Mat_ row(int y) const;
2487
+ Mat_ col(int x) const;
2488
+ Mat_ diag(int d = 0) const;
2489
+ CV_NODISCARD_STD Mat_ clone() const;
2490
+
2491
+ //! overridden forms of Mat::elemSize() etc.
2492
+ size_t elemSize() const;
2493
+ size_t elemSize1() const;
2494
+ int type() const;
2495
+ int depth() const;
2496
+ int channels() const;
2497
+ size_t step1(int i = 0) const;
2498
+ //! returns step()/sizeof(_Tp)
2499
+ size_t stepT(int i = 0) const;
2500
+
2501
+ //! overridden forms of Mat::zeros() etc. Data type is omitted, of course
2502
+ CV_NODISCARD_STD static MatExpr zeros(int rows, int cols);
2503
+ CV_NODISCARD_STD static MatExpr zeros(Size size);
2504
+ CV_NODISCARD_STD static MatExpr zeros(int _ndims, const int *_sizes);
2505
+ CV_NODISCARD_STD static MatExpr ones(int rows, int cols);
2506
+ CV_NODISCARD_STD static MatExpr ones(Size size);
2507
+ CV_NODISCARD_STD static MatExpr ones(int _ndims, const int *_sizes);
2508
+ CV_NODISCARD_STD static MatExpr eye(int rows, int cols);
2509
+ CV_NODISCARD_STD static MatExpr eye(Size size);
2510
+
2511
+ //! some more overridden methods
2512
+ Mat_ &adjustROI(int dtop, int dbottom, int dleft, int dright);
2513
+ Mat_ operator()(const Range &rowRange, const Range &colRange) const;
2514
+ Mat_ operator()(const Rect &roi) const;
2515
+ Mat_ operator()(const Range *ranges) const;
2516
+ Mat_ operator()(const std::vector<Range> &ranges) const;
2517
+
2518
+ //! more convenient forms of row and element access operators
2519
+ _Tp *operator[](int y);
2520
+ const _Tp *operator[](int y) const;
2521
+
2522
+ //! returns reference to the specified element
2523
+ _Tp &operator()(const int *idx);
2524
+ //! returns read-only reference to the specified element
2525
+ const _Tp &operator()(const int *idx) const;
2526
+
2527
+ //! returns reference to the specified element
2528
+ template <int n> _Tp &operator()(const Vec<int, n> &idx);
2529
+ //! returns read-only reference to the specified element
2530
+ template <int n> const _Tp &operator()(const Vec<int, n> &idx) const;
2531
+
2532
+ //! returns reference to the specified element (1D case)
2533
+ _Tp &operator()(int idx0);
2534
+ //! returns read-only reference to the specified element (1D case)
2535
+ const _Tp &operator()(int idx0) const;
2536
+ //! returns reference to the specified element (2D case)
2537
+ _Tp &operator()(int row, int col);
2538
+ //! returns read-only reference to the specified element (2D case)
2539
+ const _Tp &operator()(int row, int col) const;
2540
+ //! returns reference to the specified element (3D case)
2541
+ _Tp &operator()(int idx0, int idx1, int idx2);
2542
+ //! returns read-only reference to the specified element (3D case)
2543
+ const _Tp &operator()(int idx0, int idx1, int idx2) const;
2544
+
2545
+ _Tp &operator()(Point pt);
2546
+ const _Tp &operator()(Point pt) const;
2547
+
2548
+ //! conversion to vector.
2549
+ operator std::vector<_Tp>() const;
2550
+
2551
+ //! conversion to array.
2552
+ template <std::size_t _Nm> operator std::array<_Tp, _Nm>() const;
2553
+
2554
+ //! conversion to Vec
2555
+ template <int n>
2556
+ operator Vec<typename DataType<_Tp>::channel_type, n>() const;
2557
+ //! conversion to Matx
2558
+ template <int m, int n>
2559
+ operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
2560
+
2561
+ Mat_(Mat_ &&m);
2562
+ Mat_ &operator=(Mat_ &&m);
2563
+
2564
+ Mat_(Mat &&m);
2565
+ Mat_ &operator=(Mat &&m);
2566
+
2567
+ Mat_(MatExpr &&e);
2568
+ };
2569
+
2570
+ typedef Mat_<uchar> Mat1b;
2571
+ typedef Mat_<Vec2b> Mat2b;
2572
+ typedef Mat_<Vec3b> Mat3b;
2573
+ typedef Mat_<Vec4b> Mat4b;
2574
+
2575
+ typedef Mat_<short> Mat1s;
2576
+ typedef Mat_<Vec2s> Mat2s;
2577
+ typedef Mat_<Vec3s> Mat3s;
2578
+ typedef Mat_<Vec4s> Mat4s;
2579
+
2580
+ typedef Mat_<ushort> Mat1w;
2581
+ typedef Mat_<Vec2w> Mat2w;
2582
+ typedef Mat_<Vec3w> Mat3w;
2583
+ typedef Mat_<Vec4w> Mat4w;
2584
+
2585
+ typedef Mat_<int> Mat1i;
2586
+ typedef Mat_<Vec2i> Mat2i;
2587
+ typedef Mat_<Vec3i> Mat3i;
2588
+ typedef Mat_<Vec4i> Mat4i;
2589
+
2590
+ typedef Mat_<float> Mat1f;
2591
+ typedef Mat_<Vec2f> Mat2f;
2592
+ typedef Mat_<Vec3f> Mat3f;
2593
+ typedef Mat_<Vec4f> Mat4f;
2594
+
2595
+ typedef Mat_<double> Mat1d;
2596
+ typedef Mat_<Vec2d> Mat2d;
2597
+ typedef Mat_<Vec3d> Mat3d;
2598
+ typedef Mat_<Vec4d> Mat4d;
2599
+
2600
+ /////////////////////////// multi-dimensional sparse matrix
2601
+ /////////////////////////////
2602
+
2603
+ /** @brief The class SparseMat represents multi-dimensional sparse numerical
2604
+ arrays.
2605
+
2606
+ Such a sparse array can store elements of any type that Mat can store. *Sparse*
2607
+ means that only non-zero elements are stored (though, as a result of operations
2608
+ on a sparse matrix, some of its stored elements can actually become 0. It is up
2609
+ to you to detect such elements and delete them using SparseMat::erase ). The
2610
+ non-zero elements are stored in a hash table that grows when it is filled so
2611
+ that the search time is O(1) in average (regardless of whether element is there
2612
+ or not). Elements can be accessed using the following methods:
2613
+ - Query operations (SparseMat::ptr and the higher-level SparseMat::ref,
2614
+ SparseMat::value and SparseMat::find), for example:
2615
+ @code
2616
+ const int dims = 5;
2617
+ int size[5] = {10, 10, 10, 10, 10};
2618
+ SparseMat sparse_mat(dims, size, CV_32F);
2619
+ for(int i = 0; i < 1000; i++)
2620
+ {
2621
+ int idx[dims];
2622
+ for(int k = 0; k < dims; k++)
2623
+ idx[k] = rand() % size[k];
2624
+ sparse_mat.ref<float>(idx) += 1.f;
2625
+ }
2626
+ cout << "nnz = " << sparse_mat.nzcount() << endl;
2627
+ @endcode
2628
+ - Sparse matrix iterators. They are similar to MatIterator but different from
2629
+ NAryMatIterator. That is, the iteration loop is familiar to STL users:
2630
+ @code
2631
+ // prints elements of a sparse floating-point matrix
2632
+ // and the sum of elements.
2633
+ SparseMatConstIterator_<float>
2634
+ it = sparse_mat.begin<float>(),
2635
+ it_end = sparse_mat.end<float>();
2636
+ double s = 0;
2637
+ int dims = sparse_mat.dims();
2638
+ for(; it != it_end; ++it)
2639
+ {
2640
+ // print element indices and the element value
2641
+ const SparseMat::Node* n = it.node();
2642
+ printf("(");
2643
+ for(int i = 0; i < dims; i++)
2644
+ printf("%d%s", n->idx[i], i < dims-1 ? ", " : ")");
2645
+ printf(": %g\n", it.value<float>());
2646
+ s += *it;
2647
+ }
2648
+ printf("Element sum is %g\n", s);
2649
+ @endcode
2650
+ If you run this loop, you will notice that elements are not enumerated in a
2651
+ logical order (lexicographical, and so on). They come in the same order as they
2652
+ are stored in the hash table (semi-randomly). You may collect pointers to the
2653
+ nodes and sort them to get the proper ordering. Note, however, that pointers to
2654
+ the nodes may become invalid when you add more elements to the matrix. This may
2655
+ happen due to possible buffer reallocation.
2656
+ - Combination of the above 2 methods when you need to process 2 or more sparse
2657
+ matrices simultaneously. For example, this is how you can compute unnormalized
2658
+ cross-correlation of the 2 floating-point sparse matrices:
2659
+ @code
2660
+ double cross_corr(const SparseMat& a, const SparseMat& b)
2661
+ {
2662
+ const SparseMat *_a = &a, *_b = &b;
2663
+ // if b contains less elements than a,
2664
+ // it is faster to iterate through b
2665
+ if(_a->nzcount() > _b->nzcount())
2666
+ std::swap(_a, _b);
2667
+ SparseMatConstIterator_<float> it = _a->begin<float>(),
2668
+ it_end = _a->end<float>();
2669
+ double ccorr = 0;
2670
+ for(; it != it_end; ++it)
2671
+ {
2672
+ // take the next element from the first matrix
2673
+ float avalue = *it;
2674
+ const Node* anode = it.node();
2675
+ // and try to find an element with the same index in the second
2676
+ matrix.
2677
+ // since the hash value depends only on the element index,
2678
+ // reuse the hash value stored in the node
2679
+ float bvalue = _b->value<float>(anode->idx,&anode->hashval);
2680
+ ccorr += avalue*bvalue;
2681
+ }
2682
+ return ccorr;
2683
+ }
2684
+ @endcode
2685
+ */
2686
+ class CV_EXPORTS SparseMat {
2687
+ public:
2688
+ typedef SparseMatIterator iterator;
2689
+ typedef SparseMatConstIterator const_iterator;
2690
+
2691
+ enum {
2692
+ MAGIC_VAL = 0x42FD0000,
2693
+ MAX_DIM = 32,
2694
+ HASH_SCALE = 0x5bd1e995,
2695
+ HASH_BIT = 0x80000000
2696
+ };
2697
+
2698
+ //! the sparse matrix header
2699
+ struct CV_EXPORTS Hdr {
2700
+ Hdr(int _dims, const int *_sizes, int _type);
2701
+ void clear();
2702
+ int refcount;
2703
+ int dims;
2704
+ int valueOffset;
2705
+ size_t nodeSize;
2706
+ size_t nodeCount;
2707
+ size_t freeList;
2708
+ std::vector<uchar> pool;
2709
+ std::vector<size_t> hashtab;
2710
+ int size[MAX_DIM];
2711
+ };
2712
+
2713
+ //! sparse matrix node - element of a hash table
2714
+ struct CV_EXPORTS Node {
2715
+ //! hash value
2716
+ size_t hashval;
2717
+ //! index of the next node in the same hash table entry
2718
+ size_t next;
2719
+ //! index of the matrix element
2720
+ int idx[MAX_DIM];
2721
+ };
2722
+
2723
+ /** @brief Various SparseMat constructors.
2724
+ */
2725
+ SparseMat();
2726
+
2727
+ /** @overload
2728
+ @param dims Array dimensionality.
2729
+ @param _sizes Sparce matrix size on all dementions.
2730
+ @param _type Sparse matrix data type.
2731
+ */
2732
+ SparseMat(int dims, const int *_sizes, int _type);
2733
+
2734
+ /** @overload
2735
+ @param m Source matrix for copy constructor. If m is dense matrix (ocvMat)
2736
+ then it will be converted to sparse representation.
2737
+ */
2738
+ SparseMat(const SparseMat &m);
2739
+
2740
+ /** @overload
2741
+ @param m Source matrix for copy constructor. If m is dense matrix (ocvMat)
2742
+ then it will be converted to sparse representation.
2743
+ */
2744
+ explicit SparseMat(const Mat &m);
2745
+
2746
+ //! the destructor
2747
+ ~SparseMat();
2748
+
2749
+ //! assignment operator. This is O(1) operation, i.e. no data is copied
2750
+ SparseMat &operator=(const SparseMat &m);
2751
+ //! equivalent to the corresponding constructor
2752
+ SparseMat &operator=(const Mat &m);
2753
+
2754
+ //! creates full copy of the matrix
2755
+ CV_NODISCARD_STD SparseMat clone() const;
2756
+
2757
+ //! copies all the data to the destination matrix. All the previous content of
2758
+ //! m is erased
2759
+ void copyTo(SparseMat &m) const;
2760
+ //! converts sparse matrix to dense matrix.
2761
+ void copyTo(Mat &m) const;
2762
+ //! multiplies all the matrix elements by the specified scale factor alpha and
2763
+ //! converts the results to the specified data type
2764
+ void convertTo(SparseMat &m, int rtype, double alpha = 1) const;
2765
+ //! converts sparse matrix to dense n-dim matrix with optional type conversion
2766
+ //! and scaling.
2767
+ /*!
2768
+ @param [out] m - output matrix; if it does not have a proper size or type
2769
+ before the operation, it is reallocated
2770
+ @param [in] rtype - desired output matrix type or, rather, the depth since
2771
+ the number of channels are the same as the input has; if rtype is negative,
2772
+ the output matrix will have the same type as the input.
2773
+ @param [in] alpha - optional scale factor
2774
+ @param [in] beta - optional delta added to the scaled values
2775
+ */
2776
+ void convertTo(Mat &m, int rtype, double alpha = 1, double beta = 0) const;
2777
+
2778
+ // not used now
2779
+ void assignTo(SparseMat &m, int type = -1) const;
2780
+
2781
+ //! reallocates sparse matrix.
2782
+ /*!
2783
+ If the matrix already had the proper size and type,
2784
+ it is simply cleared with clear(), otherwise,
2785
+ the old matrix is released (using release()) and the new one is allocated.
2786
+ */
2787
+ void create(int dims, const int *_sizes, int _type);
2788
+ //! sets all the sparse matrix elements to 0, which means clearing the hash
2789
+ //! table.
2790
+ void clear();
2791
+ //! manually increments the reference counter to the header.
2792
+ void addref();
2793
+ // decrements the header reference counter. When the counter reaches 0, the
2794
+ // header and all the underlying data are deallocated.
2795
+ void release();
2796
+
2797
+ //! converts sparse matrix to the old-style representation; all the elements
2798
+ //! are copied.
2799
+ // operator CvSparseMat*() const;
2800
+ //! returns the size of each element in bytes (not including the overhead -
2801
+ //! the space occupied by SparseMat::Node elements)
2802
+ size_t elemSize() const;
2803
+ //! returns elemSize()/channels()
2804
+ size_t elemSize1() const;
2805
+
2806
+ //! returns type of sparse matrix elements
2807
+ int type() const;
2808
+ //! returns the depth of sparse matrix elements
2809
+ int depth() const;
2810
+ //! returns the number of channels
2811
+ int channels() const;
2812
+
2813
+ //! returns the array of sizes, or NULL if the matrix is not allocated
2814
+ const int *size() const;
2815
+ //! returns the size of i-th matrix dimension (or 0)
2816
+ int size(int i) const;
2817
+ //! returns the matrix dimensionality
2818
+ int dims() const;
2819
+ //! returns the number of non-zero elements (=the number of hash table nodes)
2820
+ size_t nzcount() const;
2821
+
2822
+ //! computes the element hash value (1D case)
2823
+ size_t hash(int i0) const;
2824
+ //! computes the element hash value (2D case)
2825
+ size_t hash(int i0, int i1) const;
2826
+ //! computes the element hash value (3D case)
2827
+ size_t hash(int i0, int i1, int i2) const;
2828
+ //! computes the element hash value (nD case)
2829
+ size_t hash(const int *idx) const;
2830
+
2831
+ //!@{
2832
+ /*!
2833
+ specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D
2834
+ case. return pointer to the matrix element.
2835
+ - if the element is there (it's non-zero), the pointer to it is returned
2836
+ - if it's not there and createMissing=false, NULL pointer is returned
2837
+ - if it's not there and createMissing=true, then the new element
2838
+ is created and initialized with 0. Pointer to it is returned
2839
+ - if the optional hashval pointer is not NULL, the element hash value is
2840
+ not computed, but *hashval is taken instead.
2841
+ */
2842
+ //! returns pointer to the specified element (1D case)
2843
+ uchar *ptr(int i0, bool createMissing, size_t *hashval = 0);
2844
+ //! returns pointer to the specified element (2D case)
2845
+ uchar *ptr(int i0, int i1, bool createMissing, size_t *hashval = 0);
2846
+ //! returns pointer to the specified element (3D case)
2847
+ uchar *ptr(int i0, int i1, int i2, bool createMissing, size_t *hashval = 0);
2848
+ //! returns pointer to the specified element (nD case)
2849
+ uchar *ptr(const int *idx, bool createMissing, size_t *hashval = 0);
2850
+ //!@}
2851
+
2852
+ //!@{
2853
+ /*!
2854
+ return read-write reference to the specified sparse matrix element.
2855
+
2856
+ `ref<_Tp>(i0,...[,hashval])` is equivalent to
2857
+ `*(_Tp*)ptr(i0,...,true[,hashval])`. The methods always return a valid
2858
+ reference. If the element did not exist, it is created and initialized with
2859
+ 0.
2860
+ */
2861
+ //! returns reference to the specified element (1D case)
2862
+ template <typename _Tp> _Tp &ref(int i0, size_t *hashval = 0);
2863
+ //! returns reference to the specified element (2D case)
2864
+ template <typename _Tp> _Tp &ref(int i0, int i1, size_t *hashval = 0);
2865
+ //! returns reference to the specified element (3D case)
2866
+ template <typename _Tp> _Tp &ref(int i0, int i1, int i2, size_t *hashval = 0);
2867
+ //! returns reference to the specified element (nD case)
2868
+ template <typename _Tp> _Tp &ref(const int *idx, size_t *hashval = 0);
2869
+ //!@}
2870
+
2871
+ //!@{
2872
+ /*!
2873
+ return value of the specified sparse matrix element.
2874
+
2875
+ `value<_Tp>(i0,...[,hashval])` is equivalent to
2876
+ @code
2877
+ { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); }
2878
+ @endcode
2879
+
2880
+ That is, if the element did not exist, the methods return 0.
2881
+ */
2882
+ //! returns value of the specified element (1D case)
2883
+ template <typename _Tp> _Tp value(int i0, size_t *hashval = 0) const;
2884
+ //! returns value of the specified element (2D case)
2885
+ template <typename _Tp> _Tp value(int i0, int i1, size_t *hashval = 0) const;
2886
+ //! returns value of the specified element (3D case)
2887
+ template <typename _Tp>
2888
+ _Tp value(int i0, int i1, int i2, size_t *hashval = 0) const;
2889
+ //! returns value of the specified element (nD case)
2890
+ template <typename _Tp> _Tp value(const int *idx, size_t *hashval = 0) const;
2891
+ //!@}
2892
+
2893
+ //!@{
2894
+ /*!
2895
+ Return pointer to the specified sparse matrix element if it exists
2896
+
2897
+ `find<_Tp>(i0,...[,hashval])` is equivalent to `(_const
2898
+ Tp*)ptr(i0,...false[,hashval])`.
2899
+
2900
+ If the specified element does not exist, the methods return NULL.
2901
+ */
2902
+ //! returns pointer to the specified element (1D case)
2903
+ template <typename _Tp> const _Tp *find(int i0, size_t *hashval = 0) const;
2904
+ //! returns pointer to the specified element (2D case)
2905
+ template <typename _Tp>
2906
+ const _Tp *find(int i0, int i1, size_t *hashval = 0) const;
2907
+ //! returns pointer to the specified element (3D case)
2908
+ template <typename _Tp>
2909
+ const _Tp *find(int i0, int i1, int i2, size_t *hashval = 0) const;
2910
+ //! returns pointer to the specified element (nD case)
2911
+ template <typename _Tp>
2912
+ const _Tp *find(const int *idx, size_t *hashval = 0) const;
2913
+ //!@}
2914
+
2915
+ //! erases the specified element (2D case)
2916
+ void erase(int i0, int i1, size_t *hashval = 0);
2917
+ //! erases the specified element (3D case)
2918
+ void erase(int i0, int i1, int i2, size_t *hashval = 0);
2919
+ //! erases the specified element (nD case)
2920
+ void erase(const int *idx, size_t *hashval = 0);
2921
+
2922
+ //!@{
2923
+ /*!
2924
+ return the sparse matrix iterator pointing to the first sparse matrix
2925
+ element
2926
+ */
2927
+ //! returns the sparse matrix iterator at the matrix beginning
2928
+ SparseMatIterator begin();
2929
+ //! returns the sparse matrix iterator at the matrix beginning
2930
+ template <typename _Tp> SparseMatIterator_<_Tp> begin();
2931
+ //! returns the read-only sparse matrix iterator at the matrix beginning
2932
+ SparseMatConstIterator begin() const;
2933
+ //! returns the read-only sparse matrix iterator at the matrix beginning
2934
+ template <typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
2935
+ //!@}
2936
+ /*!
2937
+ return the sparse matrix iterator pointing to the element following the
2938
+ last sparse matrix element
2939
+ */
2940
+ //! returns the sparse matrix iterator at the matrix end
2941
+ SparseMatIterator end();
2942
+ //! returns the read-only sparse matrix iterator at the matrix end
2943
+ SparseMatConstIterator end() const;
2944
+ //! returns the typed sparse matrix iterator at the matrix end
2945
+ template <typename _Tp> SparseMatIterator_<_Tp> end();
2946
+ //! returns the typed read-only sparse matrix iterator at the matrix end
2947
+ template <typename _Tp> SparseMatConstIterator_<_Tp> end() const;
2948
+
2949
+ //! returns the value stored in the sparse martix node
2950
+ template <typename _Tp> _Tp &value(Node *n);
2951
+ //! returns the value stored in the sparse martix node
2952
+ template <typename _Tp> const _Tp &value(const Node *n) const;
2953
+
2954
+ ////////////// some internal-use methods ///////////////
2955
+ Node *node(size_t nidx);
2956
+ const Node *node(size_t nidx) const;
2957
+
2958
+ uchar *newNode(const int *idx, size_t hashval);
2959
+ void removeNode(size_t hidx, size_t nidx, size_t previdx);
2960
+ void resizeHashTab(size_t newsize);
2961
+
2962
+ int flags;
2963
+ Hdr *hdr;
2964
+ };
2965
+
2966
+ ///////////////////////////////// SparseMat_<_Tp>
2967
+ ///////////////////////////////////////
2968
+
2969
+ /** @brief Template sparse n-dimensional array class derived from SparseMat
2970
+
2971
+ SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_
2972
+ . It simplifies notation of some operations:
2973
+ @code
2974
+ int sz[] = {10, 20, 30};
2975
+ SparseMat_<double> M(3, sz);
2976
+ ...
2977
+ M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9);
2978
+ @endcode
2979
+ */
2980
+ template <typename _Tp> class SparseMat_ : public SparseMat {
2981
+ public:
2982
+ typedef SparseMatIterator_<_Tp> iterator;
2983
+ typedef SparseMatConstIterator_<_Tp> const_iterator;
2984
+
2985
+ //! the default constructor
2986
+ SparseMat_();
2987
+ //! the full constructor equivalent to SparseMat(dims, _sizes,
2988
+ //! DataType<_Tp>::type)
2989
+ SparseMat_(int dims, const int *_sizes);
2990
+ //! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements
2991
+ //! are converted
2992
+ SparseMat_(const SparseMat &m);
2993
+ //! the copy constructor. This is O(1) operation - no data is copied
2994
+ SparseMat_(const SparseMat_ &m);
2995
+ //! converts dense matrix to the sparse form
2996
+ SparseMat_(const Mat &m);
2997
+ //! converts the old-style sparse matrix to the C++ class. All the elements
2998
+ //! are copied
2999
+ // SparseMat_(const CvSparseMat* m);
3000
+ //! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements
3001
+ //! are converted
3002
+ SparseMat_ &operator=(const SparseMat &m);
3003
+ //! the assignment operator. This is O(1) operation - no data is copied
3004
+ SparseMat_ &operator=(const SparseMat_ &m);
3005
+ //! converts dense matrix to the sparse form
3006
+ SparseMat_ &operator=(const Mat &m);
3007
+
3008
+ //! makes full copy of the matrix. All the elements are duplicated
3009
+ CV_NODISCARD_STD SparseMat_ clone() const;
3010
+ //! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type)
3011
+ void create(int dims, const int *_sizes);
3012
+ //! converts sparse matrix to the old-style CvSparseMat. All the elements are
3013
+ //! copied
3014
+ // operator CvSparseMat*() const;
3015
+
3016
+ //! returns type of the matrix elements
3017
+ int type() const;
3018
+ //! returns depth of the matrix elements
3019
+ int depth() const;
3020
+ //! returns the number of channels in each matrix element
3021
+ int channels() const;
3022
+
3023
+ //! equivalent to SparseMat::ref<_Tp>(i0, hashval)
3024
+ _Tp &ref(int i0, size_t *hashval = 0);
3025
+ //! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval)
3026
+ _Tp &ref(int i0, int i1, size_t *hashval = 0);
3027
+ //! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval)
3028
+ _Tp &ref(int i0, int i1, int i2, size_t *hashval = 0);
3029
+ //! equivalent to SparseMat::ref<_Tp>(idx, hashval)
3030
+ _Tp &ref(const int *idx, size_t *hashval = 0);
3031
+
3032
+ //! equivalent to SparseMat::value<_Tp>(i0, hashval)
3033
+ _Tp operator()(int i0, size_t *hashval = 0) const;
3034
+ //! equivalent to SparseMat::value<_Tp>(i0, i1, hashval)
3035
+ _Tp operator()(int i0, int i1, size_t *hashval = 0) const;
3036
+ //! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval)
3037
+ _Tp operator()(int i0, int i1, int i2, size_t *hashval = 0) const;
3038
+ //! equivalent to SparseMat::value<_Tp>(idx, hashval)
3039
+ _Tp operator()(const int *idx, size_t *hashval = 0) const;
3040
+
3041
+ //! returns sparse matrix iterator pointing to the first sparse matrix element
3042
+ SparseMatIterator_<_Tp> begin();
3043
+ //! returns read-only sparse matrix iterator pointing to the first sparse
3044
+ //! matrix element
3045
+ SparseMatConstIterator_<_Tp> begin() const;
3046
+ //! returns sparse matrix iterator pointing to the element following the last
3047
+ //! sparse matrix element
3048
+ SparseMatIterator_<_Tp> end();
3049
+ //! returns read-only sparse matrix iterator pointing to the element following
3050
+ //! the last sparse matrix element
3051
+ SparseMatConstIterator_<_Tp> end() const;
3052
+ };
3053
+
3054
+ ////////////////////////////////// MatConstIterator
3055
+ /////////////////////////////////////
3056
+
3057
+ class CV_EXPORTS MatConstIterator {
3058
+ public:
3059
+ typedef uchar *value_type;
3060
+ typedef ptrdiff_t difference_type;
3061
+ typedef const uchar **pointer;
3062
+ typedef uchar *reference;
3063
+
3064
+ typedef std::random_access_iterator_tag iterator_category;
3065
+
3066
+ //! default constructor
3067
+ MatConstIterator();
3068
+ //! constructor that sets the iterator to the beginning of the matrix
3069
+ MatConstIterator(const Mat *_m);
3070
+ //! constructor that sets the iterator to the specified element of the matrix
3071
+ MatConstIterator(const Mat *_m, int _row, int _col = 0);
3072
+ //! constructor that sets the iterator to the specified element of the matrix
3073
+ MatConstIterator(const Mat *_m, Point _pt);
3074
+ //! constructor that sets the iterator to the specified element of the matrix
3075
+ MatConstIterator(const Mat *_m, const int *_idx);
3076
+ //! copy constructor
3077
+ MatConstIterator(const MatConstIterator &it);
3078
+
3079
+ //! copy operator
3080
+ MatConstIterator &operator=(const MatConstIterator &it);
3081
+ //! returns the current matrix element
3082
+ const uchar *operator*() const;
3083
+ //! returns the i-th matrix element, relative to the current
3084
+ const uchar *operator[](ptrdiff_t i) const;
3085
+
3086
+ //! shifts the iterator forward by the specified number of elements
3087
+ MatConstIterator &operator+=(ptrdiff_t ofs);
3088
+ //! shifts the iterator backward by the specified number of elements
3089
+ MatConstIterator &operator-=(ptrdiff_t ofs);
3090
+ //! decrements the iterator
3091
+ MatConstIterator &operator--();
3092
+ //! decrements the iterator
3093
+ MatConstIterator operator--(int);
3094
+ //! increments the iterator
3095
+ MatConstIterator &operator++();
3096
+ //! increments the iterator
3097
+ MatConstIterator operator++(int);
3098
+ //! returns the current iterator position
3099
+ Point pos() const;
3100
+ //! returns the current iterator position
3101
+ void pos(int *_idx) const;
3102
+
3103
+ ptrdiff_t lpos() const;
3104
+ void seek(ptrdiff_t ofs, bool relative = false);
3105
+ void seek(const int *_idx, bool relative = false);
3106
+
3107
+ const Mat *m;
3108
+ size_t elemSize;
3109
+ const uchar *ptr;
3110
+ const uchar *sliceStart;
3111
+ const uchar *sliceEnd;
3112
+ };
3113
+
3114
+ ////////////////////////////////// MatConstIterator_
3115
+ ////////////////////////////////////
3116
+
3117
+ /** @brief Matrix read-only iterator
3118
+ */
3119
+ template <typename _Tp> class MatConstIterator_ : public MatConstIterator {
3120
+ public:
3121
+ typedef _Tp value_type;
3122
+ typedef ptrdiff_t difference_type;
3123
+ typedef const _Tp *pointer;
3124
+ typedef const _Tp &reference;
3125
+
3126
+ typedef std::random_access_iterator_tag iterator_category;
3127
+
3128
+ //! default constructor
3129
+ MatConstIterator_();
3130
+ //! constructor that sets the iterator to the beginning of the matrix
3131
+ MatConstIterator_(const Mat_<_Tp> *_m);
3132
+ //! constructor that sets the iterator to the specified element of the matrix
3133
+ MatConstIterator_(const Mat_<_Tp> *_m, int _row, int _col = 0);
3134
+ //! constructor that sets the iterator to the specified element of the matrix
3135
+ MatConstIterator_(const Mat_<_Tp> *_m, Point _pt);
3136
+ //! constructor that sets the iterator to the specified element of the matrix
3137
+ MatConstIterator_(const Mat_<_Tp> *_m, const int *_idx);
3138
+ //! copy constructor
3139
+ MatConstIterator_(const MatConstIterator_ &it);
3140
+
3141
+ //! copy operator
3142
+ MatConstIterator_ &operator=(const MatConstIterator_ &it);
3143
+ //! returns the current matrix element
3144
+ const _Tp &operator*() const;
3145
+ //! returns the i-th matrix element, relative to the current
3146
+ const _Tp &operator[](ptrdiff_t i) const;
3147
+
3148
+ //! shifts the iterator forward by the specified number of elements
3149
+ MatConstIterator_ &operator+=(ptrdiff_t ofs);
3150
+ //! shifts the iterator backward by the specified number of elements
3151
+ MatConstIterator_ &operator-=(ptrdiff_t ofs);
3152
+ //! decrements the iterator
3153
+ MatConstIterator_ &operator--();
3154
+ //! decrements the iterator
3155
+ MatConstIterator_ operator--(int);
3156
+ //! increments the iterator
3157
+ MatConstIterator_ &operator++();
3158
+ //! increments the iterator
3159
+ MatConstIterator_ operator++(int);
3160
+ //! returns the current iterator position
3161
+ Point pos() const;
3162
+ };
3163
+
3164
+ //////////////////////////////////// MatIterator_
3165
+ ///////////////////////////////////////
3166
+
3167
+ /** @brief Matrix read-write iterator
3168
+ */
3169
+ template <typename _Tp> class MatIterator_ : public MatConstIterator_<_Tp> {
3170
+ public:
3171
+ typedef _Tp *pointer;
3172
+ typedef _Tp &reference;
3173
+
3174
+ typedef std::random_access_iterator_tag iterator_category;
3175
+
3176
+ //! the default constructor
3177
+ MatIterator_();
3178
+ //! constructor that sets the iterator to the beginning of the matrix
3179
+ MatIterator_(Mat_<_Tp> *_m);
3180
+ //! constructor that sets the iterator to the specified element of the matrix
3181
+ MatIterator_(Mat_<_Tp> *_m, int _row, int _col = 0);
3182
+ //! constructor that sets the iterator to the specified element of the matrix
3183
+ MatIterator_(Mat_<_Tp> *_m, Point _pt);
3184
+ //! constructor that sets the iterator to the specified element of the matrix
3185
+ MatIterator_(Mat_<_Tp> *_m, const int *_idx);
3186
+ //! copy constructor
3187
+ MatIterator_(const MatIterator_ &it);
3188
+ //! copy operator
3189
+ MatIterator_ &operator=(const MatIterator_<_Tp> &it);
3190
+
3191
+ //! returns the current matrix element
3192
+ _Tp &operator*() const;
3193
+ //! returns the i-th matrix element, relative to the current
3194
+ _Tp &operator[](ptrdiff_t i) const;
3195
+
3196
+ //! shifts the iterator forward by the specified number of elements
3197
+ MatIterator_ &operator+=(ptrdiff_t ofs);
3198
+ //! shifts the iterator backward by the specified number of elements
3199
+ MatIterator_ &operator-=(ptrdiff_t ofs);
3200
+ //! decrements the iterator
3201
+ MatIterator_ &operator--();
3202
+ //! decrements the iterator
3203
+ MatIterator_ operator--(int);
3204
+ //! increments the iterator
3205
+ MatIterator_ &operator++();
3206
+ //! increments the iterator
3207
+ MatIterator_ operator++(int);
3208
+ };
3209
+
3210
+ /////////////////////////////// SparseMatConstIterator
3211
+ //////////////////////////////////
3212
+
3213
+ /** @brief Read-Only Sparse Matrix Iterator.
3214
+
3215
+ Here is how to use the iterator to compute the sum of floating-point sparse
3216
+ matrix elements:
3217
+
3218
+ \code
3219
+ SparseMatConstIterator it = m.begin(), it_end = m.end();
3220
+ double s = 0;
3221
+ CV_Assert( m.type() == CV_32F );
3222
+ for( ; it != it_end; ++it )
3223
+ s += it.value<float>();
3224
+ \endcode
3225
+ */
3226
+ class CV_EXPORTS SparseMatConstIterator {
3227
+ public:
3228
+ //! the default constructor
3229
+ SparseMatConstIterator();
3230
+ //! the full constructor setting the iterator to the first sparse matrix
3231
+ //! element
3232
+ SparseMatConstIterator(const SparseMat *_m);
3233
+ //! the copy constructor
3234
+ SparseMatConstIterator(const SparseMatConstIterator &it);
3235
+
3236
+ //! the assignment operator
3237
+ SparseMatConstIterator &operator=(const SparseMatConstIterator &it);
3238
+
3239
+ //! template method returning the current matrix element
3240
+ template <typename _Tp> const _Tp &value() const;
3241
+ //! returns the current node of the sparse matrix. it.node->idx is the current
3242
+ //! element index
3243
+ const SparseMat::Node *node() const;
3244
+
3245
+ //! moves iterator to the previous element
3246
+ SparseMatConstIterator &operator--();
3247
+ //! moves iterator to the previous element
3248
+ SparseMatConstIterator operator--(int);
3249
+ //! moves iterator to the next element
3250
+ SparseMatConstIterator &operator++();
3251
+ //! moves iterator to the next element
3252
+ SparseMatConstIterator operator++(int);
3253
+
3254
+ //! moves iterator to the element after the last element
3255
+ void seekEnd();
3256
+
3257
+ const SparseMat *m;
3258
+ size_t hashidx;
3259
+ uchar *ptr;
3260
+ };
3261
+
3262
+ ////////////////////////////////// SparseMatIterator
3263
+ ////////////////////////////////////
3264
+
3265
+ /** @brief Read-write Sparse Matrix Iterator
3266
+
3267
+ The class is similar to cv::SparseMatConstIterator,
3268
+ but can be used for in-place modification of the matrix elements.
3269
+ */
3270
+ class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator {
3271
+ public:
3272
+ //! the default constructor
3273
+ SparseMatIterator();
3274
+ //! the full constructor setting the iterator to the first sparse matrix
3275
+ //! element
3276
+ SparseMatIterator(SparseMat *_m);
3277
+ //! the full constructor setting the iterator to the specified sparse matrix
3278
+ //! element
3279
+ SparseMatIterator(SparseMat *_m, const int *idx);
3280
+ //! the copy constructor
3281
+ SparseMatIterator(const SparseMatIterator &it);
3282
+
3283
+ //! the assignment operator
3284
+ SparseMatIterator &operator=(const SparseMatIterator &it);
3285
+ //! returns read-write reference to the current sparse matrix element
3286
+ template <typename _Tp> _Tp &value() const;
3287
+ //! returns pointer to the current sparse matrix node. it.node->idx is the
3288
+ //! index of the current element (do not modify it!)
3289
+ SparseMat::Node *node() const;
3290
+
3291
+ //! moves iterator to the next element
3292
+ SparseMatIterator &operator++();
3293
+ //! moves iterator to the next element
3294
+ SparseMatIterator operator++(int);
3295
+ };
3296
+
3297
+ /////////////////////////////// SparseMatConstIterator_
3298
+ /////////////////////////////////
3299
+
3300
+ /** @brief Template Read-Only Sparse Matrix Iterator Class.
3301
+
3302
+ This is the derived from SparseMatConstIterator class that
3303
+ introduces more convenient operator *() for accessing the current element.
3304
+ */
3305
+ template <typename _Tp>
3306
+ class SparseMatConstIterator_ : public SparseMatConstIterator {
3307
+ public:
3308
+ typedef std::forward_iterator_tag iterator_category;
3309
+
3310
+ //! the default constructor
3311
+ SparseMatConstIterator_();
3312
+ //! the full constructor setting the iterator to the first sparse matrix
3313
+ //! element
3314
+ SparseMatConstIterator_(const SparseMat_<_Tp> *_m);
3315
+ SparseMatConstIterator_(const SparseMat *_m);
3316
+ //! the copy constructor
3317
+ SparseMatConstIterator_(const SparseMatConstIterator_ &it);
3318
+
3319
+ //! the assignment operator
3320
+ SparseMatConstIterator_ &operator=(const SparseMatConstIterator_ &it);
3321
+ //! the element access operator
3322
+ const _Tp &operator*() const;
3323
+
3324
+ //! moves iterator to the next element
3325
+ SparseMatConstIterator_ &operator++();
3326
+ //! moves iterator to the next element
3327
+ SparseMatConstIterator_ operator++(int);
3328
+ };
3329
+
3330
+ ///////////////////////////////// SparseMatIterator_
3331
+ ////////////////////////////////////
3332
+
3333
+ /** @brief Template Read-Write Sparse Matrix Iterator Class.
3334
+
3335
+ This is the derived from cv::SparseMatConstIterator_ class that
3336
+ introduces more convenient operator *() for accessing the current element.
3337
+ */
3338
+ template <typename _Tp>
3339
+ class SparseMatIterator_ : public SparseMatConstIterator_<_Tp> {
3340
+ public:
3341
+ typedef std::forward_iterator_tag iterator_category;
3342
+
3343
+ //! the default constructor
3344
+ SparseMatIterator_();
3345
+ //! the full constructor setting the iterator to the first sparse matrix
3346
+ //! element
3347
+ SparseMatIterator_(SparseMat_<_Tp> *_m);
3348
+ SparseMatIterator_(SparseMat *_m);
3349
+ //! the copy constructor
3350
+ SparseMatIterator_(const SparseMatIterator_ &it);
3351
+
3352
+ //! the assignment operator
3353
+ SparseMatIterator_ &operator=(const SparseMatIterator_ &it);
3354
+ //! returns the reference to the current element
3355
+ _Tp &operator*() const;
3356
+
3357
+ //! moves the iterator to the next element
3358
+ SparseMatIterator_ &operator++();
3359
+ //! moves the iterator to the next element
3360
+ SparseMatIterator_ operator++(int);
3361
+ };
3362
+
3363
+ /////////////////////////////////// NAryMatIterator
3364
+ /////////////////////////////////////
3365
+
3366
+ /** @brief n-ary multi-dimensional array iterator.
3367
+
3368
+ Use the class to implement unary, binary, and, generally, n-ary element-wise
3369
+ operations on multi-dimensional arrays. Some of the arguments of an n-ary
3370
+ function may be continuous arrays, some may be not. It is possible to use
3371
+ conventional MatIterator 's for each array but incrementing all of the iterators
3372
+ after each small operations may be a big overhead. In this case consider using
3373
+ NAryMatIterator to iterate through several matrices simultaneously as long as
3374
+ they have the same geometry (dimensionality and all the dimension sizes are the
3375
+ same). On each iteration `it.planes[0]`, `it.planes[1]`,... will be the slices
3376
+ of the corresponding matrices.
3377
+
3378
+ The example below illustrates how you can compute a normalized and threshold 3D
3379
+ color histogram:
3380
+ @code
3381
+ void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double
3382
+ minProb)
3383
+ {
3384
+ const int histSize[] = {N, N, N};
3385
+
3386
+ // make sure that the histogram has a proper size and type
3387
+ hist.create(3, histSize, CV_32F);
3388
+
3389
+ // and clear it
3390
+ hist = Scalar(0);
3391
+
3392
+ // the loop below assumes that the image
3393
+ // is a 8-bit 3-channel. check it.
3394
+ CV_Assert(image.type() == CV_8UC3);
3395
+ MatConstIterator_<Vec3b> it = image.begin<Vec3b>(),
3396
+ it_end = image.end<Vec3b>();
3397
+ for( ; it != it_end; ++it )
3398
+ {
3399
+ const Vec3b& pix = *it;
3400
+ hist.at<float>(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f;
3401
+ }
3402
+
3403
+ minProb *= image.rows*image.cols;
3404
+
3405
+ // initialize iterator (the style is different from STL).
3406
+ // after initialization the iterator will contain
3407
+ // the number of slices or planes the iterator will go through.
3408
+ // it simultaneously increments iterators for several matrices
3409
+ // supplied as a null terminated list of pointers
3410
+ const Mat* arrays[] = {&hist, 0};
3411
+ Mat planes[1];
3412
+ NAryMatIterator itNAry(arrays, planes, 1);
3413
+ double s = 0;
3414
+ // iterate through the matrix. on each iteration
3415
+ // itNAry.planes[i] (of type Mat) will be set to the current plane
3416
+ // of the i-th n-dim matrix passed to the iterator constructor.
3417
+ for(int p = 0; p < itNAry.nplanes; p++, ++itNAry)
3418
+ {
3419
+ threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0,
3420
+ THRESH_TOZERO); s += sum(itNAry.planes[0])[0];
3421
+ }
3422
+
3423
+ s = 1./s;
3424
+ itNAry = NAryMatIterator(arrays, planes, 1);
3425
+ for(int p = 0; p < itNAry.nplanes; p++, ++itNAry)
3426
+ itNAry.planes[0] *= s;
3427
+ }
3428
+ @endcode
3429
+ */
3430
+ class CV_EXPORTS NAryMatIterator {
3431
+ public:
3432
+ //! the default constructor
3433
+ NAryMatIterator();
3434
+ //! the full constructor taking arbitrary number of n-dim matrices
3435
+ NAryMatIterator(const Mat **arrays, uchar **ptrs, int narrays = -1);
3436
+ //! the full constructor taking arbitrary number of n-dim matrices
3437
+ NAryMatIterator(const Mat **arrays, Mat *planes, int narrays = -1);
3438
+ //! the separate iterator initialization method
3439
+ void init(const Mat **arrays, Mat *planes, uchar **ptrs, int narrays = -1);
3440
+
3441
+ //! proceeds to the next plane of every iterated matrix
3442
+ NAryMatIterator &operator++();
3443
+ //! proceeds to the next plane of every iterated matrix (postfix increment
3444
+ //! operator)
3445
+ NAryMatIterator operator++(int);
3446
+
3447
+ //! the iterated arrays
3448
+ const Mat **arrays;
3449
+ //! the current planes
3450
+ Mat *planes;
3451
+ //! data pointers
3452
+ uchar **ptrs;
3453
+ //! the number of arrays
3454
+ int narrays;
3455
+ //! the number of hyper-planes that the iterator steps through
3456
+ size_t nplanes;
3457
+ //! the size of each segment (in elements)
3458
+ size_t size;
3459
+
3460
+ protected:
3461
+ int iterdepth;
3462
+ size_t idx;
3463
+ };
3464
+
3465
+ ///////////////////////////////// Matrix Expressions
3466
+ ////////////////////////////////////
3467
+
3468
+ class CV_EXPORTS MatOp {
3469
+ public:
3470
+ MatOp();
3471
+ virtual ~MatOp();
3472
+
3473
+ virtual bool elementWise(const MatExpr &expr) const;
3474
+ virtual void assign(const MatExpr &expr, Mat &m, int type = -1) const = 0;
3475
+ virtual void roi(const MatExpr &expr, const Range &rowRange,
3476
+ const Range &colRange, MatExpr &res) const;
3477
+ virtual void diag(const MatExpr &expr, int d, MatExpr &res) const;
3478
+ virtual void augAssignAdd(const MatExpr &expr, Mat &m) const;
3479
+ virtual void augAssignSubtract(const MatExpr &expr, Mat &m) const;
3480
+ virtual void augAssignMultiply(const MatExpr &expr, Mat &m) const;
3481
+ virtual void augAssignDivide(const MatExpr &expr, Mat &m) const;
3482
+ virtual void augAssignAnd(const MatExpr &expr, Mat &m) const;
3483
+ virtual void augAssignOr(const MatExpr &expr, Mat &m) const;
3484
+ virtual void augAssignXor(const MatExpr &expr, Mat &m) const;
3485
+
3486
+ virtual void add(const MatExpr &expr1, const MatExpr &expr2,
3487
+ MatExpr &res) const;
3488
+ virtual void add(const MatExpr &expr1, const Scalar &s, MatExpr &res) const;
3489
+
3490
+ virtual void subtract(const MatExpr &expr1, const MatExpr &expr2,
3491
+ MatExpr &res) const;
3492
+ virtual void subtract(const Scalar &s, const MatExpr &expr,
3493
+ MatExpr &res) const;
3494
+
3495
+ virtual void multiply(const MatExpr &expr1, const MatExpr &expr2,
3496
+ MatExpr &res, double scale = 1) const;
3497
+ virtual void multiply(const MatExpr &expr1, double s, MatExpr &res) const;
3498
+
3499
+ virtual void divide(const MatExpr &expr1, const MatExpr &expr2, MatExpr &res,
3500
+ double scale = 1) const;
3501
+ virtual void divide(double s, const MatExpr &expr, MatExpr &res) const;
3502
+
3503
+ virtual void abs(const MatExpr &expr, MatExpr &res) const;
3504
+
3505
+ virtual void transpose(const MatExpr &expr, MatExpr &res) const;
3506
+ virtual void matmul(const MatExpr &expr1, const MatExpr &expr2,
3507
+ MatExpr &res) const;
3508
+ virtual void invert(const MatExpr &expr, int method, MatExpr &res) const;
3509
+
3510
+ virtual Size size(const MatExpr &expr) const;
3511
+ virtual int type(const MatExpr &expr) const;
3512
+ };
3513
+
3514
+ /** @brief Matrix expression representation
3515
+ @anchor MatrixExpressions
3516
+ This is a list of implemented matrix operations that can be combined in
3517
+ arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a
3518
+ scalar ( Scalar ), alpha for a real-valued scalar ( double )):
3519
+ - Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`,
3520
+ `-A`
3521
+ - Scaling: `A*alpha`
3522
+ - Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A`
3523
+ - Matrix multiplication: `A*B`
3524
+ - Transposition: `A.t()` (means A<sup>T</sup>)
3525
+ - Matrix inversion and pseudo-inversion, solving linear systems and
3526
+ least-squares problems: `A.inv([method]) (~ A<sup>-1</sup>)`, `A.inv([method])*B
3527
+ (~ X: AX=B)`
3528
+ - Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where *cmpop* is
3529
+ one of
3530
+ `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single
3531
+ channel mask whose elements are set to 255 (if the particular element or pair of
3532
+ elements satisfy the condition) or 0.
3533
+ - Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`,
3534
+ `~A`, where *logicop* is one of
3535
+ `&`, `|`, `^`.
3536
+ - Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`,
3537
+ `max(A, alpha)`
3538
+ - Element-wise absolute value: `abs(A)`
3539
+ - Cross-product, dot-product: `A.cross(B)`, `A.dot(B)`
3540
+ - Any function of matrix or matrices and scalars that returns a matrix or a
3541
+ scalar, such as norm, mean, sum, countNonZero, trace, determinant, repeat, and
3542
+ others.
3543
+ - Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix
3544
+ comma-separated initializers, matrix constructors and operators that extract
3545
+ sub-matrices (see Mat description).
3546
+ - Mat_<destination_type>() constructors to cast the result to the proper type.
3547
+ @note Comma-separated initializers and probably some other operations may
3548
+ require additional explicit Mat() or Mat_<T>() constructor calls to resolve a
3549
+ possible ambiguity.
3550
+
3551
+ Here are examples of matrix expressions:
3552
+ @code
3553
+ // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD)
3554
+ SVD svd(A);
3555
+ Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t();
3556
+
3557
+ // compute the new vector of parameters in the Levenberg-Marquardt algorithm
3558
+ x -= (A.t()*A +
3559
+ lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err);
3560
+
3561
+ // sharpen image using "unsharp mask" algorithm
3562
+ Mat blurred; double sigma = 1, threshold = 5, amount = 1;
3563
+ GaussianBlur(img, blurred, Size(), sigma, sigma);
3564
+ Mat lowContrastMask = abs(img - blurred) < threshold;
3565
+ Mat sharpened = img*(1+amount) + blurred*(-amount);
3566
+ img.copyTo(sharpened, lowContrastMask);
3567
+ @endcode
3568
+ */
3569
+ class CV_EXPORTS MatExpr {
3570
+ public:
3571
+ MatExpr();
3572
+ explicit MatExpr(const Mat &m);
3573
+
3574
+ MatExpr(const MatOp *_op, int _flags, const Mat &_a = Mat(),
3575
+ const Mat &_b = Mat(), const Mat &_c = Mat(), double _alpha = 1,
3576
+ double _beta = 1, const Scalar &_s = Scalar());
3577
+
3578
+ operator Mat() const;
3579
+ template <typename _Tp> operator Mat_<_Tp>() const;
3580
+
3581
+ Size size() const;
3582
+ int type() const;
3583
+
3584
+ MatExpr row(int y) const;
3585
+ MatExpr col(int x) const;
3586
+ MatExpr diag(int d = 0) const;
3587
+ MatExpr operator()(const Range &rowRange, const Range &colRange) const;
3588
+ MatExpr operator()(const Rect &roi) const;
3589
+
3590
+ MatExpr t() const;
3591
+ MatExpr inv(int method = DECOMP_LU) const;
3592
+ MatExpr mul(const MatExpr &e, double scale = 1) const;
3593
+ MatExpr mul(const Mat &m, double scale = 1) const;
3594
+
3595
+ Mat cross(const Mat &m) const;
3596
+ double dot(const Mat &m) const;
3597
+
3598
+ void swap(MatExpr &b);
3599
+
3600
+ const MatOp *op;
3601
+ int flags;
3602
+
3603
+ Mat a, b, c;
3604
+ double alpha, beta;
3605
+ Scalar s;
3606
+ };
3607
+
3608
+ //! @} core_basic
3609
+
3610
+ //! @relates cv::MatExpr
3611
+ //! @{
3612
+ CV_EXPORTS MatExpr operator+(const Mat &a, const Mat &b);
3613
+ CV_EXPORTS MatExpr operator+(const Mat &a, const Scalar &s);
3614
+ CV_EXPORTS MatExpr operator+(const Scalar &s, const Mat &a);
3615
+ CV_EXPORTS MatExpr operator+(const MatExpr &e, const Mat &m);
3616
+ CV_EXPORTS MatExpr operator+(const Mat &m, const MatExpr &e);
3617
+ CV_EXPORTS MatExpr operator+(const MatExpr &e, const Scalar &s);
3618
+ CV_EXPORTS MatExpr operator+(const Scalar &s, const MatExpr &e);
3619
+ CV_EXPORTS MatExpr operator+(const MatExpr &e1, const MatExpr &e2);
3620
+ template <typename _Tp, int m, int n>
3621
+ static inline MatExpr operator+(const Mat &a, const Matx<_Tp, m, n> &b) {
3622
+ return a + Mat(b);
3623
+ }
3624
+ template <typename _Tp, int m, int n>
3625
+ static inline MatExpr operator+(const Matx<_Tp, m, n> &a, const Mat &b) {
3626
+ return Mat(a) + b;
3627
+ }
3628
+
3629
+ CV_EXPORTS MatExpr operator-(const Mat &a, const Mat &b);
3630
+ CV_EXPORTS MatExpr operator-(const Mat &a, const Scalar &s);
3631
+ CV_EXPORTS MatExpr operator-(const Scalar &s, const Mat &a);
3632
+ CV_EXPORTS MatExpr operator-(const MatExpr &e, const Mat &m);
3633
+ CV_EXPORTS MatExpr operator-(const Mat &m, const MatExpr &e);
3634
+ CV_EXPORTS MatExpr operator-(const MatExpr &e, const Scalar &s);
3635
+ CV_EXPORTS MatExpr operator-(const Scalar &s, const MatExpr &e);
3636
+ CV_EXPORTS MatExpr operator-(const MatExpr &e1, const MatExpr &e2);
3637
+ template <typename _Tp, int m, int n>
3638
+ static inline MatExpr operator-(const Mat &a, const Matx<_Tp, m, n> &b) {
3639
+ return a - Mat(b);
3640
+ }
3641
+ template <typename _Tp, int m, int n>
3642
+ static inline MatExpr operator-(const Matx<_Tp, m, n> &a, const Mat &b) {
3643
+ return Mat(a) - b;
3644
+ }
3645
+
3646
+ CV_EXPORTS MatExpr operator-(const Mat &m);
3647
+ CV_EXPORTS MatExpr operator-(const MatExpr &e);
3648
+
3649
+ CV_EXPORTS MatExpr operator*(const Mat &a, const Mat &b);
3650
+ CV_EXPORTS MatExpr operator*(const Mat &a, double s);
3651
+ CV_EXPORTS MatExpr operator*(double s, const Mat &a);
3652
+ CV_EXPORTS MatExpr operator*(const MatExpr &e, const Mat &m);
3653
+ CV_EXPORTS MatExpr operator*(const Mat &m, const MatExpr &e);
3654
+ CV_EXPORTS MatExpr operator*(const MatExpr &e, double s);
3655
+ CV_EXPORTS MatExpr operator*(double s, const MatExpr &e);
3656
+ CV_EXPORTS MatExpr operator*(const MatExpr &e1, const MatExpr &e2);
3657
+ template <typename _Tp, int m, int n>
3658
+ static inline MatExpr operator*(const Mat &a, const Matx<_Tp, m, n> &b) {
3659
+ return a * Mat(b);
3660
+ }
3661
+ template <typename _Tp, int m, int n>
3662
+ static inline MatExpr operator*(const Matx<_Tp, m, n> &a, const Mat &b) {
3663
+ return Mat(a) * b;
3664
+ }
3665
+
3666
+ CV_EXPORTS MatExpr operator/(const Mat &a, const Mat &b);
3667
+ CV_EXPORTS MatExpr operator/(const Mat &a, double s);
3668
+ CV_EXPORTS MatExpr operator/(double s, const Mat &a);
3669
+ CV_EXPORTS MatExpr operator/(const MatExpr &e, const Mat &m);
3670
+ CV_EXPORTS MatExpr operator/(const Mat &m, const MatExpr &e);
3671
+ CV_EXPORTS MatExpr operator/(const MatExpr &e, double s);
3672
+ CV_EXPORTS MatExpr operator/(double s, const MatExpr &e);
3673
+ CV_EXPORTS MatExpr operator/(const MatExpr &e1, const MatExpr &e2);
3674
+ template <typename _Tp, int m, int n>
3675
+ static inline MatExpr operator/(const Mat &a, const Matx<_Tp, m, n> &b) {
3676
+ return a / Mat(b);
3677
+ }
3678
+ template <typename _Tp, int m, int n>
3679
+ static inline MatExpr operator/(const Matx<_Tp, m, n> &a, const Mat &b) {
3680
+ return Mat(a) / b;
3681
+ }
3682
+
3683
+ CV_EXPORTS MatExpr operator<(const Mat &a, const Mat &b);
3684
+ CV_EXPORTS MatExpr operator<(const Mat &a, double s);
3685
+ CV_EXPORTS MatExpr operator<(double s, const Mat &a);
3686
+ template <typename _Tp, int m, int n>
3687
+ static inline MatExpr operator<(const Mat &a, const Matx<_Tp, m, n> &b) {
3688
+ return a < Mat(b);
3689
+ }
3690
+ template <typename _Tp, int m, int n>
3691
+ static inline MatExpr operator<(const Matx<_Tp, m, n> &a, const Mat &b) {
3692
+ return Mat(a) < b;
3693
+ }
3694
+
3695
+ CV_EXPORTS MatExpr operator<=(const Mat &a, const Mat &b);
3696
+ CV_EXPORTS MatExpr operator<=(const Mat &a, double s);
3697
+ CV_EXPORTS MatExpr operator<=(double s, const Mat &a);
3698
+ template <typename _Tp, int m, int n>
3699
+ static inline MatExpr operator<=(const Mat &a, const Matx<_Tp, m, n> &b) {
3700
+ return a <= Mat(b);
3701
+ }
3702
+ template <typename _Tp, int m, int n>
3703
+ static inline MatExpr operator<=(const Matx<_Tp, m, n> &a, const Mat &b) {
3704
+ return Mat(a) <= b;
3705
+ }
3706
+
3707
+ CV_EXPORTS MatExpr operator==(const Mat &a, const Mat &b);
3708
+ CV_EXPORTS MatExpr operator==(const Mat &a, double s);
3709
+ CV_EXPORTS MatExpr operator==(double s, const Mat &a);
3710
+ template <typename _Tp, int m, int n>
3711
+ static inline MatExpr operator==(const Mat &a, const Matx<_Tp, m, n> &b) {
3712
+ return a == Mat(b);
3713
+ }
3714
+ template <typename _Tp, int m, int n>
3715
+ static inline MatExpr operator==(const Matx<_Tp, m, n> &a, const Mat &b) {
3716
+ return Mat(a) == b;
3717
+ }
3718
+
3719
+ CV_EXPORTS MatExpr operator!=(const Mat &a, const Mat &b);
3720
+ CV_EXPORTS MatExpr operator!=(const Mat &a, double s);
3721
+ CV_EXPORTS MatExpr operator!=(double s, const Mat &a);
3722
+ template <typename _Tp, int m, int n>
3723
+ static inline MatExpr operator!=(const Mat &a, const Matx<_Tp, m, n> &b) {
3724
+ return a != Mat(b);
3725
+ }
3726
+ template <typename _Tp, int m, int n>
3727
+ static inline MatExpr operator!=(const Matx<_Tp, m, n> &a, const Mat &b) {
3728
+ return Mat(a) != b;
3729
+ }
3730
+
3731
+ CV_EXPORTS MatExpr operator>=(const Mat &a, const Mat &b);
3732
+ CV_EXPORTS MatExpr operator>=(const Mat &a, double s);
3733
+ CV_EXPORTS MatExpr operator>=(double s, const Mat &a);
3734
+ template <typename _Tp, int m, int n>
3735
+ static inline MatExpr operator>=(const Mat &a, const Matx<_Tp, m, n> &b) {
3736
+ return a >= Mat(b);
3737
+ }
3738
+ template <typename _Tp, int m, int n>
3739
+ static inline MatExpr operator>=(const Matx<_Tp, m, n> &a, const Mat &b) {
3740
+ return Mat(a) >= b;
3741
+ }
3742
+
3743
+ CV_EXPORTS MatExpr operator>(const Mat &a, const Mat &b);
3744
+ CV_EXPORTS MatExpr operator>(const Mat &a, double s);
3745
+ CV_EXPORTS MatExpr operator>(double s, const Mat &a);
3746
+ template <typename _Tp, int m, int n>
3747
+ static inline MatExpr operator>(const Mat &a, const Matx<_Tp, m, n> &b) {
3748
+ return a > Mat(b);
3749
+ }
3750
+ template <typename _Tp, int m, int n>
3751
+ static inline MatExpr operator>(const Matx<_Tp, m, n> &a, const Mat &b) {
3752
+ return Mat(a) > b;
3753
+ }
3754
+
3755
+ CV_EXPORTS MatExpr operator&(const Mat &a, const Mat &b);
3756
+ CV_EXPORTS MatExpr operator&(const Mat &a, const Scalar &s);
3757
+ CV_EXPORTS MatExpr operator&(const Scalar &s, const Mat &a);
3758
+ template <typename _Tp, int m, int n>
3759
+ static inline MatExpr operator&(const Mat &a, const Matx<_Tp, m, n> &b) {
3760
+ return a & Mat(b);
3761
+ }
3762
+ template <typename _Tp, int m, int n>
3763
+ static inline MatExpr operator&(const Matx<_Tp, m, n> &a, const Mat &b) {
3764
+ return Mat(a) & b;
3765
+ }
3766
+
3767
+ CV_EXPORTS MatExpr operator|(const Mat &a, const Mat &b);
3768
+ CV_EXPORTS MatExpr operator|(const Mat &a, const Scalar &s);
3769
+ CV_EXPORTS MatExpr operator|(const Scalar &s, const Mat &a);
3770
+ template <typename _Tp, int m, int n>
3771
+ static inline MatExpr operator|(const Mat &a, const Matx<_Tp, m, n> &b) {
3772
+ return a | Mat(b);
3773
+ }
3774
+ template <typename _Tp, int m, int n>
3775
+ static inline MatExpr operator|(const Matx<_Tp, m, n> &a, const Mat &b) {
3776
+ return Mat(a) | b;
3777
+ }
3778
+
3779
+ CV_EXPORTS MatExpr operator^(const Mat &a, const Mat &b);
3780
+ CV_EXPORTS MatExpr operator^(const Mat &a, const Scalar &s);
3781
+ CV_EXPORTS MatExpr operator^(const Scalar &s, const Mat &a);
3782
+ template <typename _Tp, int m, int n>
3783
+ static inline MatExpr operator^(const Mat &a, const Matx<_Tp, m, n> &b) {
3784
+ return a ^ Mat(b);
3785
+ }
3786
+ template <typename _Tp, int m, int n>
3787
+ static inline MatExpr operator^(const Matx<_Tp, m, n> &a, const Mat &b) {
3788
+ return Mat(a) ^ b;
3789
+ }
3790
+
3791
+ CV_EXPORTS MatExpr operator~(const Mat &m);
3792
+
3793
+ CV_EXPORTS MatExpr min(const Mat &a, const Mat &b);
3794
+ CV_EXPORTS MatExpr min(const Mat &a, double s);
3795
+ CV_EXPORTS MatExpr min(double s, const Mat &a);
3796
+ template <typename _Tp, int m, int n>
3797
+ static inline MatExpr min(const Mat &a, const Matx<_Tp, m, n> &b) {
3798
+ return min(a, Mat(b));
3799
+ }
3800
+ template <typename _Tp, int m, int n>
3801
+ static inline MatExpr min(const Matx<_Tp, m, n> &a, const Mat &b) {
3802
+ return min(Mat(a), b);
3803
+ }
3804
+
3805
+ CV_EXPORTS MatExpr max(const Mat &a, const Mat &b);
3806
+ CV_EXPORTS MatExpr max(const Mat &a, double s);
3807
+ CV_EXPORTS MatExpr max(double s, const Mat &a);
3808
+ template <typename _Tp, int m, int n>
3809
+ static inline MatExpr max(const Mat &a, const Matx<_Tp, m, n> &b) {
3810
+ return max(a, Mat(b));
3811
+ }
3812
+ template <typename _Tp, int m, int n>
3813
+ static inline MatExpr max(const Matx<_Tp, m, n> &a, const Mat &b) {
3814
+ return max(Mat(a), b);
3815
+ }
3816
+
3817
+ /** @brief Calculates an absolute value of each matrix element.
3818
+
3819
+ abs is a meta-function that is expanded to one of absdiff or convertScaleAbs
3820
+ forms:
3821
+ - C = abs(A-B) is equivalent to `absdiff(A, B, C)`
3822
+ - C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)`
3823
+ - C = `Mat_<Vec<uchar,n> >(abs(A*alpha + beta))` is equivalent to
3824
+ `convertScaleAbs(A, C, alpha, beta)`
3825
+
3826
+ The output matrix has the same size and the same type as the input one except
3827
+ for the last case, where C is depth=CV_8U .
3828
+ @param m matrix.
3829
+ @sa @ref MatrixExpressions, absdiff, convertScaleAbs
3830
+ */
3831
+ CV_EXPORTS MatExpr abs(const Mat &m);
3832
+ /** @overload
3833
+ @param e matrix expression.
3834
+ */
3835
+ CV_EXPORTS MatExpr abs(const MatExpr &e);
3836
+ //! @} relates cv::MatExpr
3837
+
3838
+ } // namespace cv
3839
+
3840
+ #include "opencv2/core/mat.inl.hpp"
3841
+
3842
+ #endif // OPENCV_CORE_MAT_HPP