imgproc.hpp 241 KB

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