imgproc.hpp 226 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef OPENCV_IMGPROC_HPP
  43. #define OPENCV_IMGPROC_HPP
  44. #include "opencv2/core.hpp"
  45. /**
  46. @defgroup imgproc Image Processing
  47. This module includes image-processing functions.
  48. @{
  49. @defgroup imgproc_filter Image Filtering
  50. Functions and classes described in this section are used to perform various linear or non-linear
  51. filtering operations on 2D images (represented as Mat's). It means that for each pixel location
  52. \f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to
  53. compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of
  54. morphological operations, it is the minimum or maximum values, and so on. The computed response is
  55. stored in the destination image at the same location \f$(x,y)\f$. It means that the output image
  56. will be of the same size as the input image. Normally, the functions support multi-channel arrays,
  57. in which case every channel is processed independently. Therefore, the output image will also have
  58. the same number of channels as the input one.
  59. Another common feature of the functions and classes described in this section is that, unlike
  60. simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For
  61. example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when
  62. processing the left-most pixels in each row, you need pixels to the left of them, that is, outside
  63. of the image. You can let these pixels be the same as the left-most image pixels ("replicated
  64. border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant
  65. border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method.
  66. For details, see #BorderTypes
  67. @anchor filter_depths
  68. ### Depth combinations
  69. Input depth (src.depth()) | Output depth (ddepth)
  70. --------------------------|----------------------
  71. CV_8U | -1/CV_16S/CV_32F/CV_64F
  72. CV_16U/CV_16S | -1/CV_32F/CV_64F
  73. CV_32F | -1/CV_32F/CV_64F
  74. CV_64F | -1/CV_64F
  75. @note when ddepth=-1, the output image will have the same depth as the source.
  76. @defgroup imgproc_transform Geometric Image Transformations
  77. The functions in this section perform various geometrical transformations of 2D images. They do not
  78. change the image content but deform the pixel grid and map this deformed grid to the destination
  79. image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from
  80. destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the
  81. functions compute coordinates of the corresponding "donor" pixel in the source image and copy the
  82. pixel value:
  83. \f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f]
  84. In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow
  85. \texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping
  86. \f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula.
  87. The actual implementations of the geometrical transformations, from the most generic remap and to
  88. the simplest and the fastest resize, need to solve two main problems with the above formula:
  89. - Extrapolation of non-existing pixels. Similarly to the filtering functions described in the
  90. previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both
  91. of them may fall outside of the image. In this case, an extrapolation method needs to be used.
  92. OpenCV provides the same selection of extrapolation methods as in the filtering functions. In
  93. addition, it provides the method #BORDER_TRANSPARENT. This means that the corresponding pixels in
  94. the destination image will not be modified at all.
  95. - Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point
  96. numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective
  97. transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional
  98. coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the
  99. nearest integer coordinates and the corresponding pixel can be used. This is called a
  100. nearest-neighbor interpolation. However, a better result can be achieved by using more
  101. sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) ,
  102. where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y),
  103. f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ is taken as the
  104. interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See
  105. resize for details.
  106. @note The geometrical transformations do not work with `CV_8S` or `CV_32S` images.
  107. @defgroup imgproc_misc Miscellaneous Image Transformations
  108. @defgroup imgproc_draw Drawing Functions
  109. Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be
  110. rendered with antialiasing (implemented only for 8-bit images for now). All the functions include
  111. the parameter color that uses an RGB value (that may be constructed with the Scalar constructor )
  112. for color images and brightness for grayscale images. For color images, the channel ordering is
  113. normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a
  114. color using the Scalar constructor, it should look like:
  115. \f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f]
  116. If you are using your own image rendering and I/O functions, you can use any channel ordering. The
  117. drawing functions process each channel independently and do not depend on the channel order or even
  118. on the used color space. The whole image can be converted from BGR to RGB or to a different color
  119. space using cvtColor .
  120. If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also,
  121. many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means
  122. that the coordinates can be passed as fixed-point numbers encoded as integers. The number of
  123. fractional bits is specified by the shift parameter and the real point coordinates are calculated as
  124. \f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is
  125. especially effective when rendering antialiased shapes.
  126. @note The functions do not support alpha-transparency when the target image is 4-channel. In this
  127. case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint
  128. semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main
  129. image.
  130. @defgroup imgproc_color_conversions Color Space Conversions
  131. @defgroup imgproc_colormap ColorMaps in OpenCV
  132. The human perception isn't built for observing fine changes in grayscale images. Human eyes are more
  133. sensitive to observing changes between colors, so you often need to recolor your grayscale images to
  134. get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your
  135. computer vision application.
  136. In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample
  137. code reads the path to an image from command line, applies a Jet colormap on it and shows the
  138. result:
  139. @include snippets/imgproc_applyColorMap.cpp
  140. @see #ColormapTypes
  141. @defgroup imgproc_subdiv2d Planar Subdivision
  142. The Subdiv2D class described in this section is used to perform various planar subdivision on
  143. a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles
  144. using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram.
  145. In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi
  146. diagram with red lines.
  147. ![Delaunay triangulation (black) and Voronoi (red)](pics/delaunay_voronoi.png)
  148. The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast
  149. location of points on the plane, building special graphs (such as NNG,RNG), and so forth.
  150. @defgroup imgproc_hist Histograms
  151. @defgroup imgproc_shape Structural Analysis and Shape Descriptors
  152. @defgroup imgproc_motion Motion Analysis and Object Tracking
  153. @defgroup imgproc_feature Feature Detection
  154. @defgroup imgproc_object Object Detection
  155. @defgroup imgproc_c C API
  156. @defgroup imgproc_hal Hardware Acceleration Layer
  157. @{
  158. @defgroup imgproc_hal_functions Functions
  159. @defgroup imgproc_hal_interface Interface
  160. @}
  161. @}
  162. */
  163. namespace cv
  164. {
  165. /** @addtogroup imgproc
  166. @{
  167. */
  168. //! @addtogroup imgproc_filter
  169. //! @{
  170. enum SpecialFilter {
  171. FILTER_SCHARR = -1
  172. };
  173. //! type of morphological operation
  174. enum MorphTypes{
  175. MORPH_ERODE = 0, //!< see #erode
  176. MORPH_DILATE = 1, //!< see #dilate
  177. MORPH_OPEN = 2, //!< an opening operation
  178. //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f]
  179. MORPH_CLOSE = 3, //!< a closing operation
  180. //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f]
  181. MORPH_GRADIENT = 4, //!< a morphological gradient
  182. //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f]
  183. MORPH_TOPHAT = 5, //!< "top hat"
  184. //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f]
  185. MORPH_BLACKHAT = 6, //!< "black hat"
  186. //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f]
  187. MORPH_HITMISS = 7 //!< "hit or miss"
  188. //!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation
  189. };
  190. //! shape of the structuring element
  191. enum MorphShapes {
  192. MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f]
  193. MORPH_CROSS = 1, //!< a cross-shaped structuring element:
  194. //!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f]
  195. MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed
  196. //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height)
  197. };
  198. //! @} imgproc_filter
  199. //! @addtogroup imgproc_transform
  200. //! @{
  201. //! interpolation algorithm
  202. enum InterpolationFlags{
  203. /** nearest neighbor interpolation */
  204. INTER_NEAREST = 0,
  205. /** bilinear interpolation */
  206. INTER_LINEAR = 1,
  207. /** bicubic interpolation */
  208. INTER_CUBIC = 2,
  209. /** resampling using pixel area relation. It may be a preferred method for image decimation, as
  210. it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
  211. method. */
  212. INTER_AREA = 3,
  213. /** Lanczos interpolation over 8x8 neighborhood */
  214. INTER_LANCZOS4 = 4,
  215. /** Bit exact bilinear interpolation */
  216. INTER_LINEAR_EXACT = 5,
  217. /** mask for interpolation codes */
  218. INTER_MAX = 7,
  219. /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the
  220. source image, they are set to zero */
  221. WARP_FILL_OUTLIERS = 8,
  222. /** flag, inverse transformation
  223. For example, #linearPolar or #logPolar transforms:
  224. - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$
  225. - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$
  226. */
  227. WARP_INVERSE_MAP = 16
  228. };
  229. /** \brief Specify the polar mapping mode
  230. @sa warpPolar
  231. */
  232. enum WarpPolarMode
  233. {
  234. WARP_POLAR_LINEAR = 0, ///< Remaps an image to/from polar space.
  235. WARP_POLAR_LOG = 256 ///< Remaps an image to/from semilog-polar space.
  236. };
  237. enum InterpolationMasks {
  238. INTER_BITS = 5,
  239. INTER_BITS2 = INTER_BITS * 2,
  240. INTER_TAB_SIZE = 1 << INTER_BITS,
  241. INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE
  242. };
  243. //! @} imgproc_transform
  244. //! @addtogroup imgproc_misc
  245. //! @{
  246. //! Distance types for Distance Transform and M-estimators
  247. //! @see distanceTransform, fitLine
  248. enum DistanceTypes {
  249. DIST_USER = -1, //!< User defined distance
  250. DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2|
  251. DIST_L2 = 2, //!< the simple euclidean distance
  252. DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|)
  253. DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))
  254. DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998
  255. DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
  256. DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345
  257. };
  258. //! Mask size for distance transform
  259. enum DistanceTransformMasks {
  260. DIST_MASK_3 = 3, //!< mask=3
  261. DIST_MASK_5 = 5, //!< mask=5
  262. DIST_MASK_PRECISE = 0 //!<
  263. };
  264. //! type of the threshold operation
  265. //! ![threshold types](pics/threshold.png)
  266. enum ThresholdTypes {
  267. THRESH_BINARY = 0, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
  268. THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f]
  269. THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
  270. THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
  271. THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
  272. THRESH_MASK = 7,
  273. THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value
  274. THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value
  275. };
  276. //! adaptive threshold algorithm
  277. //! @see adaptiveThreshold
  278. enum AdaptiveThresholdTypes {
  279. /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times
  280. \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */
  281. ADAPTIVE_THRESH_MEAN_C = 0,
  282. /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian
  283. window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$
  284. minus C . The default sigma (standard deviation) is used for the specified blockSize . See
  285. #getGaussianKernel*/
  286. ADAPTIVE_THRESH_GAUSSIAN_C = 1
  287. };
  288. //! class of the pixel in GrabCut algorithm
  289. enum GrabCutClasses {
  290. GC_BGD = 0, //!< an obvious background pixels
  291. GC_FGD = 1, //!< an obvious foreground (object) pixel
  292. GC_PR_BGD = 2, //!< a possible background pixel
  293. GC_PR_FGD = 3 //!< a possible foreground pixel
  294. };
  295. //! GrabCut algorithm flags
  296. enum GrabCutModes {
  297. /** The function initializes the state and the mask using the provided rectangle. After that it
  298. runs iterCount iterations of the algorithm. */
  299. GC_INIT_WITH_RECT = 0,
  300. /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT
  301. and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are
  302. automatically initialized with GC_BGD .*/
  303. GC_INIT_WITH_MASK = 1,
  304. /** The value means that the algorithm should just resume. */
  305. GC_EVAL = 2,
  306. /** The value means that the algorithm should just run the grabCut algorithm (a single iteration) with the fixed model */
  307. GC_EVAL_FREEZE_MODEL = 3
  308. };
  309. //! distanceTransform algorithm flags
  310. enum DistanceTransformLabelTypes {
  311. /** each connected component of zeros in src (as well as all the non-zero pixels closest to the
  312. connected component) will be assigned the same label */
  313. DIST_LABEL_CCOMP = 0,
  314. /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */
  315. DIST_LABEL_PIXEL = 1
  316. };
  317. //! floodfill algorithm flags
  318. enum FloodFillFlags {
  319. /** If set, the difference between the current pixel and seed pixel is considered. Otherwise,
  320. the difference between neighbor pixels is considered (that is, the range is floating). */
  321. FLOODFILL_FIXED_RANGE = 1 << 16,
  322. /** If set, the function does not change the image ( newVal is ignored), and only fills the
  323. mask with the value specified in bits 8-16 of flags as described above. This option only make
  324. sense in function variants that have the mask parameter. */
  325. FLOODFILL_MASK_ONLY = 1 << 17
  326. };
  327. //! @} imgproc_misc
  328. //! @addtogroup imgproc_shape
  329. //! @{
  330. //! connected components algorithm output formats
  331. enum ConnectedComponentsTypes {
  332. CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding
  333. //!< box in the horizontal direction.
  334. CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding
  335. //!< box in the vertical direction.
  336. CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box
  337. CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box
  338. CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component
  339. #ifndef CV_DOXYGEN
  340. CC_STAT_MAX = 5 //!< Max enumeration value. Used internally only for memory allocation
  341. #endif
  342. };
  343. //! connected components algorithm
  344. enum ConnectedComponentsAlgorithmsTypes {
  345. CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
  346. CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
  347. CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
  348. };
  349. //! mode of the contour retrieval algorithm
  350. enum RetrievalModes {
  351. /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for
  352. all the contours. */
  353. RETR_EXTERNAL = 0,
  354. /** retrieves all of the contours without establishing any hierarchical relationships. */
  355. RETR_LIST = 1,
  356. /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top
  357. level, there are external boundaries of the components. At the second level, there are
  358. boundaries of the holes. If there is another contour inside a hole of a connected component, it
  359. is still put at the top level. */
  360. RETR_CCOMP = 2,
  361. /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/
  362. RETR_TREE = 3,
  363. RETR_FLOODFILL = 4 //!<
  364. };
  365. //! the contour approximation algorithm
  366. enum ContourApproximationModes {
  367. /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and
  368. (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is,
  369. max(abs(x1-x2),abs(y2-y1))==1. */
  370. CHAIN_APPROX_NONE = 1,
  371. /** compresses horizontal, vertical, and diagonal segments and leaves only their end points.
  372. For example, an up-right rectangular contour is encoded with 4 points. */
  373. CHAIN_APPROX_SIMPLE = 2,
  374. /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
  375. CHAIN_APPROX_TC89_L1 = 3,
  376. /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
  377. CHAIN_APPROX_TC89_KCOS = 4
  378. };
  379. /** @brief Shape matching methods
  380. \f$A\f$ denotes object1,\f$B\f$ denotes object2
  381. \f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$
  382. and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively.
  383. */
  384. enum ShapeMatchModes {
  385. CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f]
  386. CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f]
  387. CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f]
  388. };
  389. //! @} imgproc_shape
  390. //! @addtogroup imgproc_feature
  391. //! @{
  392. //! Variants of a Hough transform
  393. enum HoughModes {
  394. /** classical or standard Hough transform. Every line is represented by two floating-point
  395. numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line,
  396. and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must
  397. be (the created sequence will be) of CV_32FC2 type */
  398. HOUGH_STANDARD = 0,
  399. /** probabilistic Hough transform (more efficient in case if the picture contains a few long
  400. linear segments). It returns line segments rather than the whole line. Each segment is
  401. represented by starting and ending points, and the matrix must be (the created sequence will
  402. be) of the CV_32SC4 type. */
  403. HOUGH_PROBABILISTIC = 1,
  404. /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as
  405. HOUGH_STANDARD. */
  406. HOUGH_MULTI_SCALE = 2,
  407. HOUGH_GRADIENT = 3, //!< basically *21HT*, described in @cite Yuen90
  408. HOUGH_GRADIENT_ALT = 4, //!< variation of HOUGH_GRADIENT to get better accuracy
  409. };
  410. //! Variants of Line Segment %Detector
  411. enum LineSegmentDetectorModes {
  412. LSD_REFINE_NONE = 0, //!< No refinement applied
  413. LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations.
  414. LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are
  415. //!< refined through increase of precision, decrement in size, etc.
  416. };
  417. //! @} imgproc_feature
  418. /** Histogram comparison methods
  419. @ingroup imgproc_hist
  420. */
  421. enum HistCompMethods {
  422. /** Correlation
  423. \f[d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\f]
  424. where
  425. \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f]
  426. and \f$N\f$ is a total number of histogram bins. */
  427. HISTCMP_CORREL = 0,
  428. /** Chi-Square
  429. \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */
  430. HISTCMP_CHISQR = 1,
  431. /** Intersection
  432. \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */
  433. HISTCMP_INTERSECT = 2,
  434. /** Bhattacharyya distance
  435. (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.)
  436. \f[d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\f] */
  437. HISTCMP_BHATTACHARYYA = 3,
  438. HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA
  439. /** Alternative Chi-Square
  440. \f[d(H_1,H_2) = 2 * \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}\f]
  441. This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */
  442. HISTCMP_CHISQR_ALT = 4,
  443. /** Kullback-Leibler divergence
  444. \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */
  445. HISTCMP_KL_DIV = 5
  446. };
  447. /** the color conversion codes
  448. @see @ref imgproc_color_conversions
  449. @ingroup imgproc_color_conversions
  450. */
  451. enum ColorConversionCodes {
  452. COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image
  453. COLOR_RGB2RGBA = COLOR_BGR2BGRA,
  454. COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image
  455. COLOR_RGBA2RGB = COLOR_BGRA2BGR,
  456. COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)
  457. COLOR_RGB2BGRA = COLOR_BGR2RGBA,
  458. COLOR_RGBA2BGR = 3,
  459. COLOR_BGRA2RGB = COLOR_RGBA2BGR,
  460. COLOR_BGR2RGB = 4,
  461. COLOR_RGB2BGR = COLOR_BGR2RGB,
  462. COLOR_BGRA2RGBA = 5,
  463. COLOR_RGBA2BGRA = COLOR_BGRA2RGBA,
  464. COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
  465. COLOR_RGB2GRAY = 7,
  466. COLOR_GRAY2BGR = 8,
  467. COLOR_GRAY2RGB = COLOR_GRAY2BGR,
  468. COLOR_GRAY2BGRA = 9,
  469. COLOR_GRAY2RGBA = COLOR_GRAY2BGRA,
  470. COLOR_BGRA2GRAY = 10,
  471. COLOR_RGBA2GRAY = 11,
  472. COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images)
  473. COLOR_RGB2BGR565 = 13,
  474. COLOR_BGR5652BGR = 14,
  475. COLOR_BGR5652RGB = 15,
  476. COLOR_BGRA2BGR565 = 16,
  477. COLOR_RGBA2BGR565 = 17,
  478. COLOR_BGR5652BGRA = 18,
  479. COLOR_BGR5652RGBA = 19,
  480. COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images)
  481. COLOR_BGR5652GRAY = 21,
  482. COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images)
  483. COLOR_RGB2BGR555 = 23,
  484. COLOR_BGR5552BGR = 24,
  485. COLOR_BGR5552RGB = 25,
  486. COLOR_BGRA2BGR555 = 26,
  487. COLOR_RGBA2BGR555 = 27,
  488. COLOR_BGR5552BGRA = 28,
  489. COLOR_BGR5552RGBA = 29,
  490. COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images)
  491. COLOR_BGR5552GRAY = 31,
  492. COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
  493. COLOR_RGB2XYZ = 33,
  494. COLOR_XYZ2BGR = 34,
  495. COLOR_XYZ2RGB = 35,
  496. COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions"
  497. COLOR_RGB2YCrCb = 37,
  498. COLOR_YCrCb2BGR = 38,
  499. COLOR_YCrCb2RGB = 39,
  500. COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
  501. COLOR_RGB2HSV = 41,
  502. COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
  503. COLOR_RGB2Lab = 45,
  504. COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
  505. COLOR_RGB2Luv = 51,
  506. COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
  507. COLOR_RGB2HLS = 53,
  508. COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
  509. COLOR_HSV2RGB = 55,
  510. COLOR_Lab2BGR = 56,
  511. COLOR_Lab2RGB = 57,
  512. COLOR_Luv2BGR = 58,
  513. COLOR_Luv2RGB = 59,
  514. COLOR_HLS2BGR = 60,
  515. COLOR_HLS2RGB = 61,
  516. COLOR_BGR2HSV_FULL = 66,
  517. COLOR_RGB2HSV_FULL = 67,
  518. COLOR_BGR2HLS_FULL = 68,
  519. COLOR_RGB2HLS_FULL = 69,
  520. COLOR_HSV2BGR_FULL = 70,
  521. COLOR_HSV2RGB_FULL = 71,
  522. COLOR_HLS2BGR_FULL = 72,
  523. COLOR_HLS2RGB_FULL = 73,
  524. COLOR_LBGR2Lab = 74,
  525. COLOR_LRGB2Lab = 75,
  526. COLOR_LBGR2Luv = 76,
  527. COLOR_LRGB2Luv = 77,
  528. COLOR_Lab2LBGR = 78,
  529. COLOR_Lab2LRGB = 79,
  530. COLOR_Luv2LBGR = 80,
  531. COLOR_Luv2LRGB = 81,
  532. COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV
  533. COLOR_RGB2YUV = 83,
  534. COLOR_YUV2BGR = 84,
  535. COLOR_YUV2RGB = 85,
  536. //! YUV 4:2:0 family to RGB
  537. COLOR_YUV2RGB_NV12 = 90,
  538. COLOR_YUV2BGR_NV12 = 91,
  539. COLOR_YUV2RGB_NV21 = 92,
  540. COLOR_YUV2BGR_NV21 = 93,
  541. COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
  542. COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,
  543. COLOR_YUV2RGBA_NV12 = 94,
  544. COLOR_YUV2BGRA_NV12 = 95,
  545. COLOR_YUV2RGBA_NV21 = 96,
  546. COLOR_YUV2BGRA_NV21 = 97,
  547. COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
  548. COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
  549. COLOR_YUV2RGB_YV12 = 98,
  550. COLOR_YUV2BGR_YV12 = 99,
  551. COLOR_YUV2RGB_IYUV = 100,
  552. COLOR_YUV2BGR_IYUV = 101,
  553. COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
  554. COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
  555. COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
  556. COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
  557. COLOR_YUV2RGBA_YV12 = 102,
  558. COLOR_YUV2BGRA_YV12 = 103,
  559. COLOR_YUV2RGBA_IYUV = 104,
  560. COLOR_YUV2BGRA_IYUV = 105,
  561. COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
  562. COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
  563. COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
  564. COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,
  565. COLOR_YUV2GRAY_420 = 106,
  566. COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
  567. COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
  568. COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
  569. COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
  570. COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
  571. COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
  572. COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,
  573. //! YUV 4:2:2 family to RGB
  574. COLOR_YUV2RGB_UYVY = 107,
  575. COLOR_YUV2BGR_UYVY = 108,
  576. //COLOR_YUV2RGB_VYUY = 109,
  577. //COLOR_YUV2BGR_VYUY = 110,
  578. COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
  579. COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
  580. COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
  581. COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,
  582. COLOR_YUV2RGBA_UYVY = 111,
  583. COLOR_YUV2BGRA_UYVY = 112,
  584. //COLOR_YUV2RGBA_VYUY = 113,
  585. //COLOR_YUV2BGRA_VYUY = 114,
  586. COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
  587. COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
  588. COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
  589. COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,
  590. COLOR_YUV2RGB_YUY2 = 115,
  591. COLOR_YUV2BGR_YUY2 = 116,
  592. COLOR_YUV2RGB_YVYU = 117,
  593. COLOR_YUV2BGR_YVYU = 118,
  594. COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
  595. COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
  596. COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
  597. COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,
  598. COLOR_YUV2RGBA_YUY2 = 119,
  599. COLOR_YUV2BGRA_YUY2 = 120,
  600. COLOR_YUV2RGBA_YVYU = 121,
  601. COLOR_YUV2BGRA_YVYU = 122,
  602. COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
  603. COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
  604. COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
  605. COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,
  606. COLOR_YUV2GRAY_UYVY = 123,
  607. COLOR_YUV2GRAY_YUY2 = 124,
  608. //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY,
  609. COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
  610. COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
  611. COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
  612. COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
  613. COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,
  614. //! alpha premultiplication
  615. COLOR_RGBA2mRGBA = 125,
  616. COLOR_mRGBA2RGBA = 126,
  617. //! RGB to YUV 4:2:0 family
  618. COLOR_RGB2YUV_I420 = 127,
  619. COLOR_BGR2YUV_I420 = 128,
  620. COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420,
  621. COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420,
  622. COLOR_RGBA2YUV_I420 = 129,
  623. COLOR_BGRA2YUV_I420 = 130,
  624. COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,
  625. COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,
  626. COLOR_RGB2YUV_YV12 = 131,
  627. COLOR_BGR2YUV_YV12 = 132,
  628. COLOR_RGBA2YUV_YV12 = 133,
  629. COLOR_BGRA2YUV_YV12 = 134,
  630. //! Demosaicing
  631. COLOR_BayerBG2BGR = 46,
  632. COLOR_BayerGB2BGR = 47,
  633. COLOR_BayerRG2BGR = 48,
  634. COLOR_BayerGR2BGR = 49,
  635. COLOR_BayerBG2RGB = COLOR_BayerRG2BGR,
  636. COLOR_BayerGB2RGB = COLOR_BayerGR2BGR,
  637. COLOR_BayerRG2RGB = COLOR_BayerBG2BGR,
  638. COLOR_BayerGR2RGB = COLOR_BayerGB2BGR,
  639. COLOR_BayerBG2GRAY = 86,
  640. COLOR_BayerGB2GRAY = 87,
  641. COLOR_BayerRG2GRAY = 88,
  642. COLOR_BayerGR2GRAY = 89,
  643. //! Demosaicing using Variable Number of Gradients
  644. COLOR_BayerBG2BGR_VNG = 62,
  645. COLOR_BayerGB2BGR_VNG = 63,
  646. COLOR_BayerRG2BGR_VNG = 64,
  647. COLOR_BayerGR2BGR_VNG = 65,
  648. COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG,
  649. COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG,
  650. COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG,
  651. COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG,
  652. //! Edge-Aware Demosaicing
  653. COLOR_BayerBG2BGR_EA = 135,
  654. COLOR_BayerGB2BGR_EA = 136,
  655. COLOR_BayerRG2BGR_EA = 137,
  656. COLOR_BayerGR2BGR_EA = 138,
  657. COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA,
  658. COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA,
  659. COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA,
  660. COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA,
  661. //! Demosaicing with alpha channel
  662. COLOR_BayerBG2BGRA = 139,
  663. COLOR_BayerGB2BGRA = 140,
  664. COLOR_BayerRG2BGRA = 141,
  665. COLOR_BayerGR2BGRA = 142,
  666. COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA,
  667. COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA,
  668. COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA,
  669. COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA,
  670. COLOR_COLORCVT_MAX = 143
  671. };
  672. //! @addtogroup imgproc_shape
  673. //! @{
  674. //! types of intersection between rectangles
  675. enum RectanglesIntersectTypes {
  676. INTERSECT_NONE = 0, //!< No intersection
  677. INTERSECT_PARTIAL = 1, //!< There is a partial intersection
  678. INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other
  679. };
  680. /** types of line
  681. @ingroup imgproc_draw
  682. */
  683. enum LineTypes {
  684. FILLED = -1,
  685. LINE_4 = 4, //!< 4-connected line
  686. LINE_8 = 8, //!< 8-connected line
  687. LINE_AA = 16 //!< antialiased line
  688. };
  689. /** Only a subset of Hershey fonts <https://en.wikipedia.org/wiki/Hershey_fonts> are supported
  690. @ingroup imgproc_draw
  691. */
  692. enum HersheyFonts {
  693. FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font
  694. FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font
  695. FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)
  696. FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font
  697. FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX)
  698. FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX
  699. FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font
  700. FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX
  701. FONT_ITALIC = 16 //!< flag for italic font
  702. };
  703. /** Possible set of marker types used for the cv::drawMarker function
  704. @ingroup imgproc_draw
  705. */
  706. enum MarkerTypes
  707. {
  708. MARKER_CROSS = 0, //!< A crosshair marker shape
  709. MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape
  710. MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross
  711. MARKER_DIAMOND = 3, //!< A diamond marker shape
  712. MARKER_SQUARE = 4, //!< A square marker shape
  713. MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape
  714. MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape
  715. };
  716. /** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform
  717. */
  718. class CV_EXPORTS_W GeneralizedHough : public Algorithm
  719. {
  720. public:
  721. //! set template to search
  722. CV_WRAP virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0;
  723. CV_WRAP virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0;
  724. //! find template on image
  725. CV_WRAP virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0;
  726. CV_WRAP virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0;
  727. //! Canny low threshold.
  728. CV_WRAP virtual void setCannyLowThresh(int cannyLowThresh) = 0;
  729. CV_WRAP virtual int getCannyLowThresh() const = 0;
  730. //! Canny high threshold.
  731. CV_WRAP virtual void setCannyHighThresh(int cannyHighThresh) = 0;
  732. CV_WRAP virtual int getCannyHighThresh() const = 0;
  733. //! Minimum distance between the centers of the detected objects.
  734. CV_WRAP virtual void setMinDist(double minDist) = 0;
  735. CV_WRAP virtual double getMinDist() const = 0;
  736. //! Inverse ratio of the accumulator resolution to the image resolution.
  737. CV_WRAP virtual void setDp(double dp) = 0;
  738. CV_WRAP virtual double getDp() const = 0;
  739. //! Maximal size of inner buffers.
  740. CV_WRAP virtual void setMaxBufferSize(int maxBufferSize) = 0;
  741. CV_WRAP virtual int getMaxBufferSize() const = 0;
  742. };
  743. /** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform
  744. Detects position only without translation and rotation @cite Ballard1981 .
  745. */
  746. class CV_EXPORTS_W GeneralizedHoughBallard : public GeneralizedHough
  747. {
  748. public:
  749. //! R-Table levels.
  750. CV_WRAP virtual void setLevels(int levels) = 0;
  751. CV_WRAP virtual int getLevels() const = 0;
  752. //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected.
  753. CV_WRAP virtual void setVotesThreshold(int votesThreshold) = 0;
  754. CV_WRAP virtual int getVotesThreshold() const = 0;
  755. };
  756. /** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform
  757. Detects position, translation and rotation @cite Guil1999 .
  758. */
  759. class CV_EXPORTS_W GeneralizedHoughGuil : public GeneralizedHough
  760. {
  761. public:
  762. //! Angle difference in degrees between two points in feature.
  763. CV_WRAP virtual void setXi(double xi) = 0;
  764. CV_WRAP virtual double getXi() const = 0;
  765. //! Feature table levels.
  766. CV_WRAP virtual void setLevels(int levels) = 0;
  767. CV_WRAP virtual int getLevels() const = 0;
  768. //! Maximal difference between angles that treated as equal.
  769. CV_WRAP virtual void setAngleEpsilon(double angleEpsilon) = 0;
  770. CV_WRAP virtual double getAngleEpsilon() const = 0;
  771. //! Minimal rotation angle to detect in degrees.
  772. CV_WRAP virtual void setMinAngle(double minAngle) = 0;
  773. CV_WRAP virtual double getMinAngle() const = 0;
  774. //! Maximal rotation angle to detect in degrees.
  775. CV_WRAP virtual void setMaxAngle(double maxAngle) = 0;
  776. CV_WRAP virtual double getMaxAngle() const = 0;
  777. //! Angle step in degrees.
  778. CV_WRAP virtual void setAngleStep(double angleStep) = 0;
  779. CV_WRAP virtual double getAngleStep() const = 0;
  780. //! Angle votes threshold.
  781. CV_WRAP virtual void setAngleThresh(int angleThresh) = 0;
  782. CV_WRAP virtual int getAngleThresh() const = 0;
  783. //! Minimal scale to detect.
  784. CV_WRAP virtual void setMinScale(double minScale) = 0;
  785. CV_WRAP virtual double getMinScale() const = 0;
  786. //! Maximal scale to detect.
  787. CV_WRAP virtual void setMaxScale(double maxScale) = 0;
  788. CV_WRAP virtual double getMaxScale() const = 0;
  789. //! Scale step.
  790. CV_WRAP virtual void setScaleStep(double scaleStep) = 0;
  791. CV_WRAP virtual double getScaleStep() const = 0;
  792. //! Scale votes threshold.
  793. CV_WRAP virtual void setScaleThresh(int scaleThresh) = 0;
  794. CV_WRAP virtual int getScaleThresh() const = 0;
  795. //! Position votes threshold.
  796. CV_WRAP virtual void setPosThresh(int posThresh) = 0;
  797. CV_WRAP virtual int getPosThresh() const = 0;
  798. };
  799. //! @} imgproc_shape
  800. //! @addtogroup imgproc_hist
  801. //! @{
  802. /** @brief Base class for Contrast Limited Adaptive Histogram Equalization.
  803. */
  804. class CV_EXPORTS_W CLAHE : public Algorithm
  805. {
  806. public:
  807. /** @brief Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization.
  808. @param src Source image of type CV_8UC1 or CV_16UC1.
  809. @param dst Destination image.
  810. */
  811. CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0;
  812. /** @brief Sets threshold for contrast limiting.
  813. @param clipLimit threshold value.
  814. */
  815. CV_WRAP virtual void setClipLimit(double clipLimit) = 0;
  816. //! Returns threshold value for contrast limiting.
  817. CV_WRAP virtual double getClipLimit() const = 0;
  818. /** @brief Sets size of grid for histogram equalization. Input image will be divided into
  819. equally sized rectangular tiles.
  820. @param tileGridSize defines the number of tiles in row and column.
  821. */
  822. CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0;
  823. //!@brief Returns Size defines the number of tiles in row and column.
  824. CV_WRAP virtual Size getTilesGridSize() const = 0;
  825. CV_WRAP virtual void collectGarbage() = 0;
  826. };
  827. //! @} imgproc_hist
  828. //! @addtogroup imgproc_subdiv2d
  829. //! @{
  830. class CV_EXPORTS_W Subdiv2D
  831. {
  832. public:
  833. /** Subdiv2D point location cases */
  834. enum { PTLOC_ERROR = -2, //!< Point location error
  835. PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect
  836. PTLOC_INSIDE = 0, //!< Point inside some facet
  837. PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices
  838. PTLOC_ON_EDGE = 2 //!< Point on some edge
  839. };
  840. /** Subdiv2D edge type navigation (see: getEdge()) */
  841. enum { NEXT_AROUND_ORG = 0x00,
  842. NEXT_AROUND_DST = 0x22,
  843. PREV_AROUND_ORG = 0x11,
  844. PREV_AROUND_DST = 0x33,
  845. NEXT_AROUND_LEFT = 0x13,
  846. NEXT_AROUND_RIGHT = 0x31,
  847. PREV_AROUND_LEFT = 0x20,
  848. PREV_AROUND_RIGHT = 0x02
  849. };
  850. /** creates an empty Subdiv2D object.
  851. To create a new empty Delaunay subdivision you need to use the #initDelaunay function.
  852. */
  853. CV_WRAP Subdiv2D();
  854. /** @overload
  855. @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
  856. The function creates an empty Delaunay subdivision where 2D points can be added using the function
  857. insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime
  858. error is raised.
  859. */
  860. CV_WRAP Subdiv2D(Rect rect);
  861. /** @brief Creates a new empty Delaunay subdivision
  862. @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
  863. */
  864. CV_WRAP void initDelaunay(Rect rect);
  865. /** @brief Insert a single point into a Delaunay triangulation.
  866. @param pt Point to insert.
  867. The function inserts a single point into a subdivision and modifies the subdivision topology
  868. appropriately. If a point with the same coordinates exists already, no new point is added.
  869. @returns the ID of the point.
  870. @note If the point is outside of the triangulation specified rect a runtime error is raised.
  871. */
  872. CV_WRAP int insert(Point2f pt);
  873. /** @brief Insert multiple points into a Delaunay triangulation.
  874. @param ptvec Points to insert.
  875. The function inserts a vector of points into a subdivision and modifies the subdivision topology
  876. appropriately.
  877. */
  878. CV_WRAP void insert(const std::vector<Point2f>& ptvec);
  879. /** @brief Returns the location of a point within a Delaunay triangulation.
  880. @param pt Point to locate.
  881. @param edge Output edge that the point belongs to or is located to the right of it.
  882. @param vertex Optional output vertex the input point coincides with.
  883. The function locates the input point within the subdivision and gives one of the triangle edges
  884. or vertices.
  885. @returns an integer which specify one of the following five cases for point location:
  886. - The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of
  887. edges of the facet.
  888. - The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge.
  889. - The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and
  890. vertex will contain a pointer to the vertex.
  891. - The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT
  892. and no pointers are filled.
  893. - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error
  894. processing mode is selected, #PTLOC_ERROR is returned.
  895. */
  896. CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex);
  897. /** @brief Finds the subdivision vertex closest to the given point.
  898. @param pt Input point.
  899. @param nearestPt Output subdivision vertex point.
  900. The function is another function that locates the input point within the subdivision. It finds the
  901. subdivision vertex that is the closest to the input point. It is not necessarily one of vertices
  902. of the facet containing the input point, though the facet (located using locate() ) is used as a
  903. starting point.
  904. @returns vertex ID.
  905. */
  906. CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0);
  907. /** @brief Returns a list of all edges.
  908. @param edgeList Output vector.
  909. The function gives each edge as a 4 numbers vector, where each two are one of the edge
  910. vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].
  911. */
  912. CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const;
  913. /** @brief Returns a list of the leading edge ID connected to each triangle.
  914. @param leadingEdgeList Output vector.
  915. The function gives one edge ID for each triangle.
  916. */
  917. CV_WRAP void getLeadingEdgeList(CV_OUT std::vector<int>& leadingEdgeList) const;
  918. /** @brief Returns a list of all triangles.
  919. @param triangleList Output vector.
  920. The function gives each triangle as a 6 numbers vector, where each two are one of the triangle
  921. vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5].
  922. */
  923. CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const;
  924. /** @brief Returns a list of all Voronoi facets.
  925. @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector.
  926. @param facetList Output vector of the Voronoi facets.
  927. @param facetCenters Output vector of the Voronoi facets center points.
  928. */
  929. CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList,
  930. CV_OUT std::vector<Point2f>& facetCenters);
  931. /** @brief Returns vertex location from vertex ID.
  932. @param vertex vertex ID.
  933. @param firstEdge Optional. The first edge ID which is connected to the vertex.
  934. @returns vertex (x,y)
  935. */
  936. CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const;
  937. /** @brief Returns one of the edges related to the given edge.
  938. @param edge Subdivision edge ID.
  939. @param nextEdgeType Parameter specifying which of the related edges to return.
  940. The following values are possible:
  941. - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)
  942. - NEXT_AROUND_DST next around the edge vertex ( eDnext )
  943. - PREV_AROUND_ORG previous around the edge origin (reversed eRnext )
  944. - PREV_AROUND_DST previous around the edge destination (reversed eLnext )
  945. - NEXT_AROUND_LEFT next around the left facet ( eLnext )
  946. - NEXT_AROUND_RIGHT next around the right facet ( eRnext )
  947. - PREV_AROUND_LEFT previous around the left facet (reversed eOnext )
  948. - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )
  949. ![sample output](pics/quadedge.png)
  950. @returns edge ID related to the input edge.
  951. */
  952. CV_WRAP int getEdge( int edge, int nextEdgeType ) const;
  953. /** @brief Returns next edge around the edge origin.
  954. @param edge Subdivision edge ID.
  955. @returns an integer which is next edge ID around the edge origin: eOnext on the
  956. picture above if e is the input edge).
  957. */
  958. CV_WRAP int nextEdge(int edge) const;
  959. /** @brief Returns another edge of the same quad-edge.
  960. @param edge Subdivision edge ID.
  961. @param rotate Parameter specifying which of the edges of the same quad-edge as the input
  962. one to return. The following values are possible:
  963. - 0 - the input edge ( e on the picture below if e is the input edge)
  964. - 1 - the rotated edge ( eRot )
  965. - 2 - the reversed edge (reversed e (in green))
  966. - 3 - the reversed rotated edge (reversed eRot (in green))
  967. @returns one of the edges ID of the same quad-edge as the input edge.
  968. */
  969. CV_WRAP int rotateEdge(int edge, int rotate) const;
  970. CV_WRAP int symEdge(int edge) const;
  971. /** @brief Returns the edge origin.
  972. @param edge Subdivision edge ID.
  973. @param orgpt Output vertex location.
  974. @returns vertex ID.
  975. */
  976. CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const;
  977. /** @brief Returns the edge destination.
  978. @param edge Subdivision edge ID.
  979. @param dstpt Output vertex location.
  980. @returns vertex ID.
  981. */
  982. CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const;
  983. protected:
  984. int newEdge();
  985. void deleteEdge(int edge);
  986. int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0);
  987. void deletePoint(int vtx);
  988. void setEdgePoints( int edge, int orgPt, int dstPt );
  989. void splice( int edgeA, int edgeB );
  990. int connectEdges( int edgeA, int edgeB );
  991. void swapEdges( int edge );
  992. int isRightOf(Point2f pt, int edge) const;
  993. void calcVoronoi();
  994. void clearVoronoi();
  995. void checkSubdiv() const;
  996. struct CV_EXPORTS Vertex
  997. {
  998. Vertex();
  999. Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0);
  1000. bool isvirtual() const;
  1001. bool isfree() const;
  1002. int firstEdge;
  1003. int type;
  1004. Point2f pt;
  1005. };
  1006. struct CV_EXPORTS QuadEdge
  1007. {
  1008. QuadEdge();
  1009. QuadEdge(int edgeidx);
  1010. bool isfree() const;
  1011. int next[4];
  1012. int pt[4];
  1013. };
  1014. //! All of the vertices
  1015. std::vector<Vertex> vtx;
  1016. //! All of the edges
  1017. std::vector<QuadEdge> qedges;
  1018. int freeQEdge;
  1019. int freePoint;
  1020. bool validGeometry;
  1021. int recentEdge;
  1022. //! Top left corner of the bounding rect
  1023. Point2f topLeft;
  1024. //! Bottom right corner of the bounding rect
  1025. Point2f bottomRight;
  1026. };
  1027. //! @} imgproc_subdiv2d
  1028. //! @addtogroup imgproc_feature
  1029. //! @{
  1030. /** @brief Line segment detector class
  1031. following the algorithm described at @cite Rafael12 .
  1032. @note Implementation has been removed due original code license conflict
  1033. */
  1034. class CV_EXPORTS_W LineSegmentDetector : public Algorithm
  1035. {
  1036. public:
  1037. /** @brief Finds lines in the input image.
  1038. This is the output of the default parameters of the algorithm on the above shown image.
  1039. ![image](pics/building_lsd.png)
  1040. @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use:
  1041. `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
  1042. @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where
  1043. Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly
  1044. oriented depending on the gradient.
  1045. @param width Vector of widths of the regions, where the lines are found. E.g. Width of line.
  1046. @param prec Vector of precisions with which the lines are found.
  1047. @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The
  1048. bigger the value, logarithmically better the detection.
  1049. - -1 corresponds to 10 mean false alarms
  1050. - 0 corresponds to 1 mean false alarm
  1051. - 1 corresponds to 0.1 mean false alarms
  1052. This vector will be calculated only when the objects type is #LSD_REFINE_ADV.
  1053. */
  1054. CV_WRAP virtual void detect(InputArray _image, OutputArray _lines,
  1055. OutputArray width = noArray(), OutputArray prec = noArray(),
  1056. OutputArray nfa = noArray()) = 0;
  1057. /** @brief Draws the line segments on a given image.
  1058. @param _image The image, where the lines will be drawn. Should be bigger or equal to the image,
  1059. where the lines were found.
  1060. @param lines A vector of the lines that needed to be drawn.
  1061. */
  1062. CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0;
  1063. /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels.
  1064. @param size The size of the image, where lines1 and lines2 were found.
  1065. @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color.
  1066. @param lines2 The second group of lines. They visualized in red color.
  1067. @param _image Optional image, where the lines will be drawn. The image should be color(3-channel)
  1068. in order for lines1 and lines2 to be drawn in the above mentioned colors.
  1069. */
  1070. CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0;
  1071. virtual ~LineSegmentDetector() { }
  1072. };
  1073. /** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it.
  1074. The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want
  1075. to edit those, as to tailor it for their own application.
  1076. @param _refine The way found lines will be refined, see #LineSegmentDetectorModes
  1077. @param _scale The scale of the image that will be used to find the lines. Range (0..1].
  1078. @param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale.
  1079. @param _quant Bound to the quantization error on the gradient norm.
  1080. @param _ang_th Gradient angle tolerance in degrees.
  1081. @param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement
  1082. is chosen.
  1083. @param _density_th Minimal density of aligned region points in the enclosing rectangle.
  1084. @param _n_bins Number of bins in pseudo-ordering of gradient modulus.
  1085. @note Implementation has been removed due original code license conflict
  1086. */
  1087. CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(
  1088. int _refine = LSD_REFINE_STD, double _scale = 0.8,
  1089. double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5,
  1090. double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024);
  1091. //! @} imgproc_feature
  1092. //! @addtogroup imgproc_filter
  1093. //! @{
  1094. /** @brief Returns Gaussian filter coefficients.
  1095. The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter
  1096. coefficients:
  1097. \f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f]
  1098. where \f$i=0..\texttt{ksize}-1\f$ and \f$\alpha\f$ is the scale factor chosen so that \f$\sum_i G_i=1\f$.
  1099. Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize
  1100. smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly.
  1101. You may also use the higher-level GaussianBlur.
  1102. @param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive.
  1103. @param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as
  1104. `sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`.
  1105. @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
  1106. @sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur
  1107. */
  1108. CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F );
  1109. /** @brief Returns filter coefficients for computing spatial image derivatives.
  1110. The function computes and returns the filter coefficients for spatial image derivatives. When
  1111. `ksize=FILTER_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel
  1112. kernels are generated (see #Sobel). The filters are normally passed to #sepFilter2D or to
  1113. @param kx Output matrix of row filter coefficients. It has the type ktype .
  1114. @param ky Output matrix of column filter coefficients. It has the type ktype .
  1115. @param dx Derivative order in respect of x.
  1116. @param dy Derivative order in respect of y.
  1117. @param ksize Aperture size. It can be FILTER_SCHARR, 1, 3, 5, or 7.
  1118. @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not.
  1119. Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are
  1120. going to filter floating-point images, you are likely to use the normalized kernels. But if you
  1121. compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve
  1122. all the fractional bits, you may want to set normalize=false .
  1123. @param ktype Type of filter coefficients. It can be CV_32f or CV_64F .
  1124. */
  1125. CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky,
  1126. int dx, int dy, int ksize,
  1127. bool normalize = false, int ktype = CV_32F );
  1128. /** @brief Returns Gabor filter coefficients.
  1129. For more details about gabor filter equations and parameters, see: [Gabor
  1130. Filter](http://en.wikipedia.org/wiki/Gabor_filter).
  1131. @param ksize Size of the filter returned.
  1132. @param sigma Standard deviation of the gaussian envelope.
  1133. @param theta Orientation of the normal to the parallel stripes of a Gabor function.
  1134. @param lambd Wavelength of the sinusoidal factor.
  1135. @param gamma Spatial aspect ratio.
  1136. @param psi Phase offset.
  1137. @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
  1138. */
  1139. CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd,
  1140. double gamma, double psi = CV_PI*0.5, int ktype = CV_64F );
  1141. //! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
  1142. static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
  1143. /** @brief Returns a structuring element of the specified size and shape for morphological operations.
  1144. The function constructs and returns the structuring element that can be further passed to #erode,
  1145. #dilate or #morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as
  1146. the structuring element.
  1147. @param shape Element shape that could be one of #MorphShapes
  1148. @param ksize Size of the structuring element.
  1149. @param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the
  1150. anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor
  1151. position. In other cases the anchor just regulates how much the result of the morphological
  1152. operation is shifted.
  1153. */
  1154. CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));
  1155. /** @example samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp
  1156. Sample code for simple filters
  1157. ![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg)
  1158. Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details
  1159. */
  1160. /** @brief Blurs an image using the median filter.
  1161. The function smoothes an image using the median filter with the \f$\texttt{ksize} \times
  1162. \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently.
  1163. In-place operation is supported.
  1164. @note The median filter uses #BORDER_REPLICATE internally to cope with border pixels, see #BorderTypes
  1165. @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be
  1166. CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.
  1167. @param dst destination array of the same size and type as src.
  1168. @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
  1169. @sa bilateralFilter, blur, boxFilter, GaussianBlur
  1170. */
  1171. CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize );
  1172. /** @brief Blurs an image using a Gaussian filter.
  1173. The function convolves the source image with the specified Gaussian kernel. In-place filtering is
  1174. supported.
  1175. @param src input image; the image can have any number of channels, which are processed
  1176. independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  1177. @param dst output image of the same size and type as src.
  1178. @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
  1179. positive and odd. Or, they can be zero's and then they are computed from sigma.
  1180. @param sigmaX Gaussian kernel standard deviation in X direction.
  1181. @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
  1182. equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
  1183. respectively (see #getGaussianKernel for details); to fully control the result regardless of
  1184. possible future modifications of all this semantics, it is recommended to specify all of ksize,
  1185. sigmaX, and sigmaY.
  1186. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1187. @sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur
  1188. */
  1189. CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize,
  1190. double sigmaX, double sigmaY = 0,
  1191. int borderType = BORDER_DEFAULT );
  1192. /** @brief Applies the bilateral filter to an image.
  1193. The function applies bilateral filtering to the input image, as described in
  1194. http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
  1195. bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
  1196. very slow compared to most filters.
  1197. _Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<
  1198. 10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very
  1199. strong effect, making the image look "cartoonish".
  1200. _Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time
  1201. applications, and perhaps d=9 for offline applications that need heavy noise filtering.
  1202. This filter does not work inplace.
  1203. @param src Source 8-bit or floating-point, 1-channel or 3-channel image.
  1204. @param dst Destination image of the same size and type as src .
  1205. @param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
  1206. it is computed from sigmaSpace.
  1207. @param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
  1208. farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
  1209. in larger areas of semi-equal color.
  1210. @param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that
  1211. farther pixels will influence each other as long as their colors are close enough (see sigmaColor
  1212. ). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
  1213. proportional to sigmaSpace.
  1214. @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes
  1215. */
  1216. CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,
  1217. double sigmaColor, double sigmaSpace,
  1218. int borderType = BORDER_DEFAULT );
  1219. /** @brief Blurs an image using the box filter.
  1220. The function smooths an image using the kernel:
  1221. \f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f]
  1222. where
  1223. \f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f]
  1224. Unnormalized box filter is useful for computing various integral characteristics over each pixel
  1225. neighborhood, such as covariance matrices of image derivatives (used in dense optical flow
  1226. algorithms, and so on). If you need to compute pixel sums over variable-size windows, use #integral.
  1227. @param src input image.
  1228. @param dst output image of the same size and type as src.
  1229. @param ddepth the output image depth (-1 to use src.depth()).
  1230. @param ksize blurring kernel size.
  1231. @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
  1232. center.
  1233. @param normalize flag, specifying whether the kernel is normalized by its area or not.
  1234. @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes. #BORDER_WRAP is not supported.
  1235. @sa blur, bilateralFilter, GaussianBlur, medianBlur, integral
  1236. */
  1237. CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
  1238. Size ksize, Point anchor = Point(-1,-1),
  1239. bool normalize = true,
  1240. int borderType = BORDER_DEFAULT );
  1241. /** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter.
  1242. For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring
  1243. pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$.
  1244. The unnormalized square box filter can be useful in computing local image statistics such as the the local
  1245. variance and standard deviation around the neighborhood of a pixel.
  1246. @param src input image
  1247. @param dst output image of the same size and type as _src
  1248. @param ddepth the output image depth (-1 to use src.depth())
  1249. @param ksize kernel size
  1250. @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel
  1251. center.
  1252. @param normalize flag, specifying whether the kernel is to be normalized by it's area or not.
  1253. @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes. #BORDER_WRAP is not supported.
  1254. @sa boxFilter
  1255. */
  1256. CV_EXPORTS_W void sqrBoxFilter( InputArray src, OutputArray dst, int ddepth,
  1257. Size ksize, Point anchor = Point(-1, -1),
  1258. bool normalize = true,
  1259. int borderType = BORDER_DEFAULT );
  1260. /** @brief Blurs an image using the normalized box filter.
  1261. The function smooths an image using the kernel:
  1262. \f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f]
  1263. The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(),
  1264. anchor, true, borderType)`.
  1265. @param src input image; it can have any number of channels, which are processed independently, but
  1266. the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  1267. @param dst output image of the same size and type as src.
  1268. @param ksize blurring kernel size.
  1269. @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
  1270. center.
  1271. @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes. #BORDER_WRAP is not supported.
  1272. @sa boxFilter, bilateralFilter, GaussianBlur, medianBlur
  1273. */
  1274. CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
  1275. Size ksize, Point anchor = Point(-1,-1),
  1276. int borderType = BORDER_DEFAULT );
  1277. /** @brief Convolves an image with the kernel.
  1278. The function applies an arbitrary linear filter to an image. In-place operation is supported. When
  1279. the aperture is partially outside the image, the function interpolates outlier pixel values
  1280. according to the specified border mode.
  1281. The function does actually compute correlation, not the convolution:
  1282. \f[\texttt{dst} (x,y) = \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} } \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f]
  1283. That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip
  1284. the kernel using #flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows -
  1285. anchor.y - 1)`.
  1286. The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or
  1287. larger) and the direct algorithm for small kernels.
  1288. @param src input image.
  1289. @param dst output image of the same size and the same number of channels as src.
  1290. @param ddepth desired depth of the destination image, see @ref filter_depths "combinations"
  1291. @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point
  1292. matrix; if you want to apply different kernels to different channels, split the image into
  1293. separate color planes using split and process them individually.
  1294. @param anchor anchor of the kernel that indicates the relative position of a filtered point within
  1295. the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor
  1296. is at the kernel center.
  1297. @param delta optional value added to the filtered pixels before storing them in dst.
  1298. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1299. @sa sepFilter2D, dft, matchTemplate
  1300. */
  1301. CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth,
  1302. InputArray kernel, Point anchor = Point(-1,-1),
  1303. double delta = 0, int borderType = BORDER_DEFAULT );
  1304. /** @brief Applies a separable linear filter to an image.
  1305. The function applies a separable linear filter to the image. That is, first, every row of src is
  1306. filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D
  1307. kernel kernelY. The final result shifted by delta is stored in dst .
  1308. @param src Source image.
  1309. @param dst Destination image of the same size and the same number of channels as src .
  1310. @param ddepth Destination image depth, see @ref filter_depths "combinations"
  1311. @param kernelX Coefficients for filtering each row.
  1312. @param kernelY Coefficients for filtering each column.
  1313. @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor
  1314. is at the kernel center.
  1315. @param delta Value added to the filtered results before storing them.
  1316. @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1317. @sa filter2D, Sobel, GaussianBlur, boxFilter, blur
  1318. */
  1319. CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth,
  1320. InputArray kernelX, InputArray kernelY,
  1321. Point anchor = Point(-1,-1),
  1322. double delta = 0, int borderType = BORDER_DEFAULT );
  1323. /** @example samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp
  1324. Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector
  1325. ![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg)
  1326. Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details
  1327. */
  1328. /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
  1329. In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to
  1330. calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$
  1331. kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first
  1332. or the second x- or y- derivatives.
  1333. There is also the special value `ksize = #FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr
  1334. filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is
  1335. \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]
  1336. for the x-derivative, or transposed for the y-derivative.
  1337. The function calculates an image derivative by convolving the image with the appropriate kernel:
  1338. \f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]
  1339. The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less
  1340. resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)
  1341. or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first
  1342. case corresponds to a kernel of:
  1343. \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]
  1344. The second case corresponds to a kernel of:
  1345. \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]
  1346. @param src input image.
  1347. @param dst output image of the same size and the same number of channels as src .
  1348. @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
  1349. 8-bit input images it will result in truncated derivatives.
  1350. @param dx order of the derivative x.
  1351. @param dy order of the derivative y.
  1352. @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
  1353. @param scale optional scale factor for the computed derivative values; by default, no scaling is
  1354. applied (see #getDerivKernels for details).
  1355. @param delta optional delta value that is added to the results prior to storing them in dst.
  1356. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1357. @sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar
  1358. */
  1359. CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
  1360. int dx, int dy, int ksize = 3,
  1361. double scale = 1, double delta = 0,
  1362. int borderType = BORDER_DEFAULT );
  1363. /** @brief Calculates the first order image derivative in both x and y using a Sobel operator
  1364. Equivalent to calling:
  1365. @code
  1366. Sobel( src, dx, CV_16SC1, 1, 0, 3 );
  1367. Sobel( src, dy, CV_16SC1, 0, 1, 3 );
  1368. @endcode
  1369. @param src input image.
  1370. @param dx output image with first-order derivative in x.
  1371. @param dy output image with first-order derivative in y.
  1372. @param ksize size of Sobel kernel. It must be 3.
  1373. @param borderType pixel extrapolation method, see #BorderTypes.
  1374. Only #BORDER_DEFAULT=#BORDER_REFLECT_101 and #BORDER_REPLICATE are supported.
  1375. @sa Sobel
  1376. */
  1377. CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx,
  1378. OutputArray dy, int ksize = 3,
  1379. int borderType = BORDER_DEFAULT );
  1380. /** @brief Calculates the first x- or y- image derivative using Scharr operator.
  1381. The function computes the first x- or y- spatial image derivative using the Scharr operator. The
  1382. call
  1383. \f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f]
  1384. is equivalent to
  1385. \f[\texttt{Sobel(src, dst, ddepth, dx, dy, FILTER_SCHARR, scale, delta, borderType)} .\f]
  1386. @param src input image.
  1387. @param dst output image of the same size and the same number of channels as src.
  1388. @param ddepth output image depth, see @ref filter_depths "combinations"
  1389. @param dx order of the derivative x.
  1390. @param dy order of the derivative y.
  1391. @param scale optional scale factor for the computed derivative values; by default, no scaling is
  1392. applied (see #getDerivKernels for details).
  1393. @param delta optional delta value that is added to the results prior to storing them in dst.
  1394. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1395. @sa cartToPolar
  1396. */
  1397. CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth,
  1398. int dx, int dy, double scale = 1, double delta = 0,
  1399. int borderType = BORDER_DEFAULT );
  1400. /** @example samples/cpp/laplace.cpp
  1401. An example using Laplace transformations for edge detection
  1402. */
  1403. /** @brief Calculates the Laplacian of an image.
  1404. The function calculates the Laplacian of the source image by adding up the second x and y
  1405. derivatives calculated using the Sobel operator:
  1406. \f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f]
  1407. This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image
  1408. with the following \f$3 \times 3\f$ aperture:
  1409. \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]
  1410. @param src Source image.
  1411. @param dst Destination image of the same size and the same number of channels as src .
  1412. @param ddepth Desired depth of the destination image.
  1413. @param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for
  1414. details. The size must be positive and odd.
  1415. @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
  1416. applied. See #getDerivKernels for details.
  1417. @param delta Optional delta value that is added to the results prior to storing them in dst .
  1418. @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1419. @sa Sobel, Scharr
  1420. */
  1421. CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
  1422. int ksize = 1, double scale = 1, double delta = 0,
  1423. int borderType = BORDER_DEFAULT );
  1424. //! @} imgproc_filter
  1425. //! @addtogroup imgproc_feature
  1426. //! @{
  1427. /** @example samples/cpp/edge.cpp
  1428. This program demonstrates usage of the Canny edge detector
  1429. Check @ref tutorial_canny_detector "the corresponding tutorial" for more details
  1430. */
  1431. /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 .
  1432. The function finds edges in the input image and marks them in the output map edges using the
  1433. Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The
  1434. largest value is used to find initial segments of strong edges. See
  1435. <http://en.wikipedia.org/wiki/Canny_edge_detector>
  1436. @param image 8-bit input image.
  1437. @param edges output edge map; single channels 8-bit image, which has the same size as image .
  1438. @param threshold1 first threshold for the hysteresis procedure.
  1439. @param threshold2 second threshold for the hysteresis procedure.
  1440. @param apertureSize aperture size for the Sobel operator.
  1441. @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
  1442. \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
  1443. L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
  1444. L2gradient=false ).
  1445. */
  1446. CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
  1447. double threshold1, double threshold2,
  1448. int apertureSize = 3, bool L2gradient = false );
  1449. /** \overload
  1450. Finds edges in an image using the Canny algorithm with custom image gradient.
  1451. @param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3).
  1452. @param dy 16-bit y derivative of input image (same type as dx).
  1453. @param edges output edge map; single channels 8-bit image, which has the same size as image .
  1454. @param threshold1 first threshold for the hysteresis procedure.
  1455. @param threshold2 second threshold for the hysteresis procedure.
  1456. @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
  1457. \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
  1458. L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
  1459. L2gradient=false ).
  1460. */
  1461. CV_EXPORTS_W void Canny( InputArray dx, InputArray dy,
  1462. OutputArray edges,
  1463. double threshold1, double threshold2,
  1464. bool L2gradient = false );
  1465. /** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection.
  1466. The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal
  1467. eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms
  1468. of the formulae in the cornerEigenValsAndVecs description.
  1469. @param src Input single-channel 8-bit or floating-point image.
  1470. @param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as
  1471. src .
  1472. @param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).
  1473. @param ksize Aperture parameter for the Sobel operator.
  1474. @param borderType Pixel extrapolation method. See #BorderTypes. #BORDER_WRAP is not supported.
  1475. */
  1476. CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst,
  1477. int blockSize, int ksize = 3,
  1478. int borderType = BORDER_DEFAULT );
  1479. /** @brief Harris corner detector.
  1480. The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and
  1481. cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance
  1482. matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it
  1483. computes the following characteristic:
  1484. \f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f]
  1485. Corners in the image can be found as the local maxima of this response map.
  1486. @param src Input single-channel 8-bit or floating-point image.
  1487. @param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same
  1488. size as src .
  1489. @param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).
  1490. @param ksize Aperture parameter for the Sobel operator.
  1491. @param k Harris detector free parameter. See the formula above.
  1492. @param borderType Pixel extrapolation method. See #BorderTypes. #BORDER_WRAP is not supported.
  1493. */
  1494. CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,
  1495. int ksize, double k,
  1496. int borderType = BORDER_DEFAULT );
  1497. /** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection.
  1498. For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize
  1499. neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as:
  1500. \f[M = \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 & \sum _{S(p)}dI/dx dI/dy \\ \sum _{S(p)}dI/dx dI/dy & \sum _{S(p)}(dI/dy)^2 \end{bmatrix}\f]
  1501. where the derivatives are computed using the Sobel operator.
  1502. After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as
  1503. \f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where
  1504. - \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$
  1505. - \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$
  1506. - \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$
  1507. The output of the function can be used for robust edge or corner detection.
  1508. @param src Input single-channel 8-bit or floating-point image.
  1509. @param dst Image to store the results. It has the same size as src and the type CV_32FC(6) .
  1510. @param blockSize Neighborhood size (see details below).
  1511. @param ksize Aperture parameter for the Sobel operator.
  1512. @param borderType Pixel extrapolation method. See #BorderTypes. #BORDER_WRAP is not supported.
  1513. @sa cornerMinEigenVal, cornerHarris, preCornerDetect
  1514. */
  1515. CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst,
  1516. int blockSize, int ksize,
  1517. int borderType = BORDER_DEFAULT );
  1518. /** @brief Calculates a feature map for corner detection.
  1519. The function calculates the complex spatial derivative-based function of the source image
  1520. \f[\texttt{dst} = (D_x \texttt{src} )^2 \cdot D_{yy} \texttt{src} + (D_y \texttt{src} )^2 \cdot D_{xx} \texttt{src} - 2 D_x \texttt{src} \cdot D_y \texttt{src} \cdot D_{xy} \texttt{src}\f]
  1521. where \f$D_x\f$,\f$D_y\f$ are the first image derivatives, \f$D_{xx}\f$,\f$D_{yy}\f$ are the second image
  1522. derivatives, and \f$D_{xy}\f$ is the mixed derivative.
  1523. The corners can be found as local maximums of the functions, as shown below:
  1524. @code
  1525. Mat corners, dilated_corners;
  1526. preCornerDetect(image, corners, 3);
  1527. // dilation with 3x3 rectangular structuring element
  1528. dilate(corners, dilated_corners, Mat(), 1);
  1529. Mat corner_mask = corners == dilated_corners;
  1530. @endcode
  1531. @param src Source single-channel 8-bit of floating-point image.
  1532. @param dst Output image that has the type CV_32F and the same size as src .
  1533. @param ksize %Aperture size of the Sobel .
  1534. @param borderType Pixel extrapolation method. See #BorderTypes. #BORDER_WRAP is not supported.
  1535. */
  1536. CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize,
  1537. int borderType = BORDER_DEFAULT );
  1538. /** @brief Refines the corner locations.
  1539. The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as
  1540. shown on the figure below.
  1541. ![image](pics/cornersubpix.png)
  1542. Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$
  1543. to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$
  1544. subject to image and measurement noise. Consider the expression:
  1545. \f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f]
  1546. where \f${DI_{p_i}}\f$ is an image gradient at one of the points \f$p_i\f$ in a neighborhood of \f$q\f$ . The
  1547. value of \f$q\f$ is to be found so that \f$\epsilon_i\f$ is minimized. A system of equations may be set up
  1548. with \f$\epsilon_i\f$ set to zero:
  1549. \f[\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) \cdot q - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)\f]
  1550. where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first
  1551. gradient term \f$G\f$ and the second gradient term \f$b\f$ gives:
  1552. \f[q = G^{-1} \cdot b\f]
  1553. The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates
  1554. until the center stays within a set threshold.
  1555. @param image Input single-channel, 8-bit or float image.
  1556. @param corners Initial coordinates of the input corners and refined coordinates provided for
  1557. output.
  1558. @param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) ,
  1559. then a \f$(5*2+1) \times (5*2+1) = 11 \times 11\f$ search window is used.
  1560. @param zeroZone Half of the size of the dead region in the middle of the search zone over which
  1561. the summation in the formula below is not done. It is used sometimes to avoid possible
  1562. singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such
  1563. a size.
  1564. @param criteria Criteria for termination of the iterative process of corner refinement. That is,
  1565. the process of corner position refinement stops either after criteria.maxCount iterations or when
  1566. the corner position moves by less than criteria.epsilon on some iteration.
  1567. */
  1568. CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners,
  1569. Size winSize, Size zeroZone,
  1570. TermCriteria criteria );
  1571. /** @brief Determines strong corners on an image.
  1572. The function finds the most prominent corners in the image or in the specified image region, as
  1573. described in @cite Shi94
  1574. - Function calculates the corner quality measure at every source image pixel using the
  1575. #cornerMinEigenVal or #cornerHarris .
  1576. - Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are
  1577. retained).
  1578. - The corners with the minimal eigenvalue less than
  1579. \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.
  1580. - The remaining corners are sorted by the quality measure in the descending order.
  1581. - Function throws away each corner for which there is a stronger corner at a distance less than
  1582. maxDistance.
  1583. The function can be used to initialize a point-based tracker of an object.
  1584. @note If the function is called with different values A and B of the parameter qualityLevel , and
  1585. A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector
  1586. with qualityLevel=B .
  1587. @param image Input 8-bit or floating-point 32-bit, single-channel image.
  1588. @param corners Output vector of detected corners.
  1589. @param maxCorners Maximum number of corners to return. If there are more corners than are found,
  1590. the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
  1591. and all detected corners are returned.
  1592. @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
  1593. parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
  1594. (see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the
  1595. quality measure less than the product are rejected. For example, if the best corner has the
  1596. quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
  1597. less than 15 are rejected.
  1598. @param minDistance Minimum possible Euclidean distance between the returned corners.
  1599. @param mask Optional region of interest. If the image is not empty (it needs to have the type
  1600. CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
  1601. @param blockSize Size of an average block for computing a derivative covariation matrix over each
  1602. pixel neighborhood. See cornerEigenValsAndVecs .
  1603. @param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)
  1604. or #cornerMinEigenVal.
  1605. @param k Free parameter of the Harris detector.
  1606. @sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,
  1607. */
  1608. CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
  1609. int maxCorners, double qualityLevel, double minDistance,
  1610. InputArray mask = noArray(), int blockSize = 3,
  1611. bool useHarrisDetector = false, double k = 0.04 );
  1612. CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
  1613. int maxCorners, double qualityLevel, double minDistance,
  1614. InputArray mask, int blockSize,
  1615. int gradientSize, bool useHarrisDetector = false,
  1616. double k = 0.04 );
  1617. /** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp
  1618. An example using the Hough line detector
  1619. ![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg)
  1620. */
  1621. /** @brief Finds lines in a binary image using the standard Hough transform.
  1622. The function implements the standard or standard multi-scale Hough transform algorithm for line
  1623. detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough
  1624. transform.
  1625. @param image 8-bit, single-channel binary source image. The image may be modified by the function.
  1626. @param lines Output vector of lines. Each line is represented by a 2 or 3 element vector
  1627. \f$(\rho, \theta)\f$ or \f$(\rho, \theta, \textrm{votes})\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of
  1628. the image). \f$\theta\f$ is the line rotation angle in radians (
  1629. \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).
  1630. \f$\textrm{votes}\f$ is the value of accumulator.
  1631. @param rho Distance resolution of the accumulator in pixels.
  1632. @param theta Angle resolution of the accumulator in radians.
  1633. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
  1634. votes ( \f$>\texttt{threshold}\f$ ).
  1635. @param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho .
  1636. The coarse accumulator distance resolution is rho and the accurate accumulator resolution is
  1637. rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these
  1638. parameters should be positive.
  1639. @param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
  1640. @param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines.
  1641. Must fall between 0 and max_theta.
  1642. @param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines.
  1643. Must fall between min_theta and CV_PI.
  1644. */
  1645. CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,
  1646. double rho, double theta, int threshold,
  1647. double srn = 0, double stn = 0,
  1648. double min_theta = 0, double max_theta = CV_PI );
  1649. /** @brief Finds line segments in a binary image using the probabilistic Hough transform.
  1650. The function implements the probabilistic Hough transform algorithm for line detection, described
  1651. in @cite Matas00
  1652. See the line detection example below:
  1653. @include snippets/imgproc_HoughLinesP.cpp
  1654. This is a sample picture the function parameters have been tuned for:
  1655. ![image](pics/building.jpg)
  1656. And this is the output of the above program in case of the probabilistic Hough transform:
  1657. ![image](pics/houghp.png)
  1658. @param image 8-bit, single-channel binary source image. The image may be modified by the function.
  1659. @param lines Output vector of lines. Each line is represented by a 4-element vector
  1660. \f$(x_1, y_1, x_2, y_2)\f$ , where \f$(x_1,y_1)\f$ and \f$(x_2, y_2)\f$ are the ending points of each detected
  1661. line segment.
  1662. @param rho Distance resolution of the accumulator in pixels.
  1663. @param theta Angle resolution of the accumulator in radians.
  1664. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
  1665. votes ( \f$>\texttt{threshold}\f$ ).
  1666. @param minLineLength Minimum line length. Line segments shorter than that are rejected.
  1667. @param maxLineGap Maximum allowed gap between points on the same line to link them.
  1668. @sa LineSegmentDetector
  1669. */
  1670. CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,
  1671. double rho, double theta, int threshold,
  1672. double minLineLength = 0, double maxLineGap = 0 );
  1673. /** @brief Finds lines in a set of points using the standard Hough transform.
  1674. The function finds lines in a set of points using a modification of the Hough transform.
  1675. @include snippets/imgproc_HoughLinesPointSet.cpp
  1676. @param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2.
  1677. @param _lines Output vector of found lines. Each vector is encoded as a vector<Vec3d> \f$(votes, rho, theta)\f$.
  1678. The larger the value of 'votes', the higher the reliability of the Hough line.
  1679. @param lines_max Max count of hough lines.
  1680. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
  1681. votes ( \f$>\texttt{threshold}\f$ )
  1682. @param min_rho Minimum Distance value of the accumulator in pixels.
  1683. @param max_rho Maximum Distance value of the accumulator in pixels.
  1684. @param rho_step Distance resolution of the accumulator in pixels.
  1685. @param min_theta Minimum angle value of the accumulator in radians.
  1686. @param max_theta Maximum angle value of the accumulator in radians.
  1687. @param theta_step Angle resolution of the accumulator in radians.
  1688. */
  1689. CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold,
  1690. double min_rho, double max_rho, double rho_step,
  1691. double min_theta, double max_theta, double theta_step );
  1692. /** @example samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp
  1693. An example using the Hough circle detector
  1694. */
  1695. /** @brief Finds circles in a grayscale image using the Hough transform.
  1696. The function finds circles in a grayscale image using a modification of the Hough transform.
  1697. Example: :
  1698. @include snippets/imgproc_HoughLinesCircles.cpp
  1699. @note Usually the function detects the centers of circles well. However, it may fail to find correct
  1700. radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if
  1701. you know it. Or, in the case of #HOUGH_GRADIENT method you may set maxRadius to a negative number
  1702. to return centers only without radius search, and find the correct radius using an additional procedure.
  1703. It also helps to smooth image a bit unless it's already soft. For example,
  1704. GaussianBlur() with 7x7 kernel and 1.5x1.5 sigma or similar blurring may help.
  1705. @param image 8-bit, single-channel, grayscale input image.
  1706. @param circles Output vector of found circles. Each vector is encoded as 3 or 4 element
  1707. floating-point vector \f$(x, y, radius)\f$ or \f$(x, y, radius, votes)\f$ .
  1708. @param method Detection method, see #HoughModes. The available methods are #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT.
  1709. @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if
  1710. dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has
  1711. half as big width and height. For #HOUGH_GRADIENT_ALT the recommended value is dp=1.5,
  1712. unless some small very circles need to be detected.
  1713. @param minDist Minimum distance between the centers of the detected circles. If the parameter is
  1714. too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is
  1715. too large, some circles may be missed.
  1716. @param param1 First method-specific parameter. In case of #HOUGH_GRADIENT and #HOUGH_GRADIENT_ALT,
  1717. it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller).
  1718. Note that #HOUGH_GRADIENT_ALT uses #Scharr algorithm to compute image derivatives, so the threshold value
  1719. shough normally be higher, such as 300 or normally exposed and contrasty images.
  1720. @param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT, it is the
  1721. accumulator threshold for the circle centers at the detection stage. The smaller it is, the more
  1722. false circles may be detected. Circles, corresponding to the larger accumulator values, will be
  1723. returned first. In the case of #HOUGH_GRADIENT_ALT algorithm, this is the circle "perfectness" measure.
  1724. The closer it to 1, the better shaped circles algorithm selects. In most cases 0.9 should be fine.
  1725. If you want get better detection of small circles, you may decrease it to 0.85, 0.8 or even less.
  1726. But then also try to limit the search range [minRadius, maxRadius] to avoid many false circles.
  1727. @param minRadius Minimum circle radius.
  1728. @param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, #HOUGH_GRADIENT returns
  1729. centers without finding the radius. #HOUGH_GRADIENT_ALT always computes circle radiuses.
  1730. @sa fitEllipse, minEnclosingCircle
  1731. */
  1732. CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles,
  1733. int method, double dp, double minDist,
  1734. double param1 = 100, double param2 = 100,
  1735. int minRadius = 0, int maxRadius = 0 );
  1736. //! @} imgproc_feature
  1737. //! @addtogroup imgproc_filter
  1738. //! @{
  1739. /** @example samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp
  1740. Advanced morphology Transformations sample code
  1741. ![Sample screenshot](Morphology_2_Tutorial_Result.jpg)
  1742. Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details
  1743. */
  1744. /** @brief Erodes an image by using a specific structuring element.
  1745. The function erodes the source image using the specified structuring element that determines the
  1746. shape of a pixel neighborhood over which the minimum is taken:
  1747. \f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
  1748. The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In
  1749. case of multi-channel images, each channel is processed independently.
  1750. @param src input image; the number of channels can be arbitrary, but the depth should be one of
  1751. CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  1752. @param dst output image of the same size and type as src.
  1753. @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
  1754. structuring element is used. Kernel can be created using #getStructuringElement.
  1755. @param anchor position of the anchor within the element; default value (-1, -1) means that the
  1756. anchor is at the element center.
  1757. @param iterations number of times erosion is applied.
  1758. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1759. @param borderValue border value in case of a constant border
  1760. @sa dilate, morphologyEx, getStructuringElement
  1761. */
  1762. CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
  1763. Point anchor = Point(-1,-1), int iterations = 1,
  1764. int borderType = BORDER_CONSTANT,
  1765. const Scalar& borderValue = morphologyDefaultBorderValue() );
  1766. /** @example samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp
  1767. Erosion and Dilation sample code
  1768. ![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg)
  1769. Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details
  1770. */
  1771. /** @brief Dilates an image by using a specific structuring element.
  1772. The function dilates the source image using the specified structuring element that determines the
  1773. shape of a pixel neighborhood over which the maximum is taken:
  1774. \f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
  1775. The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In
  1776. case of multi-channel images, each channel is processed independently.
  1777. @param src input image; the number of channels can be arbitrary, but the depth should be one of
  1778. CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  1779. @param dst output image of the same size and type as src.
  1780. @param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
  1781. structuring element is used. Kernel can be created using #getStructuringElement
  1782. @param anchor position of the anchor within the element; default value (-1, -1) means that the
  1783. anchor is at the element center.
  1784. @param iterations number of times dilation is applied.
  1785. @param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not suported.
  1786. @param borderValue border value in case of a constant border
  1787. @sa erode, morphologyEx, getStructuringElement
  1788. */
  1789. CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
  1790. Point anchor = Point(-1,-1), int iterations = 1,
  1791. int borderType = BORDER_CONSTANT,
  1792. const Scalar& borderValue = morphologyDefaultBorderValue() );
  1793. /** @brief Performs advanced morphological transformations.
  1794. The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as
  1795. basic operations.
  1796. Any of the operations can be done in-place. In case of multi-channel images, each channel is
  1797. processed independently.
  1798. @param src Source image. The number of channels can be arbitrary. The depth should be one of
  1799. CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
  1800. @param dst Destination image of the same size and type as source image.
  1801. @param op Type of a morphological operation, see #MorphTypes
  1802. @param kernel Structuring element. It can be created using #getStructuringElement.
  1803. @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the
  1804. kernel center.
  1805. @param iterations Number of times erosion and dilation are applied.
  1806. @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  1807. @param borderValue Border value in case of a constant border. The default value has a special
  1808. meaning.
  1809. @sa dilate, erode, getStructuringElement
  1810. @note The number of iterations is the number of times erosion or dilatation operation will be applied.
  1811. For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply
  1812. successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate).
  1813. */
  1814. CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
  1815. int op, InputArray kernel,
  1816. Point anchor = Point(-1,-1), int iterations = 1,
  1817. int borderType = BORDER_CONSTANT,
  1818. const Scalar& borderValue = morphologyDefaultBorderValue() );
  1819. //! @} imgproc_filter
  1820. //! @addtogroup imgproc_transform
  1821. //! @{
  1822. /** @brief Resizes an image.
  1823. The function resize resizes the image src down to or up to the specified size. Note that the
  1824. initial dst type or size are not taken into account. Instead, the size and type are derived from
  1825. the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst,
  1826. you may call the function as follows:
  1827. @code
  1828. // explicitly specify dsize=dst.size(); fx and fy will be computed from that.
  1829. resize(src, dst, dst.size(), 0, 0, interpolation);
  1830. @endcode
  1831. If you want to decimate the image by factor of 2 in each direction, you can call the function this
  1832. way:
  1833. @code
  1834. // specify fx and fy and let the function compute the destination image size.
  1835. resize(src, dst, Size(), 0.5, 0.5, interpolation);
  1836. @endcode
  1837. To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to
  1838. enlarge an image, it will generally look best with c#INTER_CUBIC (slow) or #INTER_LINEAR
  1839. (faster but still looks OK).
  1840. @param src input image.
  1841. @param dst output image; it has the size dsize (when it is non-zero) or the size computed from
  1842. src.size(), fx, and fy; the type of dst is the same as of src.
  1843. @param dsize output image size; if it equals zero, it is computed as:
  1844. \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
  1845. Either dsize or both fx and fy must be non-zero.
  1846. @param fx scale factor along the horizontal axis; when it equals 0, it is computed as
  1847. \f[\texttt{(double)dsize.width/src.cols}\f]
  1848. @param fy scale factor along the vertical axis; when it equals 0, it is computed as
  1849. \f[\texttt{(double)dsize.height/src.rows}\f]
  1850. @param interpolation interpolation method, see #InterpolationFlags
  1851. @sa warpAffine, warpPerspective, remap
  1852. */
  1853. CV_EXPORTS_W void resize( InputArray src, OutputArray dst,
  1854. Size dsize, double fx = 0, double fy = 0,
  1855. int interpolation = INTER_LINEAR );
  1856. /** @brief Applies an affine transformation to an image.
  1857. The function warpAffine transforms the source image using the specified matrix:
  1858. \f[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\f]
  1859. when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted
  1860. with #invertAffineTransform and then put in the formula above instead of M. The function cannot
  1861. operate in-place.
  1862. @param src input image.
  1863. @param dst output image that has the size dsize and the same type as src .
  1864. @param M \f$2\times 3\f$ transformation matrix.
  1865. @param dsize size of the output image.
  1866. @param flags combination of interpolation methods (see #InterpolationFlags) and the optional
  1867. flag #WARP_INVERSE_MAP that means that M is the inverse transformation (
  1868. \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
  1869. @param borderMode pixel extrapolation method (see #BorderTypes); when
  1870. borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to
  1871. the "outliers" in the source image are not modified by the function.
  1872. @param borderValue value used in case of a constant border; by default, it is 0.
  1873. @sa warpPerspective, resize, remap, getRectSubPix, transform
  1874. */
  1875. CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,
  1876. InputArray M, Size dsize,
  1877. int flags = INTER_LINEAR,
  1878. int borderMode = BORDER_CONSTANT,
  1879. const Scalar& borderValue = Scalar());
  1880. /** @example samples/cpp/warpPerspective_demo.cpp
  1881. An example program shows using cv::findHomography and cv::warpPerspective for image warping
  1882. */
  1883. /** @brief Applies a perspective transformation to an image.
  1884. The function warpPerspective transforms the source image using the specified matrix:
  1885. \f[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
  1886. \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f]
  1887. when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert
  1888. and then put in the formula above instead of M. The function cannot operate in-place.
  1889. @param src input image.
  1890. @param dst output image that has the size dsize and the same type as src .
  1891. @param M \f$3\times 3\f$ transformation matrix.
  1892. @param dsize size of the output image.
  1893. @param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the
  1894. optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation (
  1895. \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
  1896. @param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE).
  1897. @param borderValue value used in case of a constant border; by default, it equals 0.
  1898. @sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform
  1899. */
  1900. CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst,
  1901. InputArray M, Size dsize,
  1902. int flags = INTER_LINEAR,
  1903. int borderMode = BORDER_CONSTANT,
  1904. const Scalar& borderValue = Scalar());
  1905. /** @brief Applies a generic geometrical transformation to an image.
  1906. The function remap transforms the source image using the specified map:
  1907. \f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f]
  1908. where values of pixels with non-integer coordinates are computed using one of available
  1909. interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps
  1910. in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in
  1911. \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to
  1912. convert from floating to fixed-point representations of a map is that they can yield much faster
  1913. (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),
  1914. cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.
  1915. This function cannot operate in-place.
  1916. @param src Source image.
  1917. @param dst Destination image. It has the same size as map1 and the same type as src .
  1918. @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 ,
  1919. CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point
  1920. representation to fixed-point for speed.
  1921. @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map
  1922. if map1 is (x,y) points), respectively.
  1923. @param interpolation Interpolation method (see #InterpolationFlags). The method #INTER_AREA is
  1924. not supported by this function.
  1925. @param borderMode Pixel extrapolation method (see #BorderTypes). When
  1926. borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image that
  1927. corresponds to the "outliers" in the source image are not modified by the function.
  1928. @param borderValue Value used in case of a constant border. By default, it is 0.
  1929. @note
  1930. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
  1931. */
  1932. CV_EXPORTS_W void remap( InputArray src, OutputArray dst,
  1933. InputArray map1, InputArray map2,
  1934. int interpolation, int borderMode = BORDER_CONSTANT,
  1935. const Scalar& borderValue = Scalar());
  1936. /** @brief Converts image transformation maps from one representation to another.
  1937. The function converts a pair of maps for remap from one representation to another. The following
  1938. options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are
  1939. supported:
  1940. - \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the
  1941. most frequently used conversion operation, in which the original floating-point maps (see remap )
  1942. are converted to a more compact and much faster fixed-point representation. The first output array
  1943. contains the rounded coordinates and the second array (created only when nninterpolation=false )
  1944. contains indices in the interpolation tables.
  1945. - \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but
  1946. the original maps are stored in one 2-channel matrix.
  1947. - Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same
  1948. as the originals.
  1949. @param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 .
  1950. @param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix),
  1951. respectively.
  1952. @param dstmap1 The first output map that has the type dstmap1type and the same size as src .
  1953. @param dstmap2 The second output map.
  1954. @param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or
  1955. CV_32FC2 .
  1956. @param nninterpolation Flag indicating whether the fixed-point maps are used for the
  1957. nearest-neighbor or for a more complex interpolation.
  1958. @sa remap, undistort, initUndistortRectifyMap
  1959. */
  1960. CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2,
  1961. OutputArray dstmap1, OutputArray dstmap2,
  1962. int dstmap1type, bool nninterpolation = false );
  1963. /** @brief Calculates an affine matrix of 2D rotation.
  1964. The function calculates the following matrix:
  1965. \f[\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} + (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}\f]
  1966. where
  1967. \f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f]
  1968. The transformation maps the rotation center to itself. If this is not the target, adjust the shift.
  1969. @param center Center of the rotation in the source image.
  1970. @param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the
  1971. coordinate origin is assumed to be the top-left corner).
  1972. @param scale Isotropic scale factor.
  1973. @sa getAffineTransform, warpAffine, transform
  1974. */
  1975. CV_EXPORTS_W Mat getRotationMatrix2D(Point2f center, double angle, double scale);
  1976. /** @sa getRotationMatrix2D */
  1977. CV_EXPORTS Matx23d getRotationMatrix2D_(Point2f center, double angle, double scale);
  1978. inline
  1979. Mat getRotationMatrix2D(Point2f center, double angle, double scale)
  1980. {
  1981. return Mat(getRotationMatrix2D_(center, angle, scale), true);
  1982. }
  1983. /** @brief Calculates an affine transform from three pairs of the corresponding points.
  1984. The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that:
  1985. \f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]
  1986. where
  1987. \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f]
  1988. @param src Coordinates of triangle vertices in the source image.
  1989. @param dst Coordinates of the corresponding triangle vertices in the destination image.
  1990. @sa warpAffine, transform
  1991. */
  1992. CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
  1993. /** @brief Inverts an affine transformation.
  1994. The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M:
  1995. \f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f]
  1996. The result is also a \f$2 \times 3\f$ matrix of the same type as M.
  1997. @param M Original affine transformation.
  1998. @param iM Output reverse affine transformation.
  1999. */
  2000. CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );
  2001. /** @brief Calculates a perspective transform from four pairs of the corresponding points.
  2002. The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that:
  2003. \f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]
  2004. where
  2005. \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f]
  2006. @param src Coordinates of quadrangle vertices in the source image.
  2007. @param dst Coordinates of the corresponding quadrangle vertices in the destination image.
  2008. @param solveMethod method passed to cv::solve (#DecompTypes)
  2009. @sa findHomography, warpPerspective, perspectiveTransform
  2010. */
  2011. CV_EXPORTS_W Mat getPerspectiveTransform(InputArray src, InputArray dst, int solveMethod = DECOMP_LU);
  2012. /** @overload */
  2013. CV_EXPORTS Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod = DECOMP_LU);
  2014. CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
  2015. /** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy.
  2016. The function getRectSubPix extracts pixels from src:
  2017. \f[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f]
  2018. where the values of the pixels at non-integer coordinates are retrieved using bilinear
  2019. interpolation. Every channel of multi-channel images is processed independently. Also
  2020. the image should be a single channel or three channel image. While the center of the
  2021. rectangle must be inside the image, parts of the rectangle may be outside.
  2022. @param image Source image.
  2023. @param patchSize Size of the extracted patch.
  2024. @param center Floating point coordinates of the center of the extracted rectangle within the
  2025. source image. The center must be inside the image.
  2026. @param patch Extracted patch that has the size patchSize and the same number of channels as src .
  2027. @param patchType Depth of the extracted pixels. By default, they have the same depth as src .
  2028. @sa warpAffine, warpPerspective
  2029. */
  2030. CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
  2031. Point2f center, OutputArray patch, int patchType = -1 );
  2032. /** @example samples/cpp/polar_transforms.cpp
  2033. An example using the cv::linearPolar and cv::logPolar operations
  2034. */
  2035. /** @brief Remaps an image to semilog-polar coordinates space.
  2036. @deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG);
  2037. @internal
  2038. Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image d)"):
  2039. \f[\begin{array}{l}
  2040. dst( \rho , \phi ) = src(x,y) \\
  2041. dst.size() \leftarrow src.size()
  2042. \end{array}\f]
  2043. where
  2044. \f[\begin{array}{l}
  2045. I = (dx,dy) = (x - center.x,y - center.y) \\
  2046. \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\
  2047. \phi = Kangle \cdot \texttt{angle} (I) \\
  2048. \end{array}\f]
  2049. and
  2050. \f[\begin{array}{l}
  2051. M = src.cols / log_e(maxRadius) \\
  2052. Kangle = src.rows / 2\Pi \\
  2053. \end{array}\f]
  2054. The function emulates the human "foveal" vision and can be used for fast scale and
  2055. rotation-invariant template matching, for object tracking and so forth.
  2056. @param src Source image
  2057. @param dst Destination image. It will have same size and type as src.
  2058. @param center The transformation center; where the output precision is maximal
  2059. @param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too.
  2060. @param flags A combination of interpolation methods, see #InterpolationFlags
  2061. @note
  2062. - The function can not operate in-place.
  2063. - To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
  2064. @sa cv::linearPolar
  2065. @endinternal
  2066. */
  2067. CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,
  2068. Point2f center, double M, int flags );
  2069. /** @brief Remaps an image to polar coordinates space.
  2070. @deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags)
  2071. @internal
  2072. Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image c)"):
  2073. \f[\begin{array}{l}
  2074. dst( \rho , \phi ) = src(x,y) \\
  2075. dst.size() \leftarrow src.size()
  2076. \end{array}\f]
  2077. where
  2078. \f[\begin{array}{l}
  2079. I = (dx,dy) = (x - center.x,y - center.y) \\
  2080. \rho = Kmag \cdot \texttt{magnitude} (I) ,\\
  2081. \phi = angle \cdot \texttt{angle} (I)
  2082. \end{array}\f]
  2083. and
  2084. \f[\begin{array}{l}
  2085. Kx = src.cols / maxRadius \\
  2086. Ky = src.rows / 2\Pi
  2087. \end{array}\f]
  2088. @param src Source image
  2089. @param dst Destination image. It will have same size and type as src.
  2090. @param center The transformation center;
  2091. @param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.
  2092. @param flags A combination of interpolation methods, see #InterpolationFlags
  2093. @note
  2094. - The function can not operate in-place.
  2095. - To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
  2096. @sa cv::logPolar
  2097. @endinternal
  2098. */
  2099. CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,
  2100. Point2f center, double maxRadius, int flags );
  2101. /** \brief Remaps an image to polar or semilog-polar coordinates space
  2102. @anchor polar_remaps_reference_image
  2103. ![Polar remaps reference](pics/polar_remap_doc.png)
  2104. Transform the source image using the following transformation:
  2105. \f[
  2106. dst(\rho , \phi ) = src(x,y)
  2107. \f]
  2108. where
  2109. \f[
  2110. \begin{array}{l}
  2111. \vec{I} = (x - center.x, \;y - center.y) \\
  2112. \phi = Kangle \cdot \texttt{angle} (\vec{I}) \\
  2113. \rho = \left\{\begin{matrix}
  2114. Klin \cdot \texttt{magnitude} (\vec{I}) & default \\
  2115. Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\
  2116. \end{matrix}\right.
  2117. \end{array}
  2118. \f]
  2119. and
  2120. \f[
  2121. \begin{array}{l}
  2122. Kangle = dsize.height / 2\Pi \\
  2123. Klin = dsize.width / maxRadius \\
  2124. Klog = dsize.width / log_e(maxRadius) \\
  2125. \end{array}
  2126. \f]
  2127. \par Linear vs semilog mapping
  2128. Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to `flags` to specify the polar mapping mode.
  2129. Linear is the default mode.
  2130. The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision)
  2131. in contrast to peripheral vision where acuity is minor.
  2132. \par Option on `dsize`:
  2133. - if both values in `dsize <=0 ` (default),
  2134. the destination image will have (almost) same area of source bounding circle:
  2135. \f[\begin{array}{l}
  2136. dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\
  2137. dsize.width = \texttt{cvRound}(maxRadius) \\
  2138. dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\
  2139. \end{array}\f]
  2140. - if only `dsize.height <= 0`,
  2141. the destination image area will be proportional to the bounding circle area but scaled by `Kx * Kx`:
  2142. \f[\begin{array}{l}
  2143. dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\
  2144. \end{array}
  2145. \f]
  2146. - if both values in `dsize > 0 `,
  2147. the destination image will have the given size therefore the area of the bounding circle will be scaled to `dsize`.
  2148. \par Reverse mapping
  2149. You can get reverse mapping adding #WARP_INVERSE_MAP to `flags`
  2150. \snippet polar_transforms.cpp InverseMap
  2151. In addiction, to calculate the original coordinate from a polar mapped coordinate \f$(rho, phi)->(x, y)\f$:
  2152. \snippet polar_transforms.cpp InverseCoordinate
  2153. @param src Source image.
  2154. @param dst Destination image. It will have same type as src.
  2155. @param dsize The destination image size (see description for valid options).
  2156. @param center The transformation center.
  2157. @param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.
  2158. @param flags A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode.
  2159. - Add #WARP_POLAR_LINEAR to select linear polar mapping (default)
  2160. - Add #WARP_POLAR_LOG to select semilog polar mapping
  2161. - Add #WARP_INVERSE_MAP for reverse mapping.
  2162. @note
  2163. - The function can not operate in-place.
  2164. - To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
  2165. - This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
  2166. @sa cv::remap
  2167. */
  2168. CV_EXPORTS_W void warpPolar(InputArray src, OutputArray dst, Size dsize,
  2169. Point2f center, double maxRadius, int flags);
  2170. //! @} imgproc_transform
  2171. //! @addtogroup imgproc_misc
  2172. //! @{
  2173. /** @overload */
  2174. CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );
  2175. /** @overload */
  2176. CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,
  2177. OutputArray sqsum, int sdepth = -1, int sqdepth = -1 );
  2178. /** @brief Calculates the integral of an image.
  2179. The function calculates one or more integral images for the source image as follows:
  2180. \f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f]
  2181. \f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f]
  2182. \f[\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)\f]
  2183. Using these integral images, you can calculate sum, mean, and standard deviation over a specific
  2184. up-right or rotated rectangular region of the image in a constant time, for example:
  2185. \f[\sum _{x_1 \leq x < x_2, \, y_1 \leq y < y_2} \texttt{image} (x,y) = \texttt{sum} (x_2,y_2)- \texttt{sum} (x_1,y_2)- \texttt{sum} (x_2,y_1)+ \texttt{sum} (x_1,y_1)\f]
  2186. It makes possible to do a fast blurring or fast block correlation with a variable window size, for
  2187. example. In case of multi-channel images, sums for each channel are accumulated independently.
  2188. As a practical example, the next figure shows the calculation of the integral of a straight
  2189. rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the
  2190. original image are shown, as well as the relative pixels in the integral images sum and tilted .
  2191. ![integral calculation example](pics/integral.png)
  2192. @param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f).
  2193. @param sum integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f).
  2194. @param sqsum integral image for squared pixel values; it is \f$(W+1)\times (H+1)\f$, double-precision
  2195. floating-point (64f) array.
  2196. @param tilted integral for the image rotated by 45 degrees; it is \f$(W+1)\times (H+1)\f$ array with
  2197. the same data type as sum.
  2198. @param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or
  2199. CV_64F.
  2200. @param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.
  2201. */
  2202. CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum,
  2203. OutputArray sqsum, OutputArray tilted,
  2204. int sdepth = -1, int sqdepth = -1 );
  2205. //! @} imgproc_misc
  2206. //! @addtogroup imgproc_motion
  2207. //! @{
  2208. /** @brief Adds an image to the accumulator image.
  2209. The function adds src or some of its elements to dst :
  2210. \f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f]
  2211. The function supports multi-channel images. Each channel is processed independently.
  2212. The function cv::accumulate can be used, for example, to collect statistics of a scene background
  2213. viewed by a still camera and for the further foreground-background segmentation.
  2214. @param src Input image of type CV_8UC(n), CV_16UC(n), CV_32FC(n) or CV_64FC(n), where n is a positive integer.
  2215. @param dst %Accumulator image with the same number of channels as input image, and a depth of CV_32F or CV_64F.
  2216. @param mask Optional operation mask.
  2217. @sa accumulateSquare, accumulateProduct, accumulateWeighted
  2218. */
  2219. CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
  2220. InputArray mask = noArray() );
  2221. /** @brief Adds the square of a source image to the accumulator image.
  2222. The function adds the input image src or its selected region, raised to a power of 2, to the
  2223. accumulator dst :
  2224. \f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y)^2 \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f]
  2225. The function supports multi-channel images. Each channel is processed independently.
  2226. @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
  2227. @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit
  2228. floating-point.
  2229. @param mask Optional operation mask.
  2230. @sa accumulateSquare, accumulateProduct, accumulateWeighted
  2231. */
  2232. CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst,
  2233. InputArray mask = noArray() );
  2234. /** @brief Adds the per-element product of two input images to the accumulator image.
  2235. The function adds the product of two images or their selected regions to the accumulator dst :
  2236. \f[\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src1} (x,y) \cdot \texttt{src2} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f]
  2237. The function supports multi-channel images. Each channel is processed independently.
  2238. @param src1 First input image, 1- or 3-channel, 8-bit or 32-bit floating point.
  2239. @param src2 Second input image of the same type and the same size as src1 .
  2240. @param dst %Accumulator image with the same number of channels as input images, 32-bit or 64-bit
  2241. floating-point.
  2242. @param mask Optional operation mask.
  2243. @sa accumulate, accumulateSquare, accumulateWeighted
  2244. */
  2245. CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,
  2246. InputOutputArray dst, InputArray mask=noArray() );
  2247. /** @brief Updates a running average.
  2248. The function calculates the weighted sum of the input image src and the accumulator dst so that dst
  2249. becomes a running average of a frame sequence:
  2250. \f[\texttt{dst} (x,y) \leftarrow (1- \texttt{alpha} ) \cdot \texttt{dst} (x,y) + \texttt{alpha} \cdot \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0\f]
  2251. That is, alpha regulates the update speed (how fast the accumulator "forgets" about earlier images).
  2252. The function supports multi-channel images. Each channel is processed independently.
  2253. @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
  2254. @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit
  2255. floating-point.
  2256. @param alpha Weight of the input image.
  2257. @param mask Optional operation mask.
  2258. @sa accumulate, accumulateSquare, accumulateProduct
  2259. */
  2260. CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
  2261. double alpha, InputArray mask = noArray() );
  2262. /** @brief The function is used to detect translational shifts that occur between two images.
  2263. The operation takes advantage of the Fourier shift theorem for detecting the translational shift in
  2264. the frequency domain. It can be used for fast image registration as well as motion estimation. For
  2265. more information please see <http://en.wikipedia.org/wiki/Phase_correlation>
  2266. Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed
  2267. with getOptimalDFTSize.
  2268. The function performs the following equations:
  2269. - First it applies a Hanning window (see <http://en.wikipedia.org/wiki/Hann_function>) to each
  2270. image to remove possible edge effects. This window is cached until the array size changes to speed
  2271. up processing time.
  2272. - Next it computes the forward DFTs of each source array:
  2273. \f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f]
  2274. where \f$\mathcal{F}\f$ is the forward DFT.
  2275. - It then computes the cross-power spectrum of each frequency domain array:
  2276. \f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f]
  2277. - Next the cross-correlation is converted back into the time domain via the inverse DFT:
  2278. \f[r = \mathcal{F}^{-1}\{R\}\f]
  2279. - Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to
  2280. achieve sub-pixel accuracy.
  2281. \f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f]
  2282. - If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5
  2283. centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single
  2284. peak) and will be smaller when there are multiple peaks.
  2285. @param src1 Source floating point array (CV_32FC1 or CV_64FC1)
  2286. @param src2 Source floating point array (CV_32FC1 or CV_64FC1)
  2287. @param window Floating point array with windowing coefficients to reduce edge effects (optional).
  2288. @param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional).
  2289. @returns detected phase shift (sub-pixel) between the two arrays.
  2290. @sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow
  2291. */
  2292. CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2,
  2293. InputArray window = noArray(), CV_OUT double* response = 0);
  2294. /** @brief This function computes a Hanning window coefficients in two dimensions.
  2295. See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function)
  2296. for more information.
  2297. An example is shown below:
  2298. @code
  2299. // create hanning window of size 100x100 and type CV_32F
  2300. Mat hann;
  2301. createHanningWindow(hann, Size(100, 100), CV_32F);
  2302. @endcode
  2303. @param dst Destination array to place Hann coefficients in
  2304. @param winSize The window size specifications (both width and height must be > 1)
  2305. @param type Created array type
  2306. */
  2307. CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);
  2308. //! @} imgproc_motion
  2309. //! @addtogroup imgproc_misc
  2310. //! @{
  2311. /** @brief Applies a fixed-level threshold to each array element.
  2312. The function applies fixed-level thresholding to a multiple-channel array. The function is typically
  2313. used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for
  2314. this purpose) or for removing a noise, that is, filtering out pixels with too small or too large
  2315. values. There are several types of thresholding supported by the function. They are determined by
  2316. type parameter.
  2317. Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the
  2318. above values. In these cases, the function determines the optimal threshold value using the Otsu's
  2319. or Triangle algorithm and uses it instead of the specified thresh.
  2320. @note Currently, the Otsu's and Triangle methods are implemented only for 8-bit single-channel images.
  2321. @param src input array (multiple-channel, 8-bit or 32-bit floating point).
  2322. @param dst output array of the same size and type and the same number of channels as src.
  2323. @param thresh threshold value.
  2324. @param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding
  2325. types.
  2326. @param type thresholding type (see #ThresholdTypes).
  2327. @return the computed threshold value if Otsu's or Triangle methods used.
  2328. @sa adaptiveThreshold, findContours, compare, min, max
  2329. */
  2330. CV_EXPORTS_W double threshold( InputArray src, OutputArray dst,
  2331. double thresh, double maxval, int type );
  2332. /** @brief Applies an adaptive threshold to an array.
  2333. The function transforms a grayscale image to a binary image according to the formulae:
  2334. - **THRESH_BINARY**
  2335. \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f]
  2336. - **THRESH_BINARY_INV**
  2337. \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f]
  2338. where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter).
  2339. The function can process the image in-place.
  2340. @param src Source 8-bit single-channel image.
  2341. @param dst Destination image of the same size and the same type as src.
  2342. @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
  2343. @param adaptiveMethod Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes.
  2344. The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries.
  2345. @param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV,
  2346. see #ThresholdTypes.
  2347. @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the
  2348. pixel: 3, 5, 7, and so on.
  2349. @param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it
  2350. is positive but may be zero or negative as well.
  2351. @sa threshold, blur, GaussianBlur
  2352. */
  2353. CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst,
  2354. double maxValue, int adaptiveMethod,
  2355. int thresholdType, int blockSize, double C );
  2356. //! @} imgproc_misc
  2357. //! @addtogroup imgproc_filter
  2358. //! @{
  2359. /** @example samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp
  2360. An example using pyrDown and pyrUp functions
  2361. */
  2362. /** @brief Blurs an image and downsamples it.
  2363. By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in
  2364. any case, the following conditions should be satisfied:
  2365. \f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f]
  2366. The function performs the downsampling step of the Gaussian pyramid construction. First, it
  2367. convolves the source image with the kernel:
  2368. \f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f]
  2369. Then, it downsamples the image by rejecting even rows and columns.
  2370. @param src input image.
  2371. @param dst output image; it has the specified size and the same type as src.
  2372. @param dstsize size of the output image.
  2373. @param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported)
  2374. */
  2375. CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst,
  2376. const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );
  2377. /** @brief Upsamples an image and then blurs it.
  2378. By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any
  2379. case, the following conditions should be satisfied:
  2380. \f[\begin{array}{l} | \texttt{dstsize.width} -src.cols*2| \leq ( \texttt{dstsize.width} \mod 2) \\ | \texttt{dstsize.height} -src.rows*2| \leq ( \texttt{dstsize.height} \mod 2) \end{array}\f]
  2381. The function performs the upsampling step of the Gaussian pyramid construction, though it can
  2382. actually be used to construct the Laplacian pyramid. First, it upsamples the source image by
  2383. injecting even zero rows and columns and then convolves the result with the same kernel as in
  2384. pyrDown multiplied by 4.
  2385. @param src input image.
  2386. @param dst output image. It has the specified size and the same type as src .
  2387. @param dstsize size of the output image.
  2388. @param borderType Pixel extrapolation method, see #BorderTypes (only #BORDER_DEFAULT is supported)
  2389. */
  2390. CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst,
  2391. const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );
  2392. /** @brief Constructs the Gaussian pyramid for an image.
  2393. The function constructs a vector of images and builds the Gaussian pyramid by recursively applying
  2394. pyrDown to the previously built pyramid layers, starting from `dst[0]==src`.
  2395. @param src Source image. Check pyrDown for the list of supported types.
  2396. @param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the
  2397. same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on.
  2398. @param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative.
  2399. @param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported)
  2400. */
  2401. CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst,
  2402. int maxlevel, int borderType = BORDER_DEFAULT );
  2403. //! @} imgproc_filter
  2404. //! @addtogroup imgproc_hist
  2405. //! @{
  2406. /** @example samples/cpp/demhist.cpp
  2407. An example for creating histograms of an image
  2408. */
  2409. /** @brief Calculates a histogram of a set of arrays.
  2410. The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used
  2411. to increment a histogram bin are taken from the corresponding input arrays at the same location. The
  2412. sample below shows how to compute a 2D Hue-Saturation histogram for a color image. :
  2413. @include snippets/imgproc_calcHist.cpp
  2414. @param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same
  2415. size. Each of them can have an arbitrary number of channels.
  2416. @param nimages Number of source images.
  2417. @param channels List of the dims channels used to compute the histogram. The first array channels
  2418. are numerated from 0 to images[0].channels()-1 , the second array channels are counted from
  2419. images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.
  2420. @param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size
  2421. as images[i] . The non-zero mask elements mark the array elements counted in the histogram.
  2422. @param hist Output histogram, which is a dense or sparse dims -dimensional array.
  2423. @param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS
  2424. (equal to 32 in the current OpenCV version).
  2425. @param histSize Array of histogram sizes in each dimension.
  2426. @param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the
  2427. histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower
  2428. (inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary
  2429. \f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a
  2430. uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform (
  2431. uniform=false ), then each of ranges[i] contains histSize[i]+1 elements:
  2432. \f$L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}\f$
  2433. . The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not
  2434. counted in the histogram.
  2435. @param uniform Flag indicating whether the histogram is uniform or not (see above).
  2436. @param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning
  2437. when it is allocated. This feature enables you to compute a single histogram from several sets of
  2438. arrays, or to update the histogram in time.
  2439. */
  2440. CV_EXPORTS void calcHist( const Mat* images, int nimages,
  2441. const int* channels, InputArray mask,
  2442. OutputArray hist, int dims, const int* histSize,
  2443. const float** ranges, bool uniform = true, bool accumulate = false );
  2444. /** @overload
  2445. this variant uses %SparseMat for output
  2446. */
  2447. CV_EXPORTS void calcHist( const Mat* images, int nimages,
  2448. const int* channels, InputArray mask,
  2449. SparseMat& hist, int dims,
  2450. const int* histSize, const float** ranges,
  2451. bool uniform = true, bool accumulate = false );
  2452. /** @overload */
  2453. CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
  2454. const std::vector<int>& channels,
  2455. InputArray mask, OutputArray hist,
  2456. const std::vector<int>& histSize,
  2457. const std::vector<float>& ranges,
  2458. bool accumulate = false );
  2459. /** @brief Calculates the back projection of a histogram.
  2460. The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to
  2461. #calcHist , at each location (x, y) the function collects the values from the selected channels
  2462. in the input images and finds the corresponding histogram bin. But instead of incrementing it, the
  2463. function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of
  2464. statistics, the function computes probability of each element value in respect with the empirical
  2465. probability distribution represented by the histogram. See how, for example, you can find and track
  2466. a bright-colored object in a scene:
  2467. - Before tracking, show the object to the camera so that it covers almost the whole frame.
  2468. Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant
  2469. colors in the object.
  2470. - When tracking, calculate a back projection of a hue plane of each input video frame using that
  2471. pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make
  2472. sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.
  2473. - Find connected components in the resulting picture and choose, for example, the largest
  2474. component.
  2475. This is an approximate algorithm of the CamShift color object tracker.
  2476. @param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same
  2477. size. Each of them can have an arbitrary number of channels.
  2478. @param nimages Number of source images.
  2479. @param channels The list of channels used to compute the back projection. The number of channels
  2480. must match the histogram dimensionality. The first array channels are numerated from 0 to
  2481. images[0].channels()-1 , the second array channels are counted from images[0].channels() to
  2482. images[0].channels() + images[1].channels()-1, and so on.
  2483. @param hist Input histogram that can be dense or sparse.
  2484. @param backProject Destination back projection array that is a single-channel array of the same
  2485. size and depth as images[0] .
  2486. @param ranges Array of arrays of the histogram bin boundaries in each dimension. See #calcHist .
  2487. @param scale Optional scale factor for the output back projection.
  2488. @param uniform Flag indicating whether the histogram is uniform or not (see above).
  2489. @sa calcHist, compareHist
  2490. */
  2491. CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
  2492. const int* channels, InputArray hist,
  2493. OutputArray backProject, const float** ranges,
  2494. double scale = 1, bool uniform = true );
  2495. /** @overload */
  2496. CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
  2497. const int* channels, const SparseMat& hist,
  2498. OutputArray backProject, const float** ranges,
  2499. double scale = 1, bool uniform = true );
  2500. /** @overload */
  2501. CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector<int>& channels,
  2502. InputArray hist, OutputArray dst,
  2503. const std::vector<float>& ranges,
  2504. double scale );
  2505. /** @brief Compares two histograms.
  2506. The function cv::compareHist compares two dense or two sparse histograms using the specified method.
  2507. The function returns \f$d(H_1, H_2)\f$ .
  2508. While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable
  2509. for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling
  2510. problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms
  2511. or more general sparse configurations of weighted points, consider using the #EMD function.
  2512. @param H1 First compared histogram.
  2513. @param H2 Second compared histogram of the same size as H1 .
  2514. @param method Comparison method, see #HistCompMethods
  2515. */
  2516. CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method );
  2517. /** @overload */
  2518. CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
  2519. /** @brief Equalizes the histogram of a grayscale image.
  2520. The function equalizes the histogram of the input image using the following algorithm:
  2521. - Calculate the histogram \f$H\f$ for src .
  2522. - Normalize the histogram so that the sum of histogram bins is 255.
  2523. - Compute the integral of the histogram:
  2524. \f[H'_i = \sum _{0 \le j < i} H(j)\f]
  2525. - Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$
  2526. The algorithm normalizes the brightness and increases the contrast of the image.
  2527. @param src Source 8-bit single channel image.
  2528. @param dst Destination image of the same size and type as src .
  2529. */
  2530. CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );
  2531. /** @brief Creates a smart pointer to a cv::CLAHE class and initializes it.
  2532. @param clipLimit Threshold for contrast limiting.
  2533. @param tileGridSize Size of grid for histogram equalization. Input image will be divided into
  2534. equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column.
  2535. */
  2536. CV_EXPORTS_W Ptr<CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8));
  2537. /** @brief Computes the "minimal work" distance between two weighted point configurations.
  2538. The function computes the earth mover distance and/or a lower boundary of the distance between the
  2539. two weighted point configurations. One of the applications described in @cite RubnerSept98,
  2540. @cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation
  2541. problem that is solved using some modification of a simplex algorithm, thus the complexity is
  2542. exponential in the worst case, though, on average it is much faster. In the case of a real metric
  2543. the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used
  2544. to determine roughly whether the two signatures are far enough so that they cannot relate to the
  2545. same object.
  2546. @param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix.
  2547. Each row stores the point weight followed by the point coordinates. The matrix is allowed to have
  2548. a single column (weights only) if the user-defined cost matrix is used. The weights must be
  2549. non-negative and have at least one non-zero value.
  2550. @param signature2 Second signature of the same format as signature1 , though the number of rows
  2551. may be different. The total weights may be different. In this case an extra "dummy" point is added
  2552. to either signature1 or signature2. The weights must be non-negative and have at least one non-zero
  2553. value.
  2554. @param distType Used metric. See #DistanceTypes.
  2555. @param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix
  2556. is used, lower boundary lowerBound cannot be calculated because it needs a metric function.
  2557. @param lowerBound Optional input/output parameter: lower boundary of a distance between the two
  2558. signatures that is a distance between mass centers. The lower boundary may not be calculated if
  2559. the user-defined cost matrix is used, the total weights of point configurations are not equal, or
  2560. if the signatures consist of weights only (the signature matrices have a single column). You
  2561. **must** initialize \*lowerBound . If the calculated distance between mass centers is greater or
  2562. equal to \*lowerBound (it means that the signatures are far enough), the function does not
  2563. calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on
  2564. return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound
  2565. should be set to 0.
  2566. @param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is
  2567. a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 .
  2568. */
  2569. CV_EXPORTS float EMD( InputArray signature1, InputArray signature2,
  2570. int distType, InputArray cost=noArray(),
  2571. float* lowerBound = 0, OutputArray flow = noArray() );
  2572. CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature2,
  2573. int distType, InputArray cost=noArray(),
  2574. CV_IN_OUT Ptr<float> lowerBound = Ptr<float>(), OutputArray flow = noArray() );
  2575. //! @} imgproc_hist
  2576. /** @example samples/cpp/watershed.cpp
  2577. An example using the watershed algorithm
  2578. */
  2579. /** @brief Performs a marker-based image segmentation using the watershed algorithm.
  2580. The function implements one of the variants of watershed, non-parametric marker-based segmentation
  2581. algorithm, described in @cite Meyer92 .
  2582. Before passing the image to the function, you have to roughly outline the desired regions in the
  2583. image markers with positive (\>0) indices. So, every region is represented as one or more connected
  2584. components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary
  2585. mask using #findContours and #drawContours (see the watershed.cpp demo). The markers are "seeds" of
  2586. the future image regions. All the other pixels in markers , whose relation to the outlined regions
  2587. is not known and should be defined by the algorithm, should be set to 0's. In the function output,
  2588. each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the
  2589. regions.
  2590. @note Any two neighbor connected components are not necessarily separated by a watershed boundary
  2591. (-1's pixels); for example, they can touch each other in the initial marker image passed to the
  2592. function.
  2593. @param image Input 8-bit 3-channel image.
  2594. @param markers Input/output 32-bit single-channel image (map) of markers. It should have the same
  2595. size as image .
  2596. @sa findContours
  2597. @ingroup imgproc_misc
  2598. */
  2599. CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers );
  2600. //! @addtogroup imgproc_filter
  2601. //! @{
  2602. /** @brief Performs initial step of meanshift segmentation of an image.
  2603. The function implements the filtering stage of meanshift segmentation, that is, the output of the
  2604. function is the filtered "posterized" image with color gradients and fine-grain texture flattened.
  2605. At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes
  2606. meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is
  2607. considered:
  2608. \f[(x,y): X- \texttt{sp} \le x \le X+ \texttt{sp} , Y- \texttt{sp} \le y \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)|| \le \texttt{sr}\f]
  2609. where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively
  2610. (though, the algorithm does not depend on the color space used, so any 3-component color space can
  2611. be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector
  2612. (R',G',B') are found and they act as the neighborhood center on the next iteration:
  2613. \f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f]
  2614. After the iterations over, the color components of the initial pixel (that is, the pixel from where
  2615. the iterations started) are set to the final value (average color at the last iteration):
  2616. \f[I(X,Y) <- (R*,G*,B*)\f]
  2617. When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is
  2618. run on the smallest layer first. After that, the results are propagated to the larger layer and the
  2619. iterations are run again only on those pixels where the layer colors differ by more than sr from the
  2620. lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the
  2621. results will be actually different from the ones obtained by running the meanshift procedure on the
  2622. whole original image (i.e. when maxLevel==0).
  2623. @param src The source 8-bit, 3-channel image.
  2624. @param dst The destination image of the same format and the same size as the source.
  2625. @param sp The spatial window radius.
  2626. @param sr The color window radius.
  2627. @param maxLevel Maximum level of the pyramid for the segmentation.
  2628. @param termcrit Termination criteria: when to stop meanshift iterations.
  2629. */
  2630. CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst,
  2631. double sp, double sr, int maxLevel = 1,
  2632. TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) );
  2633. //! @}
  2634. //! @addtogroup imgproc_misc
  2635. //! @{
  2636. /** @example samples/cpp/grabcut.cpp
  2637. An example using the GrabCut algorithm
  2638. ![Sample Screenshot](grabcut_output1.jpg)
  2639. */
  2640. /** @brief Runs the GrabCut algorithm.
  2641. The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut).
  2642. @param img Input 8-bit 3-channel image.
  2643. @param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when
  2644. mode is set to #GC_INIT_WITH_RECT. Its elements may have one of the #GrabCutClasses.
  2645. @param rect ROI containing a segmented object. The pixels outside of the ROI are marked as
  2646. "obvious background". The parameter is only used when mode==#GC_INIT_WITH_RECT .
  2647. @param bgdModel Temporary array for the background model. Do not modify it while you are
  2648. processing the same image.
  2649. @param fgdModel Temporary arrays for the foreground model. Do not modify it while you are
  2650. processing the same image.
  2651. @param iterCount Number of iterations the algorithm should make before returning the result. Note
  2652. that the result can be refined with further calls with mode==#GC_INIT_WITH_MASK or
  2653. mode==GC_EVAL .
  2654. @param mode Operation mode that could be one of the #GrabCutModes
  2655. */
  2656. CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect,
  2657. InputOutputArray bgdModel, InputOutputArray fgdModel,
  2658. int iterCount, int mode = GC_EVAL );
  2659. /** @example samples/cpp/distrans.cpp
  2660. An example on using the distance transform
  2661. */
  2662. /** @brief Calculates the distance to the closest zero pixel for each pixel of the source image.
  2663. The function cv::distanceTransform calculates the approximate or precise distance from every binary
  2664. image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero.
  2665. When maskSize == #DIST_MASK_PRECISE and distanceType == #DIST_L2 , the function runs the
  2666. algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library.
  2667. In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function
  2668. finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical,
  2669. diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall
  2670. distance is calculated as a sum of these basic distances. Since the distance function should be
  2671. symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all
  2672. the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the
  2673. same cost (denoted as `c`). For the #DIST_C and #DIST_L1 types, the distance is calculated
  2674. precisely, whereas for #DIST_L2 (Euclidean distance) the distance can be calculated only with a
  2675. relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV
  2676. uses the values suggested in the original paper:
  2677. - DIST_L1: `a = 1, b = 2`
  2678. - DIST_L2:
  2679. - `3 x 3`: `a=0.955, b=1.3693`
  2680. - `5 x 5`: `a=1, b=1.4, c=2.1969`
  2681. - DIST_C: `a = 1, b = 1`
  2682. Typically, for a fast, coarse distance estimation #DIST_L2, a \f$3\times 3\f$ mask is used. For a
  2683. more accurate distance estimation #DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used.
  2684. Note that both the precise and the approximate algorithms are linear on the number of pixels.
  2685. This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$
  2686. but also identifies the nearest connected component consisting of zero pixels
  2687. (labelType==#DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==#DIST_LABEL_PIXEL). Index of the
  2688. component/pixel is stored in `labels(x, y)`. When labelType==#DIST_LABEL_CCOMP, the function
  2689. automatically finds connected components of zero pixels in the input image and marks them with
  2690. distinct labels. When labelType==#DIST_LABEL_CCOMP, the function scans through the input image and
  2691. marks all the zero pixels with distinct labels.
  2692. In this mode, the complexity is still linear. That is, the function provides a very fast way to
  2693. compute the Voronoi diagram for a binary image. Currently, the second variant can use only the
  2694. approximate distance transform algorithm, i.e. maskSize=#DIST_MASK_PRECISE is not supported
  2695. yet.
  2696. @param src 8-bit, single-channel (binary) source image.
  2697. @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,
  2698. single-channel image of the same size as src.
  2699. @param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type
  2700. CV_32SC1 and the same size as src.
  2701. @param distanceType Type of distance, see #DistanceTypes
  2702. @param maskSize Size of the distance transform mask, see #DistanceTransformMasks.
  2703. #DIST_MASK_PRECISE is not supported by this variant. In case of the #DIST_L1 or #DIST_C distance type,
  2704. the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times
  2705. 5\f$ or any larger aperture.
  2706. @param labelType Type of the label array to build, see #DistanceTransformLabelTypes.
  2707. */
  2708. CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst,
  2709. OutputArray labels, int distanceType, int maskSize,
  2710. int labelType = DIST_LABEL_CCOMP );
  2711. /** @overload
  2712. @param src 8-bit, single-channel (binary) source image.
  2713. @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,
  2714. single-channel image of the same size as src .
  2715. @param distanceType Type of distance, see #DistanceTypes
  2716. @param maskSize Size of the distance transform mask, see #DistanceTransformMasks. In case of the
  2717. #DIST_L1 or #DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives
  2718. the same result as \f$5\times 5\f$ or any larger aperture.
  2719. @param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for
  2720. the first variant of the function and distanceType == #DIST_L1.
  2721. */
  2722. CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst,
  2723. int distanceType, int maskSize, int dstType=CV_32F);
  2724. /** @example samples/cpp/ffilldemo.cpp
  2725. An example using the FloodFill technique
  2726. */
  2727. /** @overload
  2728. variant without `mask` parameter
  2729. */
  2730. CV_EXPORTS int floodFill( InputOutputArray image,
  2731. Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0,
  2732. Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),
  2733. int flags = 4 );
  2734. /** @brief Fills a connected component with the given color.
  2735. The function cv::floodFill fills a connected component starting from the seed point with the specified
  2736. color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The
  2737. pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if:
  2738. - in case of a grayscale image and floating range
  2739. \f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}\f]
  2740. - in case of a grayscale image and fixed range
  2741. \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)+ \texttt{upDiff}\f]
  2742. - in case of a color image and floating range
  2743. \f[\texttt{src} (x',y')_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} (x',y')_r+ \texttt{upDiff} _r,\f]
  2744. \f[\texttt{src} (x',y')_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} (x',y')_g+ \texttt{upDiff} _g\f]
  2745. and
  2746. \f[\texttt{src} (x',y')_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} (x',y')_b+ \texttt{upDiff} _b\f]
  2747. - in case of a color image and fixed range
  2748. \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r+ \texttt{upDiff} _r,\f]
  2749. \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g+ \texttt{upDiff} _g\f]
  2750. and
  2751. \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b+ \texttt{upDiff} _b\f]
  2752. where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the
  2753. component. That is, to be added to the connected component, a color/brightness of the pixel should
  2754. be close enough to:
  2755. - Color/brightness of one of its neighbors that already belong to the connected component in case
  2756. of a floating range.
  2757. - Color/brightness of the seed point in case of a fixed range.
  2758. Use these functions to either mark a connected component with the specified color in-place, or build
  2759. a mask and then extract the contour, or copy the region to another image, and so on.
  2760. @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the
  2761. function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See
  2762. the details below.
  2763. @param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels
  2764. taller than image. Since this is both an input and output parameter, you must take responsibility
  2765. of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example,
  2766. an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the
  2767. mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags
  2768. as described below. Additionally, the function fills the border of the mask with ones to simplify
  2769. internal processing. It is therefore possible to use the same mask in multiple calls to the function
  2770. to make sure the filled areas do not overlap.
  2771. @param seedPoint Starting point.
  2772. @param newVal New value of the repainted domain pixels.
  2773. @param loDiff Maximal lower brightness/color difference between the currently observed pixel and
  2774. one of its neighbors belonging to the component, or a seed pixel being added to the component.
  2775. @param upDiff Maximal upper brightness/color difference between the currently observed pixel and
  2776. one of its neighbors belonging to the component, or a seed pixel being added to the component.
  2777. @param rect Optional output parameter set by the function to the minimum bounding rectangle of the
  2778. repainted domain.
  2779. @param flags Operation flags. The first 8 bits contain a connectivity value. The default value of
  2780. 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A
  2781. connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner)
  2782. will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill
  2783. the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest
  2784. neighbours and fill the mask with a value of 255. The following additional options occupy higher
  2785. bits and therefore may be further combined with the connectivity and mask fill values using
  2786. bit-wise or (|), see #FloodFillFlags.
  2787. @note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the
  2788. pixel \f$(x+1, y+1)\f$ in the mask .
  2789. @sa findContours
  2790. */
  2791. CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
  2792. Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0,
  2793. Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),
  2794. int flags = 4 );
  2795. //! Performs linear blending of two images:
  2796. //! \f[ \texttt{dst}(i,j) = \texttt{weights1}(i,j)*\texttt{src1}(i,j) + \texttt{weights2}(i,j)*\texttt{src2}(i,j) \f]
  2797. //! @param src1 It has a type of CV_8UC(n) or CV_32FC(n), where n is a positive integer.
  2798. //! @param src2 It has the same type and size as src1.
  2799. //! @param weights1 It has a type of CV_32FC1 and the same size with src1.
  2800. //! @param weights2 It has a type of CV_32FC1 and the same size with src1.
  2801. //! @param dst It is created if it does not have the same size and type with src1.
  2802. CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst);
  2803. //! @} imgproc_misc
  2804. //! @addtogroup imgproc_color_conversions
  2805. //! @{
  2806. /** @brief Converts an image from one color space to another.
  2807. The function converts an input image from one color space to another. In case of a transformation
  2808. to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note
  2809. that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the
  2810. bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue
  2811. component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and
  2812. sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
  2813. The conventional ranges for R, G, and B channel values are:
  2814. - 0 to 255 for CV_8U images
  2815. - 0 to 65535 for CV_16U images
  2816. - 0 to 1 for CV_32F images
  2817. In case of linear transformations, the range does not matter. But in case of a non-linear
  2818. transformation, an input RGB image should be normalized to the proper value range to get the correct
  2819. results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a
  2820. 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will
  2821. have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor ,
  2822. you need first to scale the image down:
  2823. @code
  2824. img *= 1./255;
  2825. cvtColor(img, img, COLOR_BGR2Luv);
  2826. @endcode
  2827. If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many
  2828. applications, this will not be noticeable but it is recommended to use 32-bit images in applications
  2829. that need the full range of colors or that convert an image before an operation and then convert
  2830. back.
  2831. If conversion adds the alpha channel, its value will set to the maximum of corresponding channel
  2832. range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
  2833. @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision
  2834. floating-point.
  2835. @param dst output image of the same size and depth as src.
  2836. @param code color space conversion code (see #ColorConversionCodes).
  2837. @param dstCn number of channels in the destination image; if the parameter is 0, the number of the
  2838. channels is derived automatically from src and code.
  2839. @see @ref imgproc_color_conversions
  2840. */
  2841. CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
  2842. /** @brief Converts an image from one color space to another where the source image is
  2843. stored in two planes.
  2844. This function only supports YUV420 to RGB conversion as of now.
  2845. @param src1: 8-bit image (#CV_8U) of the Y plane.
  2846. @param src2: image containing interleaved U/V plane.
  2847. @param dst: output image.
  2848. @param code: Specifies the type of conversion. It can take any of the following values:
  2849. - #COLOR_YUV2BGR_NV12
  2850. - #COLOR_YUV2RGB_NV12
  2851. - #COLOR_YUV2BGRA_NV12
  2852. - #COLOR_YUV2RGBA_NV12
  2853. - #COLOR_YUV2BGR_NV21
  2854. - #COLOR_YUV2RGB_NV21
  2855. - #COLOR_YUV2BGRA_NV21
  2856. - #COLOR_YUV2RGBA_NV21
  2857. */
  2858. CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code );
  2859. /** @brief main function for all demosaicing processes
  2860. @param src input image: 8-bit unsigned or 16-bit unsigned.
  2861. @param dst output image of the same size and depth as src.
  2862. @param code Color space conversion code (see the description below).
  2863. @param dstCn number of channels in the destination image; if the parameter is 0, the number of the
  2864. channels is derived automatically from src and code.
  2865. The function can do the following transformations:
  2866. - Demosaicing using bilinear interpolation
  2867. #COLOR_BayerBG2BGR , #COLOR_BayerGB2BGR , #COLOR_BayerRG2BGR , #COLOR_BayerGR2BGR
  2868. #COLOR_BayerBG2GRAY , #COLOR_BayerGB2GRAY , #COLOR_BayerRG2GRAY , #COLOR_BayerGR2GRAY
  2869. - Demosaicing using Variable Number of Gradients.
  2870. #COLOR_BayerBG2BGR_VNG , #COLOR_BayerGB2BGR_VNG , #COLOR_BayerRG2BGR_VNG , #COLOR_BayerGR2BGR_VNG
  2871. - Edge-Aware Demosaicing.
  2872. #COLOR_BayerBG2BGR_EA , #COLOR_BayerGB2BGR_EA , #COLOR_BayerRG2BGR_EA , #COLOR_BayerGR2BGR_EA
  2873. - Demosaicing with alpha channel
  2874. #COLOR_BayerBG2BGRA , #COLOR_BayerGB2BGRA , #COLOR_BayerRG2BGRA , #COLOR_BayerGR2BGRA
  2875. @sa cvtColor
  2876. */
  2877. CV_EXPORTS_W void demosaicing(InputArray src, OutputArray dst, int code, int dstCn = 0);
  2878. //! @} imgproc_color_conversions
  2879. //! @addtogroup imgproc_shape
  2880. //! @{
  2881. /** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape.
  2882. The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The
  2883. results are returned in the structure cv::Moments.
  2884. @param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array (
  2885. \f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ).
  2886. @param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is
  2887. used for images only.
  2888. @returns moments.
  2889. @note Only applicable to contour moments calculations from Python bindings: Note that the numpy
  2890. type for the input array should be either np.int32 or np.float32.
  2891. @sa contourArea, arcLength
  2892. */
  2893. CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false );
  2894. /** @brief Calculates seven Hu invariants.
  2895. The function calculates seven Hu invariants (introduced in @cite Hu62; see also
  2896. <http://en.wikipedia.org/wiki/Image_moment>) defined as:
  2897. \f[\begin{array}{l} hu[0]= \eta _{20}+ \eta _{02} \\ hu[1]=( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2} \\ hu[2]=( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2} \\ hu[3]=( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2} \\ hu[4]=( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ hu[5]=( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03}) \\ hu[6]=(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ \end{array}\f]
  2898. where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ .
  2899. These values are proved to be invariants to the image scale, rotation, and reflection except the
  2900. seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of
  2901. infinite image resolution. In case of raster images, the computed Hu invariants for the original and
  2902. transformed images are a bit different.
  2903. @param moments Input moments computed with moments .
  2904. @param hu Output Hu invariants.
  2905. @sa matchShapes
  2906. */
  2907. CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
  2908. /** @overload */
  2909. CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu );
  2910. //! @} imgproc_shape
  2911. //! @addtogroup imgproc_object
  2912. //! @{
  2913. //! type of the template matching operation
  2914. enum TemplateMatchModes {
  2915. TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]
  2916. TM_SQDIFF_NORMED = 1, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
  2917. TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f]
  2918. TM_CCORR_NORMED = 3, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
  2919. TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f]
  2920. //!< where
  2921. //!< \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f]
  2922. TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f]
  2923. };
  2924. /** @example samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
  2925. An example using Template Matching algorithm
  2926. */
  2927. /** @brief Compares a template against overlapped image regions.
  2928. The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against
  2929. templ using the specified method and stores the comparison results in result . Here are the formulae
  2930. for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation
  2931. is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$
  2932. After the function finishes the comparison, the best matches can be found as global minimums (when
  2933. #TM_SQDIFF was used) or maximums (when #TM_CCORR or #TM_CCOEFF was used) using the
  2934. #minMaxLoc function. In case of a color image, template summation in the numerator and each sum in
  2935. the denominator is done over all of the channels and separate mean values are used for each channel.
  2936. That is, the function can take a color template and a color image. The result will still be a
  2937. single-channel image, which is easier to analyze.
  2938. @param image Image where the search is running. It must be 8-bit or 32-bit floating-point.
  2939. @param templ Searched template. It must be not greater than the source image and have the same
  2940. data type.
  2941. @param result Map of comparison results. It must be single-channel 32-bit floating-point. If image
  2942. is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ .
  2943. @param method Parameter specifying the comparison method, see #TemplateMatchModes
  2944. @param mask Mask of searched template. It must have the same datatype and size with templ. It is
  2945. not set by default. Currently, only the #TM_SQDIFF and #TM_CCORR_NORMED methods are supported.
  2946. */
  2947. CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,
  2948. OutputArray result, int method, InputArray mask = noArray() );
  2949. //! @}
  2950. //! @addtogroup imgproc_shape
  2951. //! @{
  2952. /** @example samples/cpp/connected_components.cpp
  2953. This program demonstrates connected components and use of the trackbar
  2954. */
  2955. /** @brief computes the connected components labeled image of boolean image
  2956. image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0
  2957. represents the background label. ltype specifies the output label image type, an important
  2958. consideration based on the total number of labels or alternatively the total number of pixels in
  2959. the source image. ccltype specifies the connected components labeling algorithm to use, currently
  2960. Grana (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
  2961. for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
  2962. This function uses parallel version of both Grana and Wu's algorithms if at least one allowed
  2963. parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
  2964. @param image the 8-bit single-channel image to be labeled
  2965. @param labels destination labeled image
  2966. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
  2967. @param ltype output image label type. Currently CV_32S and CV_16U are supported.
  2968. @param ccltype connected components algorithm type (see the #ConnectedComponentsAlgorithmsTypes).
  2969. */
  2970. CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels,
  2971. int connectivity, int ltype, int ccltype);
  2972. /** @overload
  2973. @param image the 8-bit single-channel image to be labeled
  2974. @param labels destination labeled image
  2975. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
  2976. @param ltype output image label type. Currently CV_32S and CV_16U are supported.
  2977. */
  2978. CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels,
  2979. int connectivity = 8, int ltype = CV_32S);
  2980. /** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label
  2981. image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0
  2982. represents the background label. ltype specifies the output label image type, an important
  2983. consideration based on the total number of labels or alternatively the total number of pixels in
  2984. the source image. ccltype specifies the connected components labeling algorithm to use, currently
  2985. Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
  2986. for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
  2987. This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed
  2988. parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
  2989. @param image the 8-bit single-channel image to be labeled
  2990. @param labels destination labeled image
  2991. @param stats statistics output for each label, including the background label, see below for
  2992. available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
  2993. #ConnectedComponentsTypes. The data type is CV_32S.
  2994. @param centroids centroid output for each label, including the background label. Centroids are
  2995. accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.
  2996. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
  2997. @param ltype output image label type. Currently CV_32S and CV_16U are supported.
  2998. @param ccltype connected components algorithm type (see #ConnectedComponentsAlgorithmsTypes).
  2999. */
  3000. CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels,
  3001. OutputArray stats, OutputArray centroids,
  3002. int connectivity, int ltype, int ccltype);
  3003. /** @overload
  3004. @param image the 8-bit single-channel image to be labeled
  3005. @param labels destination labeled image
  3006. @param stats statistics output for each label, including the background label, see below for
  3007. available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
  3008. #ConnectedComponentsTypes. The data type is CV_32S.
  3009. @param centroids centroid output for each label, including the background label. Centroids are
  3010. accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.
  3011. @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
  3012. @param ltype output image label type. Currently CV_32S and CV_16U are supported.
  3013. */
  3014. CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels,
  3015. OutputArray stats, OutputArray centroids,
  3016. int connectivity = 8, int ltype = CV_32S);
  3017. /** @brief Finds contours in a binary image.
  3018. The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours
  3019. are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the
  3020. OpenCV sample directory.
  3021. @note Since opencv 3.2 source image is not modified by this function.
  3022. @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero
  3023. pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold ,
  3024. #adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one.
  3025. If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
  3026. @param contours Detected contours. Each contour is stored as a vector of points (e.g.
  3027. std::vector<std::vector<cv::Point> >).
  3028. @param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has
  3029. as many elements as the number of contours. For each i-th contour contours[i], the elements
  3030. hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices
  3031. in contours of the next and previous contours at the same hierarchical level, the first child
  3032. contour and the parent contour, respectively. If for the contour i there are no next, previous,
  3033. parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
  3034. @param mode Contour retrieval mode, see #RetrievalModes
  3035. @param method Contour approximation method, see #ContourApproximationModes
  3036. @param offset Optional offset by which every contour point is shifted. This is useful if the
  3037. contours are extracted from the image ROI and then they should be analyzed in the whole image
  3038. context.
  3039. */
  3040. CV_EXPORTS_W void findContours( InputArray image, OutputArrayOfArrays contours,
  3041. OutputArray hierarchy, int mode,
  3042. int method, Point offset = Point());
  3043. /** @overload */
  3044. CV_EXPORTS void findContours( InputArray image, OutputArrayOfArrays contours,
  3045. int mode, int method, Point offset = Point());
  3046. /** @example samples/cpp/squares.cpp
  3047. A program using pyramid scaling, Canny, contours and contour simplification to find
  3048. squares in a list of images (pic1-6.png). Returns sequence of squares detected on the image.
  3049. */
  3050. /** @example samples/tapi/squares.cpp
  3051. A program using pyramid scaling, Canny, contours and contour simplification to find
  3052. squares in the input image.
  3053. */
  3054. /** @brief Approximates a polygonal curve(s) with the specified precision.
  3055. The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less
  3056. vertices so that the distance between them is less or equal to the specified precision. It uses the
  3057. Douglas-Peucker algorithm <http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm>
  3058. @param curve Input vector of a 2D point stored in std::vector or Mat
  3059. @param approxCurve Result of the approximation. The type should match the type of the input curve.
  3060. @param epsilon Parameter specifying the approximation accuracy. This is the maximum distance
  3061. between the original curve and its approximation.
  3062. @param closed If true, the approximated curve is closed (its first and last vertices are
  3063. connected). Otherwise, it is not closed.
  3064. */
  3065. CV_EXPORTS_W void approxPolyDP( InputArray curve,
  3066. OutputArray approxCurve,
  3067. double epsilon, bool closed );
  3068. /** @brief Calculates a contour perimeter or a curve length.
  3069. The function computes a curve length or a closed contour perimeter.
  3070. @param curve Input vector of 2D points, stored in std::vector or Mat.
  3071. @param closed Flag indicating whether the curve is closed or not.
  3072. */
  3073. CV_EXPORTS_W double arcLength( InputArray curve, bool closed );
  3074. /** @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image.
  3075. The function calculates and returns the minimal up-right bounding rectangle for the specified point set or
  3076. non-zero pixels of gray-scale image.
  3077. @param array Input gray-scale image or 2D point set, stored in std::vector or Mat.
  3078. */
  3079. CV_EXPORTS_W Rect boundingRect( InputArray array );
  3080. /** @brief Calculates a contour area.
  3081. The function computes a contour area. Similarly to moments , the area is computed using the Green
  3082. formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using
  3083. #drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong
  3084. results for contours with self-intersections.
  3085. Example:
  3086. @code
  3087. vector<Point> contour;
  3088. contour.push_back(Point2f(0, 0));
  3089. contour.push_back(Point2f(10, 0));
  3090. contour.push_back(Point2f(10, 10));
  3091. contour.push_back(Point2f(5, 4));
  3092. double area0 = contourArea(contour);
  3093. vector<Point> approx;
  3094. approxPolyDP(contour, approx, 5, true);
  3095. double area1 = contourArea(approx);
  3096. cout << "area0 =" << area0 << endl <<
  3097. "area1 =" << area1 << endl <<
  3098. "approx poly vertices" << approx.size() << endl;
  3099. @endcode
  3100. @param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat.
  3101. @param oriented Oriented area flag. If it is true, the function returns a signed area value,
  3102. depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can
  3103. determine orientation of a contour by taking the sign of an area. By default, the parameter is
  3104. false, which means that the absolute value is returned.
  3105. */
  3106. CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false );
  3107. /** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
  3108. The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a
  3109. specified point set. Developer should keep in mind that the returned RotatedRect can contain negative
  3110. indices when data is close to the containing Mat element boundary.
  3111. @param points Input vector of 2D points, stored in std::vector\<\> or Mat
  3112. */
  3113. CV_EXPORTS_W RotatedRect minAreaRect( InputArray points );
  3114. /** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.
  3115. The function finds the four vertices of a rotated rectangle. This function is useful to draw the
  3116. rectangle. In C++, instead of using this function, you can directly use RotatedRect::points method. Please
  3117. visit the @ref tutorial_bounding_rotated_ellipses "tutorial on Creating Bounding rotated boxes and ellipses for contours" for more information.
  3118. @param box The input rotated rectangle. It may be the output of
  3119. @param points The output array of four vertices of rectangles.
  3120. */
  3121. CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points);
  3122. /** @brief Finds a circle of the minimum area enclosing a 2D point set.
  3123. The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm.
  3124. @param points Input vector of 2D points, stored in std::vector\<\> or Mat
  3125. @param center Output center of the circle.
  3126. @param radius Output radius of the circle.
  3127. */
  3128. CV_EXPORTS_W void minEnclosingCircle( InputArray points,
  3129. CV_OUT Point2f& center, CV_OUT float& radius );
  3130. /** @example samples/cpp/minarea.cpp
  3131. */
  3132. /** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area.
  3133. The function finds a triangle of minimum area enclosing the given set of 2D points and returns its
  3134. area. The output for a given 2D point set is shown in the image below. 2D points are depicted in
  3135. *red* and the enclosing triangle in *yellow*.
  3136. ![Sample output of the minimum enclosing triangle function](pics/minenclosingtriangle.png)
  3137. The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's
  3138. @cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal
  3139. enclosing triangle of a 2D convex polygon with n vertices. Since the #minEnclosingTriangle function
  3140. takes a 2D point set as input an additional preprocessing step of computing the convex hull of the
  3141. 2D point set is required. The complexity of the #convexHull function is \f$O(n log(n))\f$ which is higher
  3142. than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$.
  3143. @param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat
  3144. @param triangle Output vector of three 2D points defining the vertices of the triangle. The depth
  3145. of the OutputArray must be CV_32F.
  3146. */
  3147. CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle );
  3148. /** @brief Compares two shapes.
  3149. The function compares two shapes. All three implemented methods use the Hu invariants (see #HuMoments)
  3150. @param contour1 First contour or grayscale image.
  3151. @param contour2 Second contour or grayscale image.
  3152. @param method Comparison method, see #ShapeMatchModes
  3153. @param parameter Method-specific parameter (not supported now).
  3154. */
  3155. CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
  3156. int method, double parameter );
  3157. /** @example samples/cpp/convexhull.cpp
  3158. An example using the convexHull functionality
  3159. */
  3160. /** @brief Finds the convex hull of a point set.
  3161. The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82
  3162. that has *O(N logN)* complexity in the current implementation.
  3163. @param points Input 2D point set, stored in std::vector or Mat.
  3164. @param hull Output convex hull. It is either an integer vector of indices or vector of points. In
  3165. the first case, the hull elements are 0-based indices of the convex hull points in the original
  3166. array (since the set of convex hull points is a subset of the original point set). In the second
  3167. case, hull elements are the convex hull points themselves.
  3168. @param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise.
  3169. Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing
  3170. to the right, and its Y axis pointing upwards.
  3171. @param returnPoints Operation flag. In case of a matrix, when the flag is true, the function
  3172. returns convex hull points. Otherwise, it returns indices of the convex hull points. When the
  3173. output array is std::vector, the flag is ignored, and the output depends on the type of the
  3174. vector: std::vector\<int\> implies returnPoints=false, std::vector\<Point\> implies
  3175. returnPoints=true.
  3176. @note `points` and `hull` should be different arrays, inplace processing isn't supported.
  3177. Check @ref tutorial_hull "the corresponding tutorial" for more details.
  3178. useful links:
  3179. https://www.learnopencv.com/convex-hull-using-opencv-in-python-and-c/
  3180. */
  3181. CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull,
  3182. bool clockwise = false, bool returnPoints = true );
  3183. /** @brief Finds the convexity defects of a contour.
  3184. The figure below displays convexity defects of a hand contour:
  3185. ![image](pics/defects.png)
  3186. @param contour Input contour.
  3187. @param convexhull Convex hull obtained using convexHull that should contain indices of the contour
  3188. points that make the hull.
  3189. @param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java
  3190. interface each convexity defect is represented as 4-element integer vector (a.k.a. #Vec4i):
  3191. (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices
  3192. in the original contour of the convexity defect beginning, end and the farthest point, and
  3193. fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the
  3194. farthest contour point and the hull. That is, to get the floating-point value of the depth will be
  3195. fixpt_depth/256.0.
  3196. */
  3197. CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects );
  3198. /** @brief Tests a contour convexity.
  3199. The function tests whether the input contour is convex or not. The contour must be simple, that is,
  3200. without self-intersections. Otherwise, the function output is undefined.
  3201. @param contour Input vector of 2D points, stored in std::vector\<\> or Mat
  3202. */
  3203. CV_EXPORTS_W bool isContourConvex( InputArray contour );
  3204. /** @example samples/cpp/intersectExample.cpp
  3205. Examples of how intersectConvexConvex works
  3206. */
  3207. /** @brief Finds intersection of two convex polygons
  3208. @param _p1 First polygon
  3209. @param _p2 Second polygon
  3210. @param _p12 Output polygon describing the intersecting area
  3211. @param handleNested When true, an intersection is found if one of the polygons is fully enclosed in the other.
  3212. When false, no intersection is found. If the polygons share a side or the vertex of one polygon lies on an edge
  3213. of the other, they are not considered nested and an intersection will be found regardless of the value of handleNested.
  3214. @returns Absolute value of area of intersecting polygon
  3215. @note intersectConvexConvex doesn't confirm that both polygons are convex and will return invalid results if they aren't.
  3216. */
  3217. CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2,
  3218. OutputArray _p12, bool handleNested = true );
  3219. /** @example samples/cpp/fitellipse.cpp
  3220. An example using the fitEllipse technique
  3221. */
  3222. /** @brief Fits an ellipse around a set of 2D points.
  3223. The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of
  3224. all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon95
  3225. is used. Developer should keep in mind that it is possible that the returned
  3226. ellipse/rotatedRect data contains negative indices, due to the data points being close to the
  3227. border of the containing Mat element.
  3228. @param points Input 2D point set, stored in std::vector\<\> or Mat
  3229. */
  3230. CV_EXPORTS_W RotatedRect fitEllipse( InputArray points );
  3231. /** @brief Fits an ellipse around a set of 2D points.
  3232. The function calculates the ellipse that fits a set of 2D points.
  3233. It returns the rotated rectangle in which the ellipse is inscribed.
  3234. The Approximate Mean Square (AMS) proposed by @cite Taubin1991 is used.
  3235. For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$,
  3236. which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$.
  3237. However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$,
  3238. the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines,
  3239. quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits.
  3240. If the fit is found to be a parabolic or hyperbolic function then the standard #fitEllipse method is used.
  3241. The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves
  3242. by imposing the condition that \f$ A^T ( D_x^T D_x + D_y^T D_y) A = 1 \f$ where
  3243. the matrices \f$ Dx \f$ and \f$ Dy \f$ are the partial derivatives of the design matrix \f$ D \f$ with
  3244. respect to x and y. The matrices are formed row by row applying the following to
  3245. each of the points in the set:
  3246. \f{align*}{
  3247. D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} &
  3248. D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} &
  3249. D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\}
  3250. \f}
  3251. The AMS method minimizes the cost function
  3252. \f{equation*}{
  3253. \epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T }
  3254. \f}
  3255. The minimum cost is found by solving the generalized eigenvalue problem.
  3256. \f{equation*}{
  3257. D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A
  3258. \f}
  3259. @param points Input 2D point set, stored in std::vector\<\> or Mat
  3260. */
  3261. CV_EXPORTS_W RotatedRect fitEllipseAMS( InputArray points );
  3262. /** @brief Fits an ellipse around a set of 2D points.
  3263. The function calculates the ellipse that fits a set of 2D points.
  3264. It returns the rotated rectangle in which the ellipse is inscribed.
  3265. The Direct least square (Direct) method by @cite Fitzgibbon1999 is used.
  3266. For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$,
  3267. which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$.
  3268. However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$,
  3269. the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines,
  3270. quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits.
  3271. The Direct method confines the fit to ellipses by ensuring that \f$ 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \f$.
  3272. The condition imposed is that \f$ 4 A_{xx} A_{yy}- A_{xy}^2=1 \f$ which satisfies the inequality
  3273. and as the coefficients can be arbitrarily scaled is not overly restrictive.
  3274. \f{equation*}{
  3275. \epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix}
  3276. 0 & 0 & 2 & 0 & 0 & 0 \\
  3277. 0 & -1 & 0 & 0 & 0 & 0 \\
  3278. 2 & 0 & 0 & 0 & 0 & 0 \\
  3279. 0 & 0 & 0 & 0 & 0 & 0 \\
  3280. 0 & 0 & 0 & 0 & 0 & 0 \\
  3281. 0 & 0 & 0 & 0 & 0 & 0
  3282. \end{matrix} \right)
  3283. \f}
  3284. The minimum cost is found by solving the generalized eigenvalue problem.
  3285. \f{equation*}{
  3286. D^T D A = \lambda \left( C\right) A
  3287. \f}
  3288. The system produces only one positive eigenvalue \f$ \lambda\f$ which is chosen as the solution
  3289. with its eigenvector \f$\mathbf{u}\f$. These are used to find the coefficients
  3290. \f{equation*}{
  3291. A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u}
  3292. \f}
  3293. The scaling factor guarantees that \f$A^T C A =1\f$.
  3294. @param points Input 2D point set, stored in std::vector\<\> or Mat
  3295. */
  3296. CV_EXPORTS_W RotatedRect fitEllipseDirect( InputArray points );
  3297. /** @brief Fits a line to a 2D or 3D point set.
  3298. The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where
  3299. \f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance function, one
  3300. of the following:
  3301. - DIST_L2
  3302. \f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f]
  3303. - DIST_L1
  3304. \f[\rho (r) = r\f]
  3305. - DIST_L12
  3306. \f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f]
  3307. - DIST_FAIR
  3308. \f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f]
  3309. - DIST_WELSCH
  3310. \f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f]
  3311. - DIST_HUBER
  3312. \f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f]
  3313. The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique
  3314. that iteratively fits the line using the weighted least-squares algorithm. After each iteration the
  3315. weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ .
  3316. @param points Input vector of 2D or 3D points, stored in std::vector\<\> or Mat.
  3317. @param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements
  3318. (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and
  3319. (x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like
  3320. Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line
  3321. and (x0, y0, z0) is a point on the line.
  3322. @param distType Distance used by the M-estimator, see #DistanceTypes
  3323. @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value
  3324. is chosen.
  3325. @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line).
  3326. @param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps.
  3327. */
  3328. CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType,
  3329. double param, double reps, double aeps );
  3330. /** @brief Performs a point-in-contour test.
  3331. The function determines whether the point is inside a contour, outside, or lies on an edge (or
  3332. coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge)
  3333. value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively.
  3334. Otherwise, the return value is a signed distance between the point and the nearest contour edge.
  3335. See below a sample output of the function where each image pixel is tested against the contour:
  3336. ![sample output](pics/pointpolygon.png)
  3337. @param contour Input contour.
  3338. @param pt Point tested against the contour.
  3339. @param measureDist If true, the function estimates the signed distance from the point to the
  3340. nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.
  3341. */
  3342. CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist );
  3343. /** @brief Finds out if there is any intersection between two rotated rectangles.
  3344. If there is then the vertices of the intersecting region are returned as well.
  3345. Below are some examples of intersection configurations. The hatched pattern indicates the
  3346. intersecting region and the red vertices are returned by the function.
  3347. ![intersection examples](pics/intersection.png)
  3348. @param rect1 First rectangle
  3349. @param rect2 Second rectangle
  3350. @param intersectingRegion The output array of the vertices of the intersecting region. It returns
  3351. at most 8 vertices. Stored as std::vector\<cv::Point2f\> or cv::Mat as Mx1 of type CV_32FC2.
  3352. @returns One of #RectanglesIntersectTypes
  3353. */
  3354. CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion );
  3355. /** @brief Creates a smart pointer to a cv::GeneralizedHoughBallard class and initializes it.
  3356. */
  3357. CV_EXPORTS_W Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard();
  3358. /** @brief Creates a smart pointer to a cv::GeneralizedHoughGuil class and initializes it.
  3359. */
  3360. CV_EXPORTS_W Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil();
  3361. //! @} imgproc_shape
  3362. //! @addtogroup imgproc_colormap
  3363. //! @{
  3364. //! GNU Octave/MATLAB equivalent colormaps
  3365. enum ColormapTypes
  3366. {
  3367. COLORMAP_AUTUMN = 0, //!< ![autumn](pics/colormaps/colorscale_autumn.jpg)
  3368. COLORMAP_BONE = 1, //!< ![bone](pics/colormaps/colorscale_bone.jpg)
  3369. COLORMAP_JET = 2, //!< ![jet](pics/colormaps/colorscale_jet.jpg)
  3370. COLORMAP_WINTER = 3, //!< ![winter](pics/colormaps/colorscale_winter.jpg)
  3371. COLORMAP_RAINBOW = 4, //!< ![rainbow](pics/colormaps/colorscale_rainbow.jpg)
  3372. COLORMAP_OCEAN = 5, //!< ![ocean](pics/colormaps/colorscale_ocean.jpg)
  3373. COLORMAP_SUMMER = 6, //!< ![summer](pics/colormaps/colorscale_summer.jpg)
  3374. COLORMAP_SPRING = 7, //!< ![spring](pics/colormaps/colorscale_spring.jpg)
  3375. COLORMAP_COOL = 8, //!< ![cool](pics/colormaps/colorscale_cool.jpg)
  3376. COLORMAP_HSV = 9, //!< ![HSV](pics/colormaps/colorscale_hsv.jpg)
  3377. COLORMAP_PINK = 10, //!< ![pink](pics/colormaps/colorscale_pink.jpg)
  3378. COLORMAP_HOT = 11, //!< ![hot](pics/colormaps/colorscale_hot.jpg)
  3379. COLORMAP_PARULA = 12, //!< ![parula](pics/colormaps/colorscale_parula.jpg)
  3380. COLORMAP_MAGMA = 13, //!< ![magma](pics/colormaps/colorscale_magma.jpg)
  3381. COLORMAP_INFERNO = 14, //!< ![inferno](pics/colormaps/colorscale_inferno.jpg)
  3382. COLORMAP_PLASMA = 15, //!< ![plasma](pics/colormaps/colorscale_plasma.jpg)
  3383. COLORMAP_VIRIDIS = 16, //!< ![viridis](pics/colormaps/colorscale_viridis.jpg)
  3384. COLORMAP_CIVIDIS = 17, //!< ![cividis](pics/colormaps/colorscale_cividis.jpg)
  3385. COLORMAP_TWILIGHT = 18, //!< ![twilight](pics/colormaps/colorscale_twilight.jpg)
  3386. COLORMAP_TWILIGHT_SHIFTED = 19, //!< ![twilight shifted](pics/colormaps/colorscale_twilight_shifted.jpg)
  3387. COLORMAP_TURBO = 20 //!< ![turbo](pics/colormaps/colorscale_turbo.jpg)
  3388. };
  3389. /** @example samples/cpp/falsecolor.cpp
  3390. An example using applyColorMap function
  3391. */
  3392. /** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image.
  3393. @param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
  3394. @param dst The result is the colormapped source image. Note: Mat::create is called on dst.
  3395. @param colormap The colormap to apply, see #ColormapTypes
  3396. */
  3397. CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap);
  3398. /** @brief Applies a user colormap on a given image.
  3399. @param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
  3400. @param dst The result is the colormapped source image. Note: Mat::create is called on dst.
  3401. @param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256
  3402. */
  3403. CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor);
  3404. //! @} imgproc_colormap
  3405. //! @addtogroup imgproc_draw
  3406. //! @{
  3407. /** OpenCV color channel order is BGR[A] */
  3408. #define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)
  3409. /** @brief Draws a line segment connecting two points.
  3410. The function line draws the line segment between pt1 and pt2 points in the image. The line is
  3411. clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected
  3412. or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased
  3413. lines are drawn using Gaussian filtering.
  3414. @param img Image.
  3415. @param pt1 First point of the line segment.
  3416. @param pt2 Second point of the line segment.
  3417. @param color Line color.
  3418. @param thickness Line thickness.
  3419. @param lineType Type of the line. See #LineTypes.
  3420. @param shift Number of fractional bits in the point coordinates.
  3421. */
  3422. CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
  3423. int thickness = 1, int lineType = LINE_8, int shift = 0);
  3424. /** @brief Draws a arrow segment pointing from the first point to the second one.
  3425. The function cv::arrowedLine draws an arrow between pt1 and pt2 points in the image. See also #line.
  3426. @param img Image.
  3427. @param pt1 The point the arrow starts from.
  3428. @param pt2 The point the arrow points to.
  3429. @param color Line color.
  3430. @param thickness Line thickness.
  3431. @param line_type Type of the line. See #LineTypes
  3432. @param shift Number of fractional bits in the point coordinates.
  3433. @param tipLength The length of the arrow tip in relation to the arrow length
  3434. */
  3435. CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
  3436. int thickness=1, int line_type=8, int shift=0, double tipLength=0.1);
  3437. /** @brief Draws a simple, thick, or filled up-right rectangle.
  3438. The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners
  3439. are pt1 and pt2.
  3440. @param img Image.
  3441. @param pt1 Vertex of the rectangle.
  3442. @param pt2 Vertex of the rectangle opposite to pt1 .
  3443. @param color Rectangle color or brightness (grayscale image).
  3444. @param thickness Thickness of lines that make up the rectangle. Negative values, like #FILLED,
  3445. mean that the function has to draw a filled rectangle.
  3446. @param lineType Type of the line. See #LineTypes
  3447. @param shift Number of fractional bits in the point coordinates.
  3448. */
  3449. CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
  3450. const Scalar& color, int thickness = 1,
  3451. int lineType = LINE_8, int shift = 0);
  3452. /** @overload
  3453. use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and
  3454. r.br()-Point(1,1)` are opposite corners
  3455. */
  3456. CV_EXPORTS_W void rectangle(InputOutputArray img, Rect rec,
  3457. const Scalar& color, int thickness = 1,
  3458. int lineType = LINE_8, int shift = 0);
  3459. /** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_2.cpp
  3460. An example using drawing functions
  3461. */
  3462. /** @brief Draws a circle.
  3463. The function cv::circle draws a simple or filled circle with a given center and radius.
  3464. @param img Image where the circle is drawn.
  3465. @param center Center of the circle.
  3466. @param radius Radius of the circle.
  3467. @param color Circle color.
  3468. @param thickness Thickness of the circle outline, if positive. Negative values, like #FILLED,
  3469. mean that a filled circle is to be drawn.
  3470. @param lineType Type of the circle boundary. See #LineTypes
  3471. @param shift Number of fractional bits in the coordinates of the center and in the radius value.
  3472. */
  3473. CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius,
  3474. const Scalar& color, int thickness = 1,
  3475. int lineType = LINE_8, int shift = 0);
  3476. /** @brief Draws a simple or thick elliptic arc or fills an ellipse sector.
  3477. The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic
  3478. arc, or a filled ellipse sector. The drawing code uses general parametric form.
  3479. A piecewise-linear curve is used to approximate the elliptic arc
  3480. boundary. If you need more control of the ellipse rendering, you can retrieve the curve using
  3481. #ellipse2Poly and then render it with #polylines or fill it with #fillPoly. If you use the first
  3482. variant of the function and want to draw the whole ellipse, not an arc, pass `startAngle=0` and
  3483. `endAngle=360`. If `startAngle` is greater than `endAngle`, they are swapped. The figure below explains
  3484. the meaning of the parameters to draw the blue arc.
  3485. ![Parameters of Elliptic Arc](pics/ellipse.svg)
  3486. @param img Image.
  3487. @param center Center of the ellipse.
  3488. @param axes Half of the size of the ellipse main axes.
  3489. @param angle Ellipse rotation angle in degrees.
  3490. @param startAngle Starting angle of the elliptic arc in degrees.
  3491. @param endAngle Ending angle of the elliptic arc in degrees.
  3492. @param color Ellipse color.
  3493. @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
  3494. a filled ellipse sector is to be drawn.
  3495. @param lineType Type of the ellipse boundary. See #LineTypes
  3496. @param shift Number of fractional bits in the coordinates of the center and values of axes.
  3497. */
  3498. CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,
  3499. double angle, double startAngle, double endAngle,
  3500. const Scalar& color, int thickness = 1,
  3501. int lineType = LINE_8, int shift = 0);
  3502. /** @overload
  3503. @param img Image.
  3504. @param box Alternative ellipse representation via RotatedRect. This means that the function draws
  3505. an ellipse inscribed in the rotated rectangle.
  3506. @param color Ellipse color.
  3507. @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
  3508. a filled ellipse sector is to be drawn.
  3509. @param lineType Type of the ellipse boundary. See #LineTypes
  3510. */
  3511. CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color,
  3512. int thickness = 1, int lineType = LINE_8);
  3513. /* ----------------------------------------------------------------------------------------- */
  3514. /* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */
  3515. /* ----------------------------------------------------------------------------------------- */
  3516. /** @brief Draws a marker on a predefined position in an image.
  3517. The function cv::drawMarker draws a marker on a given position in the image. For the moment several
  3518. marker types are supported, see #MarkerTypes for more information.
  3519. @param img Image.
  3520. @param position The point where the crosshair is positioned.
  3521. @param color Line color.
  3522. @param markerType The specific type of marker you want to use, see #MarkerTypes
  3523. @param thickness Line thickness.
  3524. @param line_type Type of the line, See #LineTypes
  3525. @param markerSize The length of the marker axis [default = 20 pixels]
  3526. */
  3527. CV_EXPORTS_W void drawMarker(InputOutputArray img, Point position, const Scalar& color,
  3528. int markerType = MARKER_CROSS, int markerSize=20, int thickness=1,
  3529. int line_type=8);
  3530. /* ----------------------------------------------------------------------------------------- */
  3531. /* END OF MARKER SECTION */
  3532. /* ----------------------------------------------------------------------------------------- */
  3533. /** @overload */
  3534. CV_EXPORTS void fillConvexPoly(InputOutputArray img, const Point* pts, int npts,
  3535. const Scalar& color, int lineType = LINE_8,
  3536. int shift = 0);
  3537. /** @brief Fills a convex polygon.
  3538. The function cv::fillConvexPoly draws a filled convex polygon. This function is much faster than the
  3539. function #fillPoly . It can fill not only convex polygons but any monotonic polygon without
  3540. self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line)
  3541. twice at the most (though, its top-most and/or the bottom edge could be horizontal).
  3542. @param img Image.
  3543. @param points Polygon vertices.
  3544. @param color Polygon color.
  3545. @param lineType Type of the polygon boundaries. See #LineTypes
  3546. @param shift Number of fractional bits in the vertex coordinates.
  3547. */
  3548. CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
  3549. const Scalar& color, int lineType = LINE_8,
  3550. int shift = 0);
  3551. /** @overload */
  3552. CV_EXPORTS void fillPoly(InputOutputArray img, const Point** pts,
  3553. const int* npts, int ncontours,
  3554. const Scalar& color, int lineType = LINE_8, int shift = 0,
  3555. Point offset = Point() );
  3556. /** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp
  3557. An example using drawing functions
  3558. Check @ref tutorial_random_generator_and_text "the corresponding tutorial" for more details
  3559. */
  3560. /** @brief Fills the area bounded by one or more polygons.
  3561. The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill
  3562. complex areas, for example, areas with holes, contours with self-intersections (some of their
  3563. parts), and so forth.
  3564. @param img Image.
  3565. @param pts Array of polygons where each polygon is represented as an array of points.
  3566. @param color Polygon color.
  3567. @param lineType Type of the polygon boundaries. See #LineTypes
  3568. @param shift Number of fractional bits in the vertex coordinates.
  3569. @param offset Optional offset of all points of the contours.
  3570. */
  3571. CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
  3572. const Scalar& color, int lineType = LINE_8, int shift = 0,
  3573. Point offset = Point() );
  3574. /** @overload */
  3575. CV_EXPORTS void polylines(InputOutputArray img, const Point* const* pts, const int* npts,
  3576. int ncontours, bool isClosed, const Scalar& color,
  3577. int thickness = 1, int lineType = LINE_8, int shift = 0 );
  3578. /** @brief Draws several polygonal curves.
  3579. @param img Image.
  3580. @param pts Array of polygonal curves.
  3581. @param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed,
  3582. the function draws a line from the last vertex of each curve to its first vertex.
  3583. @param color Polyline color.
  3584. @param thickness Thickness of the polyline edges.
  3585. @param lineType Type of the line segments. See #LineTypes
  3586. @param shift Number of fractional bits in the vertex coordinates.
  3587. The function cv::polylines draws one or more polygonal curves.
  3588. */
  3589. CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
  3590. bool isClosed, const Scalar& color,
  3591. int thickness = 1, int lineType = LINE_8, int shift = 0 );
  3592. /** @example samples/cpp/contours2.cpp
  3593. An example program illustrates the use of cv::findContours and cv::drawContours
  3594. \image html WindowsQtContoursOutput.png "Screenshot of the program"
  3595. */
  3596. /** @example samples/cpp/segment_objects.cpp
  3597. An example using drawContours to clean up a background segmentation result
  3598. */
  3599. /** @brief Draws contours outlines or filled contours.
  3600. The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area
  3601. bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve
  3602. connected components from the binary image and label them: :
  3603. @include snippets/imgproc_drawContours.cpp
  3604. @param image Destination image.
  3605. @param contours All the input contours. Each contour is stored as a point vector.
  3606. @param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn.
  3607. @param color Color of the contours.
  3608. @param thickness Thickness of lines the contours are drawn with. If it is negative (for example,
  3609. thickness=#FILLED ), the contour interiors are drawn.
  3610. @param lineType Line connectivity. See #LineTypes
  3611. @param hierarchy Optional information about hierarchy. It is only needed if you want to draw only
  3612. some of the contours (see maxLevel ).
  3613. @param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn.
  3614. If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function
  3615. draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This
  3616. parameter is only taken into account when there is hierarchy available.
  3617. @param offset Optional contour shift parameter. Shift all the drawn contours by the specified
  3618. \f$\texttt{offset}=(dx,dy)\f$ .
  3619. @note When thickness=#FILLED, the function is designed to handle connected components with holes correctly
  3620. even when no hierarchy date is provided. This is done by analyzing all the outlines together
  3621. using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved
  3622. contours. In order to solve this problem, you need to call #drawContours separately for each sub-group
  3623. of contours, or iterate over the collection using contourIdx parameter.
  3624. */
  3625. CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours,
  3626. int contourIdx, const Scalar& color,
  3627. int thickness = 1, int lineType = LINE_8,
  3628. InputArray hierarchy = noArray(),
  3629. int maxLevel = INT_MAX, Point offset = Point() );
  3630. /** @brief Clips the line against the image rectangle.
  3631. The function cv::clipLine calculates a part of the line segment that is entirely within the specified
  3632. rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise,
  3633. it returns true .
  3634. @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
  3635. @param pt1 First line point.
  3636. @param pt2 Second line point.
  3637. */
  3638. CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
  3639. /** @overload
  3640. @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
  3641. @param pt1 First line point.
  3642. @param pt2 Second line point.
  3643. */
  3644. CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2);
  3645. /** @overload
  3646. @param imgRect Image rectangle.
  3647. @param pt1 First line point.
  3648. @param pt2 Second line point.
  3649. */
  3650. CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
  3651. /** @brief Approximates an elliptic arc with a polyline.
  3652. The function ellipse2Poly computes the vertices of a polyline that approximates the specified
  3653. elliptic arc. It is used by #ellipse. If `arcStart` is greater than `arcEnd`, they are swapped.
  3654. @param center Center of the arc.
  3655. @param axes Half of the size of the ellipse main axes. See #ellipse for details.
  3656. @param angle Rotation angle of the ellipse in degrees. See #ellipse for details.
  3657. @param arcStart Starting angle of the elliptic arc in degrees.
  3658. @param arcEnd Ending angle of the elliptic arc in degrees.
  3659. @param delta Angle between the subsequent polyline vertices. It defines the approximation
  3660. accuracy.
  3661. @param pts Output vector of polyline vertices.
  3662. */
  3663. CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
  3664. int arcStart, int arcEnd, int delta,
  3665. CV_OUT std::vector<Point>& pts );
  3666. /** @overload
  3667. @param center Center of the arc.
  3668. @param axes Half of the size of the ellipse main axes. See #ellipse for details.
  3669. @param angle Rotation angle of the ellipse in degrees. See #ellipse for details.
  3670. @param arcStart Starting angle of the elliptic arc in degrees.
  3671. @param arcEnd Ending angle of the elliptic arc in degrees.
  3672. @param delta Angle between the subsequent polyline vertices. It defines the approximation accuracy.
  3673. @param pts Output vector of polyline vertices.
  3674. */
  3675. CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle,
  3676. int arcStart, int arcEnd, int delta,
  3677. CV_OUT std::vector<Point2d>& pts);
  3678. /** @brief Draws a text string.
  3679. The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered
  3680. using the specified font are replaced by question marks. See #getTextSize for a text rendering code
  3681. example.
  3682. @param img Image.
  3683. @param text Text string to be drawn.
  3684. @param org Bottom-left corner of the text string in the image.
  3685. @param fontFace Font type, see #HersheyFonts.
  3686. @param fontScale Font scale factor that is multiplied by the font-specific base size.
  3687. @param color Text color.
  3688. @param thickness Thickness of the lines used to draw a text.
  3689. @param lineType Line type. See #LineTypes
  3690. @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,
  3691. it is at the top-left corner.
  3692. */
  3693. CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org,
  3694. int fontFace, double fontScale, Scalar color,
  3695. int thickness = 1, int lineType = LINE_8,
  3696. bool bottomLeftOrigin = false );
  3697. /** @brief Calculates the width and height of a text string.
  3698. The function cv::getTextSize calculates and returns the size of a box that contains the specified text.
  3699. That is, the following code renders some text, the tight box surrounding it, and the baseline: :
  3700. @code
  3701. String text = "Funny text inside the box";
  3702. int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
  3703. double fontScale = 2;
  3704. int thickness = 3;
  3705. Mat img(600, 800, CV_8UC3, Scalar::all(0));
  3706. int baseline=0;
  3707. Size textSize = getTextSize(text, fontFace,
  3708. fontScale, thickness, &baseline);
  3709. baseline += thickness;
  3710. // center the text
  3711. Point textOrg((img.cols - textSize.width)/2,
  3712. (img.rows + textSize.height)/2);
  3713. // draw the box
  3714. rectangle(img, textOrg + Point(0, baseline),
  3715. textOrg + Point(textSize.width, -textSize.height),
  3716. Scalar(0,0,255));
  3717. // ... and the baseline first
  3718. line(img, textOrg + Point(0, thickness),
  3719. textOrg + Point(textSize.width, thickness),
  3720. Scalar(0, 0, 255));
  3721. // then put the text itself
  3722. putText(img, text, textOrg, fontFace, fontScale,
  3723. Scalar::all(255), thickness, 8);
  3724. @endcode
  3725. @param text Input text string.
  3726. @param fontFace Font to use, see #HersheyFonts.
  3727. @param fontScale Font scale factor that is multiplied by the font-specific base size.
  3728. @param thickness Thickness of lines used to render the text. See #putText for details.
  3729. @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text
  3730. point.
  3731. @return The size of a box that contains the specified text.
  3732. @see putText
  3733. */
  3734. CV_EXPORTS_W Size getTextSize(const String& text, int fontFace,
  3735. double fontScale, int thickness,
  3736. CV_OUT int* baseLine);
  3737. /** @brief Calculates the font-specific size to use to achieve a given height in pixels.
  3738. @param fontFace Font to use, see cv::HersheyFonts.
  3739. @param pixelHeight Pixel height to compute the fontScale for
  3740. @param thickness Thickness of lines used to render the text.See putText for details.
  3741. @return The fontSize to use for cv::putText
  3742. @see cv::putText
  3743. */
  3744. CV_EXPORTS_W double getFontScaleFromHeight(const int fontFace,
  3745. const int pixelHeight,
  3746. const int thickness = 1);
  3747. /** @brief Line iterator
  3748. The class is used to iterate over all the pixels on the raster line
  3749. segment connecting two specified points.
  3750. The class LineIterator is used to get each pixel of a raster line. It
  3751. can be treated as versatile implementation of the Bresenham algorithm
  3752. where you can stop at each pixel and do some extra processing, for
  3753. example, grab pixel values along the line or draw a line with an effect
  3754. (for example, with XOR operation).
  3755. The number of pixels along the line is stored in LineIterator::count.
  3756. The method LineIterator::pos returns the current position in the image:
  3757. @code{.cpp}
  3758. // grabs pixels along the line (pt1, pt2)
  3759. // from 8-bit 3-channel image to the buffer
  3760. LineIterator it(img, pt1, pt2, 8);
  3761. LineIterator it2 = it;
  3762. vector<Vec3b> buf(it.count);
  3763. for(int i = 0; i < it.count; i++, ++it)
  3764. buf[i] = *(const Vec3b*)*it;
  3765. // alternative way of iterating through the line
  3766. for(int i = 0; i < it2.count; i++, ++it2)
  3767. {
  3768. Vec3b val = img.at<Vec3b>(it2.pos());
  3769. CV_Assert(buf[i] == val);
  3770. }
  3771. @endcode
  3772. */
  3773. class CV_EXPORTS LineIterator
  3774. {
  3775. public:
  3776. /** @brief initializes the iterator
  3777. creates iterators for the line connecting pt1 and pt2
  3778. the line will be clipped on the image boundaries
  3779. the line is 8-connected or 4-connected
  3780. If leftToRight=true, then the iteration is always done
  3781. from the left-most point to the right most,
  3782. not to depend on the ordering of pt1 and pt2 parameters
  3783. */
  3784. LineIterator( const Mat& img, Point pt1, Point pt2,
  3785. int connectivity = 8, bool leftToRight = false );
  3786. /** @brief returns pointer to the current pixel
  3787. */
  3788. uchar* operator *();
  3789. /** @brief prefix increment operator (++it). shifts iterator to the next pixel
  3790. */
  3791. LineIterator& operator ++();
  3792. /** @brief postfix increment operator (it++). shifts iterator to the next pixel
  3793. */
  3794. LineIterator operator ++(int);
  3795. /** @brief returns coordinates of the current pixel
  3796. */
  3797. Point pos() const;
  3798. uchar* ptr;
  3799. const uchar* ptr0;
  3800. int step, elemSize;
  3801. int err, count;
  3802. int minusDelta, plusDelta;
  3803. int minusStep, plusStep;
  3804. };
  3805. //! @cond IGNORED
  3806. // === LineIterator implementation ===
  3807. inline
  3808. uchar* LineIterator::operator *()
  3809. {
  3810. return ptr;
  3811. }
  3812. inline
  3813. LineIterator& LineIterator::operator ++()
  3814. {
  3815. int mask = err < 0 ? -1 : 0;
  3816. err += minusDelta + (plusDelta & mask);
  3817. ptr += minusStep + (plusStep & mask);
  3818. return *this;
  3819. }
  3820. inline
  3821. LineIterator LineIterator::operator ++(int)
  3822. {
  3823. LineIterator it = *this;
  3824. ++(*this);
  3825. return it;
  3826. }
  3827. inline
  3828. Point LineIterator::pos() const
  3829. {
  3830. Point p;
  3831. p.y = (int)((ptr - ptr0)/step);
  3832. p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize);
  3833. return p;
  3834. }
  3835. //! @endcond
  3836. //! @} imgproc_draw
  3837. //! @} imgproc
  3838. } // cv
  3839. #endif