core.hpp 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
  15. // Copyright (C) 2015, OpenCV Foundation, all rights reserved.
  16. // Copyright (C) 2015, Itseez Inc., 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 modification,
  20. // are permitted provided that the following conditions are met:
  21. //
  22. // * Redistribution's of source code must retain the above copyright notice,
  23. // this list of conditions and the following disclaimer.
  24. //
  25. // * Redistribution's in binary form must reproduce the above copyright notice,
  26. // this list of conditions and the following disclaimer in the documentation
  27. // and/or other materials provided with the distribution.
  28. //
  29. // * The name of the copyright holders may not be used to endorse or promote products
  30. // derived from this software without specific prior written permission.
  31. //
  32. // This software is provided by the copyright holders and contributors "as is" and
  33. // any express or implied warranties, including, but not limited to, the implied
  34. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  35. // In no event shall the Intel Corporation or contributors be liable for any direct,
  36. // indirect, incidental, special, exemplary, or consequential damages
  37. // (including, but not limited to, procurement of substitute goods or services;
  38. // loss of use, data, or profits; or business interruption) however caused
  39. // and on any theory of liability, whether in contract, strict liability,
  40. // or tort (including negligence or otherwise) arising in any way out of
  41. // the use of this software, even if advised of the possibility of such damage.
  42. //
  43. //M*/
  44. #ifndef OPENCV_CORE_HPP
  45. #define OPENCV_CORE_HPP
  46. #ifndef __cplusplus
  47. # error core.hpp header must be compiled as C++
  48. #endif
  49. #include "opencv2/core/cvdef.h"
  50. #include "opencv2/core/version.hpp"
  51. #include "opencv2/core/base.hpp"
  52. #include "opencv2/core/cvstd.hpp"
  53. #include "opencv2/core/traits.hpp"
  54. #include "opencv2/core/matx.hpp"
  55. #include "opencv2/core/types.hpp"
  56. #include "opencv2/core/mat.hpp"
  57. #include "opencv2/core/persistence.hpp"
  58. /**
  59. @defgroup core Core functionality
  60. @{
  61. @defgroup core_basic Basic structures
  62. @defgroup core_c C structures and operations
  63. @{
  64. @defgroup core_c_glue Connections with C++
  65. @}
  66. @defgroup core_array Operations on arrays
  67. @defgroup core_async Asynchronous API
  68. @defgroup core_xml XML/YAML Persistence
  69. @defgroup core_cluster Clustering
  70. @defgroup core_utils Utility and system functions and macros
  71. @{
  72. @defgroup core_utils_sse SSE utilities
  73. @defgroup core_utils_neon NEON utilities
  74. @defgroup core_utils_softfloat Softfloat support
  75. @defgroup core_utils_samples Utility functions for OpenCV samples
  76. @}
  77. @defgroup core_opengl OpenGL interoperability
  78. @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters
  79. @defgroup core_optim Optimization Algorithms
  80. @defgroup core_directx DirectX interoperability
  81. @defgroup core_eigen Eigen support
  82. @defgroup core_opencl OpenCL support
  83. @defgroup core_va_intel Intel VA-API/OpenCL (CL-VA) interoperability
  84. @defgroup core_hal Hardware Acceleration Layer
  85. @{
  86. @defgroup core_hal_functions Functions
  87. @defgroup core_hal_interface Interface
  88. @defgroup core_hal_intrin Universal intrinsics
  89. @{
  90. @defgroup core_hal_intrin_impl Private implementation helpers
  91. @}
  92. @defgroup core_lowlevel_api Low-level API for external libraries / plugins
  93. @}
  94. @}
  95. */
  96. namespace cv {
  97. //! @addtogroup core_utils
  98. //! @{
  99. /*! @brief Class passed to an error.
  100. This class encapsulates all or almost all necessary
  101. information about the error happened in the program. The exception is
  102. usually constructed and thrown implicitly via CV_Error and CV_Error_ macros.
  103. @see error
  104. */
  105. class CV_EXPORTS Exception : public std::exception
  106. {
  107. public:
  108. /*!
  109. Default constructor
  110. */
  111. Exception();
  112. /*!
  113. Full constructor. Normally the constructor is not called explicitly.
  114. Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
  115. */
  116. Exception(int _code, const String& _err, const String& _func, const String& _file, int _line);
  117. virtual ~Exception() throw();
  118. /*!
  119. \return the error description and the context as a text string.
  120. */
  121. virtual const char *what() const throw() CV_OVERRIDE;
  122. void formatMessage();
  123. String msg; ///< the formatted error message
  124. int code; ///< error code @see CVStatus
  125. String err; ///< error description
  126. String func; ///< function name. Available only when the compiler supports getting it
  127. String file; ///< source file name where the error has occurred
  128. int line; ///< line number in the source file where the error has occurred
  129. };
  130. /*! @brief Signals an error and raises the exception.
  131. By default the function prints information about the error to stderr,
  132. then it either stops if cv::setBreakOnError() had been called before or raises the exception.
  133. It is possible to alternate error processing by using #redirectError().
  134. @param exc the exception raisen.
  135. @deprecated drop this version
  136. */
  137. CV_EXPORTS CV_NORETURN void error(const Exception& exc);
  138. enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently
  139. SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted
  140. //!< independently; this flag and the previous one are
  141. //!< mutually exclusive.
  142. SORT_ASCENDING = 0, //!< each matrix row is sorted in the ascending
  143. //!< order.
  144. SORT_DESCENDING = 16 //!< each matrix row is sorted in the
  145. //!< descending order; this flag and the previous one are also
  146. //!< mutually exclusive.
  147. };
  148. //! @} core_utils
  149. //! @addtogroup core
  150. //! @{
  151. //! Covariation flags
  152. enum CovarFlags {
  153. /** The output covariance matrix is calculated as:
  154. \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...],\f]
  155. The covariance matrix will be nsamples x nsamples. Such an unusual covariance matrix is used
  156. for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for
  157. face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true
  158. covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of
  159. the "scrambled" covariance matrix. */
  160. COVAR_SCRAMBLED = 0,
  161. /**The output covariance matrix is calculated as:
  162. \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...] \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T,\f]
  163. covar will be a square matrix of the same size as the total number of elements in each input
  164. vector. One and only one of #COVAR_SCRAMBLED and #COVAR_NORMAL must be specified.*/
  165. COVAR_NORMAL = 1,
  166. /** If the flag is specified, the function does not calculate mean from
  167. the input vectors but, instead, uses the passed mean vector. This is useful if mean has been
  168. pre-calculated or known in advance, or if the covariance matrix is calculated by parts. In
  169. this case, mean is not a mean vector of the input sub-set of vectors but rather the mean
  170. vector of the whole set.*/
  171. COVAR_USE_AVG = 2,
  172. /** If the flag is specified, the covariance matrix is scaled. In the
  173. "normal" mode, scale is 1./nsamples . In the "scrambled" mode, scale is the reciprocal of the
  174. total number of elements in each input vector. By default (if the flag is not specified), the
  175. covariance matrix is not scaled ( scale=1 ).*/
  176. COVAR_SCALE = 4,
  177. /** If the flag is
  178. specified, all the input vectors are stored as rows of the samples matrix. mean should be a
  179. single-row vector in this case.*/
  180. COVAR_ROWS = 8,
  181. /** If the flag is
  182. specified, all the input vectors are stored as columns of the samples matrix. mean should be a
  183. single-column vector in this case.*/
  184. COVAR_COLS = 16
  185. };
  186. //! k-Means flags
  187. enum KmeansFlags {
  188. /** Select random initial centers in each attempt.*/
  189. KMEANS_RANDOM_CENTERS = 0,
  190. /** Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].*/
  191. KMEANS_PP_CENTERS = 2,
  192. /** During the first (and possibly the only) attempt, use the
  193. user-supplied labels instead of computing them from the initial centers. For the second and
  194. further attempts, use the random or semi-random centers. Use one of KMEANS_\*_CENTERS flag
  195. to specify the exact method.*/
  196. KMEANS_USE_INITIAL_LABELS = 1
  197. };
  198. enum ReduceTypes { REDUCE_SUM = 0, //!< the output is the sum of all rows/columns of the matrix.
  199. REDUCE_AVG = 1, //!< the output is the mean vector of all rows/columns of the matrix.
  200. REDUCE_MAX = 2, //!< the output is the maximum (column/row-wise) of all rows/columns of the matrix.
  201. REDUCE_MIN = 3 //!< the output is the minimum (column/row-wise) of all rows/columns of the matrix.
  202. };
  203. /** @brief Swaps two matrices
  204. */
  205. CV_EXPORTS void swap(Mat& a, Mat& b);
  206. /** @overload */
  207. CV_EXPORTS void swap( UMat& a, UMat& b );
  208. //! @} core
  209. //! @addtogroup core_array
  210. //! @{
  211. /** @brief Computes the source location of an extrapolated pixel.
  212. The function computes and returns the coordinate of a donor pixel corresponding to the specified
  213. extrapolated pixel when using the specified extrapolation border mode. For example, if you use
  214. cv::BORDER_WRAP mode in the horizontal direction, cv::BORDER_REFLECT_101 in the vertical direction and
  215. want to compute value of the "virtual" pixel Point(-5, 100) in a floating-point image img , it
  216. looks like:
  217. @code{.cpp}
  218. float val = img.at<float>(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101),
  219. borderInterpolate(-5, img.cols, cv::BORDER_WRAP));
  220. @endcode
  221. Normally, the function is not called directly. It is used inside filtering functions and also in
  222. copyMakeBorder.
  223. @param p 0-based coordinate of the extrapolated pixel along one of the axes, likely \<0 or \>= len
  224. @param len Length of the array along the corresponding axis.
  225. @param borderType Border type, one of the #BorderTypes, except for #BORDER_TRANSPARENT and
  226. #BORDER_ISOLATED . When borderType==#BORDER_CONSTANT , the function always returns -1, regardless
  227. of p and len.
  228. @sa copyMakeBorder
  229. */
  230. CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType);
  231. /** @example samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp
  232. An example using copyMakeBorder function.
  233. Check @ref tutorial_copyMakeBorder "the corresponding tutorial" for more details
  234. */
  235. /** @brief Forms a border around an image.
  236. The function copies the source image into the middle of the destination image. The areas to the
  237. left, to the right, above and below the copied source image will be filled with extrapolated
  238. pixels. This is not what filtering functions based on it do (they extrapolate pixels on-fly), but
  239. what other more complex functions, including your own, may do to simplify image boundary handling.
  240. The function supports the mode when src is already in the middle of dst . In this case, the
  241. function does not copy src itself but simply constructs the border, for example:
  242. @code{.cpp}
  243. // let border be the same in all directions
  244. int border=2;
  245. // constructs a larger image to fit both the image and the border
  246. Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth());
  247. // select the middle part of it w/o copying data
  248. Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows));
  249. // convert image from RGB to grayscale
  250. cvtColor(rgb, gray, COLOR_RGB2GRAY);
  251. // form a border in-place
  252. copyMakeBorder(gray, gray_buf, border, border,
  253. border, border, BORDER_REPLICATE);
  254. // now do some custom filtering ...
  255. ...
  256. @endcode
  257. @note When the source image is a part (ROI) of a bigger image, the function will try to use the
  258. pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as
  259. if src was not a ROI, use borderType | #BORDER_ISOLATED.
  260. @param src Source image.
  261. @param dst Destination image of the same type as src and the size Size(src.cols+left+right,
  262. src.rows+top+bottom) .
  263. @param top the top pixels
  264. @param bottom the bottom pixels
  265. @param left the left pixels
  266. @param right Parameter specifying how many pixels in each direction from the source image rectangle
  267. to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs
  268. to be built.
  269. @param borderType Border type. See borderInterpolate for details.
  270. @param value Border value if borderType==BORDER_CONSTANT .
  271. @sa borderInterpolate
  272. */
  273. CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst,
  274. int top, int bottom, int left, int right,
  275. int borderType, const Scalar& value = Scalar() );
  276. /** @brief Calculates the per-element sum of two arrays or an array and a scalar.
  277. The function add calculates:
  278. - Sum of two arrays when both input arrays have the same size and the same number of channels:
  279. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
  280. - Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of
  281. elements as `src1.channels()`:
  282. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
  283. - Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of
  284. elements as `src2.channels()`:
  285. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
  286. where `I` is a multi-dimensional index of array elements. In case of multi-channel arrays, each
  287. channel is processed independently.
  288. The first function in the list above can be replaced with matrix expressions:
  289. @code{.cpp}
  290. dst = src1 + src2;
  291. dst += src1; // equivalent to add(dst, src1, dst);
  292. @endcode
  293. The input arrays and the output array can all have the same or different depths. For example, you
  294. can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit
  295. floating-point array. Depth of the output array is determined by the dtype parameter. In the second
  296. and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can
  297. be set to the default -1. In this case, the output array will have the same depth as the input
  298. array, be it src1, src2 or both.
  299. @note Saturation is not applied when the output array has the depth CV_32S. You may even get
  300. result of an incorrect sign in the case of overflow.
  301. @param src1 first input array or a scalar.
  302. @param src2 second input array or a scalar.
  303. @param dst output array that has the same size and number of channels as the input array(s); the
  304. depth is defined by dtype or src1/src2.
  305. @param mask optional operation mask - 8-bit single channel array, that specifies elements of the
  306. output array to be changed.
  307. @param dtype optional depth of the output array (see the discussion below).
  308. @sa subtract, addWeighted, scaleAdd, Mat::convertTo
  309. */
  310. CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
  311. InputArray mask = noArray(), int dtype = -1);
  312. /** @brief Calculates the per-element difference between two arrays or array and a scalar.
  313. The function subtract calculates:
  314. - Difference between two arrays, when both input arrays have the same size and the same number of
  315. channels:
  316. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
  317. - Difference between an array and a scalar, when src2 is constructed from Scalar or has the same
  318. number of elements as `src1.channels()`:
  319. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f]
  320. - Difference between a scalar and an array, when src1 is constructed from Scalar or has the same
  321. number of elements as `src2.channels()`:
  322. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} - \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f]
  323. - The reverse difference between a scalar and an array in the case of `SubRS`:
  324. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src2} - \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0\f]
  325. where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
  326. channel is processed independently.
  327. The first function in the list above can be replaced with matrix expressions:
  328. @code{.cpp}
  329. dst = src1 - src2;
  330. dst -= src1; // equivalent to subtract(dst, src1, dst);
  331. @endcode
  332. The input arrays and the output array can all have the same or different depths. For example, you
  333. can subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of
  334. the output array is determined by dtype parameter. In the second and third cases above, as well as
  335. in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this
  336. case the output array will have the same depth as the input array, be it src1, src2 or both.
  337. @note Saturation is not applied when the output array has the depth CV_32S. You may even get
  338. result of an incorrect sign in the case of overflow.
  339. @param src1 first input array or a scalar.
  340. @param src2 second input array or a scalar.
  341. @param dst output array of the same size and the same number of channels as the input array.
  342. @param mask optional operation mask; this is an 8-bit single channel array that specifies elements
  343. of the output array to be changed.
  344. @param dtype optional depth of the output array
  345. @sa add, addWeighted, scaleAdd, Mat::convertTo
  346. */
  347. CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst,
  348. InputArray mask = noArray(), int dtype = -1);
  349. /** @brief Calculates the per-element scaled product of two arrays.
  350. The function multiply calculates the per-element product of two arrays:
  351. \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f]
  352. There is also a @ref MatrixExpressions -friendly variant of the first function. See Mat::mul .
  353. For a not-per-element matrix product, see gemm .
  354. @note Saturation is not applied when the output array has the depth
  355. CV_32S. You may even get result of an incorrect sign in the case of
  356. overflow.
  357. @param src1 first input array.
  358. @param src2 second input array of the same size and the same type as src1.
  359. @param dst output array of the same size and type as src1.
  360. @param scale optional scale factor.
  361. @param dtype optional depth of the output array
  362. @sa add, subtract, divide, scaleAdd, addWeighted, accumulate, accumulateProduct, accumulateSquare,
  363. Mat::convertTo
  364. */
  365. CV_EXPORTS_W void multiply(InputArray src1, InputArray src2,
  366. OutputArray dst, double scale = 1, int dtype = -1);
  367. /** @brief Performs per-element division of two arrays or a scalar by an array.
  368. The function cv::divide divides one array by another:
  369. \f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f]
  370. or a scalar by an array when there is no src1 :
  371. \f[\texttt{dst(I) = saturate(scale/src2(I))}\f]
  372. Different channels of multi-channel arrays are processed independently.
  373. For integer types when src2(I) is zero, dst(I) will also be zero.
  374. @note In case of floating point data there is no special defined behavior for zero src2(I) values.
  375. Regular floating-point division is used.
  376. Expect correct IEEE-754 behaviour for floating-point data (with NaN, Inf result values).
  377. @note Saturation is not applied when the output array has the depth CV_32S. You may even get
  378. result of an incorrect sign in the case of overflow.
  379. @param src1 first input array.
  380. @param src2 second input array of the same size and type as src1.
  381. @param scale scalar factor.
  382. @param dst output array of the same size and type as src2.
  383. @param dtype optional depth of the output array; if -1, dst will have depth src2.depth(), but in
  384. case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth().
  385. @sa multiply, add, subtract
  386. */
  387. CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst,
  388. double scale = 1, int dtype = -1);
  389. /** @overload */
  390. CV_EXPORTS_W void divide(double scale, InputArray src2,
  391. OutputArray dst, int dtype = -1);
  392. /** @brief Calculates the sum of a scaled array and another array.
  393. The function scaleAdd is one of the classical primitive linear algebra operations, known as DAXPY
  394. or SAXPY in [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It calculates
  395. the sum of a scaled array and another array:
  396. \f[\texttt{dst} (I)= \texttt{scale} \cdot \texttt{src1} (I) + \texttt{src2} (I)\f]
  397. The function can also be emulated with a matrix expression, for example:
  398. @code{.cpp}
  399. Mat A(3, 3, CV_64F);
  400. ...
  401. A.row(0) = A.row(1)*2 + A.row(2);
  402. @endcode
  403. @param src1 first input array.
  404. @param alpha scale factor for the first array.
  405. @param src2 second input array of the same size and type as src1.
  406. @param dst output array of the same size and type as src1.
  407. @sa add, addWeighted, subtract, Mat::dot, Mat::convertTo
  408. */
  409. CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);
  410. /** @example samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp
  411. Check @ref tutorial_trackbar "the corresponding tutorial" for more details
  412. */
  413. /** @brief Calculates the weighted sum of two arrays.
  414. The function addWeighted calculates the weighted sum of two arrays as follows:
  415. \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f]
  416. where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
  417. channel is processed independently.
  418. The function can be replaced with a matrix expression:
  419. @code{.cpp}
  420. dst = src1*alpha + src2*beta + gamma;
  421. @endcode
  422. @note Saturation is not applied when the output array has the depth CV_32S. You may even get
  423. result of an incorrect sign in the case of overflow.
  424. @param src1 first input array.
  425. @param alpha weight of the first array elements.
  426. @param src2 second input array of the same size and channel number as src1.
  427. @param beta weight of the second array elements.
  428. @param gamma scalar added to each sum.
  429. @param dst output array that has the same size and number of channels as the input arrays.
  430. @param dtype optional depth of the output array; when both input arrays have the same depth, dtype
  431. can be set to -1, which will be equivalent to src1.depth().
  432. @sa add, subtract, scaleAdd, Mat::convertTo
  433. */
  434. CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
  435. double beta, double gamma, OutputArray dst, int dtype = -1);
  436. /** @brief Scales, calculates absolute values, and converts the result to 8-bit.
  437. On each element of the input array, the function convertScaleAbs
  438. performs three operations sequentially: scaling, taking an absolute
  439. value, conversion to an unsigned 8-bit type:
  440. \f[\texttt{dst} (I)= \texttt{saturate\_cast<uchar>} (| \texttt{src} (I)* \texttt{alpha} + \texttt{beta} |)\f]
  441. In case of multi-channel arrays, the function processes each channel
  442. independently. When the output is not 8-bit, the operation can be
  443. emulated by calling the Mat::convertTo method (or by using matrix
  444. expressions) and then by calculating an absolute value of the result.
  445. For example:
  446. @code{.cpp}
  447. Mat_<float> A(30,30);
  448. randu(A, Scalar(-100), Scalar(100));
  449. Mat_<float> B = A*5 + 3;
  450. B = abs(B);
  451. // Mat_<float> B = abs(A*5+3) will also do the job,
  452. // but it will allocate a temporary matrix
  453. @endcode
  454. @param src input array.
  455. @param dst output array.
  456. @param alpha optional scale factor.
  457. @param beta optional delta added to the scaled values.
  458. @sa Mat::convertTo, cv::abs(const Mat&)
  459. */
  460. CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst,
  461. double alpha = 1, double beta = 0);
  462. /** @brief Converts an array to half precision floating number.
  463. This function converts FP32 (single precision floating point) from/to FP16 (half precision floating point). CV_16S format is used to represent FP16 data.
  464. There are two use modes (src -> dst): CV_32F -> CV_16S and CV_16S -> CV_32F. The input array has to have type of CV_32F or
  465. CV_16S to represent the bit depth. If the input array is neither of them, the function will raise an error.
  466. The format of half precision floating point is defined in IEEE 754-2008.
  467. @param src input array.
  468. @param dst output array.
  469. */
  470. CV_EXPORTS_W void convertFp16(InputArray src, OutputArray dst);
  471. /** @brief Performs a look-up table transform of an array.
  472. The function LUT fills the output array with values from the look-up table. Indices of the entries
  473. are taken from the input array. That is, the function processes each element of src as follows:
  474. \f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}\f]
  475. where
  476. \f[d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}\f]
  477. @param src input array of 8-bit elements.
  478. @param lut look-up table of 256 elements; in case of multi-channel input array, the table should
  479. either have a single channel (in this case the same table is used for all channels) or the same
  480. number of channels as in the input array.
  481. @param dst output array of the same size and number of channels as src, and the same depth as lut.
  482. @sa convertScaleAbs, Mat::convertTo
  483. */
  484. CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst);
  485. /** @brief Calculates the sum of array elements.
  486. The function cv::sum calculates and returns the sum of array elements,
  487. independently for each channel.
  488. @param src input array that must have from 1 to 4 channels.
  489. @sa countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce
  490. */
  491. CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src);
  492. /** @brief Counts non-zero array elements.
  493. The function returns the number of non-zero elements in src :
  494. \f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f]
  495. @param src single-channel array.
  496. @sa mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix
  497. */
  498. CV_EXPORTS_W int countNonZero( InputArray src );
  499. /** @brief Returns the list of locations of non-zero pixels
  500. Given a binary matrix (likely returned from an operation such
  501. as threshold(), compare(), >, ==, etc, return all of
  502. the non-zero indices as a cv::Mat or std::vector<cv::Point> (x,y)
  503. For example:
  504. @code{.cpp}
  505. cv::Mat binaryImage; // input, binary image
  506. cv::Mat locations; // output, locations of non-zero pixels
  507. cv::findNonZero(binaryImage, locations);
  508. // access pixel coordinates
  509. Point pnt = locations.at<Point>(i);
  510. @endcode
  511. or
  512. @code{.cpp}
  513. cv::Mat binaryImage; // input, binary image
  514. vector<Point> locations; // output, locations of non-zero pixels
  515. cv::findNonZero(binaryImage, locations);
  516. // access pixel coordinates
  517. Point pnt = locations[i];
  518. @endcode
  519. @param src single-channel array
  520. @param idx the output array, type of cv::Mat or std::vector<Point>, corresponding to non-zero indices in the input
  521. */
  522. CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx );
  523. /** @brief Calculates an average (mean) of array elements.
  524. The function cv::mean calculates the mean value M of array elements,
  525. independently for each channel, and return it:
  526. \f[\begin{array}{l} N = \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c = \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f]
  527. When all the mask elements are 0's, the function returns Scalar::all(0)
  528. @param src input array that should have from 1 to 4 channels so that the result can be stored in
  529. Scalar_ .
  530. @param mask optional operation mask.
  531. @sa countNonZero, meanStdDev, norm, minMaxLoc
  532. */
  533. CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray());
  534. /** Calculates a mean and standard deviation of array elements.
  535. The function cv::meanStdDev calculates the mean and the standard deviation M
  536. of array elements independently for each channel and returns it via the
  537. output parameters:
  538. \f[\begin{array}{l} N = \sum _{I, \texttt{mask} (I) \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N}} \end{array}\f]
  539. When all the mask elements are 0's, the function returns
  540. mean=stddev=Scalar::all(0).
  541. @note The calculated standard deviation is only the diagonal of the
  542. complete normalized covariance matrix. If the full matrix is needed, you
  543. can reshape the multi-channel array M x N to the single-channel array
  544. M\*N x mtx.channels() (only possible when the matrix is continuous) and
  545. then pass the matrix to calcCovarMatrix .
  546. @param src input array that should have from 1 to 4 channels so that the results can be stored in
  547. Scalar_ 's.
  548. @param mean output parameter: calculated mean value.
  549. @param stddev output parameter: calculated standard deviation.
  550. @param mask optional operation mask.
  551. @sa countNonZero, mean, norm, minMaxLoc, calcCovarMatrix
  552. */
  553. CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
  554. InputArray mask=noArray());
  555. /** @brief Calculates the absolute norm of an array.
  556. This version of #norm calculates the absolute norm of src1. The type of norm to calculate is specified using #NormTypes.
  557. As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
  558. The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
  559. is calculated as follows
  560. \f{align*}
  561. \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
  562. \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
  563. \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
  564. \f}
  565. and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
  566. \f{align*}
  567. \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
  568. \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
  569. \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
  570. \f}
  571. The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$.
  572. It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$.
  573. ![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
  574. When the mask parameter is specified and it is not empty, the norm is
  575. If normType is not specified, #NORM_L2 is used.
  576. calculated only over the region specified by the mask.
  577. Multi-channel input arrays are treated as single-channel arrays, that is,
  578. the results for all channels are combined.
  579. Hamming norms can only be calculated with CV_8U depth arrays.
  580. @param src1 first input array.
  581. @param normType type of the norm (see #NormTypes).
  582. @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
  583. */
  584. CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
  585. /** @brief Calculates an absolute difference norm or a relative difference norm.
  586. This version of cv::norm calculates the absolute difference norm
  587. or the relative difference norm of arrays src1 and src2.
  588. The type of norm to calculate is specified using #NormTypes.
  589. @param src1 first input array.
  590. @param src2 second input array of the same size and the same type as src1.
  591. @param normType type of the norm (see #NormTypes).
  592. @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
  593. */
  594. CV_EXPORTS_W double norm(InputArray src1, InputArray src2,
  595. int normType = NORM_L2, InputArray mask = noArray());
  596. /** @overload
  597. @param src first input array.
  598. @param normType type of the norm (see #NormTypes).
  599. */
  600. CV_EXPORTS double norm( const SparseMat& src, int normType );
  601. /** @brief Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric.
  602. This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB),
  603. between two input arrays src1 and src2. The arrays must have the same type.
  604. The PSNR is calculated as follows:
  605. \f[
  606. \texttt{PSNR} = 10 \cdot \log_{10}{\left( \frac{R^2}{MSE} \right) }
  607. \f]
  608. where R is the maximum integer value of depth (e.g. 255 in the case of CV_8U data)
  609. and MSE is the mean squared error between the two arrays.
  610. @param src1 first input array.
  611. @param src2 second input array of the same size as src1.
  612. @param R the maximum pixel value (255 by default)
  613. */
  614. CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2, double R=255.);
  615. /** @brief naive nearest neighbor finder
  616. see http://en.wikipedia.org/wiki/Nearest_neighbor_search
  617. @todo document
  618. */
  619. CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2,
  620. OutputArray dist, int dtype, OutputArray nidx,
  621. int normType = NORM_L2, int K = 0,
  622. InputArray mask = noArray(), int update = 0,
  623. bool crosscheck = false);
  624. /** @brief Normalizes the norm or value range of an array.
  625. The function cv::normalize normalizes scale and shift the input array elements so that
  626. \f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]
  627. (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
  628. \f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f]
  629. when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be
  630. normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this
  631. sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or
  632. min-max but modify the whole array, you can use norm and Mat::convertTo.
  633. In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this,
  634. the range transformation for sparse matrices is not allowed since it can shift the zero level.
  635. Possible usage with some positive example data:
  636. @code{.cpp}
  637. vector<double> positiveData = { 2.0, 8.0, 10.0 };
  638. vector<double> normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;
  639. // Norm to probability (total count)
  640. // sum(numbers) = 20.0
  641. // 2.0 0.1 (2.0/20.0)
  642. // 8.0 0.4 (8.0/20.0)
  643. // 10.0 0.5 (10.0/20.0)
  644. normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);
  645. // Norm to unit vector: ||positiveData|| = 1.0
  646. // 2.0 0.15
  647. // 8.0 0.62
  648. // 10.0 0.77
  649. normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);
  650. // Norm to max element
  651. // 2.0 0.2 (2.0/10.0)
  652. // 8.0 0.8 (8.0/10.0)
  653. // 10.0 1.0 (10.0/10.0)
  654. normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);
  655. // Norm to range [0.0;1.0]
  656. // 2.0 0.0 (shift to left border)
  657. // 8.0 0.75 (6.0/8.0)
  658. // 10.0 1.0 (shift to right border)
  659. normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);
  660. @endcode
  661. @param src input array.
  662. @param dst output array of the same size as src .
  663. @param alpha norm value to normalize to or the lower range boundary in case of the range
  664. normalization.
  665. @param beta upper range boundary in case of the range normalization; it is not used for the norm
  666. normalization.
  667. @param norm_type normalization type (see cv::NormTypes).
  668. @param dtype when negative, the output array has the same type as src; otherwise, it has the same
  669. number of channels as src and the depth =CV_MAT_DEPTH(dtype).
  670. @param mask optional operation mask.
  671. @sa norm, Mat::convertTo, SparseMat::convertTo
  672. */
  673. CV_EXPORTS_W void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0,
  674. int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray());
  675. /** @overload
  676. @param src input array.
  677. @param dst output array of the same size as src .
  678. @param alpha norm value to normalize to or the lower range boundary in case of the range
  679. normalization.
  680. @param normType normalization type (see cv::NormTypes).
  681. */
  682. CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType );
  683. /** @brief Finds the global minimum and maximum in an array.
  684. The function cv::minMaxLoc finds the minimum and maximum element values and their positions. The
  685. extremums are searched across the whole array or, if mask is not an empty array, in the specified
  686. array region.
  687. The function do not work with multi-channel arrays. If you need to find minimum or maximum
  688. elements across all the channels, use Mat::reshape first to reinterpret the array as
  689. single-channel. Or you may extract the particular channel using either extractImageCOI , or
  690. mixChannels , or split .
  691. @param src input single-channel array.
  692. @param minVal pointer to the returned minimum value; NULL is used if not required.
  693. @param maxVal pointer to the returned maximum value; NULL is used if not required.
  694. @param minLoc pointer to the returned minimum location (in 2D case); NULL is used if not required.
  695. @param maxLoc pointer to the returned maximum location (in 2D case); NULL is used if not required.
  696. @param mask optional mask used to select a sub-array.
  697. @sa max, min, compare, inRange, extractImageCOI, mixChannels, split, Mat::reshape
  698. */
  699. CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,
  700. CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0,
  701. CV_OUT Point* maxLoc = 0, InputArray mask = noArray());
  702. /** @brief Finds the global minimum and maximum in an array
  703. The function cv::minMaxIdx finds the minimum and maximum element values and their positions. The
  704. extremums are searched across the whole array or, if mask is not an empty array, in the specified
  705. array region. The function does not work with multi-channel arrays. If you need to find minimum or
  706. maximum elements across all the channels, use Mat::reshape first to reinterpret the array as
  707. single-channel. Or you may extract the particular channel using either extractImageCOI , or
  708. mixChannels , or split . In case of a sparse matrix, the minimum is found among non-zero elements
  709. only.
  710. @note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is
  711. a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2
  712. dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be
  713. (i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be
  714. (0,j1)/(0,j2)).
  715. @param src input single-channel array.
  716. @param minVal pointer to the returned minimum value; NULL is used if not required.
  717. @param maxVal pointer to the returned maximum value; NULL is used if not required.
  718. @param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
  719. Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
  720. in each dimension are stored there sequentially.
  721. @param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
  722. @param mask specified array region
  723. */
  724. CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0,
  725. int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray());
  726. /** @overload
  727. @param a input single-channel array.
  728. @param minVal pointer to the returned minimum value; NULL is used if not required.
  729. @param maxVal pointer to the returned maximum value; NULL is used if not required.
  730. @param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required;
  731. Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element
  732. in each dimension are stored there sequentially.
  733. @param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required.
  734. */
  735. CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal,
  736. double* maxVal, int* minIdx = 0, int* maxIdx = 0);
  737. /** @brief Reduces a matrix to a vector.
  738. The function #reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
  739. 1D vectors and performing the specified operation on the vectors until a single row/column is
  740. obtained. For example, the function can be used to compute horizontal and vertical projections of a
  741. raster image. In case of #REDUCE_MAX and #REDUCE_MIN , the output image should have the same type as the source one.
  742. In case of #REDUCE_SUM and #REDUCE_AVG , the output may have a larger element bit-depth to preserve accuracy.
  743. And multi-channel arrays are also supported in these two reduction modes.
  744. The following code demonstrates its usage for a single channel matrix.
  745. @snippet snippets/core_reduce.cpp example
  746. And the following code demonstrates its usage for a two-channel matrix.
  747. @snippet snippets/core_reduce.cpp example2
  748. @param src input 2D matrix.
  749. @param dst output vector. Its size and type is defined by dim and dtype parameters.
  750. @param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to
  751. a single row. 1 means that the matrix is reduced to a single column.
  752. @param rtype reduction operation that could be one of #ReduceTypes
  753. @param dtype when negative, the output vector will have the same type as the input matrix,
  754. otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()).
  755. @sa repeat
  756. */
  757. CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1);
  758. /** @brief Creates one multi-channel array out of several single-channel ones.
  759. The function cv::merge merges several arrays to make a single multi-channel array. That is, each
  760. element of the output array will be a concatenation of the elements of the input arrays, where
  761. elements of i-th input array are treated as mv[i].channels()-element vectors.
  762. The function cv::split does the reverse operation. If you need to shuffle channels in some other
  763. advanced way, use cv::mixChannels.
  764. The following example shows how to merge 3 single channel matrices into a single 3-channel matrix.
  765. @snippet snippets/core_merge.cpp example
  766. @param mv input array of matrices to be merged; all the matrices in mv must have the same
  767. size and the same depth.
  768. @param count number of input matrices when mv is a plain C array; it must be greater than zero.
  769. @param dst output array of the same size and the same depth as mv[0]; The number of channels will
  770. be equal to the parameter count.
  771. @sa mixChannels, split, Mat::reshape
  772. */
  773. CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
  774. /** @overload
  775. @param mv input vector of matrices to be merged; all the matrices in mv must have the same
  776. size and the same depth.
  777. @param dst output array of the same size and the same depth as mv[0]; The number of channels will
  778. be the total number of channels in the matrix array.
  779. */
  780. CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst);
  781. /** @brief Divides a multi-channel array into several single-channel arrays.
  782. The function cv::split splits a multi-channel array into separate single-channel arrays:
  783. \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f]
  784. If you need to extract a single channel or do some other sophisticated channel permutation, use
  785. mixChannels .
  786. The following example demonstrates how to split a 3-channel matrix into 3 single channel matrices.
  787. @snippet snippets/core_split.cpp example
  788. @param src input multi-channel array.
  789. @param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are
  790. reallocated, if needed.
  791. @sa merge, mixChannels, cvtColor
  792. */
  793. CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
  794. /** @overload
  795. @param m input multi-channel array.
  796. @param mv output vector of arrays; the arrays themselves are reallocated, if needed.
  797. */
  798. CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv);
  799. /** @brief Copies specified channels from input arrays to the specified channels of
  800. output arrays.
  801. The function cv::mixChannels provides an advanced mechanism for shuffling image channels.
  802. cv::split,cv::merge,cv::extractChannel,cv::insertChannel and some forms of cv::cvtColor are partial cases of cv::mixChannels.
  803. In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R
  804. channels swapped) and a separate alpha-channel image:
  805. @code{.cpp}
  806. Mat bgra( 100, 100, CV_8UC4, Scalar(255,0,0,255) );
  807. Mat bgr( bgra.rows, bgra.cols, CV_8UC3 );
  808. Mat alpha( bgra.rows, bgra.cols, CV_8UC1 );
  809. // forming an array of matrices is a quite efficient operation,
  810. // because the matrix data is not copied, only the headers
  811. Mat out[] = { bgr, alpha };
  812. // bgra[0] -> bgr[2], bgra[1] -> bgr[1],
  813. // bgra[2] -> bgr[0], bgra[3] -> alpha[0]
  814. int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
  815. mixChannels( &bgra, 1, out, 2, from_to, 4 );
  816. @endcode
  817. @note Unlike many other new-style C++ functions in OpenCV (see the introduction section and
  818. Mat::create ), cv::mixChannels requires the output arrays to be pre-allocated before calling the
  819. function.
  820. @param src input array or vector of matrices; all of the matrices must have the same size and the
  821. same depth.
  822. @param nsrcs number of matrices in `src`.
  823. @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
  824. depth must be the same as in `src[0]`.
  825. @param ndsts number of matrices in `dst`.
  826. @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
  827. a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
  828. dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
  829. src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
  830. src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
  831. channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
  832. filled with zero .
  833. @param npairs number of index pairs in `fromTo`.
  834. @sa split, merge, extractChannel, insertChannel, cvtColor
  835. */
  836. CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
  837. const int* fromTo, size_t npairs);
  838. /** @overload
  839. @param src input array or vector of matrices; all of the matrices must have the same size and the
  840. same depth.
  841. @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
  842. depth must be the same as in src[0].
  843. @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
  844. a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
  845. dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
  846. src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
  847. src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
  848. channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
  849. filled with zero .
  850. @param npairs number of index pairs in fromTo.
  851. */
  852. CV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
  853. const int* fromTo, size_t npairs);
  854. /** @overload
  855. @param src input array or vector of matrices; all of the matrices must have the same size and the
  856. same depth.
  857. @param dst output array or vector of matrices; all the matrices **must be allocated**; their size and
  858. depth must be the same as in src[0].
  859. @param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is
  860. a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in
  861. dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to
  862. src[0].channels()-1, the second input image channels are indexed from src[0].channels() to
  863. src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image
  864. channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is
  865. filled with zero .
  866. */
  867. CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
  868. const std::vector<int>& fromTo);
  869. /** @brief Extracts a single channel from src (coi is 0-based index)
  870. @param src input array
  871. @param dst output array
  872. @param coi index of channel to extract
  873. @sa mixChannels, split
  874. */
  875. CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
  876. /** @brief Inserts a single channel to dst (coi is 0-based index)
  877. @param src input array
  878. @param dst output array
  879. @param coi index of channel for insertion
  880. @sa mixChannels, merge
  881. */
  882. CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
  883. /** @brief Flips a 2D array around vertical, horizontal, or both axes.
  884. The function cv::flip flips the array in one of three different ways (row
  885. and column indices are 0-based):
  886. \f[\texttt{dst} _{ij} =
  887. \left\{
  888. \begin{array}{l l}
  889. \texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\
  890. \texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\
  891. \texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
  892. \end{array}
  893. \right.\f]
  894. The example scenarios of using the function are the following:
  895. * Vertical flipping of the image (flipCode == 0) to switch between
  896. top-left and bottom-left image origin. This is a typical operation
  897. in video processing on Microsoft Windows\* OS.
  898. * Horizontal flipping of the image with the subsequent horizontal
  899. shift and absolute difference calculation to check for a
  900. vertical-axis symmetry (flipCode \> 0).
  901. * Simultaneous horizontal and vertical flipping of the image with
  902. the subsequent shift and absolute difference calculation to check
  903. for a central symmetry (flipCode \< 0).
  904. * Reversing the order of point arrays (flipCode \> 0 or
  905. flipCode == 0).
  906. @param src input array.
  907. @param dst output array of the same size and type as src.
  908. @param flipCode a flag to specify how to flip the array; 0 means
  909. flipping around the x-axis and positive value (for example, 1) means
  910. flipping around y-axis. Negative value (for example, -1) means flipping
  911. around both axes.
  912. @sa transpose , repeat , completeSymm
  913. */
  914. CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);
  915. enum RotateFlags {
  916. ROTATE_90_CLOCKWISE = 0, //!<Rotate 90 degrees clockwise
  917. ROTATE_180 = 1, //!<Rotate 180 degrees clockwise
  918. ROTATE_90_COUNTERCLOCKWISE = 2, //!<Rotate 270 degrees clockwise
  919. };
  920. /** @brief Rotates a 2D array in multiples of 90 degrees.
  921. The function cv::rotate rotates the array in one of three different ways:
  922. * Rotate by 90 degrees clockwise (rotateCode = ROTATE_90_CLOCKWISE).
  923. * Rotate by 180 degrees clockwise (rotateCode = ROTATE_180).
  924. * Rotate by 270 degrees clockwise (rotateCode = ROTATE_90_COUNTERCLOCKWISE).
  925. @param src input array.
  926. @param dst output array of the same type as src. The size is the same with ROTATE_180,
  927. and the rows and cols are switched for ROTATE_90_CLOCKWISE and ROTATE_90_COUNTERCLOCKWISE.
  928. @param rotateCode an enum to specify how to rotate the array; see the enum #RotateFlags
  929. @sa transpose , repeat , completeSymm, flip, RotateFlags
  930. */
  931. CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode);
  932. /** @brief Fills the output array with repeated copies of the input array.
  933. The function cv::repeat duplicates the input array one or more times along each of the two axes:
  934. \f[\texttt{dst} _{ij}= \texttt{src} _{i\mod src.rows, \; j\mod src.cols }\f]
  935. The second variant of the function is more convenient to use with @ref MatrixExpressions.
  936. @param src input array to replicate.
  937. @param ny Flag to specify how many times the `src` is repeated along the
  938. vertical axis.
  939. @param nx Flag to specify how many times the `src` is repeated along the
  940. horizontal axis.
  941. @param dst output array of the same type as `src`.
  942. @sa cv::reduce
  943. */
  944. CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst);
  945. /** @overload
  946. @param src input array to replicate.
  947. @param ny Flag to specify how many times the `src` is repeated along the
  948. vertical axis.
  949. @param nx Flag to specify how many times the `src` is repeated along the
  950. horizontal axis.
  951. */
  952. CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx);
  953. /** @brief Applies horizontal concatenation to given matrices.
  954. The function horizontally concatenates two or more cv::Mat matrices (with the same number of rows).
  955. @code{.cpp}
  956. cv::Mat matArray[] = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
  957. cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
  958. cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
  959. cv::Mat out;
  960. cv::hconcat( matArray, 3, out );
  961. //out:
  962. //[1, 2, 3;
  963. // 1, 2, 3;
  964. // 1, 2, 3;
  965. // 1, 2, 3]
  966. @endcode
  967. @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
  968. @param nsrc number of matrices in src.
  969. @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
  970. @sa cv::vconcat(const Mat*, size_t, OutputArray), @sa cv::vconcat(InputArrayOfArrays, OutputArray) and @sa cv::vconcat(InputArray, InputArray, OutputArray)
  971. */
  972. CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
  973. /** @overload
  974. @code{.cpp}
  975. cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 4,
  976. 2, 5,
  977. 3, 6);
  978. cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 7, 10,
  979. 8, 11,
  980. 9, 12);
  981. cv::Mat C;
  982. cv::hconcat(A, B, C);
  983. //C:
  984. //[1, 4, 7, 10;
  985. // 2, 5, 8, 11;
  986. // 3, 6, 9, 12]
  987. @endcode
  988. @param src1 first input array to be considered for horizontal concatenation.
  989. @param src2 second input array to be considered for horizontal concatenation.
  990. @param dst output array. It has the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2.
  991. */
  992. CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);
  993. /** @overload
  994. @code{.cpp}
  995. std::vector<cv::Mat> matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
  996. cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
  997. cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
  998. cv::Mat out;
  999. cv::hconcat( matrices, out );
  1000. //out:
  1001. //[1, 2, 3;
  1002. // 1, 2, 3;
  1003. // 1, 2, 3;
  1004. // 1, 2, 3]
  1005. @endcode
  1006. @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
  1007. @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
  1008. same depth.
  1009. */
  1010. CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);
  1011. /** @brief Applies vertical concatenation to given matrices.
  1012. The function vertically concatenates two or more cv::Mat matrices (with the same number of cols).
  1013. @code{.cpp}
  1014. cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
  1015. cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
  1016. cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
  1017. cv::Mat out;
  1018. cv::vconcat( matArray, 3, out );
  1019. //out:
  1020. //[1, 1, 1, 1;
  1021. // 2, 2, 2, 2;
  1022. // 3, 3, 3, 3]
  1023. @endcode
  1024. @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth.
  1025. @param nsrc number of matrices in src.
  1026. @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
  1027. @sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray)
  1028. */
  1029. CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
  1030. /** @overload
  1031. @code{.cpp}
  1032. cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 7,
  1033. 2, 8,
  1034. 3, 9);
  1035. cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 4, 10,
  1036. 5, 11,
  1037. 6, 12);
  1038. cv::Mat C;
  1039. cv::vconcat(A, B, C);
  1040. //C:
  1041. //[1, 7;
  1042. // 2, 8;
  1043. // 3, 9;
  1044. // 4, 10;
  1045. // 5, 11;
  1046. // 6, 12]
  1047. @endcode
  1048. @param src1 first input array to be considered for vertical concatenation.
  1049. @param src2 second input array to be considered for vertical concatenation.
  1050. @param dst output array. It has the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2.
  1051. */
  1052. CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);
  1053. /** @overload
  1054. @code{.cpp}
  1055. std::vector<cv::Mat> matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
  1056. cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
  1057. cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
  1058. cv::Mat out;
  1059. cv::vconcat( matrices, out );
  1060. //out:
  1061. //[1, 1, 1, 1;
  1062. // 2, 2, 2, 2;
  1063. // 3, 3, 3, 3]
  1064. @endcode
  1065. @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth
  1066. @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
  1067. same depth.
  1068. */
  1069. CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);
  1070. /** @brief computes bitwise conjunction of the two arrays (dst = src1 & src2)
  1071. Calculates the per-element bit-wise conjunction of two arrays or an
  1072. array and a scalar.
  1073. The function cv::bitwise_and calculates the per-element bit-wise logical conjunction for:
  1074. * Two arrays when src1 and src2 have the same size:
  1075. \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1076. * An array and a scalar when src2 is constructed from Scalar or has
  1077. the same number of elements as `src1.channels()`:
  1078. \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
  1079. * A scalar and an array when src1 is constructed from Scalar or has
  1080. the same number of elements as `src2.channels()`:
  1081. \f[\texttt{dst} (I) = \texttt{src1} \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1082. In case of floating-point arrays, their machine-specific bit
  1083. representations (usually IEEE754-compliant) are used for the operation.
  1084. In case of multi-channel arrays, each channel is processed
  1085. independently. In the second and third cases above, the scalar is first
  1086. converted to the array type.
  1087. @param src1 first input array or a scalar.
  1088. @param src2 second input array or a scalar.
  1089. @param dst output array that has the same size and type as the input
  1090. arrays.
  1091. @param mask optional operation mask, 8-bit single channel array, that
  1092. specifies elements of the output array to be changed.
  1093. */
  1094. CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2,
  1095. OutputArray dst, InputArray mask = noArray());
  1096. /** @brief Calculates the per-element bit-wise disjunction of two arrays or an
  1097. array and a scalar.
  1098. The function cv::bitwise_or calculates the per-element bit-wise logical disjunction for:
  1099. * Two arrays when src1 and src2 have the same size:
  1100. \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1101. * An array and a scalar when src2 is constructed from Scalar or has
  1102. the same number of elements as `src1.channels()`:
  1103. \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
  1104. * A scalar and an array when src1 is constructed from Scalar or has
  1105. the same number of elements as `src2.channels()`:
  1106. \f[\texttt{dst} (I) = \texttt{src1} \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1107. In case of floating-point arrays, their machine-specific bit
  1108. representations (usually IEEE754-compliant) are used for the operation.
  1109. In case of multi-channel arrays, each channel is processed
  1110. independently. In the second and third cases above, the scalar is first
  1111. converted to the array type.
  1112. @param src1 first input array or a scalar.
  1113. @param src2 second input array or a scalar.
  1114. @param dst output array that has the same size and type as the input
  1115. arrays.
  1116. @param mask optional operation mask, 8-bit single channel array, that
  1117. specifies elements of the output array to be changed.
  1118. */
  1119. CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2,
  1120. OutputArray dst, InputArray mask = noArray());
  1121. /** @brief Calculates the per-element bit-wise "exclusive or" operation on two
  1122. arrays or an array and a scalar.
  1123. The function cv::bitwise_xor calculates the per-element bit-wise logical "exclusive-or"
  1124. operation for:
  1125. * Two arrays when src1 and src2 have the same size:
  1126. \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1127. * An array and a scalar when src2 is constructed from Scalar or has
  1128. the same number of elements as `src1.channels()`:
  1129. \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0\f]
  1130. * A scalar and an array when src1 is constructed from Scalar or has
  1131. the same number of elements as `src2.channels()`:
  1132. \f[\texttt{dst} (I) = \texttt{src1} \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
  1133. In case of floating-point arrays, their machine-specific bit
  1134. representations (usually IEEE754-compliant) are used for the operation.
  1135. In case of multi-channel arrays, each channel is processed
  1136. independently. In the 2nd and 3rd cases above, the scalar is first
  1137. converted to the array type.
  1138. @param src1 first input array or a scalar.
  1139. @param src2 second input array or a scalar.
  1140. @param dst output array that has the same size and type as the input
  1141. arrays.
  1142. @param mask optional operation mask, 8-bit single channel array, that
  1143. specifies elements of the output array to be changed.
  1144. */
  1145. CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2,
  1146. OutputArray dst, InputArray mask = noArray());
  1147. /** @brief Inverts every bit of an array.
  1148. The function cv::bitwise_not calculates per-element bit-wise inversion of the input
  1149. array:
  1150. \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f]
  1151. In case of a floating-point input array, its machine-specific bit
  1152. representation (usually IEEE754-compliant) is used for the operation. In
  1153. case of multi-channel arrays, each channel is processed independently.
  1154. @param src input array.
  1155. @param dst output array that has the same size and type as the input
  1156. array.
  1157. @param mask optional operation mask, 8-bit single channel array, that
  1158. specifies elements of the output array to be changed.
  1159. */
  1160. CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst,
  1161. InputArray mask = noArray());
  1162. /** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar.
  1163. The function cv::absdiff calculates:
  1164. * Absolute difference between two arrays when they have the same
  1165. size and type:
  1166. \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f]
  1167. * Absolute difference between an array and a scalar when the second
  1168. array is constructed from Scalar or has as many elements as the
  1169. number of channels in `src1`:
  1170. \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2} |)\f]
  1171. * Absolute difference between a scalar and an array when the first
  1172. array is constructed from Scalar or has as many elements as the
  1173. number of channels in `src2`:
  1174. \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1} - \texttt{src2}(I) |)\f]
  1175. where I is a multi-dimensional index of array elements. In case of
  1176. multi-channel arrays, each channel is processed independently.
  1177. @note Saturation is not applied when the arrays have the depth CV_32S.
  1178. You may even get a negative value in the case of overflow.
  1179. @param src1 first input array or a scalar.
  1180. @param src2 second input array or a scalar.
  1181. @param dst output array that has the same size and type as input arrays.
  1182. @sa cv::abs(const Mat&)
  1183. */
  1184. CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst);
  1185. /** @brief This is an overloaded member function, provided for convenience (python)
  1186. Copies the matrix to another one.
  1187. When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data.
  1188. @param src source matrix.
  1189. @param dst Destination matrix. If it does not have a proper size or type before the operation, it is
  1190. reallocated.
  1191. @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix
  1192. elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.
  1193. */
  1194. void CV_EXPORTS_W copyTo(InputArray src, OutputArray dst, InputArray mask);
  1195. /** @brief Checks if array elements lie between the elements of two other arrays.
  1196. The function checks the range as follows:
  1197. - For every element of a single-channel input array:
  1198. \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0\f]
  1199. - For two-channel arrays:
  1200. \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0 \land \texttt{lowerb} (I)_1 \leq \texttt{src} (I)_1 \leq \texttt{upperb} (I)_1\f]
  1201. - and so forth.
  1202. That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the
  1203. specified 1D, 2D, 3D, ... box and 0 otherwise.
  1204. When the lower and/or upper boundary parameters are scalars, the indexes
  1205. (I) at lowerb and upperb in the above formulas should be omitted.
  1206. @param src first input array.
  1207. @param lowerb inclusive lower boundary array or a scalar.
  1208. @param upperb inclusive upper boundary array or a scalar.
  1209. @param dst output array of the same size as src and CV_8U type.
  1210. */
  1211. CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb,
  1212. InputArray upperb, OutputArray dst);
  1213. /** @brief Performs the per-element comparison of two arrays or an array and scalar value.
  1214. The function compares:
  1215. * Elements of two arrays when src1 and src2 have the same size:
  1216. \f[\texttt{dst} (I) = \texttt{src1} (I) \,\texttt{cmpop}\, \texttt{src2} (I)\f]
  1217. * Elements of src1 with a scalar src2 when src2 is constructed from
  1218. Scalar or has a single element:
  1219. \f[\texttt{dst} (I) = \texttt{src1}(I) \,\texttt{cmpop}\, \texttt{src2}\f]
  1220. * src1 with elements of src2 when src1 is constructed from Scalar or
  1221. has a single element:
  1222. \f[\texttt{dst} (I) = \texttt{src1} \,\texttt{cmpop}\, \texttt{src2} (I)\f]
  1223. When the comparison result is true, the corresponding element of output
  1224. array is set to 255. The comparison operations can be replaced with the
  1225. equivalent matrix expressions:
  1226. @code{.cpp}
  1227. Mat dst1 = src1 >= src2;
  1228. Mat dst2 = src1 < 8;
  1229. ...
  1230. @endcode
  1231. @param src1 first input array or a scalar; when it is an array, it must have a single channel.
  1232. @param src2 second input array or a scalar; when it is an array, it must have a single channel.
  1233. @param dst output array of type ref CV_8U that has the same size and the same number of channels as
  1234. the input arrays.
  1235. @param cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes)
  1236. @sa checkRange, min, max, threshold
  1237. */
  1238. CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop);
  1239. /** @brief Calculates per-element minimum of two arrays or an array and a scalar.
  1240. The function cv::min calculates the per-element minimum of two arrays:
  1241. \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f]
  1242. or array and a scalar:
  1243. \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f]
  1244. @param src1 first input array.
  1245. @param src2 second input array of the same size and type as src1.
  1246. @param dst output array of the same size and type as src1.
  1247. @sa max, compare, inRange, minMaxLoc
  1248. */
  1249. CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst);
  1250. /** @overload
  1251. needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
  1252. */
  1253. CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst);
  1254. /** @overload
  1255. needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
  1256. */
  1257. CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst);
  1258. /** @brief Calculates per-element maximum of two arrays or an array and a scalar.
  1259. The function cv::max calculates the per-element maximum of two arrays:
  1260. \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f]
  1261. or array and a scalar:
  1262. \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f]
  1263. @param src1 first input array.
  1264. @param src2 second input array of the same size and type as src1 .
  1265. @param dst output array of the same size and type as src1.
  1266. @sa min, compare, inRange, minMaxLoc, @ref MatrixExpressions
  1267. */
  1268. CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst);
  1269. /** @overload
  1270. needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
  1271. */
  1272. CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst);
  1273. /** @overload
  1274. needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
  1275. */
  1276. CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst);
  1277. /** @brief Calculates a square root of array elements.
  1278. The function cv::sqrt calculates a square root of each input array element.
  1279. In case of multi-channel arrays, each channel is processed
  1280. independently. The accuracy is approximately the same as of the built-in
  1281. std::sqrt .
  1282. @param src input floating-point array.
  1283. @param dst output array of the same size and type as src.
  1284. */
  1285. CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst);
  1286. /** @brief Raises every array element to a power.
  1287. The function cv::pow raises every element of the input array to power :
  1288. \f[\texttt{dst} (I) = \fork{\texttt{src}(I)^{power}}{if \(\texttt{power}\) is integer}{|\texttt{src}(I)|^{power}}{otherwise}\f]
  1289. So, for a non-integer power exponent, the absolute values of input array
  1290. elements are used. However, it is possible to get true values for
  1291. negative values using some extra operations. In the example below,
  1292. computing the 5th root of array src shows:
  1293. @code{.cpp}
  1294. Mat mask = src < 0;
  1295. pow(src, 1./5, dst);
  1296. subtract(Scalar::all(0), dst, dst, mask);
  1297. @endcode
  1298. For some values of power, such as integer values, 0.5 and -0.5,
  1299. specialized faster algorithms are used.
  1300. Special values (NaN, Inf) are not handled.
  1301. @param src input array.
  1302. @param power exponent of power.
  1303. @param dst output array of the same size and type as src.
  1304. @sa sqrt, exp, log, cartToPolar, polarToCart
  1305. */
  1306. CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst);
  1307. /** @brief Calculates the exponent of every array element.
  1308. The function cv::exp calculates the exponent of every element of the input
  1309. array:
  1310. \f[\texttt{dst} [I] = e^{ src(I) }\f]
  1311. The maximum relative error is about 7e-6 for single-precision input and
  1312. less than 1e-10 for double-precision input. Currently, the function
  1313. converts denormalized values to zeros on output. Special values (NaN,
  1314. Inf) are not handled.
  1315. @param src input array.
  1316. @param dst output array of the same size and type as src.
  1317. @sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude
  1318. */
  1319. CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
  1320. /** @brief Calculates the natural logarithm of every array element.
  1321. The function cv::log calculates the natural logarithm of every element of the input array:
  1322. \f[\texttt{dst} (I) = \log (\texttt{src}(I)) \f]
  1323. Output on zero, negative and special (NaN, Inf) values is undefined.
  1324. @param src input array.
  1325. @param dst output array of the same size and type as src .
  1326. @sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude
  1327. */
  1328. CV_EXPORTS_W void log(InputArray src, OutputArray dst);
  1329. /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle.
  1330. The function cv::polarToCart calculates the Cartesian coordinates of each 2D
  1331. vector represented by the corresponding elements of magnitude and angle:
  1332. \f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f]
  1333. The relative accuracy of the estimated coordinates is about 1e-6.
  1334. @param magnitude input floating-point array of magnitudes of 2D vectors;
  1335. it can be an empty matrix (=Mat()), in this case, the function assumes
  1336. that all the magnitudes are =1; if it is not empty, it must have the
  1337. same size and type as angle.
  1338. @param angle input floating-point array of angles of 2D vectors.
  1339. @param x output array of x-coordinates of 2D vectors; it has the same
  1340. size and type as angle.
  1341. @param y output array of y-coordinates of 2D vectors; it has the same
  1342. size and type as angle.
  1343. @param angleInDegrees when true, the input angles are measured in
  1344. degrees, otherwise, they are measured in radians.
  1345. @sa cartToPolar, magnitude, phase, exp, log, pow, sqrt
  1346. */
  1347. CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle,
  1348. OutputArray x, OutputArray y, bool angleInDegrees = false);
  1349. /** @brief Calculates the magnitude and angle of 2D vectors.
  1350. The function cv::cartToPolar calculates either the magnitude, angle, or both
  1351. for every 2D vector (x(I),y(I)):
  1352. \f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f]
  1353. The angles are calculated with accuracy about 0.3 degrees. For the point
  1354. (0,0), the angle is set to 0.
  1355. @param x array of x-coordinates; this must be a single-precision or
  1356. double-precision floating-point array.
  1357. @param y array of y-coordinates, that must have the same size and same type as x.
  1358. @param magnitude output array of magnitudes of the same size and type as x.
  1359. @param angle output array of angles that has the same size and type as
  1360. x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees).
  1361. @param angleInDegrees a flag, indicating whether the angles are measured
  1362. in radians (which is by default), or in degrees.
  1363. @sa Sobel, Scharr
  1364. */
  1365. CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y,
  1366. OutputArray magnitude, OutputArray angle,
  1367. bool angleInDegrees = false);
  1368. /** @brief Calculates the rotation angle of 2D vectors.
  1369. The function cv::phase calculates the rotation angle of each 2D vector that
  1370. is formed from the corresponding elements of x and y :
  1371. \f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
  1372. The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
  1373. the corresponding angle(I) is set to 0.
  1374. @param x input floating-point array of x-coordinates of 2D vectors.
  1375. @param y input array of y-coordinates of 2D vectors; it must have the
  1376. same size and the same type as x.
  1377. @param angle output array of vector angles; it has the same size and
  1378. same type as x .
  1379. @param angleInDegrees when true, the function calculates the angle in
  1380. degrees, otherwise, they are measured in radians.
  1381. */
  1382. CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle,
  1383. bool angleInDegrees = false);
  1384. /** @brief Calculates the magnitude of 2D vectors.
  1385. The function cv::magnitude calculates the magnitude of 2D vectors formed
  1386. from the corresponding elements of x and y arrays:
  1387. \f[\texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f]
  1388. @param x floating-point array of x-coordinates of the vectors.
  1389. @param y floating-point array of y-coordinates of the vectors; it must
  1390. have the same size as x.
  1391. @param magnitude output array of the same size and type as x.
  1392. @sa cartToPolar, polarToCart, phase, sqrt
  1393. */
  1394. CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
  1395. /** @brief Checks every element of an input array for invalid values.
  1396. The function cv::checkRange checks that every array element is neither NaN nor infinite. When minVal \>
  1397. -DBL_MAX and maxVal \< DBL_MAX, the function also checks that each value is between minVal and
  1398. maxVal. In case of multi-channel arrays, each channel is processed independently. If some values
  1399. are out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the
  1400. function either returns false (when quiet=true) or throws an exception.
  1401. @param a input array.
  1402. @param quiet a flag, indicating whether the functions quietly return false when the array elements
  1403. are out of range or they throw an exception.
  1404. @param pos optional output parameter, when not NULL, must be a pointer to array of src.dims
  1405. elements.
  1406. @param minVal inclusive lower boundary of valid values range.
  1407. @param maxVal exclusive upper boundary of valid values range.
  1408. */
  1409. CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0,
  1410. double minVal = -DBL_MAX, double maxVal = DBL_MAX);
  1411. /** @brief converts NaN's to the given number
  1412. */
  1413. CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0);
  1414. /** @brief Performs generalized matrix multiplication.
  1415. The function cv::gemm performs generalized matrix multiplication similar to the
  1416. gemm functions in BLAS level 3. For example,
  1417. `gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`
  1418. corresponds to
  1419. \f[\texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T\f]
  1420. In case of complex (two-channel) data, performed a complex matrix
  1421. multiplication.
  1422. The function can be replaced with a matrix expression. For example, the
  1423. above call can be replaced with:
  1424. @code{.cpp}
  1425. dst = alpha*src1.t()*src2 + beta*src3.t();
  1426. @endcode
  1427. @param src1 first multiplied input matrix that could be real(CV_32FC1,
  1428. CV_64FC1) or complex(CV_32FC2, CV_64FC2).
  1429. @param src2 second multiplied input matrix of the same type as src1.
  1430. @param alpha weight of the matrix product.
  1431. @param src3 third optional delta matrix added to the matrix product; it
  1432. should have the same type as src1 and src2.
  1433. @param beta weight of src3.
  1434. @param dst output matrix; it has the proper size and the same type as
  1435. input matrices.
  1436. @param flags operation flags (cv::GemmFlags)
  1437. @sa mulTransposed , transform
  1438. */
  1439. CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
  1440. InputArray src3, double beta, OutputArray dst, int flags = 0);
  1441. /** @brief Calculates the product of a matrix and its transposition.
  1442. The function cv::mulTransposed calculates the product of src and its
  1443. transposition:
  1444. \f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f]
  1445. if aTa=true , and
  1446. \f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} ) ( \texttt{src} - \texttt{delta} )^T\f]
  1447. otherwise. The function is used to calculate the covariance matrix. With
  1448. zero delta, it can be used as a faster substitute for general matrix
  1449. product A\*B when B=A'
  1450. @param src input single-channel matrix. Note that unlike gemm, the
  1451. function can multiply not only floating-point matrices.
  1452. @param dst output square matrix.
  1453. @param aTa Flag specifying the multiplication ordering. See the
  1454. description below.
  1455. @param delta Optional delta matrix subtracted from src before the
  1456. multiplication. When the matrix is empty ( delta=noArray() ), it is
  1457. assumed to be zero, that is, nothing is subtracted. If it has the same
  1458. size as src , it is simply subtracted. Otherwise, it is "repeated" (see
  1459. repeat ) to cover the full src and then subtracted. Type of the delta
  1460. matrix, when it is not empty, must be the same as the type of created
  1461. output matrix. See the dtype parameter description below.
  1462. @param scale Optional scale factor for the matrix product.
  1463. @param dtype Optional type of the output matrix. When it is negative,
  1464. the output matrix will have the same type as src . Otherwise, it will be
  1465. type=CV_MAT_DEPTH(dtype) that should be either CV_32F or CV_64F .
  1466. @sa calcCovarMatrix, gemm, repeat, reduce
  1467. */
  1468. CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa,
  1469. InputArray delta = noArray(),
  1470. double scale = 1, int dtype = -1 );
  1471. /** @brief Transposes a matrix.
  1472. The function cv::transpose transposes the matrix src :
  1473. \f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f]
  1474. @note No complex conjugation is done in case of a complex matrix. It
  1475. should be done separately if needed.
  1476. @param src input array.
  1477. @param dst output array of the same type as src.
  1478. */
  1479. CV_EXPORTS_W void transpose(InputArray src, OutputArray dst);
  1480. /** @brief Performs the matrix transformation of every array element.
  1481. The function cv::transform performs the matrix transformation of every
  1482. element of the array src and stores the results in dst :
  1483. \f[\texttt{dst} (I) = \texttt{m} \cdot \texttt{src} (I)\f]
  1484. (when m.cols=src.channels() ), or
  1485. \f[\texttt{dst} (I) = \texttt{m} \cdot [ \texttt{src} (I); 1]\f]
  1486. (when m.cols=src.channels()+1 )
  1487. Every element of the N -channel array src is interpreted as N -element
  1488. vector that is transformed using the M x N or M x (N+1) matrix m to
  1489. M-element vector - the corresponding element of the output array dst .
  1490. The function may be used for geometrical transformation of
  1491. N -dimensional points, arbitrary linear color space transformation (such
  1492. as various kinds of RGB to YUV transforms), shuffling the image
  1493. channels, and so forth.
  1494. @param src input array that must have as many channels (1 to 4) as
  1495. m.cols or m.cols-1.
  1496. @param dst output array of the same size and depth as src; it has as
  1497. many channels as m.rows.
  1498. @param m transformation 2x2 or 2x3 floating-point matrix.
  1499. @sa perspectiveTransform, getAffineTransform, estimateAffine2D, warpAffine, warpPerspective
  1500. */
  1501. CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m );
  1502. /** @brief Performs the perspective matrix transformation of vectors.
  1503. The function cv::perspectiveTransform transforms every element of src by
  1504. treating it as a 2D or 3D vector, in the following way:
  1505. \f[(x, y, z) \rightarrow (x'/w, y'/w, z'/w)\f]
  1506. where
  1507. \f[(x', y', z', w') = \texttt{mat} \cdot \begin{bmatrix} x & y & z & 1 \end{bmatrix}\f]
  1508. and
  1509. \f[w = \fork{w'}{if \(w' \ne 0\)}{\infty}{otherwise}\f]
  1510. Here a 3D vector transformation is shown. In case of a 2D vector
  1511. transformation, the z component is omitted.
  1512. @note The function transforms a sparse set of 2D or 3D vectors. If you
  1513. want to transform an image using perspective transformation, use
  1514. warpPerspective . If you have an inverse problem, that is, you want to
  1515. compute the most probable perspective transformation out of several
  1516. pairs of corresponding points, you can use getPerspectiveTransform or
  1517. findHomography .
  1518. @param src input two-channel or three-channel floating-point array; each
  1519. element is a 2D/3D vector to be transformed.
  1520. @param dst output array of the same size and type as src.
  1521. @param m 3x3 or 4x4 floating-point transformation matrix.
  1522. @sa transform, warpPerspective, getPerspectiveTransform, findHomography
  1523. */
  1524. CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m );
  1525. /** @brief Copies the lower or the upper half of a square matrix to its another half.
  1526. The function cv::completeSymm copies the lower or the upper half of a square matrix to
  1527. its another half. The matrix diagonal remains unchanged:
  1528. - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i > j\f$ if
  1529. lowerToUpper=false
  1530. - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i < j\f$ if
  1531. lowerToUpper=true
  1532. @param m input-output floating-point square matrix.
  1533. @param lowerToUpper operation flag; if true, the lower half is copied to
  1534. the upper half. Otherwise, the upper half is copied to the lower half.
  1535. @sa flip, transpose
  1536. */
  1537. CV_EXPORTS_W void completeSymm(InputOutputArray m, bool lowerToUpper = false);
  1538. /** @brief Initializes a scaled identity matrix.
  1539. The function cv::setIdentity initializes a scaled identity matrix:
  1540. \f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f]
  1541. The function can also be emulated using the matrix initializers and the
  1542. matrix expressions:
  1543. @code
  1544. Mat A = Mat::eye(4, 3, CV_32F)*5;
  1545. // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]]
  1546. @endcode
  1547. @param mtx matrix to initialize (not necessarily square).
  1548. @param s value to assign to diagonal elements.
  1549. @sa Mat::zeros, Mat::ones, Mat::setTo, Mat::operator=
  1550. */
  1551. CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1));
  1552. /** @brief Returns the determinant of a square floating-point matrix.
  1553. The function cv::determinant calculates and returns the determinant of the
  1554. specified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the
  1555. direct method is used. For larger matrices, the function uses LU
  1556. factorization with partial pivoting.
  1557. For symmetric positively-determined matrices, it is also possible to use
  1558. eigen decomposition to calculate the determinant.
  1559. @param mtx input matrix that must have CV_32FC1 or CV_64FC1 type and
  1560. square size.
  1561. @sa trace, invert, solve, eigen, @ref MatrixExpressions
  1562. */
  1563. CV_EXPORTS_W double determinant(InputArray mtx);
  1564. /** @brief Returns the trace of a matrix.
  1565. The function cv::trace returns the sum of the diagonal elements of the
  1566. matrix mtx .
  1567. \f[\mathrm{tr} ( \texttt{mtx} ) = \sum _i \texttt{mtx} (i,i)\f]
  1568. @param mtx input matrix.
  1569. */
  1570. CV_EXPORTS_W Scalar trace(InputArray mtx);
  1571. /** @brief Finds the inverse or pseudo-inverse of a matrix.
  1572. The function cv::invert inverts the matrix src and stores the result in dst
  1573. . When the matrix src is singular or non-square, the function calculates
  1574. the pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is
  1575. minimal, where I is an identity matrix.
  1576. In case of the #DECOMP_LU method, the function returns non-zero value if
  1577. the inverse has been successfully calculated and 0 if src is singular.
  1578. In case of the #DECOMP_SVD method, the function returns the inverse
  1579. condition number of src (the ratio of the smallest singular value to the
  1580. largest singular value) and 0 if src is singular. The SVD method
  1581. calculates a pseudo-inverse matrix if src is singular.
  1582. Similarly to #DECOMP_LU, the method #DECOMP_CHOLESKY works only with
  1583. non-singular square matrices that should also be symmetrical and
  1584. positively defined. In this case, the function stores the inverted
  1585. matrix in dst and returns non-zero. Otherwise, it returns 0.
  1586. @param src input floating-point M x N matrix.
  1587. @param dst output matrix of N x M size and the same type as src.
  1588. @param flags inversion method (cv::DecompTypes)
  1589. @sa solve, SVD
  1590. */
  1591. CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU);
  1592. /** @brief Solves one or more linear systems or least-squares problems.
  1593. The function cv::solve solves a linear system or least-squares problem (the
  1594. latter is possible with SVD or QR methods, or by specifying the flag
  1595. #DECOMP_NORMAL ):
  1596. \f[\texttt{dst} = \arg \min _X \| \texttt{src1} \cdot \texttt{X} - \texttt{src2} \|\f]
  1597. If #DECOMP_LU or #DECOMP_CHOLESKY method is used, the function returns 1
  1598. if src1 (or \f$\texttt{src1}^T\texttt{src1}\f$ ) is non-singular. Otherwise,
  1599. it returns 0. In the latter case, dst is not valid. Other methods find a
  1600. pseudo-solution in case of a singular left-hand side part.
  1601. @note If you want to find a unity-norm solution of an under-defined
  1602. singular system \f$\texttt{src1}\cdot\texttt{dst}=0\f$ , the function solve
  1603. will not do the work. Use SVD::solveZ instead.
  1604. @param src1 input matrix on the left-hand side of the system.
  1605. @param src2 input matrix on the right-hand side of the system.
  1606. @param dst output solution.
  1607. @param flags solution (matrix inversion) method (#DecompTypes)
  1608. @sa invert, SVD, eigen
  1609. */
  1610. CV_EXPORTS_W bool solve(InputArray src1, InputArray src2,
  1611. OutputArray dst, int flags = DECOMP_LU);
  1612. /** @brief Sorts each row or each column of a matrix.
  1613. The function cv::sort sorts each matrix row or each matrix column in
  1614. ascending or descending order. So you should pass two operation flags to
  1615. get desired behaviour. If you want to sort matrix rows or columns
  1616. lexicographically, you can use STL std::sort generic function with the
  1617. proper comparison predicate.
  1618. @param src input single-channel array.
  1619. @param dst output array of the same size and type as src.
  1620. @param flags operation flags, a combination of #SortFlags
  1621. @sa sortIdx, randShuffle
  1622. */
  1623. CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags);
  1624. /** @brief Sorts each row or each column of a matrix.
  1625. The function cv::sortIdx sorts each matrix row or each matrix column in the
  1626. ascending or descending order. So you should pass two operation flags to
  1627. get desired behaviour. Instead of reordering the elements themselves, it
  1628. stores the indices of sorted elements in the output array. For example:
  1629. @code
  1630. Mat A = Mat::eye(3,3,CV_32F), B;
  1631. sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING);
  1632. // B will probably contain
  1633. // (because of equal elements in A some permutations are possible):
  1634. // [[1, 2, 0], [0, 2, 1], [0, 1, 2]]
  1635. @endcode
  1636. @param src input single-channel array.
  1637. @param dst output integer array of the same size as src.
  1638. @param flags operation flags that could be a combination of cv::SortFlags
  1639. @sa sort, randShuffle
  1640. */
  1641. CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags);
  1642. /** @brief Finds the real roots of a cubic equation.
  1643. The function solveCubic finds the real roots of a cubic equation:
  1644. - if coeffs is a 4-element vector:
  1645. \f[\texttt{coeffs} [0] x^3 + \texttt{coeffs} [1] x^2 + \texttt{coeffs} [2] x + \texttt{coeffs} [3] = 0\f]
  1646. - if coeffs is a 3-element vector:
  1647. \f[x^3 + \texttt{coeffs} [0] x^2 + \texttt{coeffs} [1] x + \texttt{coeffs} [2] = 0\f]
  1648. The roots are stored in the roots array.
  1649. @param coeffs equation coefficients, an array of 3 or 4 elements.
  1650. @param roots output array of real roots that has 1 or 3 elements.
  1651. @return number of real roots. It can be 0, 1 or 2.
  1652. */
  1653. CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots);
  1654. /** @brief Finds the real or complex roots of a polynomial equation.
  1655. The function cv::solvePoly finds real and complex roots of a polynomial equation:
  1656. \f[\texttt{coeffs} [n] x^{n} + \texttt{coeffs} [n-1] x^{n-1} + ... + \texttt{coeffs} [1] x + \texttt{coeffs} [0] = 0\f]
  1657. @param coeffs array of polynomial coefficients.
  1658. @param roots output (complex) array of roots.
  1659. @param maxIters maximum number of iterations the algorithm does.
  1660. */
  1661. CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300);
  1662. /** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix.
  1663. The function cv::eigen calculates just eigenvalues, or eigenvalues and eigenvectors of the symmetric
  1664. matrix src:
  1665. @code
  1666. src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t()
  1667. @endcode
  1668. @note Use cv::eigenNonSymmetric for calculation of real eigenvalues and eigenvectors of non-symmetric matrix.
  1669. @param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical
  1670. (src ^T^ == src).
  1671. @param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored
  1672. in the descending order.
  1673. @param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the
  1674. eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding
  1675. eigenvalues.
  1676. @sa eigenNonSymmetric, completeSymm , PCA
  1677. */
  1678. CV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues,
  1679. OutputArray eigenvectors = noArray());
  1680. /** @brief Calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only).
  1681. @note Assumes real eigenvalues.
  1682. The function calculates eigenvalues and eigenvectors (optional) of the square matrix src:
  1683. @code
  1684. src*eigenvectors.row(i).t() = eigenvalues.at<srcType>(i)*eigenvectors.row(i).t()
  1685. @endcode
  1686. @param src input matrix (CV_32FC1 or CV_64FC1 type).
  1687. @param eigenvalues output vector of eigenvalues (type is the same type as src).
  1688. @param eigenvectors output matrix of eigenvectors (type is the same type as src). The eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues.
  1689. @sa eigen
  1690. */
  1691. CV_EXPORTS_W void eigenNonSymmetric(InputArray src, OutputArray eigenvalues,
  1692. OutputArray eigenvectors);
  1693. /** @brief Calculates the covariance matrix of a set of vectors.
  1694. The function cv::calcCovarMatrix calculates the covariance matrix and, optionally, the mean vector of
  1695. the set of input vectors.
  1696. @param samples samples stored as separate matrices
  1697. @param nsamples number of samples
  1698. @param covar output covariance matrix of the type ctype and square size.
  1699. @param mean input or output (depending on the flags) array as the average value of the input vectors.
  1700. @param flags operation flags as a combination of #CovarFlags
  1701. @param ctype type of the matrixl; it equals 'CV_64F' by default.
  1702. @sa PCA, mulTransposed, Mahalanobis
  1703. @todo InputArrayOfArrays
  1704. */
  1705. CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
  1706. int flags, int ctype = CV_64F);
  1707. /** @overload
  1708. @note use #COVAR_ROWS or #COVAR_COLS flag
  1709. @param samples samples stored as rows/columns of a single matrix.
  1710. @param covar output covariance matrix of the type ctype and square size.
  1711. @param mean input or output (depending on the flags) array as the average value of the input vectors.
  1712. @param flags operation flags as a combination of #CovarFlags
  1713. @param ctype type of the matrixl; it equals 'CV_64F' by default.
  1714. */
  1715. CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
  1716. InputOutputArray mean, int flags, int ctype = CV_64F);
  1717. /** wrap PCA::operator() */
  1718. CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
  1719. OutputArray eigenvectors, int maxComponents = 0);
  1720. /** wrap PCA::operator() and add eigenvalues output parameter */
  1721. CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean,
  1722. OutputArray eigenvectors, OutputArray eigenvalues,
  1723. int maxComponents = 0);
  1724. /** wrap PCA::operator() */
  1725. CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
  1726. OutputArray eigenvectors, double retainedVariance);
  1727. /** wrap PCA::operator() and add eigenvalues output parameter */
  1728. CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean,
  1729. OutputArray eigenvectors, OutputArray eigenvalues,
  1730. double retainedVariance);
  1731. /** wrap PCA::project */
  1732. CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
  1733. InputArray eigenvectors, OutputArray result);
  1734. /** wrap PCA::backProject */
  1735. CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
  1736. InputArray eigenvectors, OutputArray result);
  1737. /** wrap SVD::compute */
  1738. CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 );
  1739. /** wrap SVD::backSubst */
  1740. CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
  1741. InputArray rhs, OutputArray dst );
  1742. /** @brief Calculates the Mahalanobis distance between two vectors.
  1743. The function cv::Mahalanobis calculates and returns the weighted distance between two vectors:
  1744. \f[d( \texttt{vec1} , \texttt{vec2} )= \sqrt{\sum_{i,j}{\texttt{icovar(i,j)}\cdot(\texttt{vec1}(I)-\texttt{vec2}(I))\cdot(\texttt{vec1(j)}-\texttt{vec2(j)})} }\f]
  1745. The covariance matrix may be calculated using the #calcCovarMatrix function and then inverted using
  1746. the invert function (preferably using the #DECOMP_SVD method, as the most accurate).
  1747. @param v1 first 1D input vector.
  1748. @param v2 second 1D input vector.
  1749. @param icovar inverse covariance matrix.
  1750. */
  1751. CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
  1752. /** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.
  1753. The function cv::dft performs one of the following:
  1754. - Forward the Fourier transform of a 1D vector of N elements:
  1755. \f[Y = F^{(N)} \cdot X,\f]
  1756. where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$
  1757. - Inverse the Fourier transform of a 1D vector of N elements:
  1758. \f[\begin{array}{l} X'= \left (F^{(N)} \right )^{-1} \cdot Y = \left (F^{(N)} \right )^* \cdot y \\ X = (1/N) \cdot X, \end{array}\f]
  1759. where \f$F^*=\left(\textrm{Re}(F^{(N)})-\textrm{Im}(F^{(N)})\right)^T\f$
  1760. - Forward the 2D Fourier transform of a M x N matrix:
  1761. \f[Y = F^{(M)} \cdot X \cdot F^{(N)}\f]
  1762. - Inverse the 2D Fourier transform of a M x N matrix:
  1763. \f[\begin{array}{l} X'= \left (F^{(M)} \right )^* \cdot Y \cdot \left (F^{(N)} \right )^* \\ X = \frac{1}{M \cdot N} \cdot X' \end{array}\f]
  1764. In case of real (single-channel) data, the output spectrum of the forward Fourier transform or input
  1765. spectrum of the inverse Fourier transform can be represented in a packed format called *CCS*
  1766. (complex-conjugate-symmetrical). It was borrowed from IPL (Intel\* Image Processing Library). Here
  1767. is how 2D *CCS* spectrum looks:
  1768. \f[\begin{bmatrix} Re Y_{0,0} & Re Y_{0,1} & Im Y_{0,1} & Re Y_{0,2} & Im Y_{0,2} & \cdots & Re Y_{0,N/2-1} & Im Y_{0,N/2-1} & Re Y_{0,N/2} \\ Re Y_{1,0} & Re Y_{1,1} & Im Y_{1,1} & Re Y_{1,2} & Im Y_{1,2} & \cdots & Re Y_{1,N/2-1} & Im Y_{1,N/2-1} & Re Y_{1,N/2} \\ Im Y_{1,0} & Re Y_{2,1} & Im Y_{2,1} & Re Y_{2,2} & Im Y_{2,2} & \cdots & Re Y_{2,N/2-1} & Im Y_{2,N/2-1} & Im Y_{1,N/2} \\ \hdotsfor{9} \\ Re Y_{M/2-1,0} & Re Y_{M-3,1} & Im Y_{M-3,1} & \hdotsfor{3} & Re Y_{M-3,N/2-1} & Im Y_{M-3,N/2-1}& Re Y_{M/2-1,N/2} \\ Im Y_{M/2-1,0} & Re Y_{M-2,1} & Im Y_{M-2,1} & \hdotsfor{3} & Re Y_{M-2,N/2-1} & Im Y_{M-2,N/2-1}& Im Y_{M/2-1,N/2} \\ Re Y_{M/2,0} & Re Y_{M-1,1} & Im Y_{M-1,1} & \hdotsfor{3} & Re Y_{M-1,N/2-1} & Im Y_{M-1,N/2-1}& Re Y_{M/2,N/2} \end{bmatrix}\f]
  1769. In case of 1D transform of a real vector, the output looks like the first row of the matrix above.
  1770. So, the function chooses an operation mode depending on the flags and size of the input array:
  1771. - If #DFT_ROWS is set or the input array has a single row or single column, the function
  1772. performs a 1D forward or inverse transform of each row of a matrix when #DFT_ROWS is set.
  1773. Otherwise, it performs a 2D transform.
  1774. - If the input array is real and #DFT_INVERSE is not set, the function performs a forward 1D or
  1775. 2D transform:
  1776. - When #DFT_COMPLEX_OUTPUT is set, the output is a complex matrix of the same size as
  1777. input.
  1778. - When #DFT_COMPLEX_OUTPUT is not set, the output is a real matrix of the same size as
  1779. input. In case of 2D transform, it uses the packed format as shown above. In case of a
  1780. single 1D transform, it looks like the first row of the matrix above. In case of
  1781. multiple 1D transforms (when using the #DFT_ROWS flag), each row of the output matrix
  1782. looks like the first row of the matrix above.
  1783. - If the input array is complex and either #DFT_INVERSE or #DFT_REAL_OUTPUT are not set, the
  1784. output is a complex array of the same size as input. The function performs a forward or
  1785. inverse 1D or 2D transform of the whole input array or each row of the input array
  1786. independently, depending on the flags DFT_INVERSE and DFT_ROWS.
  1787. - When #DFT_INVERSE is set and the input array is real, or it is complex but #DFT_REAL_OUTPUT
  1788. is set, the output is a real array of the same size as input. The function performs a 1D or 2D
  1789. inverse transformation of the whole input array or each individual row, depending on the flags
  1790. #DFT_INVERSE and #DFT_ROWS.
  1791. If #DFT_SCALE is set, the scaling is done after the transformation.
  1792. Unlike dct , the function supports arrays of arbitrary size. But only those arrays are processed
  1793. efficiently, whose sizes can be factorized in a product of small prime numbers (2, 3, and 5 in the
  1794. current implementation). Such an efficient DFT size can be calculated using the getOptimalDFTSize
  1795. method.
  1796. The sample below illustrates how to calculate a DFT-based convolution of two 2D real arrays:
  1797. @code
  1798. void convolveDFT(InputArray A, InputArray B, OutputArray C)
  1799. {
  1800. // reallocate the output array if needed
  1801. C.create(abs(A.rows - B.rows)+1, abs(A.cols - B.cols)+1, A.type());
  1802. Size dftSize;
  1803. // calculate the size of DFT transform
  1804. dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1);
  1805. dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1);
  1806. // allocate temporary buffers and initialize them with 0's
  1807. Mat tempA(dftSize, A.type(), Scalar::all(0));
  1808. Mat tempB(dftSize, B.type(), Scalar::all(0));
  1809. // copy A and B to the top-left corners of tempA and tempB, respectively
  1810. Mat roiA(tempA, Rect(0,0,A.cols,A.rows));
  1811. A.copyTo(roiA);
  1812. Mat roiB(tempB, Rect(0,0,B.cols,B.rows));
  1813. B.copyTo(roiB);
  1814. // now transform the padded A & B in-place;
  1815. // use "nonzeroRows" hint for faster processing
  1816. dft(tempA, tempA, 0, A.rows);
  1817. dft(tempB, tempB, 0, B.rows);
  1818. // multiply the spectrums;
  1819. // the function handles packed spectrum representations well
  1820. mulSpectrums(tempA, tempB, tempA);
  1821. // transform the product back from the frequency domain.
  1822. // Even though all the result rows will be non-zero,
  1823. // you need only the first C.rows of them, and thus you
  1824. // pass nonzeroRows == C.rows
  1825. dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows);
  1826. // now copy the result back to C.
  1827. tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C);
  1828. // all the temporary buffers will be deallocated automatically
  1829. }
  1830. @endcode
  1831. To optimize this sample, consider the following approaches:
  1832. - Since nonzeroRows != 0 is passed to the forward transform calls and since A and B are copied to
  1833. the top-left corners of tempA and tempB, respectively, it is not necessary to clear the whole
  1834. tempA and tempB. It is only necessary to clear the tempA.cols - A.cols ( tempB.cols - B.cols)
  1835. rightmost columns of the matrices.
  1836. - This DFT-based convolution does not have to be applied to the whole big arrays, especially if B
  1837. is significantly smaller than A or vice versa. Instead, you can calculate convolution by parts.
  1838. To do this, you need to split the output array C into multiple tiles. For each tile, estimate
  1839. which parts of A and B are required to calculate convolution in this tile. If the tiles in C are
  1840. too small, the speed will decrease a lot because of repeated work. In the ultimate case, when
  1841. each tile in C is a single pixel, the algorithm becomes equivalent to the naive convolution
  1842. algorithm. If the tiles are too big, the temporary arrays tempA and tempB become too big and
  1843. there is also a slowdown because of bad cache locality. So, there is an optimal tile size
  1844. somewhere in the middle.
  1845. - If different tiles in C can be calculated in parallel and, thus, the convolution is done by
  1846. parts, the loop can be threaded.
  1847. All of the above improvements have been implemented in #matchTemplate and #filter2D . Therefore, by
  1848. using them, you can get the performance even better than with the above theoretically optimal
  1849. implementation. Though, those two functions actually calculate cross-correlation, not convolution,
  1850. so you need to "flip" the second convolution operand B vertically and horizontally using flip .
  1851. @note
  1852. - An example using the discrete fourier transform can be found at
  1853. opencv_source_code/samples/cpp/dft.cpp
  1854. - (Python) An example using the dft functionality to perform Wiener deconvolution can be found
  1855. at opencv_source/samples/python/deconvolution.py
  1856. - (Python) An example rearranging the quadrants of a Fourier image can be found at
  1857. opencv_source/samples/python/dft.py
  1858. @param src input array that could be real or complex.
  1859. @param dst output array whose size and type depends on the flags .
  1860. @param flags transformation flags, representing a combination of the #DftFlags
  1861. @param nonzeroRows when the parameter is not zero, the function assumes that only the first
  1862. nonzeroRows rows of the input array (#DFT_INVERSE is not set) or only the first nonzeroRows of the
  1863. output array (#DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the
  1864. rows more efficiently and save some time; this technique is very useful for calculating array
  1865. cross-correlation or convolution using DFT.
  1866. @sa dct , getOptimalDFTSize , mulSpectrums, filter2D , matchTemplate , flip , cartToPolar ,
  1867. magnitude , phase
  1868. */
  1869. CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
  1870. /** @brief Calculates the inverse Discrete Fourier Transform of a 1D or 2D array.
  1871. idft(src, dst, flags) is equivalent to dft(src, dst, flags | #DFT_INVERSE) .
  1872. @note None of dft and idft scales the result by default. So, you should pass #DFT_SCALE to one of
  1873. dft or idft explicitly to make these transforms mutually inverse.
  1874. @sa dft, dct, idct, mulSpectrums, getOptimalDFTSize
  1875. @param src input floating-point real or complex array.
  1876. @param dst output array whose size and type depend on the flags.
  1877. @param flags operation flags (see dft and #DftFlags).
  1878. @param nonzeroRows number of dst rows to process; the rest of the rows have undefined content (see
  1879. the convolution sample in dft description.
  1880. */
  1881. CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0);
  1882. /** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array.
  1883. The function cv::dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D
  1884. floating-point array:
  1885. - Forward Cosine transform of a 1D vector of N elements:
  1886. \f[Y = C^{(N)} \cdot X\f]
  1887. where
  1888. \f[C^{(N)}_{jk}= \sqrt{\alpha_j/N} \cos \left ( \frac{\pi(2k+1)j}{2N} \right )\f]
  1889. and
  1890. \f$\alpha_0=1\f$, \f$\alpha_j=2\f$ for *j \> 0*.
  1891. - Inverse Cosine transform of a 1D vector of N elements:
  1892. \f[X = \left (C^{(N)} \right )^{-1} \cdot Y = \left (C^{(N)} \right )^T \cdot Y\f]
  1893. (since \f$C^{(N)}\f$ is an orthogonal matrix, \f$C^{(N)} \cdot \left(C^{(N)}\right)^T = I\f$ )
  1894. - Forward 2D Cosine transform of M x N matrix:
  1895. \f[Y = C^{(N)} \cdot X \cdot \left (C^{(N)} \right )^T\f]
  1896. - Inverse 2D Cosine transform of M x N matrix:
  1897. \f[X = \left (C^{(N)} \right )^T \cdot X \cdot C^{(N)}\f]
  1898. The function chooses the mode of operation by looking at the flags and size of the input array:
  1899. - If (flags & #DCT_INVERSE) == 0 , the function does a forward 1D or 2D transform. Otherwise, it
  1900. is an inverse 1D or 2D transform.
  1901. - If (flags & #DCT_ROWS) != 0 , the function performs a 1D transform of each row.
  1902. - If the array is a single column or a single row, the function performs a 1D transform.
  1903. - If none of the above is true, the function performs a 2D transform.
  1904. @note Currently dct supports even-size arrays (2, 4, 6 ...). For data analysis and approximation, you
  1905. can pad the array when necessary.
  1906. Also, the function performance depends very much, and not monotonically, on the array size (see
  1907. getOptimalDFTSize ). In the current implementation DCT of a vector of size N is calculated via DFT
  1908. of a vector of size N/2 . Thus, the optimal DCT size N1 \>= N can be calculated as:
  1909. @code
  1910. size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); }
  1911. N1 = getOptimalDCTSize(N);
  1912. @endcode
  1913. @param src input floating-point array.
  1914. @param dst output array of the same size and type as src .
  1915. @param flags transformation flags as a combination of cv::DftFlags (DCT_*)
  1916. @sa dft , getOptimalDFTSize , idct
  1917. */
  1918. CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0);
  1919. /** @brief Calculates the inverse Discrete Cosine Transform of a 1D or 2D array.
  1920. idct(src, dst, flags) is equivalent to dct(src, dst, flags | DCT_INVERSE).
  1921. @param src input floating-point single-channel array.
  1922. @param dst output array of the same size and type as src.
  1923. @param flags operation flags.
  1924. @sa dct, dft, idft, getOptimalDFTSize
  1925. */
  1926. CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0);
  1927. /** @brief Performs the per-element multiplication of two Fourier spectrums.
  1928. The function cv::mulSpectrums performs the per-element multiplication of the two CCS-packed or complex
  1929. matrices that are results of a real or complex Fourier transform.
  1930. The function, together with dft and idft , may be used to calculate convolution (pass conjB=false )
  1931. or correlation (pass conjB=true ) of two arrays rapidly. When the arrays are complex, they are
  1932. simply multiplied (per element) with an optional conjugation of the second-array elements. When the
  1933. arrays are real, they are assumed to be CCS-packed (see dft for details).
  1934. @param a first input array.
  1935. @param b second input array of the same size and type as src1 .
  1936. @param c output array of the same size and type as src1 .
  1937. @param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that
  1938. each row of src1 and src2 is an independent 1D Fourier spectrum. If you do not want to use this flag, then simply add a `0` as value.
  1939. @param conjB optional flag that conjugates the second input array before the multiplication (true)
  1940. or not (false).
  1941. */
  1942. CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c,
  1943. int flags, bool conjB = false);
  1944. /** @brief Returns the optimal DFT size for a given vector size.
  1945. DFT performance is not a monotonic function of a vector size. Therefore, when you calculate
  1946. convolution of two arrays or perform the spectral analysis of an array, it usually makes sense to
  1947. pad the input data with zeros to get a bit larger array that can be transformed much faster than the
  1948. original one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the fastest to process.
  1949. Though, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2)
  1950. are also processed quite efficiently.
  1951. The function cv::getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize
  1952. so that the DFT of a vector of size N can be processed efficiently. In the current implementation N
  1953. = 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r.
  1954. The function returns a negative number if vecsize is too large (very close to INT_MAX ).
  1955. While the function cannot be used directly to estimate the optimal vector size for DCT transform
  1956. (since the current DCT implementation supports only even-size vectors), it can be easily processed
  1957. as getOptimalDFTSize((vecsize+1)/2)\*2.
  1958. @param vecsize vector size.
  1959. @sa dft , dct , idft , idct , mulSpectrums
  1960. */
  1961. CV_EXPORTS_W int getOptimalDFTSize(int vecsize);
  1962. /** @brief Returns the default random number generator.
  1963. The function cv::theRNG returns the default random number generator. For each thread, there is a
  1964. separate random number generator, so you can use the function safely in multi-thread environments.
  1965. If you just need to get a single random number using this generator or initialize an array, you can
  1966. use randu or randn instead. But if you are going to generate many random numbers inside a loop, it
  1967. is much faster to use this function to retrieve the generator and then use RNG::operator _Tp() .
  1968. @sa RNG, randu, randn
  1969. */
  1970. CV_EXPORTS RNG& theRNG();
  1971. /** @brief Sets state of default random number generator.
  1972. The function cv::setRNGSeed sets state of default random number generator to custom value.
  1973. @param seed new state for default random number generator
  1974. @sa RNG, randu, randn
  1975. */
  1976. CV_EXPORTS_W void setRNGSeed(int seed);
  1977. /** @brief Generates a single uniformly-distributed random number or an array of random numbers.
  1978. Non-template variant of the function fills the matrix dst with uniformly-distributed
  1979. random numbers from the specified range:
  1980. \f[\texttt{low} _c \leq \texttt{dst} (I)_c < \texttt{high} _c\f]
  1981. @param dst output array of random numbers; the array must be pre-allocated.
  1982. @param low inclusive lower boundary of the generated random numbers.
  1983. @param high exclusive upper boundary of the generated random numbers.
  1984. @sa RNG, randn, theRNG
  1985. */
  1986. CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high);
  1987. /** @brief Fills the array with normally distributed random numbers.
  1988. The function cv::randn fills the matrix dst with normally distributed random numbers with the specified
  1989. mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the
  1990. value range of the output array data type.
  1991. @param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels.
  1992. @param mean mean value (expectation) of the generated random numbers.
  1993. @param stddev standard deviation of the generated random numbers; it can be either a vector (in
  1994. which case a diagonal standard deviation matrix is assumed) or a square matrix.
  1995. @sa RNG, randu
  1996. */
  1997. CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev);
  1998. /** @brief Shuffles the array elements randomly.
  1999. The function cv::randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and
  2000. swapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor .
  2001. @param dst input/output numerical 1D array.
  2002. @param iterFactor scale factor that determines the number of random swap operations (see the details
  2003. below).
  2004. @param rng optional random number generator used for shuffling; if it is zero, theRNG () is used
  2005. instead.
  2006. @sa RNG, sort
  2007. */
  2008. CV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0);
  2009. /** @brief Principal Component Analysis
  2010. The class is used to calculate a special basis for a set of vectors. The
  2011. basis will consist of eigenvectors of the covariance matrix calculated
  2012. from the input set of vectors. The class %PCA can also transform
  2013. vectors to/from the new coordinate space defined by the basis. Usually,
  2014. in this new coordinate system, each vector from the original set (and
  2015. any linear combination of such vectors) can be quite accurately
  2016. approximated by taking its first few components, corresponding to the
  2017. eigenvectors of the largest eigenvalues of the covariance matrix.
  2018. Geometrically it means that you calculate a projection of the vector to
  2019. a subspace formed by a few eigenvectors corresponding to the dominant
  2020. eigenvalues of the covariance matrix. And usually such a projection is
  2021. very close to the original vector. So, you can represent the original
  2022. vector from a high-dimensional space with a much shorter vector
  2023. consisting of the projected vector's coordinates in the subspace. Such a
  2024. transformation is also known as Karhunen-Loeve Transform, or KLT.
  2025. See http://en.wikipedia.org/wiki/Principal_component_analysis
  2026. The sample below is the function that takes two matrices. The first
  2027. function stores a set of vectors (a row per vector) that is used to
  2028. calculate PCA. The second function stores another "test" set of vectors
  2029. (a row per vector). First, these vectors are compressed with PCA, then
  2030. reconstructed back, and then the reconstruction error norm is computed
  2031. and printed for each vector. :
  2032. @code{.cpp}
  2033. using namespace cv;
  2034. PCA compressPCA(const Mat& pcaset, int maxComponents,
  2035. const Mat& testset, Mat& compressed)
  2036. {
  2037. PCA pca(pcaset, // pass the data
  2038. Mat(), // we do not have a pre-computed mean vector,
  2039. // so let the PCA engine to compute it
  2040. PCA::DATA_AS_ROW, // indicate that the vectors
  2041. // are stored as matrix rows
  2042. // (use PCA::DATA_AS_COL if the vectors are
  2043. // the matrix columns)
  2044. maxComponents // specify, how many principal components to retain
  2045. );
  2046. // if there is no test data, just return the computed basis, ready-to-use
  2047. if( !testset.data )
  2048. return pca;
  2049. CV_Assert( testset.cols == pcaset.cols );
  2050. compressed.create(testset.rows, maxComponents, testset.type());
  2051. Mat reconstructed;
  2052. for( int i = 0; i < testset.rows; i++ )
  2053. {
  2054. Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed;
  2055. // compress the vector, the result will be stored
  2056. // in the i-th row of the output matrix
  2057. pca.project(vec, coeffs);
  2058. // and then reconstruct it
  2059. pca.backProject(coeffs, reconstructed);
  2060. // and measure the error
  2061. printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2));
  2062. }
  2063. return pca;
  2064. }
  2065. @endcode
  2066. @sa calcCovarMatrix, mulTransposed, SVD, dft, dct
  2067. */
  2068. class CV_EXPORTS PCA
  2069. {
  2070. public:
  2071. enum Flags { DATA_AS_ROW = 0, //!< indicates that the input samples are stored as matrix rows
  2072. DATA_AS_COL = 1, //!< indicates that the input samples are stored as matrix columns
  2073. USE_AVG = 2 //!
  2074. };
  2075. /** @brief default constructor
  2076. The default constructor initializes an empty %PCA structure. The other
  2077. constructors initialize the structure and call PCA::operator()().
  2078. */
  2079. PCA();
  2080. /** @overload
  2081. @param data input samples stored as matrix rows or matrix columns.
  2082. @param mean optional mean value; if the matrix is empty (@c noArray()),
  2083. the mean is computed from the data.
  2084. @param flags operation flags; currently the parameter is only used to
  2085. specify the data layout (PCA::Flags)
  2086. @param maxComponents maximum number of components that %PCA should
  2087. retain; by default, all the components are retained.
  2088. */
  2089. PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0);
  2090. /** @overload
  2091. @param data input samples stored as matrix rows or matrix columns.
  2092. @param mean optional mean value; if the matrix is empty (noArray()),
  2093. the mean is computed from the data.
  2094. @param flags operation flags; currently the parameter is only used to
  2095. specify the data layout (PCA::Flags)
  2096. @param retainedVariance Percentage of variance that PCA should retain.
  2097. Using this parameter will let the PCA decided how many components to
  2098. retain but it will always keep at least 2.
  2099. */
  2100. PCA(InputArray data, InputArray mean, int flags, double retainedVariance);
  2101. /** @brief performs %PCA
  2102. The operator performs %PCA of the supplied dataset. It is safe to reuse
  2103. the same PCA structure for multiple datasets. That is, if the structure
  2104. has been previously used with another dataset, the existing internal
  2105. data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref
  2106. mean are allocated and computed.
  2107. The computed @ref eigenvalues are sorted from the largest to the smallest and
  2108. the corresponding @ref eigenvectors are stored as eigenvectors rows.
  2109. @param data input samples stored as the matrix rows or as the matrix
  2110. columns.
  2111. @param mean optional mean value; if the matrix is empty (noArray()),
  2112. the mean is computed from the data.
  2113. @param flags operation flags; currently the parameter is only used to
  2114. specify the data layout. (Flags)
  2115. @param maxComponents maximum number of components that PCA should
  2116. retain; by default, all the components are retained.
  2117. */
  2118. PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents = 0);
  2119. /** @overload
  2120. @param data input samples stored as the matrix rows or as the matrix
  2121. columns.
  2122. @param mean optional mean value; if the matrix is empty (noArray()),
  2123. the mean is computed from the data.
  2124. @param flags operation flags; currently the parameter is only used to
  2125. specify the data layout. (PCA::Flags)
  2126. @param retainedVariance Percentage of variance that %PCA should retain.
  2127. Using this parameter will let the %PCA decided how many components to
  2128. retain but it will always keep at least 2.
  2129. */
  2130. PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance);
  2131. /** @brief Projects vector(s) to the principal component subspace.
  2132. The methods project one or more vectors to the principal component
  2133. subspace, where each vector projection is represented by coefficients in
  2134. the principal component basis. The first form of the method returns the
  2135. matrix that the second form writes to the result. So the first form can
  2136. be used as a part of expression while the second form can be more
  2137. efficient in a processing loop.
  2138. @param vec input vector(s); must have the same dimensionality and the
  2139. same layout as the input data used at %PCA phase, that is, if
  2140. DATA_AS_ROW are specified, then `vec.cols==data.cols`
  2141. (vector dimensionality) and `vec.rows` is the number of vectors to
  2142. project, and the same is true for the PCA::DATA_AS_COL case.
  2143. */
  2144. Mat project(InputArray vec) const;
  2145. /** @overload
  2146. @param vec input vector(s); must have the same dimensionality and the
  2147. same layout as the input data used at PCA phase, that is, if
  2148. DATA_AS_ROW are specified, then `vec.cols==data.cols`
  2149. (vector dimensionality) and `vec.rows` is the number of vectors to
  2150. project, and the same is true for the PCA::DATA_AS_COL case.
  2151. @param result output vectors; in case of PCA::DATA_AS_COL, the
  2152. output matrix has as many columns as the number of input vectors, this
  2153. means that `result.cols==vec.cols` and the number of rows match the
  2154. number of principal components (for example, `maxComponents` parameter
  2155. passed to the constructor).
  2156. */
  2157. void project(InputArray vec, OutputArray result) const;
  2158. /** @brief Reconstructs vectors from their PC projections.
  2159. The methods are inverse operations to PCA::project. They take PC
  2160. coordinates of projected vectors and reconstruct the original vectors.
  2161. Unless all the principal components have been retained, the
  2162. reconstructed vectors are different from the originals. But typically,
  2163. the difference is small if the number of components is large enough (but
  2164. still much smaller than the original vector dimensionality). As a
  2165. result, PCA is used.
  2166. @param vec coordinates of the vectors in the principal component
  2167. subspace, the layout and size are the same as of PCA::project output
  2168. vectors.
  2169. */
  2170. Mat backProject(InputArray vec) const;
  2171. /** @overload
  2172. @param vec coordinates of the vectors in the principal component
  2173. subspace, the layout and size are the same as of PCA::project output
  2174. vectors.
  2175. @param result reconstructed vectors; the layout and size are the same as
  2176. of PCA::project input vectors.
  2177. */
  2178. void backProject(InputArray vec, OutputArray result) const;
  2179. /** @brief write PCA objects
  2180. Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage
  2181. */
  2182. void write(FileStorage& fs) const;
  2183. /** @brief load PCA objects
  2184. Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode
  2185. */
  2186. void read(const FileNode& fn);
  2187. Mat eigenvectors; //!< eigenvectors of the covariation matrix
  2188. Mat eigenvalues; //!< eigenvalues of the covariation matrix
  2189. Mat mean; //!< mean value subtracted before the projection and added after the back projection
  2190. };
  2191. /** @example samples/cpp/pca.cpp
  2192. An example using %PCA for dimensionality reduction while maintaining an amount of variance
  2193. */
  2194. /** @example samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp
  2195. Check @ref tutorial_introduction_to_pca "the corresponding tutorial" for more details
  2196. */
  2197. /**
  2198. @brief Linear Discriminant Analysis
  2199. @todo document this class
  2200. */
  2201. class CV_EXPORTS LDA
  2202. {
  2203. public:
  2204. /** @brief constructor
  2205. Initializes a LDA with num_components (default 0).
  2206. */
  2207. explicit LDA(int num_components = 0);
  2208. /** Initializes and performs a Discriminant Analysis with Fisher's
  2209. Optimization Criterion on given data in src and corresponding labels
  2210. in labels. If 0 (or less) number of components are given, they are
  2211. automatically determined for given data in computation.
  2212. */
  2213. LDA(InputArrayOfArrays src, InputArray labels, int num_components = 0);
  2214. /** Serializes this object to a given filename.
  2215. */
  2216. void save(const String& filename) const;
  2217. /** Deserializes this object from a given filename.
  2218. */
  2219. void load(const String& filename);
  2220. /** Serializes this object to a given cv::FileStorage.
  2221. */
  2222. void save(FileStorage& fs) const;
  2223. /** Deserializes this object from a given cv::FileStorage.
  2224. */
  2225. void load(const FileStorage& node);
  2226. /** destructor
  2227. */
  2228. ~LDA();
  2229. /** Compute the discriminants for data in src (row aligned) and labels.
  2230. */
  2231. void compute(InputArrayOfArrays src, InputArray labels);
  2232. /** Projects samples into the LDA subspace.
  2233. src may be one or more row aligned samples.
  2234. */
  2235. Mat project(InputArray src);
  2236. /** Reconstructs projections from the LDA subspace.
  2237. src may be one or more row aligned projections.
  2238. */
  2239. Mat reconstruct(InputArray src);
  2240. /** Returns the eigenvectors of this LDA.
  2241. */
  2242. Mat eigenvectors() const { return _eigenvectors; }
  2243. /** Returns the eigenvalues of this LDA.
  2244. */
  2245. Mat eigenvalues() const { return _eigenvalues; }
  2246. static Mat subspaceProject(InputArray W, InputArray mean, InputArray src);
  2247. static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src);
  2248. protected:
  2249. int _num_components;
  2250. Mat _eigenvectors;
  2251. Mat _eigenvalues;
  2252. void lda(InputArrayOfArrays src, InputArray labels);
  2253. };
  2254. /** @brief Singular Value Decomposition
  2255. Class for computing Singular Value Decomposition of a floating-point
  2256. matrix. The Singular Value Decomposition is used to solve least-square
  2257. problems, under-determined linear systems, invert matrices, compute
  2258. condition numbers, and so on.
  2259. If you want to compute a condition number of a matrix or an absolute value of
  2260. its determinant, you do not need `u` and `vt`. You can pass
  2261. flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u
  2262. and vt must be computed, which is not necessary most of the time.
  2263. @sa invert, solve, eigen, determinant
  2264. */
  2265. class CV_EXPORTS SVD
  2266. {
  2267. public:
  2268. enum Flags {
  2269. /** allow the algorithm to modify the decomposed matrix; it can save space and speed up
  2270. processing. currently ignored. */
  2271. MODIFY_A = 1,
  2272. /** indicates that only a vector of singular values `w` is to be processed, while u and vt
  2273. will be set to empty matrices */
  2274. NO_UV = 2,
  2275. /** when the matrix is not square, by default the algorithm produces u and vt matrices of
  2276. sufficiently large size for the further A reconstruction; if, however, FULL_UV flag is
  2277. specified, u and vt will be full-size square orthogonal matrices.*/
  2278. FULL_UV = 4
  2279. };
  2280. /** @brief the default constructor
  2281. initializes an empty SVD structure
  2282. */
  2283. SVD();
  2284. /** @overload
  2285. initializes an empty SVD structure and then calls SVD::operator()
  2286. @param src decomposed matrix. The depth has to be CV_32F or CV_64F.
  2287. @param flags operation flags (SVD::Flags)
  2288. */
  2289. SVD( InputArray src, int flags = 0 );
  2290. /** @brief the operator that performs SVD. The previously allocated u, w and vt are released.
  2291. The operator performs the singular value decomposition of the supplied
  2292. matrix. The u,`vt` , and the vector of singular values w are stored in
  2293. the structure. The same SVD structure can be reused many times with
  2294. different matrices. Each time, if needed, the previous u,`vt` , and w
  2295. are reclaimed and the new matrices are created, which is all handled by
  2296. Mat::create.
  2297. @param src decomposed matrix. The depth has to be CV_32F or CV_64F.
  2298. @param flags operation flags (SVD::Flags)
  2299. */
  2300. SVD& operator ()( InputArray src, int flags = 0 );
  2301. /** @brief decomposes matrix and stores the results to user-provided matrices
  2302. The methods/functions perform SVD of matrix. Unlike SVD::SVD constructor
  2303. and SVD::operator(), they store the results to the user-provided
  2304. matrices:
  2305. @code{.cpp}
  2306. Mat A, w, u, vt;
  2307. SVD::compute(A, w, u, vt);
  2308. @endcode
  2309. @param src decomposed matrix. The depth has to be CV_32F or CV_64F.
  2310. @param w calculated singular values
  2311. @param u calculated left singular vectors
  2312. @param vt transposed matrix of right singular vectors
  2313. @param flags operation flags - see SVD::Flags.
  2314. */
  2315. static void compute( InputArray src, OutputArray w,
  2316. OutputArray u, OutputArray vt, int flags = 0 );
  2317. /** @overload
  2318. computes singular values of a matrix
  2319. @param src decomposed matrix. The depth has to be CV_32F or CV_64F.
  2320. @param w calculated singular values
  2321. @param flags operation flags - see SVD::Flags.
  2322. */
  2323. static void compute( InputArray src, OutputArray w, int flags = 0 );
  2324. /** @brief performs back substitution
  2325. */
  2326. static void backSubst( InputArray w, InputArray u,
  2327. InputArray vt, InputArray rhs,
  2328. OutputArray dst );
  2329. /** @brief solves an under-determined singular linear system
  2330. The method finds a unit-length solution x of a singular linear system
  2331. A\*x = 0. Depending on the rank of A, there can be no solutions, a
  2332. single solution or an infinite number of solutions. In general, the
  2333. algorithm solves the following problem:
  2334. \f[dst = \arg \min _{x: \| x \| =1} \| src \cdot x \|\f]
  2335. @param src left-hand-side matrix.
  2336. @param dst found solution.
  2337. */
  2338. static void solveZ( InputArray src, OutputArray dst );
  2339. /** @brief performs a singular value back substitution.
  2340. The method calculates a back substitution for the specified right-hand
  2341. side:
  2342. \f[\texttt{x} = \texttt{vt} ^T \cdot diag( \texttt{w} )^{-1} \cdot \texttt{u} ^T \cdot \texttt{rhs} \sim \texttt{A} ^{-1} \cdot \texttt{rhs}\f]
  2343. Using this technique you can either get a very accurate solution of the
  2344. convenient linear system, or the best (in the least-squares terms)
  2345. pseudo-solution of an overdetermined linear system.
  2346. @param rhs right-hand side of a linear system (u\*w\*v')\*dst = rhs to
  2347. be solved, where A has been previously decomposed.
  2348. @param dst found solution of the system.
  2349. @note Explicit SVD with the further back substitution only makes sense
  2350. if you need to solve many linear systems with the same left-hand side
  2351. (for example, src ). If all you need is to solve a single system
  2352. (possibly with multiple rhs immediately available), simply call solve
  2353. add pass #DECOMP_SVD there. It does absolutely the same thing.
  2354. */
  2355. void backSubst( InputArray rhs, OutputArray dst ) const;
  2356. /** @todo document */
  2357. template<typename _Tp, int m, int n, int nm> static
  2358. void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt );
  2359. /** @todo document */
  2360. template<typename _Tp, int m, int n, int nm> static
  2361. void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w );
  2362. /** @todo document */
  2363. template<typename _Tp, int m, int n, int nm, int nb> static
  2364. void backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst );
  2365. Mat u, w, vt;
  2366. };
  2367. /** @brief Random Number Generator
  2368. Random number generator. It encapsulates the state (currently, a 64-bit
  2369. integer) and has methods to return scalar random values and to fill
  2370. arrays with random values. Currently it supports uniform and Gaussian
  2371. (normal) distributions. The generator uses Multiply-With-Carry
  2372. algorithm, introduced by G. Marsaglia (
  2373. <http://en.wikipedia.org/wiki/Multiply-with-carry> ).
  2374. Gaussian-distribution random numbers are generated using the Ziggurat
  2375. algorithm ( <http://en.wikipedia.org/wiki/Ziggurat_algorithm> ),
  2376. introduced by G. Marsaglia and W. W. Tsang.
  2377. */
  2378. class CV_EXPORTS RNG
  2379. {
  2380. public:
  2381. enum { UNIFORM = 0,
  2382. NORMAL = 1
  2383. };
  2384. /** @brief constructor
  2385. These are the RNG constructors. The first form sets the state to some
  2386. pre-defined value, equal to 2\*\*32-1 in the current implementation. The
  2387. second form sets the state to the specified value. If you passed state=0
  2388. , the constructor uses the above default value instead to avoid the
  2389. singular random number sequence, consisting of all zeros.
  2390. */
  2391. RNG();
  2392. /** @overload
  2393. @param state 64-bit value used to initialize the RNG.
  2394. */
  2395. RNG(uint64 state);
  2396. /**The method updates the state using the MWC algorithm and returns the
  2397. next 32-bit random number.*/
  2398. unsigned next();
  2399. /**Each of the methods updates the state using the MWC algorithm and
  2400. returns the next random number of the specified type. In case of integer
  2401. types, the returned number is from the available value range for the
  2402. specified type. In case of floating-point types, the returned value is
  2403. from [0,1) range.
  2404. */
  2405. operator uchar();
  2406. /** @overload */
  2407. operator schar();
  2408. /** @overload */
  2409. operator ushort();
  2410. /** @overload */
  2411. operator short();
  2412. /** @overload */
  2413. operator unsigned();
  2414. /** @overload */
  2415. operator int();
  2416. /** @overload */
  2417. operator float();
  2418. /** @overload */
  2419. operator double();
  2420. /** @brief returns a random integer sampled uniformly from [0, N).
  2421. The methods transform the state using the MWC algorithm and return the
  2422. next random number. The first form is equivalent to RNG::next . The
  2423. second form returns the random number modulo N , which means that the
  2424. result is in the range [0, N) .
  2425. */
  2426. unsigned operator ()();
  2427. /** @overload
  2428. @param N upper non-inclusive boundary of the returned random number.
  2429. */
  2430. unsigned operator ()(unsigned N);
  2431. /** @brief returns uniformly distributed integer random number from [a,b) range
  2432. The methods transform the state using the MWC algorithm and return the
  2433. next uniformly-distributed random number of the specified type, deduced
  2434. from the input parameter type, from the range [a, b) . There is a nuance
  2435. illustrated by the following sample:
  2436. @code{.cpp}
  2437. RNG rng;
  2438. // always produces 0
  2439. double a = rng.uniform(0, 1);
  2440. // produces double from [0, 1)
  2441. double a1 = rng.uniform((double)0, (double)1);
  2442. // produces float from [0, 1)
  2443. float b = rng.uniform(0.f, 1.f);
  2444. // produces double from [0, 1)
  2445. double c = rng.uniform(0., 1.);
  2446. // may cause compiler error because of ambiguity:
  2447. // RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)?
  2448. double d = rng.uniform(0, 0.999999);
  2449. @endcode
  2450. The compiler does not take into account the type of the variable to
  2451. which you assign the result of RNG::uniform . The only thing that
  2452. matters to the compiler is the type of a and b parameters. So, if you
  2453. want a floating-point random number, but the range boundaries are
  2454. integer numbers, either put dots in the end, if they are constants, or
  2455. use explicit type cast operators, as in the a1 initialization above.
  2456. @param a lower inclusive boundary of the returned random number.
  2457. @param b upper non-inclusive boundary of the returned random number.
  2458. */
  2459. int uniform(int a, int b);
  2460. /** @overload */
  2461. float uniform(float a, float b);
  2462. /** @overload */
  2463. double uniform(double a, double b);
  2464. /** @brief Fills arrays with random numbers.
  2465. @param mat 2D or N-dimensional matrix; currently matrices with more than
  2466. 4 channels are not supported by the methods, use Mat::reshape as a
  2467. possible workaround.
  2468. @param distType distribution type, RNG::UNIFORM or RNG::NORMAL.
  2469. @param a first distribution parameter; in case of the uniform
  2470. distribution, this is an inclusive lower boundary, in case of the normal
  2471. distribution, this is a mean value.
  2472. @param b second distribution parameter; in case of the uniform
  2473. distribution, this is a non-inclusive upper boundary, in case of the
  2474. normal distribution, this is a standard deviation (diagonal of the
  2475. standard deviation matrix or the full standard deviation matrix).
  2476. @param saturateRange pre-saturation flag; for uniform distribution only;
  2477. if true, the method will first convert a and b to the acceptable value
  2478. range (according to the mat datatype) and then will generate uniformly
  2479. distributed random numbers within the range [saturate(a), saturate(b)),
  2480. if saturateRange=false, the method will generate uniformly distributed
  2481. random numbers in the original range [a, b) and then will saturate them,
  2482. it means, for example, that
  2483. <tt>theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX)</tt> will likely
  2484. produce array mostly filled with 0's and 255's, since the range (0, 255)
  2485. is significantly smaller than [-DBL_MAX, DBL_MAX).
  2486. Each of the methods fills the matrix with the random values from the
  2487. specified distribution. As the new numbers are generated, the RNG state
  2488. is updated accordingly. In case of multiple-channel images, every
  2489. channel is filled independently, which means that RNG cannot generate
  2490. samples from the multi-dimensional Gaussian distribution with
  2491. non-diagonal covariance matrix directly. To do that, the method
  2492. generates samples from multi-dimensional standard Gaussian distribution
  2493. with zero mean and identity covariation matrix, and then transforms them
  2494. using transform to get samples from the specified Gaussian distribution.
  2495. */
  2496. void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );
  2497. /** @brief Returns the next random number sampled from the Gaussian distribution
  2498. @param sigma standard deviation of the distribution.
  2499. The method transforms the state using the MWC algorithm and returns the
  2500. next random number from the Gaussian distribution N(0,sigma) . That is,
  2501. the mean value of the returned random numbers is zero and the standard
  2502. deviation is the specified sigma .
  2503. */
  2504. double gaussian(double sigma);
  2505. uint64 state;
  2506. bool operator ==(const RNG& other) const;
  2507. };
  2508. /** @brief Mersenne Twister random number generator
  2509. Inspired by http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
  2510. @todo document
  2511. */
  2512. class CV_EXPORTS RNG_MT19937
  2513. {
  2514. public:
  2515. RNG_MT19937();
  2516. RNG_MT19937(unsigned s);
  2517. void seed(unsigned s);
  2518. unsigned next();
  2519. operator int();
  2520. operator unsigned();
  2521. operator float();
  2522. operator double();
  2523. unsigned operator ()(unsigned N);
  2524. unsigned operator ()();
  2525. /** @brief returns uniformly distributed integer random number from [a,b) range*/
  2526. int uniform(int a, int b);
  2527. /** @brief returns uniformly distributed floating-point random number from [a,b) range*/
  2528. float uniform(float a, float b);
  2529. /** @brief returns uniformly distributed double-precision floating-point random number from [a,b) range*/
  2530. double uniform(double a, double b);
  2531. private:
  2532. enum PeriodParameters {N = 624, M = 397};
  2533. unsigned state[N];
  2534. int mti;
  2535. };
  2536. //! @} core_array
  2537. //! @addtogroup core_cluster
  2538. //! @{
  2539. /** @example samples/cpp/kmeans.cpp
  2540. An example on K-means clustering
  2541. */
  2542. /** @brief Finds centers of clusters and groups input samples around the clusters.
  2543. The function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters
  2544. and groups the input samples around the clusters. As an output, \f$\texttt{bestLabels}_i\f$ contains a
  2545. 0-based cluster index for the sample stored in the \f$i^{th}\f$ row of the samples matrix.
  2546. @note
  2547. - (Python) An example on K-means clustering can be found at
  2548. opencv_source_code/samples/python/kmeans.py
  2549. @param data Data for clustering. An array of N-Dimensional points with float coordinates is needed.
  2550. Examples of this array can be:
  2551. - Mat points(count, 2, CV_32F);
  2552. - Mat points(count, 1, CV_32FC2);
  2553. - Mat points(1, count, CV_32FC2);
  2554. - std::vector\<cv::Point2f\> points(sampleCount);
  2555. @param K Number of clusters to split the set by.
  2556. @param bestLabels Input/output integer array that stores the cluster indices for every sample.
  2557. @param criteria The algorithm termination criteria, that is, the maximum number of iterations and/or
  2558. the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster
  2559. centers moves by less than criteria.epsilon on some iteration, the algorithm stops.
  2560. @param attempts Flag to specify the number of times the algorithm is executed using different
  2561. initial labellings. The algorithm returns the labels that yield the best compactness (see the last
  2562. function parameter).
  2563. @param flags Flag that can take values of cv::KmeansFlags
  2564. @param centers Output matrix of the cluster centers, one row per each cluster center.
  2565. @return The function returns the compactness measure that is computed as
  2566. \f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f]
  2567. after every attempt. The best (minimum) value is chosen and the corresponding labels and the
  2568. compactness value are returned by the function. Basically, you can use only the core of the
  2569. function, set the number of attempts to 1, initialize labels each time using a custom algorithm,
  2570. pass them with the ( flags = #KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best
  2571. (most-compact) clustering.
  2572. */
  2573. CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels,
  2574. TermCriteria criteria, int attempts,
  2575. int flags, OutputArray centers = noArray() );
  2576. //! @} core_cluster
  2577. //! @addtogroup core_basic
  2578. //! @{
  2579. /////////////////////////////// Formatted output of cv::Mat ///////////////////////////
  2580. /** @todo document */
  2581. class CV_EXPORTS Formatted
  2582. {
  2583. public:
  2584. virtual const char* next() = 0;
  2585. virtual void reset() = 0;
  2586. virtual ~Formatted();
  2587. };
  2588. /** @todo document */
  2589. class CV_EXPORTS Formatter
  2590. {
  2591. public:
  2592. enum FormatType {
  2593. FMT_DEFAULT = 0,
  2594. FMT_MATLAB = 1,
  2595. FMT_CSV = 2,
  2596. FMT_PYTHON = 3,
  2597. FMT_NUMPY = 4,
  2598. FMT_C = 5
  2599. };
  2600. virtual ~Formatter();
  2601. virtual Ptr<Formatted> format(const Mat& mtx) const = 0;
  2602. virtual void set16fPrecision(int p = 4) = 0;
  2603. virtual void set32fPrecision(int p = 8) = 0;
  2604. virtual void set64fPrecision(int p = 16) = 0;
  2605. virtual void setMultiline(bool ml = true) = 0;
  2606. static Ptr<Formatter> get(Formatter::FormatType fmt = FMT_DEFAULT);
  2607. };
  2608. static inline
  2609. String& operator << (String& out, Ptr<Formatted> fmtd)
  2610. {
  2611. fmtd->reset();
  2612. for(const char* str = fmtd->next(); str; str = fmtd->next())
  2613. out += cv::String(str);
  2614. return out;
  2615. }
  2616. static inline
  2617. String& operator << (String& out, const Mat& mtx)
  2618. {
  2619. return out << Formatter::get()->format(mtx);
  2620. }
  2621. //////////////////////////////////////// Algorithm ////////////////////////////////////
  2622. class CV_EXPORTS Algorithm;
  2623. template<typename _Tp, typename _EnumTp = void> struct ParamType {};
  2624. /** @brief This is a base class for all more or less complex algorithms in OpenCV
  2625. especially for classes of algorithms, for which there can be multiple implementations. The examples
  2626. are stereo correspondence (for which there are algorithms like block matching, semi-global block
  2627. matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians
  2628. models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck
  2629. etc.).
  2630. Here is example of SimpleBlobDetector use in your application via Algorithm interface:
  2631. @snippet snippets/core_various.cpp Algorithm
  2632. */
  2633. class CV_EXPORTS_W Algorithm
  2634. {
  2635. public:
  2636. Algorithm();
  2637. virtual ~Algorithm();
  2638. /** @brief Clears the algorithm state
  2639. */
  2640. CV_WRAP virtual void clear() {}
  2641. /** @brief Stores algorithm parameters in a file storage
  2642. */
  2643. virtual void write(FileStorage& fs) const { CV_UNUSED(fs); }
  2644. /** @brief simplified API for language bindings
  2645. * @overload
  2646. */
  2647. CV_WRAP void write(const Ptr<FileStorage>& fs, const String& name = String()) const;
  2648. /** @brief Reads algorithm parameters from a file storage
  2649. */
  2650. CV_WRAP virtual void read(const FileNode& fn) { CV_UNUSED(fn); }
  2651. /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
  2652. */
  2653. CV_WRAP virtual bool empty() const { return false; }
  2654. /** @brief Reads algorithm from the file node
  2655. This is static template method of Algorithm. It's usage is following (in the case of SVM):
  2656. @code
  2657. cv::FileStorage fsRead("example.xml", FileStorage::READ);
  2658. Ptr<SVM> svm = Algorithm::read<SVM>(fsRead.root());
  2659. @endcode
  2660. In order to make this method work, the derived class must overwrite Algorithm::read(const
  2661. FileNode& fn) and also have static create() method without parameters
  2662. (or with all the optional parameters)
  2663. */
  2664. template<typename _Tp> static Ptr<_Tp> read(const FileNode& fn)
  2665. {
  2666. Ptr<_Tp> obj = _Tp::create();
  2667. obj->read(fn);
  2668. return !obj->empty() ? obj : Ptr<_Tp>();
  2669. }
  2670. /** @brief Loads algorithm from the file
  2671. @param filename Name of the file to read.
  2672. @param objname The optional name of the node to read (if empty, the first top-level node will be used)
  2673. This is static template method of Algorithm. It's usage is following (in the case of SVM):
  2674. @code
  2675. Ptr<SVM> svm = Algorithm::load<SVM>("my_svm_model.xml");
  2676. @endcode
  2677. In order to make this method work, the derived class must overwrite Algorithm::read(const
  2678. FileNode& fn).
  2679. */
  2680. template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
  2681. {
  2682. FileStorage fs(filename, FileStorage::READ);
  2683. CV_Assert(fs.isOpened());
  2684. FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
  2685. if (fn.empty()) return Ptr<_Tp>();
  2686. Ptr<_Tp> obj = _Tp::create();
  2687. obj->read(fn);
  2688. return !obj->empty() ? obj : Ptr<_Tp>();
  2689. }
  2690. /** @brief Loads algorithm from a String
  2691. @param strModel The string variable containing the model you want to load.
  2692. @param objname The optional name of the node to read (if empty, the first top-level node will be used)
  2693. This is static template method of Algorithm. It's usage is following (in the case of SVM):
  2694. @code
  2695. Ptr<SVM> svm = Algorithm::loadFromString<SVM>(myStringModel);
  2696. @endcode
  2697. */
  2698. template<typename _Tp> static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String())
  2699. {
  2700. FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY);
  2701. FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
  2702. Ptr<_Tp> obj = _Tp::create();
  2703. obj->read(fn);
  2704. return !obj->empty() ? obj : Ptr<_Tp>();
  2705. }
  2706. /** Saves the algorithm to a file.
  2707. In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */
  2708. CV_WRAP virtual void save(const String& filename) const;
  2709. /** Returns the algorithm string identifier.
  2710. This string is used as top level xml/yml node tag when the object is saved to a file or string. */
  2711. CV_WRAP virtual String getDefaultName() const;
  2712. protected:
  2713. void writeFormat(FileStorage& fs) const;
  2714. };
  2715. enum struct Param {
  2716. INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7,
  2717. UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12
  2718. };
  2719. template<> struct ParamType<bool>
  2720. {
  2721. typedef bool const_param_type;
  2722. typedef bool member_type;
  2723. static const Param type = Param::BOOLEAN;
  2724. };
  2725. template<> struct ParamType<int>
  2726. {
  2727. typedef int const_param_type;
  2728. typedef int member_type;
  2729. static const Param type = Param::INT;
  2730. };
  2731. template<> struct ParamType<double>
  2732. {
  2733. typedef double const_param_type;
  2734. typedef double member_type;
  2735. static const Param type = Param::REAL;
  2736. };
  2737. template<> struct ParamType<String>
  2738. {
  2739. typedef const String& const_param_type;
  2740. typedef String member_type;
  2741. static const Param type = Param::STRING;
  2742. };
  2743. template<> struct ParamType<Mat>
  2744. {
  2745. typedef const Mat& const_param_type;
  2746. typedef Mat member_type;
  2747. static const Param type = Param::MAT;
  2748. };
  2749. template<> struct ParamType<std::vector<Mat> >
  2750. {
  2751. typedef const std::vector<Mat>& const_param_type;
  2752. typedef std::vector<Mat> member_type;
  2753. static const Param type = Param::MAT_VECTOR;
  2754. };
  2755. template<> struct ParamType<Algorithm>
  2756. {
  2757. typedef const Ptr<Algorithm>& const_param_type;
  2758. typedef Ptr<Algorithm> member_type;
  2759. static const Param type = Param::ALGORITHM;
  2760. };
  2761. template<> struct ParamType<float>
  2762. {
  2763. typedef float const_param_type;
  2764. typedef float member_type;
  2765. static const Param type = Param::FLOAT;
  2766. };
  2767. template<> struct ParamType<unsigned>
  2768. {
  2769. typedef unsigned const_param_type;
  2770. typedef unsigned member_type;
  2771. static const Param type = Param::UNSIGNED_INT;
  2772. };
  2773. template<> struct ParamType<uint64>
  2774. {
  2775. typedef uint64 const_param_type;
  2776. typedef uint64 member_type;
  2777. static const Param type = Param::UINT64;
  2778. };
  2779. template<> struct ParamType<uchar>
  2780. {
  2781. typedef uchar const_param_type;
  2782. typedef uchar member_type;
  2783. static const Param type = Param::UCHAR;
  2784. };
  2785. template<> struct ParamType<Scalar>
  2786. {
  2787. typedef const Scalar& const_param_type;
  2788. typedef Scalar member_type;
  2789. static const Param type = Param::SCALAR;
  2790. };
  2791. template<typename _Tp>
  2792. struct ParamType<_Tp, typename std::enable_if< std::is_enum<_Tp>::value >::type>
  2793. {
  2794. typedef typename std::underlying_type<_Tp>::type const_param_type;
  2795. typedef typename std::underlying_type<_Tp>::type member_type;
  2796. static const Param type = Param::INT;
  2797. };
  2798. //! @} core_basic
  2799. } //namespace cv
  2800. #include "opencv2/core/operations.hpp"
  2801. #include "opencv2/core/cvstd.inl.hpp"
  2802. #include "opencv2/core/utility.hpp"
  2803. #include "opencv2/core/optim.hpp"
  2804. #include "opencv2/core/ovx.hpp"
  2805. #endif /*OPENCV_CORE_HPP*/