core.hpp 148 KB

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