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