mat.inl.hpp 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Copyright (C) 2013, 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_MATRIX_OPERATIONS_HPP
  45. #define OPENCV_CORE_MATRIX_OPERATIONS_HPP
  46. #ifndef __cplusplus
  47. # error mat.inl.hpp header must be compiled as C++
  48. #endif
  49. #ifdef _MSC_VER
  50. #pragma warning( push )
  51. #pragma warning( disable: 4127 )
  52. #endif
  53. #if defined(CV_SKIP_DISABLE_CLANG_ENUM_WARNINGS)
  54. // nothing
  55. #elif defined(CV_FORCE_DISABLE_CLANG_ENUM_WARNINGS)
  56. #define CV_DISABLE_CLANG_ENUM_WARNINGS
  57. #elif defined(__clang__) && defined(__has_warning)
  58. #if __has_warning("-Wdeprecated-enum-enum-conversion") && __has_warning("-Wdeprecated-anon-enum-enum-conversion")
  59. #define CV_DISABLE_CLANG_ENUM_WARNINGS
  60. #endif
  61. #endif
  62. #ifdef CV_DISABLE_CLANG_ENUM_WARNINGS
  63. #pragma clang diagnostic push
  64. #pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"
  65. #pragma clang diagnostic ignored "-Wdeprecated-anon-enum-enum-conversion"
  66. #endif
  67. namespace cv
  68. {
  69. CV__DEBUG_NS_BEGIN
  70. //! @cond IGNORED
  71. ////////////////////////// Custom (raw) type wrapper //////////////////////////
  72. template<typename _Tp> static inline
  73. int rawType()
  74. {
  75. CV_StaticAssert(sizeof(_Tp) <= CV_CN_MAX, "sizeof(_Tp) is too large");
  76. const int elemSize = sizeof(_Tp);
  77. return (int)CV_MAKETYPE(CV_8U, elemSize);
  78. }
  79. //////////////////////// Input/Output Arrays ////////////////////////
  80. inline void _InputArray::init(int _flags, const void* _obj)
  81. { flags = _flags; obj = (void*)_obj; }
  82. inline void _InputArray::init(int _flags, const void* _obj, Size _sz)
  83. { flags = _flags; obj = (void*)_obj; sz = _sz; }
  84. inline void* _InputArray::getObj() const { return obj; }
  85. inline int _InputArray::getFlags() const { return flags; }
  86. inline Size _InputArray::getSz() const { return sz; }
  87. inline _InputArray::_InputArray() { init(NONE, 0); }
  88. inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); }
  89. inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); }
  90. inline _InputArray::_InputArray(const std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); }
  91. inline _InputArray::_InputArray(const UMat& m) { init(UMAT+ACCESS_READ, &m); }
  92. inline _InputArray::_InputArray(const std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_READ, &vec); }
  93. template<typename _Tp> inline
  94. _InputArray::_InputArray(const std::vector<_Tp>& vec)
  95. { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
  96. #ifdef CV_CXX_STD_ARRAY
  97. template<typename _Tp, std::size_t _Nm> inline
  98. _InputArray::_InputArray(const std::array<_Tp, _Nm>& arr)
  99. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }
  100. template<std::size_t _Nm> inline
  101. _InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
  102. { init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); }
  103. #endif
  104. inline
  105. _InputArray::_InputArray(const std::vector<bool>& vec)
  106. { init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type<bool>::value + ACCESS_READ, &vec); }
  107. template<typename _Tp> inline
  108. _InputArray::_InputArray(const std::vector<std::vector<_Tp> >& vec)
  109. { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
  110. inline
  111. _InputArray::_InputArray(const std::vector<std::vector<bool> >&)
  112. { CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > is not supported!\n"); }
  113. template<typename _Tp> inline
  114. _InputArray::_InputArray(const std::vector<Mat_<_Tp> >& vec)
  115. { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
  116. template<typename _Tp, int m, int n> inline
  117. _InputArray::_InputArray(const Matx<_Tp, m, n>& mtx)
  118. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); }
  119. template<typename _Tp> inline
  120. _InputArray::_InputArray(const _Tp* vec, int n)
  121. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); }
  122. template<typename _Tp> inline
  123. _InputArray::_InputArray(const Mat_<_Tp>& m)
  124. { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); }
  125. inline _InputArray::_InputArray(const double& val)
  126. { init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); }
  127. inline _InputArray::_InputArray(const cuda::GpuMat& d_mat)
  128. { init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); }
  129. inline _InputArray::_InputArray(const std::vector<cuda::GpuMat>& d_mat)
  130. { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);}
  131. inline _InputArray::_InputArray(const ogl::Buffer& buf)
  132. { init(OPENGL_BUFFER + ACCESS_READ, &buf); }
  133. inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem)
  134. { init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); }
  135. template<typename _Tp> inline
  136. _InputArray _InputArray::rawIn(const std::vector<_Tp>& vec)
  137. {
  138. _InputArray v;
  139. v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_READ;
  140. v.obj = (void*)&vec;
  141. return v;
  142. }
  143. #ifdef CV_CXX_STD_ARRAY
  144. template<typename _Tp, std::size_t _Nm> inline
  145. _InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr)
  146. {
  147. _InputArray v;
  148. v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ;
  149. v.obj = (void*)arr.data();
  150. v.sz = Size(1, _Nm);
  151. return v;
  152. }
  153. #endif
  154. inline _InputArray::~_InputArray() {}
  155. inline Mat _InputArray::getMat(int i) const
  156. {
  157. if( kind() == MAT && i < 0 )
  158. return *(const Mat*)obj;
  159. return getMat_(i);
  160. }
  161. inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
  162. inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; }
  163. inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; }
  164. inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; }
  165. inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; }
  166. inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR ||
  167. kind() == _InputArray::STD_BOOL_VECTOR ||
  168. (kind() == _InputArray::MATX && (sz.width <= 1 || sz.height <= 1)); }
  169. inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; }
  170. inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; }
  171. ////////////////////////////////////////////////////////////////////////////////////////
  172. inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); }
  173. inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); }
  174. inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); }
  175. inline _OutputArray::_OutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); }
  176. inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); }
  177. inline _OutputArray::_OutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); }
  178. template<typename _Tp> inline
  179. _OutputArray::_OutputArray(std::vector<_Tp>& vec)
  180. { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  181. #ifdef CV_CXX_STD_ARRAY
  182. template<typename _Tp, std::size_t _Nm> inline
  183. _OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr)
  184. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
  185. template<std::size_t _Nm> inline
  186. _OutputArray::_OutputArray(std::array<Mat, _Nm>& arr)
  187. { init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
  188. #endif
  189. inline
  190. _OutputArray::_OutputArray(std::vector<bool>&)
  191. { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an output array\n"); }
  192. template<typename _Tp> inline
  193. _OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec)
  194. { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  195. inline
  196. _OutputArray::_OutputArray(std::vector<std::vector<bool> >&)
  197. { CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > cannot be an output array\n"); }
  198. template<typename _Tp> inline
  199. _OutputArray::_OutputArray(std::vector<Mat_<_Tp> >& vec)
  200. { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  201. template<typename _Tp> inline
  202. _OutputArray::_OutputArray(Mat_<_Tp>& m)
  203. { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
  204. template<typename _Tp, int m, int n> inline
  205. _OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx)
  206. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
  207. template<typename _Tp> inline
  208. _OutputArray::_OutputArray(_Tp* vec, int n)
  209. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
  210. template<typename _Tp> inline
  211. _OutputArray::_OutputArray(const std::vector<_Tp>& vec)
  212. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  213. #ifdef CV_CXX_STD_ARRAY
  214. template<typename _Tp, std::size_t _Nm> inline
  215. _OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr)
  216. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
  217. template<std::size_t _Nm> inline
  218. _OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
  219. { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
  220. #endif
  221. template<typename _Tp> inline
  222. _OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec)
  223. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  224. template<typename _Tp> inline
  225. _OutputArray::_OutputArray(const std::vector<Mat_<_Tp> >& vec)
  226. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
  227. template<typename _Tp> inline
  228. _OutputArray::_OutputArray(const Mat_<_Tp>& m)
  229. { init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
  230. template<typename _Tp, int m, int n> inline
  231. _OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx)
  232. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
  233. template<typename _Tp> inline
  234. _OutputArray::_OutputArray(const _Tp* vec, int n)
  235. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
  236. inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat)
  237. { init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }
  238. inline _OutputArray::_OutputArray(std::vector<cuda::GpuMat>& d_mat)
  239. { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);}
  240. inline _OutputArray::_OutputArray(ogl::Buffer& buf)
  241. { init(OPENGL_BUFFER + ACCESS_WRITE, &buf); }
  242. inline _OutputArray::_OutputArray(cuda::HostMem& cuda_mem)
  243. { init(CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); }
  244. inline _OutputArray::_OutputArray(const Mat& m)
  245. { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_WRITE, &m); }
  246. inline _OutputArray::_OutputArray(const std::vector<Mat>& vec)
  247. { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_WRITE, &vec); }
  248. inline _OutputArray::_OutputArray(const UMat& m)
  249. { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_WRITE, &m); }
  250. inline _OutputArray::_OutputArray(const std::vector<UMat>& vec)
  251. { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_WRITE, &vec); }
  252. inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat)
  253. { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }
  254. inline _OutputArray::_OutputArray(const ogl::Buffer& buf)
  255. { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); }
  256. inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem)
  257. { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); }
  258. template<typename _Tp> inline
  259. _OutputArray _OutputArray::rawOut(std::vector<_Tp>& vec)
  260. {
  261. _OutputArray v;
  262. v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_WRITE;
  263. v.obj = (void*)&vec;
  264. return v;
  265. }
  266. #ifdef CV_CXX_STD_ARRAY
  267. template<typename _Tp, std::size_t _Nm> inline
  268. _OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr)
  269. {
  270. _OutputArray v;
  271. v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE;
  272. v.obj = (void*)arr.data();
  273. v.sz = Size(1, _Nm);
  274. return v;
  275. }
  276. #endif
  277. ///////////////////////////////////////////////////////////////////////////////////////////
  278. inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); }
  279. inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); }
  280. inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); }
  281. inline _InputOutputArray::_InputOutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); }
  282. inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); }
  283. inline _InputOutputArray::_InputOutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_RW, &vec); }
  284. template<typename _Tp> inline
  285. _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec)
  286. { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  287. #ifdef CV_CXX_STD_ARRAY
  288. template<typename _Tp, std::size_t _Nm> inline
  289. _InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr)
  290. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
  291. template<std::size_t _Nm> inline
  292. _InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr)
  293. { init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
  294. #endif
  295. inline _InputOutputArray::_InputOutputArray(std::vector<bool>&)
  296. { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); }
  297. template<typename _Tp> inline
  298. _InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec)
  299. { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  300. template<typename _Tp> inline
  301. _InputOutputArray::_InputOutputArray(std::vector<Mat_<_Tp> >& vec)
  302. { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  303. template<typename _Tp> inline
  304. _InputOutputArray::_InputOutputArray(Mat_<_Tp>& m)
  305. { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
  306. template<typename _Tp, int m, int n> inline
  307. _InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx)
  308. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
  309. template<typename _Tp> inline
  310. _InputOutputArray::_InputOutputArray(_Tp* vec, int n)
  311. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
  312. template<typename _Tp> inline
  313. _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec)
  314. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  315. #ifdef CV_CXX_STD_ARRAY
  316. template<typename _Tp, std::size_t _Nm> inline
  317. _InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr)
  318. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
  319. template<std::size_t _Nm> inline
  320. _InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
  321. { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
  322. #endif
  323. template<typename _Tp> inline
  324. _InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec)
  325. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  326. template<typename _Tp> inline
  327. _InputOutputArray::_InputOutputArray(const std::vector<Mat_<_Tp> >& vec)
  328. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
  329. template<typename _Tp> inline
  330. _InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m)
  331. { init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
  332. template<typename _Tp, int m, int n> inline
  333. _InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx)
  334. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
  335. template<typename _Tp> inline
  336. _InputOutputArray::_InputOutputArray(const _Tp* vec, int n)
  337. { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
  338. inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat)
  339. { init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); }
  340. inline _InputOutputArray::_InputOutputArray(ogl::Buffer& buf)
  341. { init(OPENGL_BUFFER + ACCESS_RW, &buf); }
  342. inline _InputOutputArray::_InputOutputArray(cuda::HostMem& cuda_mem)
  343. { init(CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); }
  344. inline _InputOutputArray::_InputOutputArray(const Mat& m)
  345. { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_RW, &m); }
  346. inline _InputOutputArray::_InputOutputArray(const std::vector<Mat>& vec)
  347. { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_RW, &vec); }
  348. inline _InputOutputArray::_InputOutputArray(const UMat& m)
  349. { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_RW, &m); }
  350. inline _InputOutputArray::_InputOutputArray(const std::vector<UMat>& vec)
  351. { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_RW, &vec); }
  352. inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat)
  353. { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); }
  354. inline _InputOutputArray::_InputOutputArray(const std::vector<cuda::GpuMat>& d_mat)
  355. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);}
  356. template<> inline _InputOutputArray::_InputOutputArray(std::vector<cuda::GpuMat>& d_mat)
  357. { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);}
  358. inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf)
  359. { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); }
  360. inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem)
  361. { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); }
  362. template<typename _Tp> inline
  363. _InputOutputArray _InputOutputArray::rawInOut(std::vector<_Tp>& vec)
  364. {
  365. _InputOutputArray v;
  366. v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_RW;
  367. v.obj = (void*)&vec;
  368. return v;
  369. }
  370. #ifdef CV_CXX_STD_ARRAY
  371. template<typename _Tp, std::size_t _Nm> inline
  372. _InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr)
  373. {
  374. _InputOutputArray v;
  375. v.flags = FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW;
  376. v.obj = (void*)arr.data();
  377. v.sz = Size(1, _Nm);
  378. return v;
  379. }
  380. #endif
  381. template<typename _Tp> static inline _InputArray rawIn(_Tp& v) { return _InputArray::rawIn(v); }
  382. template<typename _Tp> static inline _OutputArray rawOut(_Tp& v) { return _OutputArray::rawOut(v); }
  383. template<typename _Tp> static inline _InputOutputArray rawInOut(_Tp& v) { return _InputOutputArray::rawInOut(v); }
  384. CV__DEBUG_NS_END
  385. //////////////////////////////////////////// Mat //////////////////////////////////////////
  386. template<typename _Tp> inline
  387. Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
  388. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
  389. cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  390. {
  391. if(vec.empty())
  392. return;
  393. if( !copyData )
  394. {
  395. step[0] = step[1] = sizeof(_Tp);
  396. datastart = data = (uchar*)&vec[0];
  397. datalimit = dataend = datastart + rows * step[0];
  398. }
  399. else
  400. Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
  401. }
  402. #ifdef CV_CXX11
  403. template<typename _Tp, typename> inline
  404. Mat::Mat(const std::initializer_list<_Tp> list)
  405. : Mat()
  406. {
  407. CV_Assert(list.size() != 0);
  408. Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
  409. }
  410. template<typename _Tp> inline
  411. Mat::Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list)
  412. : Mat()
  413. {
  414. size_t size_total = 1;
  415. for(auto s : sizes)
  416. size_total *= s;
  417. CV_Assert(list.size() != 0);
  418. CV_Assert(size_total == list.size());
  419. Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
  420. }
  421. #endif
  422. #ifdef CV_CXX_STD_ARRAY
  423. template<typename _Tp, std::size_t _Nm> inline
  424. Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
  425. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()),
  426. cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  427. {
  428. if(arr.empty())
  429. return;
  430. if( !copyData )
  431. {
  432. step[0] = step[1] = sizeof(_Tp);
  433. datastart = data = (uchar*)arr.data();
  434. datalimit = dataend = datastart + rows * step[0];
  435. }
  436. else
  437. Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this);
  438. }
  439. #endif
  440. template<typename _Tp, int n> inline
  441. Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
  442. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0),
  443. datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  444. {
  445. if( !copyData )
  446. {
  447. step[0] = step[1] = sizeof(_Tp);
  448. datastart = data = (uchar*)vec.val;
  449. datalimit = dataend = datastart + rows * step[0];
  450. }
  451. else
  452. Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this);
  453. }
  454. template<typename _Tp, int m, int n> inline
  455. Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
  456. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0),
  457. datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  458. {
  459. if( !copyData )
  460. {
  461. step[0] = cols * sizeof(_Tp);
  462. step[1] = sizeof(_Tp);
  463. datastart = data = (uchar*)M.val;
  464. datalimit = dataend = datastart + rows * step[0];
  465. }
  466. else
  467. Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this);
  468. }
  469. template<typename _Tp> inline
  470. Mat::Mat(const Point_<_Tp>& pt, bool copyData)
  471. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0),
  472. datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  473. {
  474. if( !copyData )
  475. {
  476. step[0] = step[1] = sizeof(_Tp);
  477. datastart = data = (uchar*)&pt.x;
  478. datalimit = dataend = datastart + rows * step[0];
  479. }
  480. else
  481. {
  482. create(2, 1, traits::Type<_Tp>::value);
  483. ((_Tp*)data)[0] = pt.x;
  484. ((_Tp*)data)[1] = pt.y;
  485. }
  486. }
  487. template<typename _Tp> inline
  488. Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
  489. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0),
  490. datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
  491. {
  492. if( !copyData )
  493. {
  494. step[0] = step[1] = sizeof(_Tp);
  495. datastart = data = (uchar*)&pt.x;
  496. datalimit = dataend = datastart + rows * step[0];
  497. }
  498. else
  499. {
  500. create(3, 1, traits::Type<_Tp>::value);
  501. ((_Tp*)data)[0] = pt.x;
  502. ((_Tp*)data)[1] = pt.y;
  503. ((_Tp*)data)[2] = pt.z;
  504. }
  505. }
  506. template<typename _Tp> inline
  507. Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer)
  508. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0),
  509. datastart(0), dataend(0), allocator(0), u(0), size(&rows)
  510. {
  511. *this = commaInitializer.operator Mat_<_Tp>();
  512. }
  513. inline
  514. Mat Mat::row(int y) const
  515. {
  516. return Mat(*this, Range(y, y + 1), Range::all());
  517. }
  518. inline
  519. Mat Mat::col(int x) const
  520. {
  521. return Mat(*this, Range::all(), Range(x, x + 1));
  522. }
  523. inline
  524. Mat Mat::rowRange(int startrow, int endrow) const
  525. {
  526. return Mat(*this, Range(startrow, endrow), Range::all());
  527. }
  528. inline
  529. Mat Mat::rowRange(const Range& r) const
  530. {
  531. return Mat(*this, r, Range::all());
  532. }
  533. inline
  534. Mat Mat::colRange(int startcol, int endcol) const
  535. {
  536. return Mat(*this, Range::all(), Range(startcol, endcol));
  537. }
  538. inline
  539. Mat Mat::colRange(const Range& r) const
  540. {
  541. return Mat(*this, Range::all(), r);
  542. }
  543. inline
  544. Mat Mat::operator()( Range _rowRange, Range _colRange ) const
  545. {
  546. return Mat(*this, _rowRange, _colRange);
  547. }
  548. inline
  549. Mat Mat::operator()( const Rect& roi ) const
  550. {
  551. return Mat(*this, roi);
  552. }
  553. inline
  554. Mat Mat::operator()(const Range* ranges) const
  555. {
  556. return Mat(*this, ranges);
  557. }
  558. inline
  559. Mat Mat::operator()(const std::vector<Range>& ranges) const
  560. {
  561. return Mat(*this, ranges);
  562. }
  563. inline
  564. bool Mat::isContinuous() const
  565. {
  566. return (flags & CONTINUOUS_FLAG) != 0;
  567. }
  568. inline
  569. bool Mat::isSubmatrix() const
  570. {
  571. return (flags & SUBMATRIX_FLAG) != 0;
  572. }
  573. inline
  574. size_t Mat::elemSize() const
  575. {
  576. size_t res = dims > 0 ? step.p[dims - 1] : 0;
  577. CV_DbgAssert(res != 0);
  578. return res;
  579. }
  580. inline
  581. size_t Mat::elemSize1() const
  582. {
  583. return CV_ELEM_SIZE1(flags);
  584. }
  585. inline
  586. int Mat::type() const
  587. {
  588. return CV_MAT_TYPE(flags);
  589. }
  590. inline
  591. int Mat::depth() const
  592. {
  593. return CV_MAT_DEPTH(flags);
  594. }
  595. inline
  596. int Mat::channels() const
  597. {
  598. return CV_MAT_CN(flags);
  599. }
  600. inline
  601. uchar* Mat::ptr(int y)
  602. {
  603. CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
  604. return data + step.p[0] * y;
  605. }
  606. inline
  607. const uchar* Mat::ptr(int y) const
  608. {
  609. CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
  610. return data + step.p[0] * y;
  611. }
  612. template<typename _Tp> inline
  613. _Tp* Mat::ptr(int y)
  614. {
  615. CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
  616. return (_Tp*)(data + step.p[0] * y);
  617. }
  618. template<typename _Tp> inline
  619. const _Tp* Mat::ptr(int y) const
  620. {
  621. CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
  622. return (const _Tp*)(data + step.p[0] * y);
  623. }
  624. inline
  625. uchar* Mat::ptr(int i0, int i1)
  626. {
  627. CV_DbgAssert(dims >= 2);
  628. CV_DbgAssert(data);
  629. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  630. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  631. return data + i0 * step.p[0] + i1 * step.p[1];
  632. }
  633. inline
  634. const uchar* Mat::ptr(int i0, int i1) const
  635. {
  636. CV_DbgAssert(dims >= 2);
  637. CV_DbgAssert(data);
  638. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  639. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  640. return data + i0 * step.p[0] + i1 * step.p[1];
  641. }
  642. template<typename _Tp> inline
  643. _Tp* Mat::ptr(int i0, int i1)
  644. {
  645. CV_DbgAssert(dims >= 2);
  646. CV_DbgAssert(data);
  647. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  648. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  649. return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1]);
  650. }
  651. template<typename _Tp> inline
  652. const _Tp* Mat::ptr(int i0, int i1) const
  653. {
  654. CV_DbgAssert(dims >= 2);
  655. CV_DbgAssert(data);
  656. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  657. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  658. return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1]);
  659. }
  660. inline
  661. uchar* Mat::ptr(int i0, int i1, int i2)
  662. {
  663. CV_DbgAssert(dims >= 3);
  664. CV_DbgAssert(data);
  665. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  666. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  667. CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
  668. return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2];
  669. }
  670. inline
  671. const uchar* Mat::ptr(int i0, int i1, int i2) const
  672. {
  673. CV_DbgAssert(dims >= 3);
  674. CV_DbgAssert(data);
  675. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  676. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  677. CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
  678. return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2];
  679. }
  680. template<typename _Tp> inline
  681. _Tp* Mat::ptr(int i0, int i1, int i2)
  682. {
  683. CV_DbgAssert(dims >= 3);
  684. CV_DbgAssert(data);
  685. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  686. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  687. CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
  688. return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]);
  689. }
  690. template<typename _Tp> inline
  691. const _Tp* Mat::ptr(int i0, int i1, int i2) const
  692. {
  693. CV_DbgAssert(dims >= 3);
  694. CV_DbgAssert(data);
  695. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  696. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  697. CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
  698. return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]);
  699. }
  700. inline
  701. uchar* Mat::ptr(const int* idx)
  702. {
  703. int i, d = dims;
  704. uchar* p = data;
  705. CV_DbgAssert( d >= 1 && p );
  706. for( i = 0; i < d; i++ )
  707. {
  708. CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
  709. p += idx[i] * step.p[i];
  710. }
  711. return p;
  712. }
  713. inline
  714. const uchar* Mat::ptr(const int* idx) const
  715. {
  716. int i, d = dims;
  717. uchar* p = data;
  718. CV_DbgAssert( d >= 1 && p );
  719. for( i = 0; i < d; i++ )
  720. {
  721. CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
  722. p += idx[i] * step.p[i];
  723. }
  724. return p;
  725. }
  726. template<typename _Tp> inline
  727. _Tp* Mat::ptr(const int* idx)
  728. {
  729. int i, d = dims;
  730. uchar* p = data;
  731. CV_DbgAssert( d >= 1 && p );
  732. for( i = 0; i < d; i++ )
  733. {
  734. CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
  735. p += idx[i] * step.p[i];
  736. }
  737. return (_Tp*)p;
  738. }
  739. template<typename _Tp> inline
  740. const _Tp* Mat::ptr(const int* idx) const
  741. {
  742. int i, d = dims;
  743. uchar* p = data;
  744. CV_DbgAssert( d >= 1 && p );
  745. for( i = 0; i < d; i++ )
  746. {
  747. CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
  748. p += idx[i] * step.p[i];
  749. }
  750. return (const _Tp*)p;
  751. }
  752. template<typename _Tp> inline
  753. _Tp& Mat::at(int i0, int i1)
  754. {
  755. CV_DbgAssert(dims <= 2);
  756. CV_DbgAssert(data);
  757. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  758. CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
  759. CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
  760. return ((_Tp*)(data + step.p[0] * i0))[i1];
  761. }
  762. template<typename _Tp> inline
  763. const _Tp& Mat::at(int i0, int i1) const
  764. {
  765. CV_DbgAssert(dims <= 2);
  766. CV_DbgAssert(data);
  767. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  768. CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
  769. CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
  770. return ((const _Tp*)(data + step.p[0] * i0))[i1];
  771. }
  772. template<typename _Tp> inline
  773. _Tp& Mat::at(Point pt)
  774. {
  775. CV_DbgAssert(dims <= 2);
  776. CV_DbgAssert(data);
  777. CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
  778. CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
  779. CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
  780. return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
  781. }
  782. template<typename _Tp> inline
  783. const _Tp& Mat::at(Point pt) const
  784. {
  785. CV_DbgAssert(dims <= 2);
  786. CV_DbgAssert(data);
  787. CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
  788. CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
  789. CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
  790. return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
  791. }
  792. template<typename _Tp> inline
  793. _Tp& Mat::at(int i0)
  794. {
  795. CV_DbgAssert(dims <= 2);
  796. CV_DbgAssert(data);
  797. CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
  798. CV_DbgAssert(elemSize() == sizeof(_Tp));
  799. if( isContinuous() || size.p[0] == 1 )
  800. return ((_Tp*)data)[i0];
  801. if( size.p[1] == 1 )
  802. return *(_Tp*)(data + step.p[0] * i0);
  803. int i = i0 / cols, j = i0 - i * cols;
  804. return ((_Tp*)(data + step.p[0] * i))[j];
  805. }
  806. template<typename _Tp> inline
  807. const _Tp& Mat::at(int i0) const
  808. {
  809. CV_DbgAssert(dims <= 2);
  810. CV_DbgAssert(data);
  811. CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
  812. CV_DbgAssert(elemSize() == sizeof(_Tp));
  813. if( isContinuous() || size.p[0] == 1 )
  814. return ((const _Tp*)data)[i0];
  815. if( size.p[1] == 1 )
  816. return *(const _Tp*)(data + step.p[0] * i0);
  817. int i = i0 / cols, j = i0 - i * cols;
  818. return ((const _Tp*)(data + step.p[0] * i))[j];
  819. }
  820. template<typename _Tp> inline
  821. _Tp& Mat::at(int i0, int i1, int i2)
  822. {
  823. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  824. return *(_Tp*)ptr(i0, i1, i2);
  825. }
  826. template<typename _Tp> inline
  827. const _Tp& Mat::at(int i0, int i1, int i2) const
  828. {
  829. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  830. return *(const _Tp*)ptr(i0, i1, i2);
  831. }
  832. template<typename _Tp> inline
  833. _Tp& Mat::at(const int* idx)
  834. {
  835. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  836. return *(_Tp*)ptr(idx);
  837. }
  838. template<typename _Tp> inline
  839. const _Tp& Mat::at(const int* idx) const
  840. {
  841. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  842. return *(const _Tp*)ptr(idx);
  843. }
  844. template<typename _Tp, int n> inline
  845. _Tp& Mat::at(const Vec<int, n>& idx)
  846. {
  847. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  848. return *(_Tp*)ptr(idx.val);
  849. }
  850. template<typename _Tp, int n> inline
  851. const _Tp& Mat::at(const Vec<int, n>& idx) const
  852. {
  853. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  854. return *(const _Tp*)ptr(idx.val);
  855. }
  856. template<typename _Tp> inline
  857. MatConstIterator_<_Tp> Mat::begin() const
  858. {
  859. if (empty())
  860. return MatConstIterator_<_Tp>();
  861. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  862. return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
  863. }
  864. template<typename _Tp> inline
  865. MatConstIterator_<_Tp> Mat::end() const
  866. {
  867. if (empty())
  868. return MatConstIterator_<_Tp>();
  869. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  870. MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this);
  871. it += total();
  872. return it;
  873. }
  874. template<typename _Tp> inline
  875. MatIterator_<_Tp> Mat::begin()
  876. {
  877. if (empty())
  878. return MatIterator_<_Tp>();
  879. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  880. return MatIterator_<_Tp>((Mat_<_Tp>*)this);
  881. }
  882. template<typename _Tp> inline
  883. MatIterator_<_Tp> Mat::end()
  884. {
  885. if (empty())
  886. return MatIterator_<_Tp>();
  887. CV_DbgAssert( elemSize() == sizeof(_Tp) );
  888. MatIterator_<_Tp> it((Mat_<_Tp>*)this);
  889. it += total();
  890. return it;
  891. }
  892. template<typename _Tp, typename Functor> inline
  893. void Mat::forEach(const Functor& operation) {
  894. this->forEach_impl<_Tp>(operation);
  895. }
  896. template<typename _Tp, typename Functor> inline
  897. void Mat::forEach(const Functor& operation) const {
  898. // call as not const
  899. (const_cast<Mat*>(this))->forEach<_Tp>(operation);
  900. }
  901. template<typename _Tp> inline
  902. Mat::operator std::vector<_Tp>() const
  903. {
  904. std::vector<_Tp> v;
  905. copyTo(v);
  906. return v;
  907. }
  908. #ifdef CV_CXX_STD_ARRAY
  909. template<typename _Tp, std::size_t _Nm> inline
  910. Mat::operator std::array<_Tp, _Nm>() const
  911. {
  912. std::array<_Tp, _Nm> v;
  913. copyTo(v);
  914. return v;
  915. }
  916. #endif
  917. template<typename _Tp, int n> inline
  918. Mat::operator Vec<_Tp, n>() const
  919. {
  920. CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) &&
  921. rows + cols - 1 == n && channels() == 1 );
  922. if( isContinuous() && type() == traits::Type<_Tp>::value )
  923. return Vec<_Tp, n>((_Tp*)data);
  924. Vec<_Tp, n> v;
  925. Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val);
  926. convertTo(tmp, tmp.type());
  927. return v;
  928. }
  929. template<typename _Tp, int m, int n> inline
  930. Mat::operator Matx<_Tp, m, n>() const
  931. {
  932. CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 );
  933. if( isContinuous() && type() == traits::Type<_Tp>::value )
  934. return Matx<_Tp, m, n>((_Tp*)data);
  935. Matx<_Tp, m, n> mtx;
  936. Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val);
  937. convertTo(tmp, tmp.type());
  938. return mtx;
  939. }
  940. template<typename _Tp> inline
  941. void Mat::push_back(const _Tp& elem)
  942. {
  943. if( !data )
  944. {
  945. *this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone();
  946. return;
  947. }
  948. CV_Assert(traits::Type<_Tp>::value == type() && cols == 1
  949. /* && dims == 2 (cols == 1 implies dims == 2) */);
  950. const uchar* tmp = dataend + step[0];
  951. if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
  952. {
  953. *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem;
  954. dataend = tmp;
  955. }
  956. else
  957. push_back_(&elem);
  958. }
  959. template<typename _Tp> inline
  960. void Mat::push_back(const Mat_<_Tp>& m)
  961. {
  962. push_back((const Mat&)m);
  963. }
  964. template<> inline
  965. void Mat::push_back(const MatExpr& expr)
  966. {
  967. push_back(static_cast<Mat>(expr));
  968. }
  969. template<typename _Tp> inline
  970. void Mat::push_back(const std::vector<_Tp>& v)
  971. {
  972. push_back(Mat(v));
  973. }
  974. #ifdef CV_CXX_MOVE_SEMANTICS
  975. inline
  976. Mat::Mat(Mat&& m)
  977. : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
  978. datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator),
  979. u(m.u), size(&rows)
  980. {
  981. if (m.dims <= 2) // move new step/size info
  982. {
  983. step[0] = m.step[0];
  984. step[1] = m.step[1];
  985. }
  986. else
  987. {
  988. CV_DbgAssert(m.step.p != m.step.buf);
  989. step.p = m.step.p;
  990. size.p = m.size.p;
  991. m.step.p = m.step.buf;
  992. m.size.p = &m.rows;
  993. }
  994. m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
  995. m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL;
  996. m.allocator = NULL;
  997. m.u = NULL;
  998. }
  999. inline
  1000. Mat& Mat::operator = (Mat&& m)
  1001. {
  1002. if (this == &m)
  1003. return *this;
  1004. release();
  1005. flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data;
  1006. datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator;
  1007. u = m.u;
  1008. if (step.p != step.buf) // release self step/size
  1009. {
  1010. fastFree(step.p);
  1011. step.p = step.buf;
  1012. size.p = &rows;
  1013. }
  1014. if (m.dims <= 2) // move new step/size info
  1015. {
  1016. step[0] = m.step[0];
  1017. step[1] = m.step[1];
  1018. }
  1019. else
  1020. {
  1021. CV_DbgAssert(m.step.p != m.step.buf);
  1022. step.p = m.step.p;
  1023. size.p = m.size.p;
  1024. m.step.p = m.step.buf;
  1025. m.size.p = &m.rows;
  1026. }
  1027. m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
  1028. m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL;
  1029. m.allocator = NULL;
  1030. m.u = NULL;
  1031. return *this;
  1032. }
  1033. #endif
  1034. ///////////////////////////// MatSize ////////////////////////////
  1035. inline
  1036. MatSize::MatSize(int* _p) CV_NOEXCEPT
  1037. : p(_p) {}
  1038. inline
  1039. int MatSize::dims() const CV_NOEXCEPT
  1040. {
  1041. return (p - 1)[0];
  1042. }
  1043. inline
  1044. Size MatSize::operator()() const
  1045. {
  1046. CV_DbgAssert(dims() <= 2);
  1047. return Size(p[1], p[0]);
  1048. }
  1049. inline
  1050. const int& MatSize::operator[](int i) const
  1051. {
  1052. CV_DbgAssert(i < dims());
  1053. #ifdef __OPENCV_BUILD
  1054. CV_DbgAssert(i >= 0);
  1055. #endif
  1056. return p[i];
  1057. }
  1058. inline
  1059. int& MatSize::operator[](int i)
  1060. {
  1061. CV_DbgAssert(i < dims());
  1062. #ifdef __OPENCV_BUILD
  1063. CV_DbgAssert(i >= 0);
  1064. #endif
  1065. return p[i];
  1066. }
  1067. inline
  1068. MatSize::operator const int*() const CV_NOEXCEPT
  1069. {
  1070. return p;
  1071. }
  1072. inline
  1073. bool MatSize::operator != (const MatSize& sz) const CV_NOEXCEPT
  1074. {
  1075. return !(*this == sz);
  1076. }
  1077. ///////////////////////////// MatStep ////////////////////////////
  1078. inline
  1079. MatStep::MatStep() CV_NOEXCEPT
  1080. {
  1081. p = buf; p[0] = p[1] = 0;
  1082. }
  1083. inline
  1084. MatStep::MatStep(size_t s) CV_NOEXCEPT
  1085. {
  1086. p = buf; p[0] = s; p[1] = 0;
  1087. }
  1088. inline
  1089. const size_t& MatStep::operator[](int i) const CV_NOEXCEPT
  1090. {
  1091. return p[i];
  1092. }
  1093. inline
  1094. size_t& MatStep::operator[](int i) CV_NOEXCEPT
  1095. {
  1096. return p[i];
  1097. }
  1098. inline MatStep::operator size_t() const
  1099. {
  1100. CV_DbgAssert( p == buf );
  1101. return buf[0];
  1102. }
  1103. inline MatStep& MatStep::operator = (size_t s)
  1104. {
  1105. CV_DbgAssert( p == buf );
  1106. buf[0] = s;
  1107. return *this;
  1108. }
  1109. ////////////////////////////// Mat_<_Tp> ////////////////////////////
  1110. template<typename _Tp> inline
  1111. Mat_<_Tp>::Mat_() CV_NOEXCEPT
  1112. : Mat()
  1113. {
  1114. flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
  1115. }
  1116. template<typename _Tp> inline
  1117. Mat_<_Tp>::Mat_(int _rows, int _cols)
  1118. : Mat(_rows, _cols, traits::Type<_Tp>::value)
  1119. {
  1120. }
  1121. template<typename _Tp> inline
  1122. Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value)
  1123. : Mat(_rows, _cols, traits::Type<_Tp>::value)
  1124. {
  1125. *this = value;
  1126. }
  1127. template<typename _Tp> inline
  1128. Mat_<_Tp>::Mat_(Size _sz)
  1129. : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
  1130. {}
  1131. template<typename _Tp> inline
  1132. Mat_<_Tp>::Mat_(Size _sz, const _Tp& value)
  1133. : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
  1134. {
  1135. *this = value;
  1136. }
  1137. template<typename _Tp> inline
  1138. Mat_<_Tp>::Mat_(int _dims, const int* _sz)
  1139. : Mat(_dims, _sz, traits::Type<_Tp>::value)
  1140. {}
  1141. template<typename _Tp> inline
  1142. Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s)
  1143. : Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s))
  1144. {}
  1145. template<typename _Tp> inline
  1146. Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps)
  1147. : Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps)
  1148. {}
  1149. template<typename _Tp> inline
  1150. Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges)
  1151. : Mat(m, ranges)
  1152. {}
  1153. template<typename _Tp> inline
  1154. Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const std::vector<Range>& ranges)
  1155. : Mat(m, ranges)
  1156. {}
  1157. template<typename _Tp> inline
  1158. Mat_<_Tp>::Mat_(const Mat& m)
  1159. : Mat()
  1160. {
  1161. flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
  1162. *this = m;
  1163. }
  1164. template<typename _Tp> inline
  1165. Mat_<_Tp>::Mat_(const Mat_& m)
  1166. : Mat(m)
  1167. {}
  1168. template<typename _Tp> inline
  1169. Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps)
  1170. : Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps)
  1171. {}
  1172. template<typename _Tp> inline
  1173. Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange)
  1174. : Mat(m, _rowRange, _colRange)
  1175. {}
  1176. template<typename _Tp> inline
  1177. Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
  1178. : Mat(m, roi)
  1179. {}
  1180. template<typename _Tp> template<int n> inline
  1181. Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData)
  1182. : Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec)
  1183. {
  1184. CV_Assert(n%DataType<_Tp>::channels == 0);
  1185. if( copyData )
  1186. *this = clone();
  1187. }
  1188. template<typename _Tp> template<int m, int n> inline
  1189. Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool copyData)
  1190. : Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M)
  1191. {
  1192. CV_Assert(n % DataType<_Tp>::channels == 0);
  1193. if( copyData )
  1194. *this = clone();
  1195. }
  1196. template<typename _Tp> inline
  1197. Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
  1198. : Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
  1199. {
  1200. CV_Assert(2 % DataType<_Tp>::channels == 0);
  1201. if( copyData )
  1202. *this = clone();
  1203. }
  1204. template<typename _Tp> inline
  1205. Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
  1206. : Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
  1207. {
  1208. CV_Assert(3 % DataType<_Tp>::channels == 0);
  1209. if( copyData )
  1210. *this = clone();
  1211. }
  1212. template<typename _Tp> inline
  1213. Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer)
  1214. : Mat(commaInitializer)
  1215. {}
  1216. template<typename _Tp> inline
  1217. Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData)
  1218. : Mat(vec, copyData)
  1219. {}
  1220. #ifdef CV_CXX11
  1221. template<typename _Tp> inline
  1222. Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list)
  1223. : Mat(list)
  1224. {}
  1225. template<typename _Tp> inline
  1226. Mat_<_Tp>::Mat_(const std::initializer_list<int> sizes, std::initializer_list<_Tp> list)
  1227. : Mat(sizes, list)
  1228. {}
  1229. #endif
  1230. #ifdef CV_CXX_STD_ARRAY
  1231. template<typename _Tp> template<std::size_t _Nm> inline
  1232. Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData)
  1233. : Mat(arr, copyData)
  1234. {}
  1235. #endif
  1236. template<typename _Tp> inline
  1237. Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
  1238. {
  1239. if (m.empty())
  1240. {
  1241. release();
  1242. return *this;
  1243. }
  1244. if( traits::Type<_Tp>::value == m.type() )
  1245. {
  1246. Mat::operator = (m);
  1247. return *this;
  1248. }
  1249. if( traits::Depth<_Tp>::value == m.depth() )
  1250. {
  1251. return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0));
  1252. }
  1253. CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty());
  1254. m.convertTo(*this, type());
  1255. return *this;
  1256. }
  1257. template<typename _Tp> inline
  1258. Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m)
  1259. {
  1260. Mat::operator=(m);
  1261. return *this;
  1262. }
  1263. template<typename _Tp> inline
  1264. Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s)
  1265. {
  1266. typedef typename DataType<_Tp>::vec_type VT;
  1267. Mat::operator=(Scalar((const VT&)s));
  1268. return *this;
  1269. }
  1270. template<typename _Tp> inline
  1271. void Mat_<_Tp>::create(int _rows, int _cols)
  1272. {
  1273. Mat::create(_rows, _cols, traits::Type<_Tp>::value);
  1274. }
  1275. template<typename _Tp> inline
  1276. void Mat_<_Tp>::create(Size _sz)
  1277. {
  1278. Mat::create(_sz, traits::Type<_Tp>::value);
  1279. }
  1280. template<typename _Tp> inline
  1281. void Mat_<_Tp>::create(int _dims, const int* _sz)
  1282. {
  1283. Mat::create(_dims, _sz, traits::Type<_Tp>::value);
  1284. }
  1285. template<typename _Tp> inline
  1286. void Mat_<_Tp>::release()
  1287. {
  1288. Mat::release();
  1289. flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
  1290. }
  1291. template<typename _Tp> inline
  1292. Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const
  1293. {
  1294. return Mat_<_Tp>(Mat::cross(m));
  1295. }
  1296. template<typename _Tp> template<typename T2> inline
  1297. Mat_<_Tp>::operator Mat_<T2>() const
  1298. {
  1299. return Mat_<T2>(static_cast<const Mat&>(*this));
  1300. }
  1301. template<typename _Tp> inline
  1302. Mat_<_Tp> Mat_<_Tp>::row(int y) const
  1303. {
  1304. return Mat_(*this, Range(y, y+1), Range::all());
  1305. }
  1306. template<typename _Tp> inline
  1307. Mat_<_Tp> Mat_<_Tp>::col(int x) const
  1308. {
  1309. return Mat_(*this, Range::all(), Range(x, x+1));
  1310. }
  1311. template<typename _Tp> inline
  1312. Mat_<_Tp> Mat_<_Tp>::diag(int d) const
  1313. {
  1314. return Mat_(Mat::diag(d));
  1315. }
  1316. template<typename _Tp> inline
  1317. Mat_<_Tp> Mat_<_Tp>::clone() const
  1318. {
  1319. return Mat_(Mat::clone());
  1320. }
  1321. template<typename _Tp> inline
  1322. size_t Mat_<_Tp>::elemSize() const
  1323. {
  1324. CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) );
  1325. return sizeof(_Tp);
  1326. }
  1327. template<typename _Tp> inline
  1328. size_t Mat_<_Tp>::elemSize1() const
  1329. {
  1330. CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp) / DataType<_Tp>::channels );
  1331. return sizeof(_Tp) / DataType<_Tp>::channels;
  1332. }
  1333. template<typename _Tp> inline
  1334. int Mat_<_Tp>::type() const
  1335. {
  1336. CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value );
  1337. return traits::Type<_Tp>::value;
  1338. }
  1339. template<typename _Tp> inline
  1340. int Mat_<_Tp>::depth() const
  1341. {
  1342. CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value );
  1343. return traits::Depth<_Tp>::value;
  1344. }
  1345. template<typename _Tp> inline
  1346. int Mat_<_Tp>::channels() const
  1347. {
  1348. CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels );
  1349. return DataType<_Tp>::channels;
  1350. }
  1351. template<typename _Tp> inline
  1352. size_t Mat_<_Tp>::stepT(int i) const
  1353. {
  1354. return step.p[i] / elemSize();
  1355. }
  1356. template<typename _Tp> inline
  1357. size_t Mat_<_Tp>::step1(int i) const
  1358. {
  1359. return step.p[i] / elemSize1();
  1360. }
  1361. template<typename _Tp> inline
  1362. Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
  1363. {
  1364. return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright));
  1365. }
  1366. template<typename _Tp> inline
  1367. Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const
  1368. {
  1369. return Mat_<_Tp>(*this, _rowRange, _colRange);
  1370. }
  1371. template<typename _Tp> inline
  1372. Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const
  1373. {
  1374. return Mat_<_Tp>(*this, roi);
  1375. }
  1376. template<typename _Tp> inline
  1377. Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const
  1378. {
  1379. return Mat_<_Tp>(*this, ranges);
  1380. }
  1381. template<typename _Tp> inline
  1382. Mat_<_Tp> Mat_<_Tp>::operator()(const std::vector<Range>& ranges) const
  1383. {
  1384. return Mat_<_Tp>(*this, ranges);
  1385. }
  1386. template<typename _Tp> inline
  1387. _Tp* Mat_<_Tp>::operator [](int y)
  1388. {
  1389. CV_DbgAssert( 0 <= y && y < size.p[0] );
  1390. return (_Tp*)(data + y*step.p[0]);
  1391. }
  1392. template<typename _Tp> inline
  1393. const _Tp* Mat_<_Tp>::operator [](int y) const
  1394. {
  1395. CV_DbgAssert( 0 <= y && y < size.p[0] );
  1396. return (const _Tp*)(data + y*step.p[0]);
  1397. }
  1398. template<typename _Tp> inline
  1399. _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
  1400. {
  1401. CV_DbgAssert(dims <= 2);
  1402. CV_DbgAssert(data);
  1403. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  1404. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  1405. CV_DbgAssert(type() == traits::Type<_Tp>::value);
  1406. return ((_Tp*)(data + step.p[0] * i0))[i1];
  1407. }
  1408. template<typename _Tp> inline
  1409. const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
  1410. {
  1411. CV_DbgAssert(dims <= 2);
  1412. CV_DbgAssert(data);
  1413. CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
  1414. CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
  1415. CV_DbgAssert(type() == traits::Type<_Tp>::value);
  1416. return ((const _Tp*)(data + step.p[0] * i0))[i1];
  1417. }
  1418. template<typename _Tp> inline
  1419. _Tp& Mat_<_Tp>::operator ()(Point pt)
  1420. {
  1421. CV_DbgAssert(dims <= 2);
  1422. CV_DbgAssert(data);
  1423. CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
  1424. CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
  1425. CV_DbgAssert(type() == traits::Type<_Tp>::value);
  1426. return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
  1427. }
  1428. template<typename _Tp> inline
  1429. const _Tp& Mat_<_Tp>::operator ()(Point pt) const
  1430. {
  1431. CV_DbgAssert(dims <= 2);
  1432. CV_DbgAssert(data);
  1433. CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
  1434. CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
  1435. CV_DbgAssert(type() == traits::Type<_Tp>::value);
  1436. return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
  1437. }
  1438. template<typename _Tp> inline
  1439. _Tp& Mat_<_Tp>::operator ()(const int* idx)
  1440. {
  1441. return Mat::at<_Tp>(idx);
  1442. }
  1443. template<typename _Tp> inline
  1444. const _Tp& Mat_<_Tp>::operator ()(const int* idx) const
  1445. {
  1446. return Mat::at<_Tp>(idx);
  1447. }
  1448. template<typename _Tp> template<int n> inline
  1449. _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx)
  1450. {
  1451. return Mat::at<_Tp>(idx);
  1452. }
  1453. template<typename _Tp> template<int n> inline
  1454. const _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) const
  1455. {
  1456. return Mat::at<_Tp>(idx);
  1457. }
  1458. template<typename _Tp> inline
  1459. _Tp& Mat_<_Tp>::operator ()(int i0)
  1460. {
  1461. return this->at<_Tp>(i0);
  1462. }
  1463. template<typename _Tp> inline
  1464. const _Tp& Mat_<_Tp>::operator ()(int i0) const
  1465. {
  1466. return this->at<_Tp>(i0);
  1467. }
  1468. template<typename _Tp> inline
  1469. _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2)
  1470. {
  1471. return this->at<_Tp>(i0, i1, i2);
  1472. }
  1473. template<typename _Tp> inline
  1474. const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const
  1475. {
  1476. return this->at<_Tp>(i0, i1, i2);
  1477. }
  1478. template<typename _Tp> inline
  1479. Mat_<_Tp>::operator std::vector<_Tp>() const
  1480. {
  1481. std::vector<_Tp> v;
  1482. copyTo(v);
  1483. return v;
  1484. }
  1485. #ifdef CV_CXX_STD_ARRAY
  1486. template<typename _Tp> template<std::size_t _Nm> inline
  1487. Mat_<_Tp>::operator std::array<_Tp, _Nm>() const
  1488. {
  1489. std::array<_Tp, _Nm> a;
  1490. copyTo(a);
  1491. return a;
  1492. }
  1493. #endif
  1494. template<typename _Tp> template<int n> inline
  1495. Mat_<_Tp>::operator Vec<typename DataType<_Tp>::channel_type, n>() const
  1496. {
  1497. CV_Assert(n % DataType<_Tp>::channels == 0);
  1498. #if defined _MSC_VER
  1499. const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround)
  1500. return pMat->operator Vec<typename DataType<_Tp>::channel_type, n>();
  1501. #else
  1502. return this->Mat::operator Vec<typename DataType<_Tp>::channel_type, n>();
  1503. #endif
  1504. }
  1505. template<typename _Tp> template<int m, int n> inline
  1506. Mat_<_Tp>::operator Matx<typename DataType<_Tp>::channel_type, m, n>() const
  1507. {
  1508. CV_Assert(n % DataType<_Tp>::channels == 0);
  1509. #if defined _MSC_VER
  1510. const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround)
  1511. Matx<typename DataType<_Tp>::channel_type, m, n> res = pMat->operator Matx<typename DataType<_Tp>::channel_type, m, n>();
  1512. return res;
  1513. #else
  1514. Matx<typename DataType<_Tp>::channel_type, m, n> res = this->Mat::operator Matx<typename DataType<_Tp>::channel_type, m, n>();
  1515. return res;
  1516. #endif
  1517. }
  1518. template<typename _Tp> inline
  1519. MatConstIterator_<_Tp> Mat_<_Tp>::begin() const
  1520. {
  1521. return Mat::begin<_Tp>();
  1522. }
  1523. template<typename _Tp> inline
  1524. MatConstIterator_<_Tp> Mat_<_Tp>::end() const
  1525. {
  1526. return Mat::end<_Tp>();
  1527. }
  1528. template<typename _Tp> inline
  1529. MatIterator_<_Tp> Mat_<_Tp>::begin()
  1530. {
  1531. return Mat::begin<_Tp>();
  1532. }
  1533. template<typename _Tp> inline
  1534. MatIterator_<_Tp> Mat_<_Tp>::end()
  1535. {
  1536. return Mat::end<_Tp>();
  1537. }
  1538. template<typename _Tp> template<typename Functor> inline
  1539. void Mat_<_Tp>::forEach(const Functor& operation) {
  1540. Mat::forEach<_Tp, Functor>(operation);
  1541. }
  1542. template<typename _Tp> template<typename Functor> inline
  1543. void Mat_<_Tp>::forEach(const Functor& operation) const {
  1544. Mat::forEach<_Tp, Functor>(operation);
  1545. }
  1546. #ifdef CV_CXX_MOVE_SEMANTICS
  1547. template<typename _Tp> inline
  1548. Mat_<_Tp>::Mat_(Mat_&& m)
  1549. : Mat(std::move(m))
  1550. {
  1551. }
  1552. template<typename _Tp> inline
  1553. Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m)
  1554. {
  1555. Mat::operator = (std::move(m));
  1556. return *this;
  1557. }
  1558. template<typename _Tp> inline
  1559. Mat_<_Tp>::Mat_(Mat&& m)
  1560. : Mat()
  1561. {
  1562. flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
  1563. *this = std::move(m);
  1564. }
  1565. template<typename _Tp> inline
  1566. Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m)
  1567. {
  1568. if (m.empty())
  1569. {
  1570. release();
  1571. return *this;
  1572. }
  1573. if( traits::Type<_Tp>::value == m.type() )
  1574. {
  1575. Mat::operator = ((Mat&&)m);
  1576. return *this;
  1577. }
  1578. if( traits::Depth<_Tp>::value == m.depth() )
  1579. {
  1580. Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0));
  1581. return *this;
  1582. }
  1583. CV_DbgAssert(DataType<_Tp>::channels == m.channels());
  1584. m.convertTo(*this, type());
  1585. return *this;
  1586. }
  1587. template<typename _Tp> inline
  1588. Mat_<_Tp>::Mat_(MatExpr&& e)
  1589. : Mat()
  1590. {
  1591. flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
  1592. *this = Mat(e);
  1593. }
  1594. #endif
  1595. ///////////////////////////// SparseMat /////////////////////////////
  1596. inline
  1597. SparseMat SparseMat::clone() const
  1598. {
  1599. SparseMat temp;
  1600. this->copyTo(temp);
  1601. return temp;
  1602. }
  1603. inline
  1604. size_t SparseMat::elemSize() const
  1605. {
  1606. return CV_ELEM_SIZE(flags);
  1607. }
  1608. inline
  1609. size_t SparseMat::elemSize1() const
  1610. {
  1611. return CV_ELEM_SIZE1(flags);
  1612. }
  1613. inline
  1614. int SparseMat::type() const
  1615. {
  1616. return CV_MAT_TYPE(flags);
  1617. }
  1618. inline
  1619. int SparseMat::depth() const
  1620. {
  1621. return CV_MAT_DEPTH(flags);
  1622. }
  1623. inline
  1624. int SparseMat::channels() const
  1625. {
  1626. return CV_MAT_CN(flags);
  1627. }
  1628. inline
  1629. const int* SparseMat::size() const
  1630. {
  1631. return hdr ? hdr->size : 0;
  1632. }
  1633. inline
  1634. int SparseMat::size(int i) const
  1635. {
  1636. if( hdr )
  1637. {
  1638. CV_DbgAssert((unsigned)i < (unsigned)hdr->dims);
  1639. return hdr->size[i];
  1640. }
  1641. return 0;
  1642. }
  1643. inline
  1644. int SparseMat::dims() const
  1645. {
  1646. return hdr ? hdr->dims : 0;
  1647. }
  1648. inline
  1649. size_t SparseMat::nzcount() const
  1650. {
  1651. return hdr ? hdr->nodeCount : 0;
  1652. }
  1653. template<typename _Tp> inline
  1654. _Tp& SparseMat::ref(int i0, size_t* hashval)
  1655. {
  1656. return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval);
  1657. }
  1658. template<typename _Tp> inline
  1659. _Tp& SparseMat::ref(int i0, int i1, size_t* hashval)
  1660. {
  1661. return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval);
  1662. }
  1663. template<typename _Tp> inline
  1664. _Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval)
  1665. {
  1666. return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval);
  1667. }
  1668. template<typename _Tp> inline
  1669. _Tp& SparseMat::ref(const int* idx, size_t* hashval)
  1670. {
  1671. return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval);
  1672. }
  1673. template<typename _Tp> inline
  1674. _Tp SparseMat::value(int i0, size_t* hashval) const
  1675. {
  1676. const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
  1677. return p ? *p : _Tp();
  1678. }
  1679. template<typename _Tp> inline
  1680. _Tp SparseMat::value(int i0, int i1, size_t* hashval) const
  1681. {
  1682. const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
  1683. return p ? *p : _Tp();
  1684. }
  1685. template<typename _Tp> inline
  1686. _Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const
  1687. {
  1688. const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
  1689. return p ? *p : _Tp();
  1690. }
  1691. template<typename _Tp> inline
  1692. _Tp SparseMat::value(const int* idx, size_t* hashval) const
  1693. {
  1694. const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
  1695. return p ? *p : _Tp();
  1696. }
  1697. template<typename _Tp> inline
  1698. const _Tp* SparseMat::find(int i0, size_t* hashval) const
  1699. {
  1700. return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
  1701. }
  1702. template<typename _Tp> inline
  1703. const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const
  1704. {
  1705. return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
  1706. }
  1707. template<typename _Tp> inline
  1708. const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const
  1709. {
  1710. return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
  1711. }
  1712. template<typename _Tp> inline
  1713. const _Tp* SparseMat::find(const int* idx, size_t* hashval) const
  1714. {
  1715. return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
  1716. }
  1717. template<typename _Tp> inline
  1718. _Tp& SparseMat::value(Node* n)
  1719. {
  1720. return *(_Tp*)((uchar*)n + hdr->valueOffset);
  1721. }
  1722. template<typename _Tp> inline
  1723. const _Tp& SparseMat::value(const Node* n) const
  1724. {
  1725. return *(const _Tp*)((const uchar*)n + hdr->valueOffset);
  1726. }
  1727. inline
  1728. SparseMat::Node* SparseMat::node(size_t nidx)
  1729. {
  1730. return (Node*)(void*)&hdr->pool[nidx];
  1731. }
  1732. inline
  1733. const SparseMat::Node* SparseMat::node(size_t nidx) const
  1734. {
  1735. return (const Node*)(const void*)&hdr->pool[nidx];
  1736. }
  1737. inline
  1738. SparseMatIterator SparseMat::begin()
  1739. {
  1740. return SparseMatIterator(this);
  1741. }
  1742. inline
  1743. SparseMatConstIterator SparseMat::begin() const
  1744. {
  1745. return SparseMatConstIterator(this);
  1746. }
  1747. inline
  1748. SparseMatIterator SparseMat::end()
  1749. {
  1750. SparseMatIterator it(this);
  1751. it.seekEnd();
  1752. return it;
  1753. }
  1754. inline
  1755. SparseMatConstIterator SparseMat::end() const
  1756. {
  1757. SparseMatConstIterator it(this);
  1758. it.seekEnd();
  1759. return it;
  1760. }
  1761. template<typename _Tp> inline
  1762. SparseMatIterator_<_Tp> SparseMat::begin()
  1763. {
  1764. return SparseMatIterator_<_Tp>(this);
  1765. }
  1766. template<typename _Tp> inline
  1767. SparseMatConstIterator_<_Tp> SparseMat::begin() const
  1768. {
  1769. return SparseMatConstIterator_<_Tp>(this);
  1770. }
  1771. template<typename _Tp> inline
  1772. SparseMatIterator_<_Tp> SparseMat::end()
  1773. {
  1774. SparseMatIterator_<_Tp> it(this);
  1775. it.seekEnd();
  1776. return it;
  1777. }
  1778. template<typename _Tp> inline
  1779. SparseMatConstIterator_<_Tp> SparseMat::end() const
  1780. {
  1781. SparseMatConstIterator_<_Tp> it(this);
  1782. it.seekEnd();
  1783. return it;
  1784. }
  1785. ///////////////////////////// SparseMat_ ////////////////////////////
  1786. template<typename _Tp> inline
  1787. SparseMat_<_Tp>::SparseMat_()
  1788. {
  1789. flags = MAGIC_VAL | traits::Type<_Tp>::value;
  1790. }
  1791. template<typename _Tp> inline
  1792. SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes)
  1793. : SparseMat(_dims, _sizes, traits::Type<_Tp>::value)
  1794. {}
  1795. template<typename _Tp> inline
  1796. SparseMat_<_Tp>::SparseMat_(const SparseMat& m)
  1797. {
  1798. if( m.type() == traits::Type<_Tp>::value )
  1799. *this = (const SparseMat_<_Tp>&)m;
  1800. else
  1801. m.convertTo(*this, traits::Type<_Tp>::value);
  1802. }
  1803. template<typename _Tp> inline
  1804. SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m)
  1805. {
  1806. this->flags = m.flags;
  1807. this->hdr = m.hdr;
  1808. if( this->hdr )
  1809. CV_XADD(&this->hdr->refcount, 1);
  1810. }
  1811. template<typename _Tp> inline
  1812. SparseMat_<_Tp>::SparseMat_(const Mat& m)
  1813. {
  1814. SparseMat sm(m);
  1815. *this = sm;
  1816. }
  1817. template<typename _Tp> inline
  1818. SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m)
  1819. {
  1820. if( this != &m )
  1821. {
  1822. if( m.hdr ) CV_XADD(&m.hdr->refcount, 1);
  1823. release();
  1824. flags = m.flags;
  1825. hdr = m.hdr;
  1826. }
  1827. return *this;
  1828. }
  1829. template<typename _Tp> inline
  1830. SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m)
  1831. {
  1832. if( m.type() == traits::Type<_Tp>::value )
  1833. return (*this = (const SparseMat_<_Tp>&)m);
  1834. m.convertTo(*this, traits::Type<_Tp>::value);
  1835. return *this;
  1836. }
  1837. template<typename _Tp> inline
  1838. SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const Mat& m)
  1839. {
  1840. return (*this = SparseMat(m));
  1841. }
  1842. template<typename _Tp> inline
  1843. SparseMat_<_Tp> SparseMat_<_Tp>::clone() const
  1844. {
  1845. SparseMat_<_Tp> m;
  1846. this->copyTo(m);
  1847. return m;
  1848. }
  1849. template<typename _Tp> inline
  1850. void SparseMat_<_Tp>::create(int _dims, const int* _sizes)
  1851. {
  1852. SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value);
  1853. }
  1854. template<typename _Tp> inline
  1855. int SparseMat_<_Tp>::type() const
  1856. {
  1857. return traits::Type<_Tp>::value;
  1858. }
  1859. template<typename _Tp> inline
  1860. int SparseMat_<_Tp>::depth() const
  1861. {
  1862. return traits::Depth<_Tp>::value;
  1863. }
  1864. template<typename _Tp> inline
  1865. int SparseMat_<_Tp>::channels() const
  1866. {
  1867. return DataType<_Tp>::channels;
  1868. }
  1869. template<typename _Tp> inline
  1870. _Tp& SparseMat_<_Tp>::ref(int i0, size_t* hashval)
  1871. {
  1872. return SparseMat::ref<_Tp>(i0, hashval);
  1873. }
  1874. template<typename _Tp> inline
  1875. _Tp SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const
  1876. {
  1877. return SparseMat::value<_Tp>(i0, hashval);
  1878. }
  1879. template<typename _Tp> inline
  1880. _Tp& SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval)
  1881. {
  1882. return SparseMat::ref<_Tp>(i0, i1, hashval);
  1883. }
  1884. template<typename _Tp> inline
  1885. _Tp SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const
  1886. {
  1887. return SparseMat::value<_Tp>(i0, i1, hashval);
  1888. }
  1889. template<typename _Tp> inline
  1890. _Tp& SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval)
  1891. {
  1892. return SparseMat::ref<_Tp>(i0, i1, i2, hashval);
  1893. }
  1894. template<typename _Tp> inline
  1895. _Tp SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const
  1896. {
  1897. return SparseMat::value<_Tp>(i0, i1, i2, hashval);
  1898. }
  1899. template<typename _Tp> inline
  1900. _Tp& SparseMat_<_Tp>::ref(const int* idx, size_t* hashval)
  1901. {
  1902. return SparseMat::ref<_Tp>(idx, hashval);
  1903. }
  1904. template<typename _Tp> inline
  1905. _Tp SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const
  1906. {
  1907. return SparseMat::value<_Tp>(idx, hashval);
  1908. }
  1909. template<typename _Tp> inline
  1910. SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin()
  1911. {
  1912. return SparseMatIterator_<_Tp>(this);
  1913. }
  1914. template<typename _Tp> inline
  1915. SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const
  1916. {
  1917. return SparseMatConstIterator_<_Tp>(this);
  1918. }
  1919. template<typename _Tp> inline
  1920. SparseMatIterator_<_Tp> SparseMat_<_Tp>::end()
  1921. {
  1922. SparseMatIterator_<_Tp> it(this);
  1923. it.seekEnd();
  1924. return it;
  1925. }
  1926. template<typename _Tp> inline
  1927. SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const
  1928. {
  1929. SparseMatConstIterator_<_Tp> it(this);
  1930. it.seekEnd();
  1931. return it;
  1932. }
  1933. ////////////////////////// MatConstIterator /////////////////////////
  1934. inline
  1935. MatConstIterator::MatConstIterator()
  1936. : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0)
  1937. {}
  1938. inline
  1939. MatConstIterator::MatConstIterator(const Mat* _m)
  1940. : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
  1941. {
  1942. if( m && m->isContinuous() )
  1943. {
  1944. CV_Assert(!m->empty());
  1945. sliceStart = m->ptr();
  1946. sliceEnd = sliceStart + m->total()*elemSize;
  1947. }
  1948. seek((const int*)0);
  1949. }
  1950. inline
  1951. MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col)
  1952. : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
  1953. {
  1954. CV_Assert(m && m->dims <= 2);
  1955. if( m->isContinuous() )
  1956. {
  1957. CV_Assert(!m->empty());
  1958. sliceStart = m->ptr();
  1959. sliceEnd = sliceStart + m->total()*elemSize;
  1960. }
  1961. int idx[] = {_row, _col};
  1962. seek(idx);
  1963. }
  1964. inline
  1965. MatConstIterator::MatConstIterator(const Mat* _m, Point _pt)
  1966. : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
  1967. {
  1968. CV_Assert(m && m->dims <= 2);
  1969. if( m->isContinuous() )
  1970. {
  1971. CV_Assert(!m->empty());
  1972. sliceStart = m->ptr();
  1973. sliceEnd = sliceStart + m->total()*elemSize;
  1974. }
  1975. int idx[] = {_pt.y, _pt.x};
  1976. seek(idx);
  1977. }
  1978. inline
  1979. MatConstIterator::MatConstIterator(const MatConstIterator& it)
  1980. : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd)
  1981. {}
  1982. inline
  1983. MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it )
  1984. {
  1985. m = it.m; elemSize = it.elemSize; ptr = it.ptr;
  1986. sliceStart = it.sliceStart; sliceEnd = it.sliceEnd;
  1987. return *this;
  1988. }
  1989. inline
  1990. const uchar* MatConstIterator::operator *() const
  1991. {
  1992. return ptr;
  1993. }
  1994. inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs)
  1995. {
  1996. if( !m || ofs == 0 )
  1997. return *this;
  1998. ptrdiff_t ofsb = ofs*elemSize;
  1999. ptr += ofsb;
  2000. if( ptr < sliceStart || sliceEnd <= ptr )
  2001. {
  2002. ptr -= ofsb;
  2003. seek(ofs, true);
  2004. }
  2005. return *this;
  2006. }
  2007. inline
  2008. MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs)
  2009. {
  2010. return (*this += -ofs);
  2011. }
  2012. inline
  2013. MatConstIterator& MatConstIterator::operator --()
  2014. {
  2015. if( m && (ptr -= elemSize) < sliceStart )
  2016. {
  2017. ptr += elemSize;
  2018. seek(-1, true);
  2019. }
  2020. return *this;
  2021. }
  2022. inline
  2023. MatConstIterator MatConstIterator::operator --(int)
  2024. {
  2025. MatConstIterator b = *this;
  2026. *this += -1;
  2027. return b;
  2028. }
  2029. inline
  2030. MatConstIterator& MatConstIterator::operator ++()
  2031. {
  2032. if( m && (ptr += elemSize) >= sliceEnd )
  2033. {
  2034. ptr -= elemSize;
  2035. seek(1, true);
  2036. }
  2037. return *this;
  2038. }
  2039. inline MatConstIterator MatConstIterator::operator ++(int)
  2040. {
  2041. MatConstIterator b = *this;
  2042. *this += 1;
  2043. return b;
  2044. }
  2045. static inline
  2046. bool operator == (const MatConstIterator& a, const MatConstIterator& b)
  2047. {
  2048. return a.m == b.m && a.ptr == b.ptr;
  2049. }
  2050. static inline
  2051. bool operator != (const MatConstIterator& a, const MatConstIterator& b)
  2052. {
  2053. return !(a == b);
  2054. }
  2055. static inline
  2056. bool operator < (const MatConstIterator& a, const MatConstIterator& b)
  2057. {
  2058. return a.ptr < b.ptr;
  2059. }
  2060. static inline
  2061. bool operator > (const MatConstIterator& a, const MatConstIterator& b)
  2062. {
  2063. return a.ptr > b.ptr;
  2064. }
  2065. static inline
  2066. bool operator <= (const MatConstIterator& a, const MatConstIterator& b)
  2067. {
  2068. return a.ptr <= b.ptr;
  2069. }
  2070. static inline
  2071. bool operator >= (const MatConstIterator& a, const MatConstIterator& b)
  2072. {
  2073. return a.ptr >= b.ptr;
  2074. }
  2075. static inline
  2076. ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a)
  2077. {
  2078. if( a.m != b.m )
  2079. return ((size_t)(-1) >> 1);
  2080. if( a.sliceEnd == b.sliceEnd )
  2081. return (b.ptr - a.ptr)/static_cast<ptrdiff_t>(b.elemSize);
  2082. return b.lpos() - a.lpos();
  2083. }
  2084. static inline
  2085. MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs)
  2086. {
  2087. MatConstIterator b = a;
  2088. return b += ofs;
  2089. }
  2090. static inline
  2091. MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a)
  2092. {
  2093. MatConstIterator b = a;
  2094. return b += ofs;
  2095. }
  2096. static inline
  2097. MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs)
  2098. {
  2099. MatConstIterator b = a;
  2100. return b += -ofs;
  2101. }
  2102. inline
  2103. const uchar* MatConstIterator::operator [](ptrdiff_t i) const
  2104. {
  2105. return *(*this + i);
  2106. }
  2107. ///////////////////////// MatConstIterator_ /////////////////////////
  2108. template<typename _Tp> inline
  2109. MatConstIterator_<_Tp>::MatConstIterator_()
  2110. {}
  2111. template<typename _Tp> inline
  2112. MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m)
  2113. : MatConstIterator(_m)
  2114. {}
  2115. template<typename _Tp> inline
  2116. MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col)
  2117. : MatConstIterator(_m, _row, _col)
  2118. {}
  2119. template<typename _Tp> inline
  2120. MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, Point _pt)
  2121. : MatConstIterator(_m, _pt)
  2122. {}
  2123. template<typename _Tp> inline
  2124. MatConstIterator_<_Tp>::MatConstIterator_(const MatConstIterator_& it)
  2125. : MatConstIterator(it)
  2126. {}
  2127. template<typename _Tp> inline
  2128. MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it )
  2129. {
  2130. MatConstIterator::operator = (it);
  2131. return *this;
  2132. }
  2133. template<typename _Tp> inline
  2134. const _Tp& MatConstIterator_<_Tp>::operator *() const
  2135. {
  2136. return *(_Tp*)(this->ptr);
  2137. }
  2138. template<typename _Tp> inline
  2139. MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs)
  2140. {
  2141. MatConstIterator::operator += (ofs);
  2142. return *this;
  2143. }
  2144. template<typename _Tp> inline
  2145. MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs)
  2146. {
  2147. return (*this += -ofs);
  2148. }
  2149. template<typename _Tp> inline
  2150. MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --()
  2151. {
  2152. MatConstIterator::operator --();
  2153. return *this;
  2154. }
  2155. template<typename _Tp> inline
  2156. MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int)
  2157. {
  2158. MatConstIterator_ b = *this;
  2159. MatConstIterator::operator --();
  2160. return b;
  2161. }
  2162. template<typename _Tp> inline
  2163. MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++()
  2164. {
  2165. MatConstIterator::operator ++();
  2166. return *this;
  2167. }
  2168. template<typename _Tp> inline
  2169. MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int)
  2170. {
  2171. MatConstIterator_ b = *this;
  2172. MatConstIterator::operator ++();
  2173. return b;
  2174. }
  2175. template<typename _Tp> inline
  2176. Point MatConstIterator_<_Tp>::pos() const
  2177. {
  2178. if( !m )
  2179. return Point();
  2180. CV_DbgAssert( m->dims <= 2 );
  2181. if( m->isContinuous() )
  2182. {
  2183. ptrdiff_t ofs = (const _Tp*)ptr - (const _Tp*)m->data;
  2184. int y = (int)(ofs / m->cols);
  2185. int x = (int)(ofs - (ptrdiff_t)y * m->cols);
  2186. return Point(x, y);
  2187. }
  2188. else
  2189. {
  2190. ptrdiff_t ofs = (uchar*)ptr - m->data;
  2191. int y = (int)(ofs / m->step);
  2192. int x = (int)((ofs - y * m->step)/sizeof(_Tp));
  2193. return Point(x, y);
  2194. }
  2195. }
  2196. template<typename _Tp> static inline
  2197. bool operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
  2198. {
  2199. return a.m == b.m && a.ptr == b.ptr;
  2200. }
  2201. template<typename _Tp> static inline
  2202. bool operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
  2203. {
  2204. return a.m != b.m || a.ptr != b.ptr;
  2205. }
  2206. template<typename _Tp> static inline
  2207. MatConstIterator_<_Tp> operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
  2208. {
  2209. MatConstIterator t = (const MatConstIterator&)a + ofs;
  2210. return (MatConstIterator_<_Tp>&)t;
  2211. }
  2212. template<typename _Tp> static inline
  2213. MatConstIterator_<_Tp> operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a)
  2214. {
  2215. MatConstIterator t = (const MatConstIterator&)a + ofs;
  2216. return (MatConstIterator_<_Tp>&)t;
  2217. }
  2218. template<typename _Tp> static inline
  2219. MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
  2220. {
  2221. MatConstIterator t = (const MatConstIterator&)a - ofs;
  2222. return (MatConstIterator_<_Tp>&)t;
  2223. }
  2224. template<typename _Tp> inline
  2225. const _Tp& MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const
  2226. {
  2227. return *(_Tp*)MatConstIterator::operator [](i);
  2228. }
  2229. //////////////////////////// MatIterator_ ///////////////////////////
  2230. template<typename _Tp> inline
  2231. MatIterator_<_Tp>::MatIterator_()
  2232. : MatConstIterator_<_Tp>()
  2233. {}
  2234. template<typename _Tp> inline
  2235. MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m)
  2236. : MatConstIterator_<_Tp>(_m)
  2237. {}
  2238. template<typename _Tp> inline
  2239. MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col)
  2240. : MatConstIterator_<_Tp>(_m, _row, _col)
  2241. {}
  2242. template<typename _Tp> inline
  2243. MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, Point _pt)
  2244. : MatConstIterator_<_Tp>(_m, _pt)
  2245. {}
  2246. template<typename _Tp> inline
  2247. MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, const int* _idx)
  2248. : MatConstIterator_<_Tp>(_m, _idx)
  2249. {}
  2250. template<typename _Tp> inline
  2251. MatIterator_<_Tp>::MatIterator_(const MatIterator_& it)
  2252. : MatConstIterator_<_Tp>(it)
  2253. {}
  2254. template<typename _Tp> inline
  2255. MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it )
  2256. {
  2257. MatConstIterator::operator = (it);
  2258. return *this;
  2259. }
  2260. template<typename _Tp> inline
  2261. _Tp& MatIterator_<_Tp>::operator *() const
  2262. {
  2263. return *(_Tp*)(this->ptr);
  2264. }
  2265. template<typename _Tp> inline
  2266. MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs)
  2267. {
  2268. MatConstIterator::operator += (ofs);
  2269. return *this;
  2270. }
  2271. template<typename _Tp> inline
  2272. MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs)
  2273. {
  2274. MatConstIterator::operator += (-ofs);
  2275. return *this;
  2276. }
  2277. template<typename _Tp> inline
  2278. MatIterator_<_Tp>& MatIterator_<_Tp>::operator --()
  2279. {
  2280. MatConstIterator::operator --();
  2281. return *this;
  2282. }
  2283. template<typename _Tp> inline
  2284. MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int)
  2285. {
  2286. MatIterator_ b = *this;
  2287. MatConstIterator::operator --();
  2288. return b;
  2289. }
  2290. template<typename _Tp> inline
  2291. MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++()
  2292. {
  2293. MatConstIterator::operator ++();
  2294. return *this;
  2295. }
  2296. template<typename _Tp> inline
  2297. MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int)
  2298. {
  2299. MatIterator_ b = *this;
  2300. MatConstIterator::operator ++();
  2301. return b;
  2302. }
  2303. template<typename _Tp> inline
  2304. _Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const
  2305. {
  2306. return *(*this + i);
  2307. }
  2308. template<typename _Tp> static inline
  2309. bool operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
  2310. {
  2311. return a.m == b.m && a.ptr == b.ptr;
  2312. }
  2313. template<typename _Tp> static inline
  2314. bool operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
  2315. {
  2316. return a.m != b.m || a.ptr != b.ptr;
  2317. }
  2318. template<typename _Tp> static inline
  2319. MatIterator_<_Tp> operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
  2320. {
  2321. MatConstIterator t = (const MatConstIterator&)a + ofs;
  2322. return (MatIterator_<_Tp>&)t;
  2323. }
  2324. template<typename _Tp> static inline
  2325. MatIterator_<_Tp> operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a)
  2326. {
  2327. MatConstIterator t = (const MatConstIterator&)a + ofs;
  2328. return (MatIterator_<_Tp>&)t;
  2329. }
  2330. template<typename _Tp> static inline
  2331. MatIterator_<_Tp> operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
  2332. {
  2333. MatConstIterator t = (const MatConstIterator&)a - ofs;
  2334. return (MatIterator_<_Tp>&)t;
  2335. }
  2336. /////////////////////// SparseMatConstIterator //////////////////////
  2337. inline
  2338. SparseMatConstIterator::SparseMatConstIterator()
  2339. : m(0), hashidx(0), ptr(0)
  2340. {}
  2341. inline
  2342. SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it)
  2343. : m(it.m), hashidx(it.hashidx), ptr(it.ptr)
  2344. {}
  2345. inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it)
  2346. {
  2347. if( this != &it )
  2348. {
  2349. m = it.m;
  2350. hashidx = it.hashidx;
  2351. ptr = it.ptr;
  2352. }
  2353. return *this;
  2354. }
  2355. template<typename _Tp> inline
  2356. const _Tp& SparseMatConstIterator::value() const
  2357. {
  2358. return *(const _Tp*)ptr;
  2359. }
  2360. inline
  2361. const SparseMat::Node* SparseMatConstIterator::node() const
  2362. {
  2363. return (ptr && m && m->hdr) ? (const SparseMat::Node*)(const void*)(ptr - m->hdr->valueOffset) : 0;
  2364. }
  2365. inline
  2366. SparseMatConstIterator SparseMatConstIterator::operator ++(int)
  2367. {
  2368. SparseMatConstIterator it = *this;
  2369. ++*this;
  2370. return it;
  2371. }
  2372. inline
  2373. void SparseMatConstIterator::seekEnd()
  2374. {
  2375. if( m && m->hdr )
  2376. {
  2377. hashidx = m->hdr->hashtab.size();
  2378. ptr = 0;
  2379. }
  2380. }
  2381. static inline
  2382. bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
  2383. {
  2384. return it1.m == it2.m && it1.ptr == it2.ptr;
  2385. }
  2386. static inline
  2387. bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
  2388. {
  2389. return !(it1 == it2);
  2390. }
  2391. ///////////////////////// SparseMatIterator /////////////////////////
  2392. inline
  2393. SparseMatIterator::SparseMatIterator()
  2394. {}
  2395. inline
  2396. SparseMatIterator::SparseMatIterator(SparseMat* _m)
  2397. : SparseMatConstIterator(_m)
  2398. {}
  2399. inline
  2400. SparseMatIterator::SparseMatIterator(const SparseMatIterator& it)
  2401. : SparseMatConstIterator(it)
  2402. {}
  2403. inline
  2404. SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it)
  2405. {
  2406. (SparseMatConstIterator&)*this = it;
  2407. return *this;
  2408. }
  2409. template<typename _Tp> inline
  2410. _Tp& SparseMatIterator::value() const
  2411. {
  2412. return *(_Tp*)ptr;
  2413. }
  2414. inline
  2415. SparseMat::Node* SparseMatIterator::node() const
  2416. {
  2417. return (SparseMat::Node*)SparseMatConstIterator::node();
  2418. }
  2419. inline
  2420. SparseMatIterator& SparseMatIterator::operator ++()
  2421. {
  2422. SparseMatConstIterator::operator ++();
  2423. return *this;
  2424. }
  2425. inline
  2426. SparseMatIterator SparseMatIterator::operator ++(int)
  2427. {
  2428. SparseMatIterator it = *this;
  2429. ++*this;
  2430. return it;
  2431. }
  2432. ////////////////////// SparseMatConstIterator_ //////////////////////
  2433. template<typename _Tp> inline
  2434. SparseMatConstIterator_<_Tp>::SparseMatConstIterator_()
  2435. {}
  2436. template<typename _Tp> inline
  2437. SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m)
  2438. : SparseMatConstIterator(_m)
  2439. {}
  2440. template<typename _Tp> inline
  2441. SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m)
  2442. : SparseMatConstIterator(_m)
  2443. {
  2444. CV_Assert( _m->type() == traits::Type<_Tp>::value );
  2445. }
  2446. template<typename _Tp> inline
  2447. SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it)
  2448. : SparseMatConstIterator(it)
  2449. {}
  2450. template<typename _Tp> inline
  2451. SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it)
  2452. {
  2453. return reinterpret_cast<SparseMatConstIterator_<_Tp>&>
  2454. (*reinterpret_cast<SparseMatConstIterator*>(this) =
  2455. reinterpret_cast<const SparseMatConstIterator&>(it));
  2456. }
  2457. template<typename _Tp> inline
  2458. const _Tp& SparseMatConstIterator_<_Tp>::operator *() const
  2459. {
  2460. return *(const _Tp*)this->ptr;
  2461. }
  2462. template<typename _Tp> inline
  2463. SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator ++()
  2464. {
  2465. SparseMatConstIterator::operator ++();
  2466. return *this;
  2467. }
  2468. template<typename _Tp> inline
  2469. SparseMatConstIterator_<_Tp> SparseMatConstIterator_<_Tp>::operator ++(int)
  2470. {
  2471. SparseMatConstIterator_<_Tp> it = *this;
  2472. SparseMatConstIterator::operator ++();
  2473. return it;
  2474. }
  2475. ///////////////////////// SparseMatIterator_ ////////////////////////
  2476. template<typename _Tp> inline
  2477. SparseMatIterator_<_Tp>::SparseMatIterator_()
  2478. {}
  2479. template<typename _Tp> inline
  2480. SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m)
  2481. : SparseMatConstIterator_<_Tp>(_m)
  2482. {}
  2483. template<typename _Tp> inline
  2484. SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat* _m)
  2485. : SparseMatConstIterator_<_Tp>(_m)
  2486. {}
  2487. template<typename _Tp> inline
  2488. SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it)
  2489. : SparseMatConstIterator_<_Tp>(it)
  2490. {}
  2491. template<typename _Tp> inline
  2492. SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it)
  2493. {
  2494. return reinterpret_cast<SparseMatIterator_<_Tp>&>
  2495. (*reinterpret_cast<SparseMatConstIterator*>(this) =
  2496. reinterpret_cast<const SparseMatConstIterator&>(it));
  2497. }
  2498. template<typename _Tp> inline
  2499. _Tp& SparseMatIterator_<_Tp>::operator *() const
  2500. {
  2501. return *(_Tp*)this->ptr;
  2502. }
  2503. template<typename _Tp> inline
  2504. SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator ++()
  2505. {
  2506. SparseMatConstIterator::operator ++();
  2507. return *this;
  2508. }
  2509. template<typename _Tp> inline
  2510. SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int)
  2511. {
  2512. SparseMatIterator_<_Tp> it = *this;
  2513. SparseMatConstIterator::operator ++();
  2514. return it;
  2515. }
  2516. //////////////////////// MatCommaInitializer_ ///////////////////////
  2517. template<typename _Tp> inline
  2518. MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m)
  2519. : it(_m)
  2520. {}
  2521. template<typename _Tp> template<typename T2> inline
  2522. MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v)
  2523. {
  2524. CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() );
  2525. *this->it = _Tp(v);
  2526. ++this->it;
  2527. return *this;
  2528. }
  2529. template<typename _Tp> inline
  2530. MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
  2531. {
  2532. CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() );
  2533. return Mat_<_Tp>(*this->it.m);
  2534. }
  2535. template<typename _Tp, typename T2> static inline
  2536. MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val)
  2537. {
  2538. MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
  2539. return (commaInitializer, val);
  2540. }
  2541. ///////////////////////// Matrix Expressions ////////////////////////
  2542. inline
  2543. Mat& Mat::operator = (const MatExpr& e)
  2544. {
  2545. e.op->assign(e, *this);
  2546. return *this;
  2547. }
  2548. template<typename _Tp> inline
  2549. Mat_<_Tp>::Mat_(const MatExpr& e)
  2550. {
  2551. e.op->assign(e, *this, traits::Type<_Tp>::value);
  2552. }
  2553. template<typename _Tp> inline
  2554. Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e)
  2555. {
  2556. e.op->assign(e, *this, traits::Type<_Tp>::value);
  2557. return *this;
  2558. }
  2559. template<typename _Tp> inline
  2560. MatExpr Mat_<_Tp>::zeros(int rows, int cols)
  2561. {
  2562. return Mat::zeros(rows, cols, traits::Type<_Tp>::value);
  2563. }
  2564. template<typename _Tp> inline
  2565. MatExpr Mat_<_Tp>::zeros(Size sz)
  2566. {
  2567. return Mat::zeros(sz, traits::Type<_Tp>::value);
  2568. }
  2569. template<typename _Tp> inline
  2570. MatExpr Mat_<_Tp>::ones(int rows, int cols)
  2571. {
  2572. return Mat::ones(rows, cols, traits::Type<_Tp>::value);
  2573. }
  2574. template<typename _Tp> inline
  2575. MatExpr Mat_<_Tp>::ones(Size sz)
  2576. {
  2577. return Mat::ones(sz, traits::Type<_Tp>::value);
  2578. }
  2579. template<typename _Tp> inline
  2580. MatExpr Mat_<_Tp>::eye(int rows, int cols)
  2581. {
  2582. return Mat::eye(rows, cols, traits::Type<_Tp>::value);
  2583. }
  2584. template<typename _Tp> inline
  2585. MatExpr Mat_<_Tp>::eye(Size sz)
  2586. {
  2587. return Mat::eye(sz, traits::Type<_Tp>::value);
  2588. }
  2589. inline
  2590. MatExpr::MatExpr()
  2591. : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s()
  2592. {}
  2593. inline
  2594. MatExpr::MatExpr(const MatOp* _op, int _flags, const Mat& _a, const Mat& _b,
  2595. const Mat& _c, double _alpha, double _beta, const Scalar& _s)
  2596. : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s)
  2597. {}
  2598. inline
  2599. MatExpr::operator Mat() const
  2600. {
  2601. Mat m;
  2602. op->assign(*this, m);
  2603. return m;
  2604. }
  2605. template<typename _Tp> inline
  2606. MatExpr::operator Mat_<_Tp>() const
  2607. {
  2608. Mat_<_Tp> m;
  2609. op->assign(*this, m, traits::Type<_Tp>::value);
  2610. return m;
  2611. }
  2612. template<typename _Tp> static inline
  2613. MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
  2614. {
  2615. return cv::min((const Mat&)a, (const Mat&)b);
  2616. }
  2617. template<typename _Tp> static inline
  2618. MatExpr min(const Mat_<_Tp>& a, double s)
  2619. {
  2620. return cv::min((const Mat&)a, s);
  2621. }
  2622. template<typename _Tp> static inline
  2623. MatExpr min(double s, const Mat_<_Tp>& a)
  2624. {
  2625. return cv::min((const Mat&)a, s);
  2626. }
  2627. template<typename _Tp> static inline
  2628. MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
  2629. {
  2630. return cv::max((const Mat&)a, (const Mat&)b);
  2631. }
  2632. template<typename _Tp> static inline
  2633. MatExpr max(const Mat_<_Tp>& a, double s)
  2634. {
  2635. return cv::max((const Mat&)a, s);
  2636. }
  2637. template<typename _Tp> static inline
  2638. MatExpr max(double s, const Mat_<_Tp>& a)
  2639. {
  2640. return cv::max((const Mat&)a, s);
  2641. }
  2642. template<typename _Tp> static inline
  2643. MatExpr abs(const Mat_<_Tp>& m)
  2644. {
  2645. return cv::abs((const Mat&)m);
  2646. }
  2647. static inline
  2648. Mat& operator += (Mat& a, const MatExpr& b)
  2649. {
  2650. b.op->augAssignAdd(b, a);
  2651. return a;
  2652. }
  2653. static inline
  2654. const Mat& operator += (const Mat& a, const MatExpr& b)
  2655. {
  2656. b.op->augAssignAdd(b, (Mat&)a);
  2657. return a;
  2658. }
  2659. template<typename _Tp> static inline
  2660. Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b)
  2661. {
  2662. b.op->augAssignAdd(b, a);
  2663. return a;
  2664. }
  2665. template<typename _Tp> static inline
  2666. const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b)
  2667. {
  2668. b.op->augAssignAdd(b, (Mat&)a);
  2669. return a;
  2670. }
  2671. static inline
  2672. Mat& operator -= (Mat& a, const MatExpr& b)
  2673. {
  2674. b.op->augAssignSubtract(b, a);
  2675. return a;
  2676. }
  2677. static inline
  2678. const Mat& operator -= (const Mat& a, const MatExpr& b)
  2679. {
  2680. b.op->augAssignSubtract(b, (Mat&)a);
  2681. return a;
  2682. }
  2683. template<typename _Tp> static inline
  2684. Mat_<_Tp>& operator -= (Mat_<_Tp>& a, const MatExpr& b)
  2685. {
  2686. b.op->augAssignSubtract(b, a);
  2687. return a;
  2688. }
  2689. template<typename _Tp> static inline
  2690. const Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b)
  2691. {
  2692. b.op->augAssignSubtract(b, (Mat&)a);
  2693. return a;
  2694. }
  2695. static inline
  2696. Mat& operator *= (Mat& a, const MatExpr& b)
  2697. {
  2698. b.op->augAssignMultiply(b, a);
  2699. return a;
  2700. }
  2701. static inline
  2702. const Mat& operator *= (const Mat& a, const MatExpr& b)
  2703. {
  2704. b.op->augAssignMultiply(b, (Mat&)a);
  2705. return a;
  2706. }
  2707. template<typename _Tp> static inline
  2708. Mat_<_Tp>& operator *= (Mat_<_Tp>& a, const MatExpr& b)
  2709. {
  2710. b.op->augAssignMultiply(b, a);
  2711. return a;
  2712. }
  2713. template<typename _Tp> static inline
  2714. const Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b)
  2715. {
  2716. b.op->augAssignMultiply(b, (Mat&)a);
  2717. return a;
  2718. }
  2719. static inline
  2720. Mat& operator /= (Mat& a, const MatExpr& b)
  2721. {
  2722. b.op->augAssignDivide(b, a);
  2723. return a;
  2724. }
  2725. static inline
  2726. const Mat& operator /= (const Mat& a, const MatExpr& b)
  2727. {
  2728. b.op->augAssignDivide(b, (Mat&)a);
  2729. return a;
  2730. }
  2731. template<typename _Tp> static inline
  2732. Mat_<_Tp>& operator /= (Mat_<_Tp>& a, const MatExpr& b)
  2733. {
  2734. b.op->augAssignDivide(b, a);
  2735. return a;
  2736. }
  2737. template<typename _Tp> static inline
  2738. const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b)
  2739. {
  2740. b.op->augAssignDivide(b, (Mat&)a);
  2741. return a;
  2742. }
  2743. //////////////////////////////// UMat ////////////////////////////////
  2744. template<typename _Tp> inline
  2745. UMat::UMat(const std::vector<_Tp>& vec, bool copyData)
  2746. : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
  2747. cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows)
  2748. {
  2749. if(vec.empty())
  2750. return;
  2751. if( !copyData )
  2752. {
  2753. // !!!TODO!!!
  2754. CV_Error(Error::StsNotImplemented, "");
  2755. }
  2756. else
  2757. Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
  2758. }
  2759. inline
  2760. UMat UMat::row(int y) const
  2761. {
  2762. return UMat(*this, Range(y, y + 1), Range::all());
  2763. }
  2764. inline
  2765. UMat UMat::col(int x) const
  2766. {
  2767. return UMat(*this, Range::all(), Range(x, x + 1));
  2768. }
  2769. inline
  2770. UMat UMat::rowRange(int startrow, int endrow) const
  2771. {
  2772. return UMat(*this, Range(startrow, endrow), Range::all());
  2773. }
  2774. inline
  2775. UMat UMat::rowRange(const Range& r) const
  2776. {
  2777. return UMat(*this, r, Range::all());
  2778. }
  2779. inline
  2780. UMat UMat::colRange(int startcol, int endcol) const
  2781. {
  2782. return UMat(*this, Range::all(), Range(startcol, endcol));
  2783. }
  2784. inline
  2785. UMat UMat::colRange(const Range& r) const
  2786. {
  2787. return UMat(*this, Range::all(), r);
  2788. }
  2789. inline
  2790. UMat UMat::operator()( Range _rowRange, Range _colRange ) const
  2791. {
  2792. return UMat(*this, _rowRange, _colRange);
  2793. }
  2794. inline
  2795. UMat UMat::operator()( const Rect& roi ) const
  2796. {
  2797. return UMat(*this, roi);
  2798. }
  2799. inline
  2800. UMat UMat::operator()(const Range* ranges) const
  2801. {
  2802. return UMat(*this, ranges);
  2803. }
  2804. inline
  2805. UMat UMat::operator()(const std::vector<Range>& ranges) const
  2806. {
  2807. return UMat(*this, ranges);
  2808. }
  2809. inline
  2810. bool UMat::isContinuous() const
  2811. {
  2812. return (flags & CONTINUOUS_FLAG) != 0;
  2813. }
  2814. inline
  2815. bool UMat::isSubmatrix() const
  2816. {
  2817. return (flags & SUBMATRIX_FLAG) != 0;
  2818. }
  2819. inline
  2820. size_t UMat::elemSize() const
  2821. {
  2822. size_t res = dims > 0 ? step.p[dims - 1] : 0;
  2823. CV_DbgAssert(res != 0);
  2824. return res;
  2825. }
  2826. inline
  2827. size_t UMat::elemSize1() const
  2828. {
  2829. return CV_ELEM_SIZE1(flags);
  2830. }
  2831. inline
  2832. int UMat::type() const
  2833. {
  2834. return CV_MAT_TYPE(flags);
  2835. }
  2836. inline
  2837. int UMat::depth() const
  2838. {
  2839. return CV_MAT_DEPTH(flags);
  2840. }
  2841. inline
  2842. int UMat::channels() const
  2843. {
  2844. return CV_MAT_CN(flags);
  2845. }
  2846. inline
  2847. size_t UMat::step1(int i) const
  2848. {
  2849. return step.p[i] / elemSize1();
  2850. }
  2851. #ifdef CV_CXX_MOVE_SEMANTICS
  2852. inline
  2853. UMat::UMat(UMat&& m)
  2854. : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator),
  2855. usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows)
  2856. {
  2857. if (m.dims <= 2) // move new step/size info
  2858. {
  2859. step[0] = m.step[0];
  2860. step[1] = m.step[1];
  2861. }
  2862. else
  2863. {
  2864. CV_DbgAssert(m.step.p != m.step.buf);
  2865. step.p = m.step.p;
  2866. size.p = m.size.p;
  2867. m.step.p = m.step.buf;
  2868. m.size.p = &m.rows;
  2869. }
  2870. m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
  2871. m.allocator = NULL;
  2872. m.u = NULL;
  2873. m.offset = 0;
  2874. }
  2875. inline
  2876. UMat& UMat::operator = (UMat&& m)
  2877. {
  2878. if (this == &m)
  2879. return *this;
  2880. release();
  2881. flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols;
  2882. allocator = m.allocator; usageFlags = m.usageFlags;
  2883. u = m.u;
  2884. offset = m.offset;
  2885. if (step.p != step.buf) // release self step/size
  2886. {
  2887. fastFree(step.p);
  2888. step.p = step.buf;
  2889. size.p = &rows;
  2890. }
  2891. if (m.dims <= 2) // move new step/size info
  2892. {
  2893. step[0] = m.step[0];
  2894. step[1] = m.step[1];
  2895. }
  2896. else
  2897. {
  2898. CV_DbgAssert(m.step.p != m.step.buf);
  2899. step.p = m.step.p;
  2900. size.p = m.size.p;
  2901. m.step.p = m.step.buf;
  2902. m.size.p = &m.rows;
  2903. }
  2904. m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
  2905. m.allocator = NULL;
  2906. m.u = NULL;
  2907. m.offset = 0;
  2908. return *this;
  2909. }
  2910. #endif
  2911. inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; }
  2912. inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; }
  2913. inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; }
  2914. inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; }
  2915. inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; }
  2916. inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; }
  2917. inline void UMatData::markDeviceMemMapped(bool flag)
  2918. {
  2919. if(flag)
  2920. flags |= DEVICE_MEM_MAPPED;
  2921. else
  2922. flags &= ~DEVICE_MEM_MAPPED;
  2923. }
  2924. inline void UMatData::markHostCopyObsolete(bool flag)
  2925. {
  2926. if(flag)
  2927. flags |= HOST_COPY_OBSOLETE;
  2928. else
  2929. flags &= ~HOST_COPY_OBSOLETE;
  2930. }
  2931. inline void UMatData::markDeviceCopyObsolete(bool flag)
  2932. {
  2933. if(flag)
  2934. flags |= DEVICE_COPY_OBSOLETE;
  2935. else
  2936. flags &= ~DEVICE_COPY_OBSOLETE;
  2937. }
  2938. //! @endcond
  2939. static inline
  2940. void swap(MatExpr& a, MatExpr& b) { a.swap(b); }
  2941. } //cv
  2942. #ifdef _MSC_VER
  2943. #pragma warning( pop )
  2944. #endif
  2945. #ifdef CV_DISABLE_CLANG_ENUM_WARNINGS
  2946. #undef CV_DISABLE_CLANG_ENUM_WARNINGS
  2947. #pragma clang diagnostic pop
  2948. #endif
  2949. #endif