123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945 |
- /*M///////////////////////////////////////////////////////////////////////////////////////
- //
- // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
- //
- // By downloading, copying, installing or using the software you agree to this license.
- // If you do not agree to this license, do not download, install,
- // copy or use the software.
- //
- //
- // License Agreement
- // For Open Source Computer Vision Library
- //
- // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
- // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
- // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
- // Copyright (C) 2015, Itseez Inc., all rights reserved.
- // Third party copyrights are property of their respective owners.
- //
- // Redistribution and use in source and binary forms, with or without modification,
- // are permitted provided that the following conditions are met:
- //
- // * Redistribution's of source code must retain the above copyright notice,
- // this list of conditions and the following disclaimer.
- //
- // * Redistribution's in binary form must reproduce the above copyright notice,
- // this list of conditions and the following disclaimer in the documentation
- // and/or other materials provided with the distribution.
- //
- // * The name of the copyright holders may not be used to endorse or promote products
- // derived from this software without specific prior written permission.
- //
- // This software is provided by the copyright holders and contributors "as is" and
- // any express or implied warranties, including, but not limited to, the implied
- // warranties of merchantability and fitness for a particular purpose are disclaimed.
- // In no event shall the Intel Corporation or contributors be liable for any direct,
- // indirect, incidental, special, exemplary, or consequential damages
- // (including, but not limited to, procurement of substitute goods or services;
- // loss of use, data, or profits; or business interruption) however caused
- // and on any theory of liability, whether in contract, strict liability,
- // or tort (including negligence or otherwise) arising in any way out of
- // the use of this software, even if advised of the possibility of such damage.
- //
- //M*/
- #ifndef OPENCV_CORE_MATRIX_OPERATIONS_HPP
- #define OPENCV_CORE_MATRIX_OPERATIONS_HPP
- #ifndef __cplusplus
- # error mat.inl.hpp header must be compiled as C++
- #endif
- #ifdef _MSC_VER
- #pragma warning( push )
- #pragma warning( disable: 4127 )
- #endif
- namespace cv
- {
- CV__DEBUG_NS_BEGIN
- //! @cond IGNORED
- //////////////////////// Input/Output Arrays ////////////////////////
- inline void _InputArray::init(int _flags, const void* _obj)
- { flags = _flags; obj = (void*)_obj; }
- inline void _InputArray::init(int _flags, const void* _obj, Size _sz)
- { flags = _flags; obj = (void*)_obj; sz = _sz; }
- inline void* _InputArray::getObj() const { return obj; }
- inline int _InputArray::getFlags() const { return flags; }
- inline Size _InputArray::getSz() const { return sz; }
- inline _InputArray::_InputArray() { init(NONE, 0); }
- inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); }
- inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); }
- inline _InputArray::_InputArray(const std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); }
- inline _InputArray::_InputArray(const UMat& m) { init(UMAT+ACCESS_READ, &m); }
- inline _InputArray::_InputArray(const std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_READ, &vec); }
- template<typename _Tp> inline
- _InputArray::_InputArray(const std::vector<_Tp>& vec)
- { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- _InputArray::_InputArray(const std::array<_Tp, _Nm>& arr)
- { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); }
- template<std::size_t _Nm> inline
- _InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
- { init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); }
- #endif
- inline
- _InputArray::_InputArray(const std::vector<bool>& vec)
- { init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type<bool>::value + ACCESS_READ, &vec); }
- template<typename _Tp> inline
- _InputArray::_InputArray(const std::vector<std::vector<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
- inline
- _InputArray::_InputArray(const std::vector<std::vector<bool> >&)
- { CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > is not supported!\n"); }
- template<typename _Tp> inline
- _InputArray::_InputArray(const std::vector<Mat_<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); }
- template<typename _Tp, int m, int n> inline
- _InputArray::_InputArray(const Matx<_Tp, m, n>& mtx)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); }
- template<typename _Tp> inline
- _InputArray::_InputArray(const _Tp* vec, int n)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); }
- template<typename _Tp> inline
- _InputArray::_InputArray(const Mat_<_Tp>& m)
- { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); }
- inline _InputArray::_InputArray(const double& val)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); }
- inline _InputArray::_InputArray(const MatExpr& expr)
- { init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr); }
- inline _InputArray::_InputArray(const cuda::GpuMat& d_mat)
- { init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); }
- inline _InputArray::_InputArray(const std::vector<cuda::GpuMat>& d_mat)
- { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);}
- inline _InputArray::_InputArray(const ogl::Buffer& buf)
- { init(OPENGL_BUFFER + ACCESS_READ, &buf); }
- inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem)
- { init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); }
- inline _InputArray::~_InputArray() {}
- inline Mat _InputArray::getMat(int i) const
- {
- if( kind() == MAT && i < 0 )
- return *(const Mat*)obj;
- return getMat_(i);
- }
- inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
- inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; }
- inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; }
- inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; }
- inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; }
- inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR ||
- kind() == _InputArray::STD_BOOL_VECTOR ||
- kind() == _InputArray::STD_ARRAY; }
- inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; }
- inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; }
- ////////////////////////////////////////////////////////////////////////////////////////
- inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); }
- inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); }
- inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); }
- inline _OutputArray::_OutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); }
- inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); }
- inline _OutputArray::_OutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(std::vector<_Tp>& vec)
- { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- _OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr)
- { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
- template<std::size_t _Nm> inline
- _OutputArray::_OutputArray(std::array<Mat, _Nm>& arr)
- { init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
- #endif
- inline
- _OutputArray::_OutputArray(std::vector<bool>&)
- { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an output array\n"); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- inline
- _OutputArray::_OutputArray(std::vector<std::vector<bool> >&)
- { CV_Error(Error::StsUnsupportedFormat, "std::vector<std::vector<bool> > cannot be an output array\n"); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(std::vector<Mat_<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(Mat_<_Tp>& m)
- { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
- template<typename _Tp, int m, int n> inline
- _OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(_Tp* vec, int n)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(const std::vector<_Tp>& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- _OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr)
- { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
- template<std::size_t _Nm> inline
- _OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
- { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
- #endif
- template<typename _Tp> inline
- _OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(const std::vector<Mat_<_Tp> >& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(const Mat_<_Tp>& m)
- { init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); }
- template<typename _Tp, int m, int n> inline
- _OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); }
- template<typename _Tp> inline
- _OutputArray::_OutputArray(const _Tp* vec, int n)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); }
- inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat)
- { init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }
- inline _OutputArray::_OutputArray(std::vector<cuda::GpuMat>& d_mat)
- { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);}
- inline _OutputArray::_OutputArray(ogl::Buffer& buf)
- { init(OPENGL_BUFFER + ACCESS_WRITE, &buf); }
- inline _OutputArray::_OutputArray(cuda::HostMem& cuda_mem)
- { init(CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); }
- inline _OutputArray::_OutputArray(const Mat& m)
- { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_WRITE, &m); }
- inline _OutputArray::_OutputArray(const std::vector<Mat>& vec)
- { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_WRITE, &vec); }
- inline _OutputArray::_OutputArray(const UMat& m)
- { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_WRITE, &m); }
- inline _OutputArray::_OutputArray(const std::vector<UMat>& vec)
- { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_WRITE, &vec); }
- inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat)
- { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }
- inline _OutputArray::_OutputArray(const ogl::Buffer& buf)
- { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); }
- inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem)
- { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); }
- ///////////////////////////////////////////////////////////////////////////////////////////
- inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); }
- inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); }
- inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); }
- inline _InputOutputArray::_InputOutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); }
- inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); }
- inline _InputOutputArray::_InputOutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_RW, &vec); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec)
- { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- _InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr)
- { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
- template<std::size_t _Nm> inline
- _InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr)
- { init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
- #endif
- inline _InputOutputArray::_InputOutputArray(std::vector<bool>&)
- { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(std::vector<Mat_<_Tp> >& vec)
- { init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(Mat_<_Tp>& m)
- { init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
- template<typename _Tp, int m, int n> inline
- _InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(_Tp* vec, int n)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- _InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr)
- { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); }
- template<std::size_t _Nm> inline
- _InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
- { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
- #endif
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(const std::vector<Mat_<_Tp> >& vec)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m)
- { init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); }
- template<typename _Tp, int m, int n> inline
- _InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); }
- template<typename _Tp> inline
- _InputOutputArray::_InputOutputArray(const _Tp* vec, int n)
- { init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); }
- inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat)
- { init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); }
- inline _InputOutputArray::_InputOutputArray(ogl::Buffer& buf)
- { init(OPENGL_BUFFER + ACCESS_RW, &buf); }
- inline _InputOutputArray::_InputOutputArray(cuda::HostMem& cuda_mem)
- { init(CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); }
- inline _InputOutputArray::_InputOutputArray(const Mat& m)
- { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_RW, &m); }
- inline _InputOutputArray::_InputOutputArray(const std::vector<Mat>& vec)
- { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_RW, &vec); }
- inline _InputOutputArray::_InputOutputArray(const UMat& m)
- { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_RW, &m); }
- inline _InputOutputArray::_InputOutputArray(const std::vector<UMat>& vec)
- { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_RW, &vec); }
- inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat)
- { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); }
- inline _InputOutputArray::_InputOutputArray(const std::vector<cuda::GpuMat>& d_mat)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);}
- template<> inline _InputOutputArray::_InputOutputArray(std::vector<cuda::GpuMat>& d_mat)
- { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);}
- inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf)
- { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); }
- inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem)
- { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); }
- CV__DEBUG_NS_END
- //////////////////////////////////////////// Mat //////////////////////////////////////////
- inline
- Mat::Mat()
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {}
- inline
- Mat::Mat(int _rows, int _cols, int _type)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_rows, _cols, _type);
- }
- inline
- Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_rows, _cols, _type);
- *this = _s;
- }
- inline
- Mat::Mat(Size _sz, int _type)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create( _sz.height, _sz.width, _type );
- }
- inline
- Mat::Mat(Size _sz, int _type, const Scalar& _s)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_sz.height, _sz.width, _type);
- *this = _s;
- }
- inline
- Mat::Mat(int _dims, const int* _sz, int _type)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_dims, _sz, _type);
- }
- inline
- Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_dims, _sz, _type);
- *this = _s;
- }
- inline
- Mat::Mat(const std::vector<int>& _sz, int _type)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_sz, _type);
- }
- inline
- Mat::Mat(const std::vector<int>& _sz, int _type, const Scalar& _s)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
- datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- create(_sz, _type);
- *this = _s;
- }
- inline
- Mat::Mat(const Mat& m)
- : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
- datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator),
- u(m.u), size(&rows), step(0)
- {
- if( u )
- CV_XADD(&u->refcount, 1);
- if( m.dims <= 2 )
- {
- step[0] = m.step[0]; step[1] = m.step[1];
- }
- else
- {
- dims = 0;
- copySize(m);
- }
- }
- inline
- Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
- : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols),
- data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0),
- allocator(0), u(0), size(&rows)
- {
- CV_Assert(total() == 0 || data != NULL);
- size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type);
- size_t minstep = cols * esz;
- if( _step == AUTO_STEP )
- {
- _step = minstep;
- }
- else
- {
- CV_DbgAssert( _step >= minstep );
- if (_step % esz1 != 0)
- {
- CV_Error(Error::BadStep, "Step must be a multiple of esz1");
- }
- }
- step[0] = _step;
- step[1] = esz;
- datalimit = datastart + _step * rows;
- dataend = datalimit - _step + minstep;
- updateContinuityFlag();
- }
- inline
- Mat::Mat(Size _sz, int _type, void* _data, size_t _step)
- : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width),
- data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0),
- allocator(0), u(0), size(&rows)
- {
- CV_Assert(total() == 0 || data != NULL);
- size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type);
- size_t minstep = cols*esz;
- if( _step == AUTO_STEP )
- {
- _step = minstep;
- }
- else
- {
- CV_DbgAssert( _step >= minstep );
- if (_step % esz1 != 0)
- {
- CV_Error(Error::BadStep, "Step must be a multiple of esz1");
- }
- }
- step[0] = _step;
- step[1] = esz;
- datalimit = datastart + _step*rows;
- dataend = datalimit - _step + minstep;
- updateContinuityFlag();
- }
- template<typename _Tp> inline
- Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
- cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if(vec.empty())
- return;
- if( !copyData )
- {
- step[0] = step[1] = sizeof(_Tp);
- datastart = data = (uchar*)&vec[0];
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
- }
- #ifdef CV_CXX11
- template<typename _Tp, typename> inline
- Mat::Mat(const std::initializer_list<_Tp> list)
- : Mat()
- {
- CV_Assert(list.size() != 0);
- Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
- }
- template<typename _Tp> inline
- Mat::Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list)
- : Mat()
- {
- size_t size_total = 1;
- for(auto s : sizes)
- size_total *= s;
- CV_Assert(list.size() != 0);
- CV_Assert(size_total == list.size());
- Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
- }
- #endif
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()),
- cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if(arr.empty())
- return;
- if( !copyData )
- {
- step[0] = step[1] = sizeof(_Tp);
- datastart = data = (uchar*)arr.data();
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this);
- }
- #endif
- template<typename _Tp, int n> inline
- Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0),
- datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if( !copyData )
- {
- step[0] = step[1] = sizeof(_Tp);
- datastart = data = (uchar*)vec.val;
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this);
- }
- template<typename _Tp, int m, int n> inline
- Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0),
- datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if( !copyData )
- {
- step[0] = cols * sizeof(_Tp);
- step[1] = sizeof(_Tp);
- datastart = data = (uchar*)M.val;
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this);
- }
- template<typename _Tp> inline
- Mat::Mat(const Point_<_Tp>& pt, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0),
- datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if( !copyData )
- {
- step[0] = step[1] = sizeof(_Tp);
- datastart = data = (uchar*)&pt.x;
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- {
- create(2, 1, traits::Type<_Tp>::value);
- ((_Tp*)data)[0] = pt.x;
- ((_Tp*)data)[1] = pt.y;
- }
- }
- template<typename _Tp> inline
- Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0),
- datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0)
- {
- if( !copyData )
- {
- step[0] = step[1] = sizeof(_Tp);
- datastart = data = (uchar*)&pt.x;
- datalimit = dataend = datastart + rows * step[0];
- }
- else
- {
- create(3, 1, traits::Type<_Tp>::value);
- ((_Tp*)data)[0] = pt.x;
- ((_Tp*)data)[1] = pt.y;
- ((_Tp*)data)[2] = pt.z;
- }
- }
- template<typename _Tp> inline
- Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0),
- datastart(0), dataend(0), allocator(0), u(0), size(&rows)
- {
- *this = commaInitializer.operator Mat_<_Tp>();
- }
- inline
- Mat::~Mat()
- {
- release();
- if( step.p != step.buf )
- fastFree(step.p);
- }
- inline
- Mat& Mat::operator = (const Mat& m)
- {
- if( this != &m )
- {
- if( m.u )
- CV_XADD(&m.u->refcount, 1);
- release();
- flags = m.flags;
- if( dims <= 2 && m.dims <= 2 )
- {
- dims = m.dims;
- rows = m.rows;
- cols = m.cols;
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- copySize(m);
- data = m.data;
- datastart = m.datastart;
- dataend = m.dataend;
- datalimit = m.datalimit;
- allocator = m.allocator;
- u = m.u;
- }
- return *this;
- }
- inline
- Mat Mat::row(int y) const
- {
- return Mat(*this, Range(y, y + 1), Range::all());
- }
- inline
- Mat Mat::col(int x) const
- {
- return Mat(*this, Range::all(), Range(x, x + 1));
- }
- inline
- Mat Mat::rowRange(int startrow, int endrow) const
- {
- return Mat(*this, Range(startrow, endrow), Range::all());
- }
- inline
- Mat Mat::rowRange(const Range& r) const
- {
- return Mat(*this, r, Range::all());
- }
- inline
- Mat Mat::colRange(int startcol, int endcol) const
- {
- return Mat(*this, Range::all(), Range(startcol, endcol));
- }
- inline
- Mat Mat::colRange(const Range& r) const
- {
- return Mat(*this, Range::all(), r);
- }
- inline
- Mat Mat::clone() const
- {
- Mat m;
- copyTo(m);
- return m;
- }
- inline
- void Mat::assignTo( Mat& m, int _type ) const
- {
- if( _type < 0 )
- m = *this;
- else
- convertTo(m, _type);
- }
- inline
- void Mat::create(int _rows, int _cols, int _type)
- {
- _type &= TYPE_MASK;
- if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data )
- return;
- int sz[] = {_rows, _cols};
- create(2, sz, _type);
- }
- inline
- void Mat::create(Size _sz, int _type)
- {
- create(_sz.height, _sz.width, _type);
- }
- inline
- void Mat::addref()
- {
- if( u )
- CV_XADD(&u->refcount, 1);
- }
- inline
- void Mat::release()
- {
- if( u && CV_XADD(&u->refcount, -1) == 1 )
- deallocate();
- u = NULL;
- datastart = dataend = datalimit = data = 0;
- for(int i = 0; i < dims; i++)
- size.p[i] = 0;
- #ifdef _DEBUG
- flags = MAGIC_VAL;
- dims = rows = cols = 0;
- if(step.p != step.buf)
- {
- fastFree(step.p);
- step.p = step.buf;
- size.p = &rows;
- }
- #endif
- }
- inline
- Mat Mat::operator()( Range _rowRange, Range _colRange ) const
- {
- return Mat(*this, _rowRange, _colRange);
- }
- inline
- Mat Mat::operator()( const Rect& roi ) const
- {
- return Mat(*this, roi);
- }
- inline
- Mat Mat::operator()(const Range* ranges) const
- {
- return Mat(*this, ranges);
- }
- inline
- Mat Mat::operator()(const std::vector<Range>& ranges) const
- {
- return Mat(*this, ranges);
- }
- inline
- bool Mat::isContinuous() const
- {
- return (flags & CONTINUOUS_FLAG) != 0;
- }
- inline
- bool Mat::isSubmatrix() const
- {
- return (flags & SUBMATRIX_FLAG) != 0;
- }
- inline
- size_t Mat::elemSize() const
- {
- return dims > 0 ? step.p[dims - 1] : 0;
- }
- inline
- size_t Mat::elemSize1() const
- {
- return CV_ELEM_SIZE1(flags);
- }
- inline
- int Mat::type() const
- {
- return CV_MAT_TYPE(flags);
- }
- inline
- int Mat::depth() const
- {
- return CV_MAT_DEPTH(flags);
- }
- inline
- int Mat::channels() const
- {
- return CV_MAT_CN(flags);
- }
- inline
- size_t Mat::step1(int i) const
- {
- return step.p[i] / elemSize1();
- }
- inline
- bool Mat::empty() const
- {
- return data == 0 || total() == 0 || dims == 0;
- }
- inline
- size_t Mat::total() const
- {
- if( dims <= 2 )
- return (size_t)rows * cols;
- size_t p = 1;
- for( int i = 0; i < dims; i++ )
- p *= size[i];
- return p;
- }
- inline
- size_t Mat::total(int startDim, int endDim) const
- {
- CV_Assert( 0 <= startDim && startDim <= endDim);
- size_t p = 1;
- int endDim_ = endDim <= dims ? endDim : dims;
- for( int i = startDim; i < endDim_; i++ )
- p *= size[i];
- return p;
- }
- inline
- uchar* Mat::ptr(int y)
- {
- CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
- return data + step.p[0] * y;
- }
- inline
- const uchar* Mat::ptr(int y) const
- {
- CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
- return data + step.p[0] * y;
- }
- template<typename _Tp> inline
- _Tp* Mat::ptr(int y)
- {
- CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) );
- return (_Tp*)(data + step.p[0] * y);
- }
- template<typename _Tp> inline
- const _Tp* Mat::ptr(int y) const
- {
- CV_DbgAssert( y == 0 || (data && dims >= 1 && data && (unsigned)y < (unsigned)size.p[0]) );
- return (const _Tp*)(data + step.p[0] * y);
- }
- inline
- uchar* Mat::ptr(int i0, int i1)
- {
- CV_DbgAssert(dims >= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- return data + i0 * step.p[0] + i1 * step.p[1];
- }
- inline
- const uchar* Mat::ptr(int i0, int i1) const
- {
- CV_DbgAssert(dims >= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- return data + i0 * step.p[0] + i1 * step.p[1];
- }
- template<typename _Tp> inline
- _Tp* Mat::ptr(int i0, int i1)
- {
- CV_DbgAssert(dims >= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1]);
- }
- template<typename _Tp> inline
- const _Tp* Mat::ptr(int i0, int i1) const
- {
- CV_DbgAssert(dims >= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1]);
- }
- inline
- uchar* Mat::ptr(int i0, int i1, int i2)
- {
- CV_DbgAssert(dims >= 3);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
- return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2];
- }
- inline
- const uchar* Mat::ptr(int i0, int i1, int i2) const
- {
- CV_DbgAssert(dims >= 3);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
- return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2];
- }
- template<typename _Tp> inline
- _Tp* Mat::ptr(int i0, int i1, int i2)
- {
- CV_DbgAssert(dims >= 3);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
- return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]);
- }
- template<typename _Tp> inline
- const _Tp* Mat::ptr(int i0, int i1, int i2) const
- {
- CV_DbgAssert(dims >= 3);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]);
- return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]);
- }
- inline
- uchar* Mat::ptr(const int* idx)
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( d >= 1 && p );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
- p += idx[i] * step.p[i];
- }
- return p;
- }
- inline
- const uchar* Mat::ptr(const int* idx) const
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( d >= 1 && p );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
- p += idx[i] * step.p[i];
- }
- return p;
- }
- template<typename _Tp> inline
- _Tp* Mat::ptr(const int* idx)
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( d >= 1 && p );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
- p += idx[i] * step.p[i];
- }
- return (_Tp*)p;
- }
- template<typename _Tp> inline
- const _Tp* Mat::ptr(const int* idx) const
- {
- int i, d = dims;
- uchar* p = data;
- CV_DbgAssert( d >= 1 && p );
- for( i = 0; i < d; i++ )
- {
- CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
- p += idx[i] * step.p[i];
- }
- return (const _Tp*)p;
- }
- template<typename _Tp> inline
- _Tp& Mat::at(int i0, int i1)
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
- CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
- return ((_Tp*)(data + step.p[0] * i0))[i1];
- }
- template<typename _Tp> inline
- const _Tp& Mat::at(int i0, int i1) const
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
- CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
- return ((const _Tp*)(data + step.p[0] * i0))[i1];
- }
- template<typename _Tp> inline
- _Tp& Mat::at(Point pt)
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
- CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
- return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
- }
- template<typename _Tp> inline
- const _Tp& Mat::at(Point pt) const
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
- CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1());
- return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
- }
- template<typename _Tp> inline
- _Tp& Mat::at(int i0)
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
- CV_DbgAssert(elemSize() == sizeof(_Tp));
- if( isContinuous() || size.p[0] == 1 )
- return ((_Tp*)data)[i0];
- if( size.p[1] == 1 )
- return *(_Tp*)(data + step.p[0] * i0);
- int i = i0 / cols, j = i0 - i * cols;
- return ((_Tp*)(data + step.p[0] * i))[j];
- }
- template<typename _Tp> inline
- const _Tp& Mat::at(int i0) const
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
- CV_DbgAssert(elemSize() == sizeof(_Tp));
- if( isContinuous() || size.p[0] == 1 )
- return ((const _Tp*)data)[i0];
- if( size.p[1] == 1 )
- return *(const _Tp*)(data + step.p[0] * i0);
- int i = i0 / cols, j = i0 - i * cols;
- return ((const _Tp*)(data + step.p[0] * i))[j];
- }
- template<typename _Tp> inline
- _Tp& Mat::at(int i0, int i1, int i2)
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(_Tp*)ptr(i0, i1, i2);
- }
- template<typename _Tp> inline
- const _Tp& Mat::at(int i0, int i1, int i2) const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(const _Tp*)ptr(i0, i1, i2);
- }
- template<typename _Tp> inline
- _Tp& Mat::at(const int* idx)
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(_Tp*)ptr(idx);
- }
- template<typename _Tp> inline
- const _Tp& Mat::at(const int* idx) const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(const _Tp*)ptr(idx);
- }
- template<typename _Tp, int n> inline
- _Tp& Mat::at(const Vec<int, n>& idx)
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(_Tp*)ptr(idx.val);
- }
- template<typename _Tp, int n> inline
- const _Tp& Mat::at(const Vec<int, n>& idx) const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return *(const _Tp*)ptr(idx.val);
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> Mat::begin() const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> Mat::end() const
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this);
- it += total();
- return it;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> Mat::begin()
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- return MatIterator_<_Tp>((Mat_<_Tp>*)this);
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> Mat::end()
- {
- CV_DbgAssert( elemSize() == sizeof(_Tp) );
- MatIterator_<_Tp> it((Mat_<_Tp>*)this);
- it += total();
- return it;
- }
- template<typename _Tp, typename Functor> inline
- void Mat::forEach(const Functor& operation) {
- this->forEach_impl<_Tp>(operation);
- }
- template<typename _Tp, typename Functor> inline
- void Mat::forEach(const Functor& operation) const {
- // call as not const
- (const_cast<Mat*>(this))->forEach<_Tp>(operation);
- }
- template<typename _Tp> inline
- Mat::operator std::vector<_Tp>() const
- {
- std::vector<_Tp> v;
- copyTo(v);
- return v;
- }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp, std::size_t _Nm> inline
- Mat::operator std::array<_Tp, _Nm>() const
- {
- std::array<_Tp, _Nm> v;
- copyTo(v);
- return v;
- }
- #endif
- template<typename _Tp, int n> inline
- Mat::operator Vec<_Tp, n>() const
- {
- CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) &&
- rows + cols - 1 == n && channels() == 1 );
- if( isContinuous() && type() == traits::Type<_Tp>::value )
- return Vec<_Tp, n>((_Tp*)data);
- Vec<_Tp, n> v;
- Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val);
- convertTo(tmp, tmp.type());
- return v;
- }
- template<typename _Tp, int m, int n> inline
- Mat::operator Matx<_Tp, m, n>() const
- {
- CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 );
- if( isContinuous() && type() == traits::Type<_Tp>::value )
- return Matx<_Tp, m, n>((_Tp*)data);
- Matx<_Tp, m, n> mtx;
- Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val);
- convertTo(tmp, tmp.type());
- return mtx;
- }
- template<typename _Tp> inline
- void Mat::push_back(const _Tp& elem)
- {
- if( !data )
- {
- *this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone();
- return;
- }
- CV_Assert(traits::Type<_Tp>::value == type() && cols == 1
- /* && dims == 2 (cols == 1 implies dims == 2) */);
- const uchar* tmp = dataend + step[0];
- if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
- {
- *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem;
- dataend = tmp;
- }
- else
- push_back_(&elem);
- }
- template<typename _Tp> inline
- void Mat::push_back(const Mat_<_Tp>& m)
- {
- push_back((const Mat&)m);
- }
- template<> inline
- void Mat::push_back(const MatExpr& expr)
- {
- push_back(static_cast<Mat>(expr));
- }
- template<typename _Tp> inline
- void Mat::push_back(const std::vector<_Tp>& v)
- {
- push_back(Mat(v));
- }
- #ifdef CV_CXX_MOVE_SEMANTICS
- inline
- Mat::Mat(Mat&& m)
- : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
- datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator),
- u(m.u), size(&rows)
- {
- if (m.dims <= 2) // move new step/size info
- {
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- {
- CV_DbgAssert(m.step.p != m.step.buf);
- step.p = m.step.p;
- size.p = m.size.p;
- m.step.p = m.step.buf;
- m.size.p = &m.rows;
- }
- m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
- m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL;
- m.allocator = NULL;
- m.u = NULL;
- }
- inline
- Mat& Mat::operator = (Mat&& m)
- {
- if (this == &m)
- return *this;
- release();
- flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data;
- datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator;
- u = m.u;
- if (step.p != step.buf) // release self step/size
- {
- fastFree(step.p);
- step.p = step.buf;
- size.p = &rows;
- }
- if (m.dims <= 2) // move new step/size info
- {
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- {
- CV_DbgAssert(m.step.p != m.step.buf);
- step.p = m.step.p;
- size.p = m.size.p;
- m.step.p = m.step.buf;
- m.size.p = &m.rows;
- }
- m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
- m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL;
- m.allocator = NULL;
- m.u = NULL;
- return *this;
- }
- #endif
- ///////////////////////////// MatSize ////////////////////////////
- inline
- MatSize::MatSize(int* _p)
- : p(_p) {}
- inline
- int MatSize::dims() const
- {
- return (p - 1)[0];
- }
- inline
- Size MatSize::operator()() const
- {
- CV_DbgAssert(dims() <= 2);
- return Size(p[1], p[0]);
- }
- inline
- const int& MatSize::operator[](int i) const
- {
- CV_DbgAssert(i < dims());
- #ifdef __OPENCV_BUILD
- CV_DbgAssert(i >= 0);
- #endif
- return p[i];
- }
- inline
- int& MatSize::operator[](int i)
- {
- CV_DbgAssert(i < dims());
- #ifdef __OPENCV_BUILD
- CV_DbgAssert(i >= 0);
- #endif
- return p[i];
- }
- inline
- MatSize::operator const int*() const
- {
- return p;
- }
- inline
- bool MatSize::operator == (const MatSize& sz) const
- {
- int d = dims();
- int dsz = sz.dims();
- if( d != dsz )
- return false;
- if( d == 2 )
- return p[0] == sz.p[0] && p[1] == sz.p[1];
- for( int i = 0; i < d; i++ )
- if( p[i] != sz.p[i] )
- return false;
- return true;
- }
- inline
- bool MatSize::operator != (const MatSize& sz) const
- {
- return !(*this == sz);
- }
- ///////////////////////////// MatStep ////////////////////////////
- inline
- MatStep::MatStep()
- {
- p = buf; p[0] = p[1] = 0;
- }
- inline
- MatStep::MatStep(size_t s)
- {
- p = buf; p[0] = s; p[1] = 0;
- }
- inline
- const size_t& MatStep::operator[](int i) const
- {
- return p[i];
- }
- inline
- size_t& MatStep::operator[](int i)
- {
- return p[i];
- }
- inline MatStep::operator size_t() const
- {
- CV_DbgAssert( p == buf );
- return buf[0];
- }
- inline MatStep& MatStep::operator = (size_t s)
- {
- CV_DbgAssert( p == buf );
- buf[0] = s;
- return *this;
- }
- ////////////////////////////// Mat_<_Tp> ////////////////////////////
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_()
- : Mat()
- {
- flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _rows, int _cols)
- : Mat(_rows, _cols, traits::Type<_Tp>::value)
- {
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value)
- : Mat(_rows, _cols, traits::Type<_Tp>::value)
- {
- *this = value;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(Size _sz)
- : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(Size _sz, const _Tp& value)
- : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value)
- {
- *this = value;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _dims, const int* _sz)
- : Mat(_dims, _sz, traits::Type<_Tp>::value)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s)
- : Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s))
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps)
- : Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges)
- : Mat(m, ranges)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const std::vector<Range>& ranges)
- : Mat(m, ranges)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat& m)
- : Mat()
- {
- flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
- *this = m;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat_& m)
- : Mat(m)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps)
- : Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange)
- : Mat(m, _rowRange, _colRange)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
- : Mat(m, roi)
- {}
- template<typename _Tp> template<int n> inline
- Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData)
- : Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec)
- {
- CV_Assert(n%DataType<_Tp>::channels == 0);
- if( copyData )
- *this = clone();
- }
- template<typename _Tp> template<int m, int n> inline
- Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool copyData)
- : Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M)
- {
- CV_Assert(n % DataType<_Tp>::channels == 0);
- if( copyData )
- *this = clone();
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
- : Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
- {
- CV_Assert(2 % DataType<_Tp>::channels == 0);
- if( copyData )
- *this = clone();
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
- : Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt)
- {
- CV_Assert(3 % DataType<_Tp>::channels == 0);
- if( copyData )
- *this = clone();
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer)
- : Mat(commaInitializer)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData)
- : Mat(vec, copyData)
- {}
- #ifdef CV_CXX11
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list)
- : Mat(list)
- {}
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const std::initializer_list<int> sizes, std::initializer_list<_Tp> list)
- : Mat(sizes, list)
- {}
- #endif
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp> template<std::size_t _Nm> inline
- Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData)
- : Mat(arr, copyData)
- {}
- #endif
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
- {
- if( traits::Type<_Tp>::value == m.type() )
- {
- Mat::operator = (m);
- return *this;
- }
- if( traits::Depth<_Tp>::value == m.depth() )
- {
- return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0));
- }
- CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty());
- m.convertTo(*this, type());
- return *this;
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m)
- {
- Mat::operator=(m);
- return *this;
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s)
- {
- typedef typename DataType<_Tp>::vec_type VT;
- Mat::operator=(Scalar((const VT&)s));
- return *this;
- }
- template<typename _Tp> inline
- void Mat_<_Tp>::create(int _rows, int _cols)
- {
- Mat::create(_rows, _cols, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- void Mat_<_Tp>::create(Size _sz)
- {
- Mat::create(_sz, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- void Mat_<_Tp>::create(int _dims, const int* _sz)
- {
- Mat::create(_dims, _sz, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- void Mat_<_Tp>::release()
- {
- Mat::release();
- #ifdef _DEBUG
- flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
- #endif
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const
- {
- return Mat_<_Tp>(Mat::cross(m));
- }
- template<typename _Tp> template<typename T2> inline
- Mat_<_Tp>::operator Mat_<T2>() const
- {
- return Mat_<T2>(*this);
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::row(int y) const
- {
- return Mat_(*this, Range(y, y+1), Range::all());
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::col(int x) const
- {
- return Mat_(*this, Range::all(), Range(x, x+1));
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::diag(int d) const
- {
- return Mat_(Mat::diag(d));
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::clone() const
- {
- return Mat_(Mat::clone());
- }
- template<typename _Tp> inline
- size_t Mat_<_Tp>::elemSize() const
- {
- CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) );
- return sizeof(_Tp);
- }
- template<typename _Tp> inline
- size_t Mat_<_Tp>::elemSize1() const
- {
- CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp) / DataType<_Tp>::channels );
- return sizeof(_Tp) / DataType<_Tp>::channels;
- }
- template<typename _Tp> inline
- int Mat_<_Tp>::type() const
- {
- CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value );
- return traits::Type<_Tp>::value;
- }
- template<typename _Tp> inline
- int Mat_<_Tp>::depth() const
- {
- CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value );
- return traits::Depth<_Tp>::value;
- }
- template<typename _Tp> inline
- int Mat_<_Tp>::channels() const
- {
- CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels );
- return DataType<_Tp>::channels;
- }
- template<typename _Tp> inline
- size_t Mat_<_Tp>::stepT(int i) const
- {
- return step.p[i] / elemSize();
- }
- template<typename _Tp> inline
- size_t Mat_<_Tp>::step1(int i) const
- {
- return step.p[i] / elemSize1();
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
- {
- return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright));
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const
- {
- return Mat_<_Tp>(*this, _rowRange, _colRange);
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const
- {
- return Mat_<_Tp>(*this, roi);
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const
- {
- return Mat_<_Tp>(*this, ranges);
- }
- template<typename _Tp> inline
- Mat_<_Tp> Mat_<_Tp>::operator()(const std::vector<Range>& ranges) const
- {
- return Mat_<_Tp>(*this, ranges);
- }
- template<typename _Tp> inline
- _Tp* Mat_<_Tp>::operator [](int y)
- {
- CV_DbgAssert( 0 <= y && y < size.p[0] );
- return (_Tp*)(data + y*step.p[0]);
- }
- template<typename _Tp> inline
- const _Tp* Mat_<_Tp>::operator [](int y) const
- {
- CV_DbgAssert( 0 <= y && y < size.p[0] );
- return (const _Tp*)(data + y*step.p[0]);
- }
- template<typename _Tp> inline
- _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert(type() == traits::Type<_Tp>::value);
- return ((_Tp*)(data + step.p[0] * i0))[i1];
- }
- template<typename _Tp> inline
- const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
- CV_DbgAssert(type() == traits::Type<_Tp>::value);
- return ((const _Tp*)(data + step.p[0] * i0))[i1];
- }
- template<typename _Tp> inline
- _Tp& Mat_<_Tp>::operator ()(Point pt)
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
- CV_DbgAssert(type() == traits::Type<_Tp>::value);
- return ((_Tp*)(data + step.p[0] * pt.y))[pt.x];
- }
- template<typename _Tp> inline
- const _Tp& Mat_<_Tp>::operator ()(Point pt) const
- {
- CV_DbgAssert(dims <= 2);
- CV_DbgAssert(data);
- CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
- CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
- CV_DbgAssert(type() == traits::Type<_Tp>::value);
- return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x];
- }
- template<typename _Tp> inline
- _Tp& Mat_<_Tp>::operator ()(const int* idx)
- {
- return Mat::at<_Tp>(idx);
- }
- template<typename _Tp> inline
- const _Tp& Mat_<_Tp>::operator ()(const int* idx) const
- {
- return Mat::at<_Tp>(idx);
- }
- template<typename _Tp> template<int n> inline
- _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx)
- {
- return Mat::at<_Tp>(idx);
- }
- template<typename _Tp> template<int n> inline
- const _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) const
- {
- return Mat::at<_Tp>(idx);
- }
- template<typename _Tp> inline
- _Tp& Mat_<_Tp>::operator ()(int i0)
- {
- return this->at<_Tp>(i0);
- }
- template<typename _Tp> inline
- const _Tp& Mat_<_Tp>::operator ()(int i0) const
- {
- return this->at<_Tp>(i0);
- }
- template<typename _Tp> inline
- _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2)
- {
- return this->at<_Tp>(i0, i1, i2);
- }
- template<typename _Tp> inline
- const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const
- {
- return this->at<_Tp>(i0, i1, i2);
- }
- template<typename _Tp> inline
- Mat_<_Tp>::operator std::vector<_Tp>() const
- {
- std::vector<_Tp> v;
- copyTo(v);
- return v;
- }
- #ifdef CV_CXX_STD_ARRAY
- template<typename _Tp> template<std::size_t _Nm> inline
- Mat_<_Tp>::operator std::array<_Tp, _Nm>() const
- {
- std::array<_Tp, _Nm> a;
- copyTo(a);
- return a;
- }
- #endif
- template<typename _Tp> template<int n> inline
- Mat_<_Tp>::operator Vec<typename DataType<_Tp>::channel_type, n>() const
- {
- CV_Assert(n % DataType<_Tp>::channels == 0);
- #if defined _MSC_VER
- const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround)
- return pMat->operator Vec<typename DataType<_Tp>::channel_type, n>();
- #else
- return this->Mat::operator Vec<typename DataType<_Tp>::channel_type, n>();
- #endif
- }
- template<typename _Tp> template<int m, int n> inline
- Mat_<_Tp>::operator Matx<typename DataType<_Tp>::channel_type, m, n>() const
- {
- CV_Assert(n % DataType<_Tp>::channels == 0);
- #if defined _MSC_VER
- const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround)
- Matx<typename DataType<_Tp>::channel_type, m, n> res = pMat->operator Matx<typename DataType<_Tp>::channel_type, m, n>();
- return res;
- #else
- Matx<typename DataType<_Tp>::channel_type, m, n> res = this->Mat::operator Matx<typename DataType<_Tp>::channel_type, m, n>();
- return res;
- #endif
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> Mat_<_Tp>::begin() const
- {
- return Mat::begin<_Tp>();
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> Mat_<_Tp>::end() const
- {
- return Mat::end<_Tp>();
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> Mat_<_Tp>::begin()
- {
- return Mat::begin<_Tp>();
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> Mat_<_Tp>::end()
- {
- return Mat::end<_Tp>();
- }
- template<typename _Tp> template<typename Functor> inline
- void Mat_<_Tp>::forEach(const Functor& operation) {
- Mat::forEach<_Tp, Functor>(operation);
- }
- template<typename _Tp> template<typename Functor> inline
- void Mat_<_Tp>::forEach(const Functor& operation) const {
- Mat::forEach<_Tp, Functor>(operation);
- }
- #ifdef CV_CXX_MOVE_SEMANTICS
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(Mat_&& m)
- : Mat(m)
- {
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m)
- {
- Mat::operator = (std::move(m));
- return *this;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(Mat&& m)
- : Mat()
- {
- flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
- *this = m;
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m)
- {
- if( traits::Type<_Tp>::value == m.type() )
- {
- Mat::operator = ((Mat&&)m);
- return *this;
- }
- if( traits::Depth<_Tp>::value == m.depth() )
- {
- Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0));
- return *this;
- }
- CV_DbgAssert(DataType<_Tp>::channels == m.channels());
- m.convertTo(*this, type());
- return *this;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(MatExpr&& e)
- : Mat()
- {
- flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value;
- *this = Mat(e);
- }
- #endif
- ///////////////////////////// SparseMat /////////////////////////////
- inline
- SparseMat::SparseMat()
- : flags(MAGIC_VAL), hdr(0)
- {}
- inline
- SparseMat::SparseMat(int _dims, const int* _sizes, int _type)
- : flags(MAGIC_VAL), hdr(0)
- {
- create(_dims, _sizes, _type);
- }
- inline
- SparseMat::SparseMat(const SparseMat& m)
- : flags(m.flags), hdr(m.hdr)
- {
- addref();
- }
- inline
- SparseMat::~SparseMat()
- {
- release();
- }
- inline
- SparseMat& SparseMat::operator = (const SparseMat& m)
- {
- if( this != &m )
- {
- if( m.hdr )
- CV_XADD(&m.hdr->refcount, 1);
- release();
- flags = m.flags;
- hdr = m.hdr;
- }
- return *this;
- }
- inline
- SparseMat& SparseMat::operator = (const Mat& m)
- {
- return (*this = SparseMat(m));
- }
- inline
- SparseMat SparseMat::clone() const
- {
- SparseMat temp;
- this->copyTo(temp);
- return temp;
- }
- inline
- void SparseMat::assignTo( SparseMat& m, int _type ) const
- {
- if( _type < 0 )
- m = *this;
- else
- convertTo(m, _type);
- }
- inline
- void SparseMat::addref()
- {
- if( hdr )
- CV_XADD(&hdr->refcount, 1);
- }
- inline
- void SparseMat::release()
- {
- if( hdr && CV_XADD(&hdr->refcount, -1) == 1 )
- delete hdr;
- hdr = 0;
- }
- inline
- size_t SparseMat::elemSize() const
- {
- return CV_ELEM_SIZE(flags);
- }
- inline
- size_t SparseMat::elemSize1() const
- {
- return CV_ELEM_SIZE1(flags);
- }
- inline
- int SparseMat::type() const
- {
- return CV_MAT_TYPE(flags);
- }
- inline
- int SparseMat::depth() const
- {
- return CV_MAT_DEPTH(flags);
- }
- inline
- int SparseMat::channels() const
- {
- return CV_MAT_CN(flags);
- }
- inline
- const int* SparseMat::size() const
- {
- return hdr ? hdr->size : 0;
- }
- inline
- int SparseMat::size(int i) const
- {
- if( hdr )
- {
- CV_DbgAssert((unsigned)i < (unsigned)hdr->dims);
- return hdr->size[i];
- }
- return 0;
- }
- inline
- int SparseMat::dims() const
- {
- return hdr ? hdr->dims : 0;
- }
- inline
- size_t SparseMat::nzcount() const
- {
- return hdr ? hdr->nodeCount : 0;
- }
- inline
- size_t SparseMat::hash(int i0) const
- {
- return (size_t)i0;
- }
- inline
- size_t SparseMat::hash(int i0, int i1) const
- {
- return (size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1;
- }
- inline
- size_t SparseMat::hash(int i0, int i1, int i2) const
- {
- return ((size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1) * HASH_SCALE + (unsigned)i2;
- }
- inline
- size_t SparseMat::hash(const int* idx) const
- {
- size_t h = (unsigned)idx[0];
- if( !hdr )
- return 0;
- int d = hdr->dims;
- for(int i = 1; i < d; i++ )
- h = h * HASH_SCALE + (unsigned)idx[i];
- return h;
- }
- template<typename _Tp> inline
- _Tp& SparseMat::ref(int i0, size_t* hashval)
- {
- return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat::ref(int i0, int i1, size_t* hashval)
- {
- return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval)
- {
- return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat::ref(const int* idx, size_t* hashval)
- {
- return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval);
- }
- template<typename _Tp> inline
- _Tp SparseMat::value(int i0, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline
- _Tp SparseMat::value(int i0, int i1, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline
- _Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline
- _Tp SparseMat::value(const int* idx, size_t* hashval) const
- {
- const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
- return p ? *p : _Tp();
- }
- template<typename _Tp> inline
- const _Tp* SparseMat::find(int i0, size_t* hashval) const
- {
- return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
- }
- template<typename _Tp> inline
- const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const
- {
- return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
- }
- template<typename _Tp> inline
- const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const
- {
- return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
- }
- template<typename _Tp> inline
- const _Tp* SparseMat::find(const int* idx, size_t* hashval) const
- {
- return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat::value(Node* n)
- {
- return *(_Tp*)((uchar*)n + hdr->valueOffset);
- }
- template<typename _Tp> inline
- const _Tp& SparseMat::value(const Node* n) const
- {
- return *(const _Tp*)((const uchar*)n + hdr->valueOffset);
- }
- inline
- SparseMat::Node* SparseMat::node(size_t nidx)
- {
- return (Node*)(void*)&hdr->pool[nidx];
- }
- inline
- const SparseMat::Node* SparseMat::node(size_t nidx) const
- {
- return (const Node*)(const void*)&hdr->pool[nidx];
- }
- inline
- SparseMatIterator SparseMat::begin()
- {
- return SparseMatIterator(this);
- }
- inline
- SparseMatConstIterator SparseMat::begin() const
- {
- return SparseMatConstIterator(this);
- }
- inline
- SparseMatIterator SparseMat::end()
- {
- SparseMatIterator it(this);
- it.seekEnd();
- return it;
- }
- inline
- SparseMatConstIterator SparseMat::end() const
- {
- SparseMatConstIterator it(this);
- it.seekEnd();
- return it;
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp> SparseMat::begin()
- {
- return SparseMatIterator_<_Tp>(this);
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp> SparseMat::begin() const
- {
- return SparseMatConstIterator_<_Tp>(this);
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp> SparseMat::end()
- {
- SparseMatIterator_<_Tp> it(this);
- it.seekEnd();
- return it;
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp> SparseMat::end() const
- {
- SparseMatConstIterator_<_Tp> it(this);
- it.seekEnd();
- return it;
- }
- ///////////////////////////// SparseMat_ ////////////////////////////
- template<typename _Tp> inline
- SparseMat_<_Tp>::SparseMat_()
- {
- flags = MAGIC_VAL | traits::Type<_Tp>::value;
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes)
- : SparseMat(_dims, _sizes, traits::Type<_Tp>::value)
- {}
- template<typename _Tp> inline
- SparseMat_<_Tp>::SparseMat_(const SparseMat& m)
- {
- if( m.type() == traits::Type<_Tp>::value )
- *this = (const SparseMat_<_Tp>&)m;
- else
- m.convertTo(*this, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m)
- {
- this->flags = m.flags;
- this->hdr = m.hdr;
- if( this->hdr )
- CV_XADD(&this->hdr->refcount, 1);
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>::SparseMat_(const Mat& m)
- {
- SparseMat sm(m);
- *this = sm;
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m)
- {
- if( this != &m )
- {
- if( m.hdr ) CV_XADD(&m.hdr->refcount, 1);
- release();
- flags = m.flags;
- hdr = m.hdr;
- }
- return *this;
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m)
- {
- if( m.type() == traits::Type<_Tp>::value )
- return (*this = (const SparseMat_<_Tp>&)m);
- m.convertTo(*this, traits::Type<_Tp>::value);
- return *this;
- }
- template<typename _Tp> inline
- SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const Mat& m)
- {
- return (*this = SparseMat(m));
- }
- template<typename _Tp> inline
- SparseMat_<_Tp> SparseMat_<_Tp>::clone() const
- {
- SparseMat_<_Tp> m;
- this->copyTo(m);
- return m;
- }
- template<typename _Tp> inline
- void SparseMat_<_Tp>::create(int _dims, const int* _sizes)
- {
- SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- int SparseMat_<_Tp>::type() const
- {
- return traits::Type<_Tp>::value;
- }
- template<typename _Tp> inline
- int SparseMat_<_Tp>::depth() const
- {
- return traits::Depth<_Tp>::value;
- }
- template<typename _Tp> inline
- int SparseMat_<_Tp>::channels() const
- {
- return DataType<_Tp>::channels;
- }
- template<typename _Tp> inline
- _Tp& SparseMat_<_Tp>::ref(int i0, size_t* hashval)
- {
- return SparseMat::ref<_Tp>(i0, hashval);
- }
- template<typename _Tp> inline
- _Tp SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const
- {
- return SparseMat::value<_Tp>(i0, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval)
- {
- return SparseMat::ref<_Tp>(i0, i1, hashval);
- }
- template<typename _Tp> inline
- _Tp SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const
- {
- return SparseMat::value<_Tp>(i0, i1, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval)
- {
- return SparseMat::ref<_Tp>(i0, i1, i2, hashval);
- }
- template<typename _Tp> inline
- _Tp SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const
- {
- return SparseMat::value<_Tp>(i0, i1, i2, hashval);
- }
- template<typename _Tp> inline
- _Tp& SparseMat_<_Tp>::ref(const int* idx, size_t* hashval)
- {
- return SparseMat::ref<_Tp>(idx, hashval);
- }
- template<typename _Tp> inline
- _Tp SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const
- {
- return SparseMat::value<_Tp>(idx, hashval);
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin()
- {
- return SparseMatIterator_<_Tp>(this);
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const
- {
- return SparseMatConstIterator_<_Tp>(this);
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp> SparseMat_<_Tp>::end()
- {
- SparseMatIterator_<_Tp> it(this);
- it.seekEnd();
- return it;
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const
- {
- SparseMatConstIterator_<_Tp> it(this);
- it.seekEnd();
- return it;
- }
- ////////////////////////// MatConstIterator /////////////////////////
- inline
- MatConstIterator::MatConstIterator()
- : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0)
- {}
- inline
- MatConstIterator::MatConstIterator(const Mat* _m)
- : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
- {
- if( m && m->isContinuous() )
- {
- sliceStart = m->ptr();
- sliceEnd = sliceStart + m->total()*elemSize;
- }
- seek((const int*)0);
- }
- inline
- MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col)
- : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
- {
- CV_Assert(m && m->dims <= 2);
- if( m->isContinuous() )
- {
- sliceStart = m->ptr();
- sliceEnd = sliceStart + m->total()*elemSize;
- }
- int idx[] = {_row, _col};
- seek(idx);
- }
- inline
- MatConstIterator::MatConstIterator(const Mat* _m, Point _pt)
- : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
- {
- CV_Assert(m && m->dims <= 2);
- if( m->isContinuous() )
- {
- sliceStart = m->ptr();
- sliceEnd = sliceStart + m->total()*elemSize;
- }
- int idx[] = {_pt.y, _pt.x};
- seek(idx);
- }
- inline
- MatConstIterator::MatConstIterator(const MatConstIterator& it)
- : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd)
- {}
- inline
- MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it )
- {
- m = it.m; elemSize = it.elemSize; ptr = it.ptr;
- sliceStart = it.sliceStart; sliceEnd = it.sliceEnd;
- return *this;
- }
- inline
- const uchar* MatConstIterator::operator *() const
- {
- return ptr;
- }
- inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs)
- {
- if( !m || ofs == 0 )
- return *this;
- ptrdiff_t ofsb = ofs*elemSize;
- ptr += ofsb;
- if( ptr < sliceStart || sliceEnd <= ptr )
- {
- ptr -= ofsb;
- seek(ofs, true);
- }
- return *this;
- }
- inline
- MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs)
- {
- return (*this += -ofs);
- }
- inline
- MatConstIterator& MatConstIterator::operator --()
- {
- if( m && (ptr -= elemSize) < sliceStart )
- {
- ptr += elemSize;
- seek(-1, true);
- }
- return *this;
- }
- inline
- MatConstIterator MatConstIterator::operator --(int)
- {
- MatConstIterator b = *this;
- *this += -1;
- return b;
- }
- inline
- MatConstIterator& MatConstIterator::operator ++()
- {
- if( m && (ptr += elemSize) >= sliceEnd )
- {
- ptr -= elemSize;
- seek(1, true);
- }
- return *this;
- }
- inline MatConstIterator MatConstIterator::operator ++(int)
- {
- MatConstIterator b = *this;
- *this += 1;
- return b;
- }
- static inline
- bool operator == (const MatConstIterator& a, const MatConstIterator& b)
- {
- return a.m == b.m && a.ptr == b.ptr;
- }
- static inline
- bool operator != (const MatConstIterator& a, const MatConstIterator& b)
- {
- return !(a == b);
- }
- static inline
- bool operator < (const MatConstIterator& a, const MatConstIterator& b)
- {
- return a.ptr < b.ptr;
- }
- static inline
- bool operator > (const MatConstIterator& a, const MatConstIterator& b)
- {
- return a.ptr > b.ptr;
- }
- static inline
- bool operator <= (const MatConstIterator& a, const MatConstIterator& b)
- {
- return a.ptr <= b.ptr;
- }
- static inline
- bool operator >= (const MatConstIterator& a, const MatConstIterator& b)
- {
- return a.ptr >= b.ptr;
- }
- static inline
- ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a)
- {
- if( a.m != b.m )
- return ((size_t)(-1) >> 1);
- if( a.sliceEnd == b.sliceEnd )
- return (b.ptr - a.ptr)/static_cast<ptrdiff_t>(b.elemSize);
- return b.lpos() - a.lpos();
- }
- static inline
- MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs)
- {
- MatConstIterator b = a;
- return b += ofs;
- }
- static inline
- MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a)
- {
- MatConstIterator b = a;
- return b += ofs;
- }
- static inline
- MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs)
- {
- MatConstIterator b = a;
- return b += -ofs;
- }
- inline
- const uchar* MatConstIterator::operator [](ptrdiff_t i) const
- {
- return *(*this + i);
- }
- ///////////////////////// MatConstIterator_ /////////////////////////
- template<typename _Tp> inline
- MatConstIterator_<_Tp>::MatConstIterator_()
- {}
- template<typename _Tp> inline
- MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m)
- : MatConstIterator(_m)
- {}
- template<typename _Tp> inline
- MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col)
- : MatConstIterator(_m, _row, _col)
- {}
- template<typename _Tp> inline
- MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, Point _pt)
- : MatConstIterator(_m, _pt)
- {}
- template<typename _Tp> inline
- MatConstIterator_<_Tp>::MatConstIterator_(const MatConstIterator_& it)
- : MatConstIterator(it)
- {}
- template<typename _Tp> inline
- MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it )
- {
- MatConstIterator::operator = (it);
- return *this;
- }
- template<typename _Tp> inline
- const _Tp& MatConstIterator_<_Tp>::operator *() const
- {
- return *(_Tp*)(this->ptr);
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs)
- {
- MatConstIterator::operator += (ofs);
- return *this;
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs)
- {
- return (*this += -ofs);
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --()
- {
- MatConstIterator::operator --();
- return *this;
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int)
- {
- MatConstIterator_ b = *this;
- MatConstIterator::operator --();
- return b;
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++()
- {
- MatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline
- MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int)
- {
- MatConstIterator_ b = *this;
- MatConstIterator::operator ++();
- return b;
- }
- template<typename _Tp> inline
- Point MatConstIterator_<_Tp>::pos() const
- {
- if( !m )
- return Point();
- CV_DbgAssert( m->dims <= 2 );
- if( m->isContinuous() )
- {
- ptrdiff_t ofs = (const _Tp*)ptr - (const _Tp*)m->data;
- int y = (int)(ofs / m->cols);
- int x = (int)(ofs - (ptrdiff_t)y * m->cols);
- return Point(x, y);
- }
- else
- {
- ptrdiff_t ofs = (uchar*)ptr - m->data;
- int y = (int)(ofs / m->step);
- int x = (int)((ofs - y * m->step)/sizeof(_Tp));
- return Point(x, y);
- }
- }
- template<typename _Tp> static inline
- bool operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- {
- return a.m == b.m && a.ptr == b.ptr;
- }
- template<typename _Tp> static inline
- bool operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
- {
- return a.m != b.m || a.ptr != b.ptr;
- }
- template<typename _Tp> static inline
- MatConstIterator_<_Tp> operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
- {
- MatConstIterator t = (const MatConstIterator&)a + ofs;
- return (MatConstIterator_<_Tp>&)t;
- }
- template<typename _Tp> static inline
- MatConstIterator_<_Tp> operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a)
- {
- MatConstIterator t = (const MatConstIterator&)a + ofs;
- return (MatConstIterator_<_Tp>&)t;
- }
- template<typename _Tp> static inline
- MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
- {
- MatConstIterator t = (const MatConstIterator&)a - ofs;
- return (MatConstIterator_<_Tp>&)t;
- }
- template<typename _Tp> inline
- const _Tp& MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const
- {
- return *(_Tp*)MatConstIterator::operator [](i);
- }
- //////////////////////////// MatIterator_ ///////////////////////////
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_()
- : MatConstIterator_<_Tp>()
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m)
- : MatConstIterator_<_Tp>(_m)
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col)
- : MatConstIterator_<_Tp>(_m, _row, _col)
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, Point _pt)
- : MatConstIterator_<_Tp>(_m, _pt)
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, const int* _idx)
- : MatConstIterator_<_Tp>(_m, _idx)
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>::MatIterator_(const MatIterator_& it)
- : MatConstIterator_<_Tp>(it)
- {}
- template<typename _Tp> inline
- MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it )
- {
- MatConstIterator::operator = (it);
- return *this;
- }
- template<typename _Tp> inline
- _Tp& MatIterator_<_Tp>::operator *() const
- {
- return *(_Tp*)(this->ptr);
- }
- template<typename _Tp> inline
- MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs)
- {
- MatConstIterator::operator += (ofs);
- return *this;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs)
- {
- MatConstIterator::operator += (-ofs);
- return *this;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp>& MatIterator_<_Tp>::operator --()
- {
- MatConstIterator::operator --();
- return *this;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int)
- {
- MatIterator_ b = *this;
- MatConstIterator::operator --();
- return b;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++()
- {
- MatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline
- MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int)
- {
- MatIterator_ b = *this;
- MatConstIterator::operator ++();
- return b;
- }
- template<typename _Tp> inline
- _Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const
- {
- return *(*this + i);
- }
- template<typename _Tp> static inline
- bool operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
- {
- return a.m == b.m && a.ptr == b.ptr;
- }
- template<typename _Tp> static inline
- bool operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
- {
- return a.m != b.m || a.ptr != b.ptr;
- }
- template<typename _Tp> static inline
- MatIterator_<_Tp> operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
- {
- MatConstIterator t = (const MatConstIterator&)a + ofs;
- return (MatIterator_<_Tp>&)t;
- }
- template<typename _Tp> static inline
- MatIterator_<_Tp> operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a)
- {
- MatConstIterator t = (const MatConstIterator&)a + ofs;
- return (MatIterator_<_Tp>&)t;
- }
- template<typename _Tp> static inline
- MatIterator_<_Tp> operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
- {
- MatConstIterator t = (const MatConstIterator&)a - ofs;
- return (MatIterator_<_Tp>&)t;
- }
- /////////////////////// SparseMatConstIterator //////////////////////
- inline
- SparseMatConstIterator::SparseMatConstIterator()
- : m(0), hashidx(0), ptr(0)
- {}
- inline
- SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it)
- : m(it.m), hashidx(it.hashidx), ptr(it.ptr)
- {}
- inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it)
- {
- if( this != &it )
- {
- m = it.m;
- hashidx = it.hashidx;
- ptr = it.ptr;
- }
- return *this;
- }
- template<typename _Tp> inline
- const _Tp& SparseMatConstIterator::value() const
- {
- return *(const _Tp*)ptr;
- }
- inline
- const SparseMat::Node* SparseMatConstIterator::node() const
- {
- return (ptr && m && m->hdr) ? (const SparseMat::Node*)(const void*)(ptr - m->hdr->valueOffset) : 0;
- }
- inline
- SparseMatConstIterator SparseMatConstIterator::operator ++(int)
- {
- SparseMatConstIterator it = *this;
- ++*this;
- return it;
- }
- inline
- void SparseMatConstIterator::seekEnd()
- {
- if( m && m->hdr )
- {
- hashidx = m->hdr->hashtab.size();
- ptr = 0;
- }
- }
- static inline
- bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
- {
- return it1.m == it2.m && it1.ptr == it2.ptr;
- }
- static inline
- bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
- {
- return !(it1 == it2);
- }
- ///////////////////////// SparseMatIterator /////////////////////////
- inline
- SparseMatIterator::SparseMatIterator()
- {}
- inline
- SparseMatIterator::SparseMatIterator(SparseMat* _m)
- : SparseMatConstIterator(_m)
- {}
- inline
- SparseMatIterator::SparseMatIterator(const SparseMatIterator& it)
- : SparseMatConstIterator(it)
- {}
- inline
- SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it)
- {
- (SparseMatConstIterator&)*this = it;
- return *this;
- }
- template<typename _Tp> inline
- _Tp& SparseMatIterator::value() const
- {
- return *(_Tp*)ptr;
- }
- inline
- SparseMat::Node* SparseMatIterator::node() const
- {
- return (SparseMat::Node*)SparseMatConstIterator::node();
- }
- inline
- SparseMatIterator& SparseMatIterator::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- inline
- SparseMatIterator SparseMatIterator::operator ++(int)
- {
- SparseMatIterator it = *this;
- ++*this;
- return it;
- }
- ////////////////////// SparseMatConstIterator_ //////////////////////
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_()
- {}
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m)
- : SparseMatConstIterator(_m)
- {}
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m)
- : SparseMatConstIterator(_m)
- {
- CV_Assert( _m->type() == traits::Type<_Tp>::value );
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it)
- : SparseMatConstIterator(it)
- {}
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it)
- {
- return reinterpret_cast<SparseMatConstIterator_<_Tp>&>
- (*reinterpret_cast<SparseMatConstIterator*>(this) =
- reinterpret_cast<const SparseMatConstIterator&>(it));
- }
- template<typename _Tp> inline
- const _Tp& SparseMatConstIterator_<_Tp>::operator *() const
- {
- return *(const _Tp*)this->ptr;
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline
- SparseMatConstIterator_<_Tp> SparseMatConstIterator_<_Tp>::operator ++(int)
- {
- SparseMatConstIterator_<_Tp> it = *this;
- SparseMatConstIterator::operator ++();
- return it;
- }
- ///////////////////////// SparseMatIterator_ ////////////////////////
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_()
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m)
- : SparseMatConstIterator_<_Tp>(_m)
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat* _m)
- : SparseMatConstIterator_<_Tp>(_m)
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it)
- : SparseMatConstIterator_<_Tp>(it)
- {}
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it)
- {
- return reinterpret_cast<SparseMatIterator_<_Tp>&>
- (*reinterpret_cast<SparseMatConstIterator*>(this) =
- reinterpret_cast<const SparseMatConstIterator&>(it));
- }
- template<typename _Tp> inline
- _Tp& SparseMatIterator_<_Tp>::operator *() const
- {
- return *(_Tp*)this->ptr;
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator ++()
- {
- SparseMatConstIterator::operator ++();
- return *this;
- }
- template<typename _Tp> inline
- SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int)
- {
- SparseMatIterator_<_Tp> it = *this;
- SparseMatConstIterator::operator ++();
- return it;
- }
- //////////////////////// MatCommaInitializer_ ///////////////////////
- template<typename _Tp> inline
- MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m)
- : it(_m)
- {}
- template<typename _Tp> template<typename T2> inline
- MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v)
- {
- CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() );
- *this->it = _Tp(v);
- ++this->it;
- return *this;
- }
- template<typename _Tp> inline
- MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
- {
- CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() );
- return Mat_<_Tp>(*this->it.m);
- }
- template<typename _Tp, typename T2> static inline
- MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val)
- {
- MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
- return (commaInitializer, val);
- }
- ///////////////////////// Matrix Expressions ////////////////////////
- inline
- Mat& Mat::operator = (const MatExpr& e)
- {
- e.op->assign(e, *this);
- return *this;
- }
- template<typename _Tp> inline
- Mat_<_Tp>::Mat_(const MatExpr& e)
- {
- e.op->assign(e, *this, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e)
- {
- e.op->assign(e, *this, traits::Type<_Tp>::value);
- return *this;
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::zeros(int rows, int cols)
- {
- return Mat::zeros(rows, cols, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::zeros(Size sz)
- {
- return Mat::zeros(sz, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::ones(int rows, int cols)
- {
- return Mat::ones(rows, cols, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::ones(Size sz)
- {
- return Mat::ones(sz, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::eye(int rows, int cols)
- {
- return Mat::eye(rows, cols, traits::Type<_Tp>::value);
- }
- template<typename _Tp> inline
- MatExpr Mat_<_Tp>::eye(Size sz)
- {
- return Mat::eye(sz, traits::Type<_Tp>::value);
- }
- inline
- MatExpr::MatExpr()
- : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s()
- {}
- inline
- MatExpr::MatExpr(const MatOp* _op, int _flags, const Mat& _a, const Mat& _b,
- const Mat& _c, double _alpha, double _beta, const Scalar& _s)
- : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s)
- {}
- inline
- MatExpr::operator Mat() const
- {
- Mat m;
- op->assign(*this, m);
- return m;
- }
- template<typename _Tp> inline
- MatExpr::operator Mat_<_Tp>() const
- {
- Mat_<_Tp> m;
- op->assign(*this, m, traits::Type<_Tp>::value);
- return m;
- }
- template<typename _Tp> static inline
- MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- return cv::min((const Mat&)a, (const Mat&)b);
- }
- template<typename _Tp> static inline
- MatExpr min(const Mat_<_Tp>& a, double s)
- {
- return cv::min((const Mat&)a, s);
- }
- template<typename _Tp> static inline
- MatExpr min(double s, const Mat_<_Tp>& a)
- {
- return cv::min((const Mat&)a, s);
- }
- template<typename _Tp> static inline
- MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
- {
- return cv::max((const Mat&)a, (const Mat&)b);
- }
- template<typename _Tp> static inline
- MatExpr max(const Mat_<_Tp>& a, double s)
- {
- return cv::max((const Mat&)a, s);
- }
- template<typename _Tp> static inline
- MatExpr max(double s, const Mat_<_Tp>& a)
- {
- return cv::max((const Mat&)a, s);
- }
- template<typename _Tp> static inline
- MatExpr abs(const Mat_<_Tp>& m)
- {
- return cv::abs((const Mat&)m);
- }
- static inline
- Mat& operator += (Mat& a, const MatExpr& b)
- {
- b.op->augAssignAdd(b, a);
- return a;
- }
- static inline
- const Mat& operator += (const Mat& a, const MatExpr& b)
- {
- b.op->augAssignAdd(b, (Mat&)a);
- return a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignAdd(b, a);
- return a;
- }
- template<typename _Tp> static inline
- const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignAdd(b, (Mat&)a);
- return a;
- }
- static inline
- Mat& operator -= (Mat& a, const MatExpr& b)
- {
- b.op->augAssignSubtract(b, a);
- return a;
- }
- static inline
- const Mat& operator -= (const Mat& a, const MatExpr& b)
- {
- b.op->augAssignSubtract(b, (Mat&)a);
- return a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator -= (Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignSubtract(b, a);
- return a;
- }
- template<typename _Tp> static inline
- const Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignSubtract(b, (Mat&)a);
- return a;
- }
- static inline
- Mat& operator *= (Mat& a, const MatExpr& b)
- {
- b.op->augAssignMultiply(b, a);
- return a;
- }
- static inline
- const Mat& operator *= (const Mat& a, const MatExpr& b)
- {
- b.op->augAssignMultiply(b, (Mat&)a);
- return a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator *= (Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignMultiply(b, a);
- return a;
- }
- template<typename _Tp> static inline
- const Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignMultiply(b, (Mat&)a);
- return a;
- }
- static inline
- Mat& operator /= (Mat& a, const MatExpr& b)
- {
- b.op->augAssignDivide(b, a);
- return a;
- }
- static inline
- const Mat& operator /= (const Mat& a, const MatExpr& b)
- {
- b.op->augAssignDivide(b, (Mat&)a);
- return a;
- }
- template<typename _Tp> static inline
- Mat_<_Tp>& operator /= (Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignDivide(b, a);
- return a;
- }
- template<typename _Tp> static inline
- const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b)
- {
- b.op->augAssignDivide(b, (Mat&)a);
- return a;
- }
- //////////////////////////////// UMat ////////////////////////////////
- inline
- UMat::UMat(UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {}
- inline
- UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create(_rows, _cols, _type);
- }
- inline
- UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create(_rows, _cols, _type);
- *this = _s;
- }
- inline
- UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create( _sz.height, _sz.width, _type );
- }
- inline
- UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create(_sz.height, _sz.width, _type);
- *this = _s;
- }
- inline
- UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create(_dims, _sz, _type);
- }
- inline
- UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags)
- : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows)
- {
- create(_dims, _sz, _type);
- *this = _s;
- }
- inline
- UMat::UMat(const UMat& m)
- : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator),
- usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows)
- {
- addref();
- if( m.dims <= 2 )
- {
- step[0] = m.step[0]; step[1] = m.step[1];
- }
- else
- {
- dims = 0;
- copySize(m);
- }
- }
- template<typename _Tp> inline
- UMat::UMat(const std::vector<_Tp>& vec, bool copyData)
- : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
- cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows)
- {
- if(vec.empty())
- return;
- if( !copyData )
- {
- // !!!TODO!!!
- CV_Error(Error::StsNotImplemented, "");
- }
- else
- Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
- }
- inline
- UMat& UMat::operator = (const UMat& m)
- {
- if( this != &m )
- {
- const_cast<UMat&>(m).addref();
- release();
- flags = m.flags;
- if( dims <= 2 && m.dims <= 2 )
- {
- dims = m.dims;
- rows = m.rows;
- cols = m.cols;
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- copySize(m);
- allocator = m.allocator;
- if (usageFlags == USAGE_DEFAULT)
- usageFlags = m.usageFlags;
- u = m.u;
- offset = m.offset;
- }
- return *this;
- }
- inline
- UMat UMat::row(int y) const
- {
- return UMat(*this, Range(y, y + 1), Range::all());
- }
- inline
- UMat UMat::col(int x) const
- {
- return UMat(*this, Range::all(), Range(x, x + 1));
- }
- inline
- UMat UMat::rowRange(int startrow, int endrow) const
- {
- return UMat(*this, Range(startrow, endrow), Range::all());
- }
- inline
- UMat UMat::rowRange(const Range& r) const
- {
- return UMat(*this, r, Range::all());
- }
- inline
- UMat UMat::colRange(int startcol, int endcol) const
- {
- return UMat(*this, Range::all(), Range(startcol, endcol));
- }
- inline
- UMat UMat::colRange(const Range& r) const
- {
- return UMat(*this, Range::all(), r);
- }
- inline
- UMat UMat::clone() const
- {
- UMat m;
- copyTo(m);
- return m;
- }
- inline
- void UMat::assignTo( UMat& m, int _type ) const
- {
- if( _type < 0 )
- m = *this;
- else
- convertTo(m, _type);
- }
- inline
- void UMat::create(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags)
- {
- _type &= TYPE_MASK;
- if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && u )
- return;
- int sz[] = {_rows, _cols};
- create(2, sz, _type, _usageFlags);
- }
- inline
- void UMat::create(Size _sz, int _type, UMatUsageFlags _usageFlags)
- {
- create(_sz.height, _sz.width, _type, _usageFlags);
- }
- inline
- void UMat::addref()
- {
- if( u )
- CV_XADD(&(u->urefcount), 1);
- }
- inline void UMat::release()
- {
- if( u && CV_XADD(&(u->urefcount), -1) == 1 )
- deallocate();
- for(int i = 0; i < dims; i++)
- size.p[i] = 0;
- u = 0;
- }
- inline
- UMat UMat::operator()( Range _rowRange, Range _colRange ) const
- {
- return UMat(*this, _rowRange, _colRange);
- }
- inline
- UMat UMat::operator()( const Rect& roi ) const
- {
- return UMat(*this, roi);
- }
- inline
- UMat UMat::operator()(const Range* ranges) const
- {
- return UMat(*this, ranges);
- }
- inline
- UMat UMat::operator()(const std::vector<Range>& ranges) const
- {
- return UMat(*this, ranges);
- }
- inline
- bool UMat::isContinuous() const
- {
- return (flags & CONTINUOUS_FLAG) != 0;
- }
- inline
- bool UMat::isSubmatrix() const
- {
- return (flags & SUBMATRIX_FLAG) != 0;
- }
- inline
- size_t UMat::elemSize() const
- {
- return dims > 0 ? step.p[dims - 1] : 0;
- }
- inline
- size_t UMat::elemSize1() const
- {
- return CV_ELEM_SIZE1(flags);
- }
- inline
- int UMat::type() const
- {
- return CV_MAT_TYPE(flags);
- }
- inline
- int UMat::depth() const
- {
- return CV_MAT_DEPTH(flags);
- }
- inline
- int UMat::channels() const
- {
- return CV_MAT_CN(flags);
- }
- inline
- size_t UMat::step1(int i) const
- {
- return step.p[i] / elemSize1();
- }
- inline
- bool UMat::empty() const
- {
- return u == 0 || total() == 0 || dims == 0;
- }
- inline
- size_t UMat::total() const
- {
- if( dims <= 2 )
- return (size_t)rows * cols;
- size_t p = 1;
- for( int i = 0; i < dims; i++ )
- p *= size[i];
- return p;
- }
- #ifdef CV_CXX_MOVE_SEMANTICS
- inline
- UMat::UMat(UMat&& m)
- : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator),
- usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows)
- {
- if (m.dims <= 2) // move new step/size info
- {
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- {
- CV_DbgAssert(m.step.p != m.step.buf);
- step.p = m.step.p;
- size.p = m.size.p;
- m.step.p = m.step.buf;
- m.size.p = &m.rows;
- }
- m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
- m.allocator = NULL;
- m.u = NULL;
- m.offset = 0;
- }
- inline
- UMat& UMat::operator = (UMat&& m)
- {
- if (this == &m)
- return *this;
- release();
- flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols;
- allocator = m.allocator; usageFlags = m.usageFlags;
- u = m.u;
- offset = m.offset;
- if (step.p != step.buf) // release self step/size
- {
- fastFree(step.p);
- step.p = step.buf;
- size.p = &rows;
- }
- if (m.dims <= 2) // move new step/size info
- {
- step[0] = m.step[0];
- step[1] = m.step[1];
- }
- else
- {
- CV_DbgAssert(m.step.p != m.step.buf);
- step.p = m.step.p;
- size.p = m.size.p;
- m.step.p = m.step.buf;
- m.size.p = &m.rows;
- }
- m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0;
- m.allocator = NULL;
- m.u = NULL;
- m.offset = 0;
- return *this;
- }
- #endif
- inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; }
- inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; }
- inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; }
- inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; }
- inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; }
- inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; }
- inline void UMatData::markDeviceMemMapped(bool flag)
- {
- if(flag)
- flags |= DEVICE_MEM_MAPPED;
- else
- flags &= ~DEVICE_MEM_MAPPED;
- }
- inline void UMatData::markHostCopyObsolete(bool flag)
- {
- if(flag)
- flags |= HOST_COPY_OBSOLETE;
- else
- flags &= ~HOST_COPY_OBSOLETE;
- }
- inline void UMatData::markDeviceCopyObsolete(bool flag)
- {
- if(flag)
- flags |= DEVICE_COPY_OBSOLETE;
- else
- flags &= ~DEVICE_COPY_OBSOLETE;
- }
- //! @endcond
- } //cv
- #ifdef _MSC_VER
- #pragma warning( pop )
- #endif
- #endif
|