100% found this document useful (1 vote)
603 views50 pages

Video Analytics Notes

Machine learning for facial recognition

Uploaded by

Darlington Etaje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
100% found this document useful (1 vote)
603 views50 pages

Video Analytics Notes

Machine learning for facial recognition

Uploaded by

Darlington Etaje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 50
Video Mnalylics using OpenCV and hhton Shells & EDU CEA educhion fo Video Analytics hk wag Feld vider annbjfics i vey imporfat fer surveillince ond stanly. = Nideo analytics ig ta process «fF cnalyging videos, ga her Ve iene” tebe! We ae pein, ne a A relevent information fon digifal xideo- > This vs Afferent fom video compression, brie V cHenpts te expli tke vedurdancy in digital vides ‘fir Fe purpose of reduce HY, avolyfics ts Concomed wit, yndeshuding Ke corte} of Nicer - of Vi. nalyfi ¢ = Pesearch i= Conpufernision [his tet focus in her covere] > Poller Giabysts > Madicg } Clligence Surveillance shail ad Tanspotation 2. Video coufet aay 35 (cA) > latelegont wees: ‘ Goal Nido aralybes ves Cupiler vider algoribyes obicl enodle it fe perceive or cee, ad wnchine inbelldgace te lepet learn RA deans infeeaces er of ae auplpticg % sQvg uneerstonding . wheel wy motion 1 Jn odditien te sefech ng) rection, analytics gpa lifes K wob'on aS On abject, Unetis fn ds The’ conto’ arind Te chief ad iF able te teacl Te ebject Byrougy SORE $0 2 D Segquactation ® Chish cafioy Fea ching : Acid hargus bien. = a\Seamedshinn (3 fel prac Aieicling comgen 4 exlonclunairehvese 7 ge for fustee ane lys’s mal gyal oak rs a , LS Prels jhef have clonged ace refyred fo as Fregrond Reel; those fhef doust change are called Excfoaiunsl reels. Berefok Seyructatim «abe called “Background SubTee ction’ ‘ The vem lt of Segantabion is ome ov ure foregrond EhL; a blob ing a ‘colleefion Ff connected preels. a Bac kyon d ~firel have wo waticn fey remain coustot Phewah te vite —> Foreground Pieel out wmoting ~ have wolion. => Blob, will sepacle = pechicalay © iat From dB background Ju a Nideo or in & scene 3 Cagsibicah mis Fe pres of poaltbying exch LOG ond acsign 2g chs lebel Fo f- ae #3 res aa Tis yesalts in a a Sretpi BE, cach blob we aM Ms ing chars oho WMehicle, animal, eke, 435 thet akject fo giseotld be’ a vsehicle, - animal, pevron, ef S 2 Iracking of classified porgrudd blobs Faker place over rucltphe Frames as objects mow Lrough he fi eld of wev. “EC, Ganla ht TaN sine Raed sale Ecce Ch sedeg ae ele foes F te eLject by conveding Keep a hon fm s chan sng. > Adivity Recognition Tis 5 tke Final Moe nes fe reale, of letFieafion om ¥ Tracking, port labs the Track of mulhiple diode bo infer Te activity wcuping in Ihe wider. Lofer laslanct if hue Lileks courtiponding te people progress wely come closer this cou he yepre as cates people IP hus blebs move Lagipets a a ~elec! amclhey Colvtype hea 0 meegh, AES : ean ane pe rcs pean Soh ee Peer evem be eaagts Hho in §-&it, dhegred ai Nhan Ge Cons fo eho nave RI ale Re V eakees rangep Prov Oto 25S. ste lege, oles “owe actially devehing te cole ofe olaiere bfef 25] 255] 255254] ap¢fass| z55[ ess _ [elofololelolo ass | 257] 255 fass ass ess] ass 25s] ts [0 fo) D 265 [255 | 285 foxy 25 | fh feo-fd 28 ic} nss| © |o. er ed 0 285 (| 0: 258 i 2 12 1255 ass wk ko'ho ws/eeh ol hes 6] “he ee ast > 263 did \ rc: Bierce Ty [ofe fe fo feTololet a Fer TR Bue Matei x. ke o fololele le fe & Xpreseding ack ae ofole ssl olo| > ah BES repre resenting tee ® pslo [> due cdr bch ir extrene ° psslo |? COR, © Die} >| —s Fan ke Green (Maher, AN, y pyeve os 2 SAOsIEe. wepresting be Lack Eslow, o ol|elo and 25S 1% now represertip ‘ a fo ree Bae pe bk pape eee vepreseding black colo, od LSS Vepreserts red colour. Now Lets gee ee wotnies I pebws: Adding fe MidMe Gloucs: blue +Blackf Med = Niclet Colour Adding be Spend Colours Black + Greent Black? Green Glow Tis is how we me getty olifleven} Kinds of colours in our Thaye Dene Open foo ipill basically seal wik BOR fermaf. We will lel vik Rese ZS meferter again and again in au lwneges « P-7.© Please Tun Over U \ac, Mf Re parameters Hs dL or Wee ASS 7 tas on ond Lighfaess USL col has te Sand lL, ov Hue, ais cs hight > Hue, indicates 4K Colac SOnGIION of te lig lt m hea rie oe ie red, yelro, reen, Cyan hue, ma sefafion bobs Feetece he Sauce of the. eit: os bled Sa night Css te color magorte Doebinelion of ved cod Une) rated of woke Cig voit a Frequency hash erm Ben Que) The sible Seckun of Uight we have differat cle shades. ate be Sef cight pak we Lave violet colo Sha Be algth pd ve hove ved cobur ditfercace etree te wiibl spechrows of Light and WSL mdel ts Bef Ba relef cs d by Te Magenta Glor Ded} tle : rpced Gy Te Magen ——as fn Hsl / Cefoust J eer, = the wo0eks Arcalew, se it Seu bor his te difference aw be represented ena wik he wishle spectrum circle insead- Ahue of oP Light: we Love wraqenfa Seo Jule he soe again ingens of rorelef - 2s a hue of O° w Croala Hue bot Be ye Pst wodel of wo Yellevs 000 pagel Oo [etl O Oo Oo Lilt ~* ye (gl Ble O Pare ‘ a (We ewe represeni itech es cliffect degree: 9 ue ct oo = we 3eo" ees ay PTE at one bd fo nals een erat ae ntufral 3 values run from 0% , which 0 no cole, \ t te, Side te Pulesh sikedion Ga given hue a}! ¢ perasfage of Graney ie ( Te move “feo tae of leght 1% ConCanlrated arund we wave ( Te wa seflected hk ae will Le, ¢ MA p Oo Oo it oO nye ~ lighess Libis lndieses Te a ae . _- C = ae Ce Lelor complelely black at Soto °o epi legs grep a Bs put jad at 100% tt becomes ° mola Hsl cole a Color wih wenkinun, lightness C28) is anys obi 5 wo wally what fhe Hie 07 Saturation Abate ove tye 1s okhined as Crone et wiLolerd/2 ten mat lofor ts GB convent Wi The maxcmum Valu, and minelor \'s fr “pt ah i seltaute vale - spectrin, alead Hs Clee Mode ( Te HSV Ghur model uses He porarelee Vale iusfead jf Aaldnen he oder wik maximum Value 2255) con be any cov Li rede pet poles hil pete ye ny \ HY ‘ ekki inden hy as " Sito fe Tee red C2SS.0 “ou aoe Nahe defyed f as waxleley,) 9 ar! lw a Neue of 255 ieee sy bye is VSS —> wees mun cin al : db wee pox Cole ite RR orgs ee ly ered bas 4 Madi brightness of 255 a is showy > loo res a VAR nem wi — CaaS 4 gs 2 DIS *s A p ae yaork tte Wied = ‘ 5) et var Gort Loum pacison of Glov Meds RPT A 5 Gc Medel ~ Tre Plt, of Hs wk so2eo, Nue on Ke hati zerdo/ / axis, and eghtrers Nalue on The ae fea} oxis | y : sal 24 peazecfer 1 | Yellew en es cies Ce) f rly fie hevigoutal clivection, we veve Fou ped Fe magenta Colour ale te vechionl divection, We move from Sick Colon ocd ifs lightness fs Increasing Fill We get fo white. : 35 @ ts cought at 295 sk picid a3 5, os Be 3° tyneeds Ushtress wsill increase. } The pleb of HSV wif 5225, Hee fo The lows ganda aig” and byhleess) Nelow on Be nectical axis. Dev fe vest is aan Crd Bert wes an enr x Nalue 15 einen ad we Aewnierd direction ond Wrox fun Ted poe Upwacd dieofion Ctisw) The phd of Het wit = US. Yue on Te honiguta{ avis, od Safwation on te wtic| ARS —alrqhtness 35 28S ybich iy maximus Rerefore it will [be cousplelely uhate CS tpt. Giahves s fit Te plo} of ASY wk Y= 255, Hoe on hovigedal exis, ane hod ee Nechies| axis, partis he plot of ASL unk Le i ad V= 129 vespecdivel, and again Hue on hevizental axis od Sifivclion on Te vechical axis OO0000000" —laaage heading Process om i ? jwrtad©) fuachion > It beads an image from K specified He and rehuns it. iE yeads an Image as a Os of, RGB values. IE fe image camat be read (because sing File, imprpe- pereprions, unsupported invalid gedik Porchin rpfiens an eel ashi (Mot #3 defa== Even TF Fe image pak is neorg, “ Od ew any cerry Lut ped etage will give us Nene. Different format of an image? O = Niadeos bitmaps — K bap *. die O° > Drs files — * SPS. “ps, “jpe ° —> DpEG 200 Files — *jpr = Prable Nebveck, Graphics — *, ) © — Peja nerf i = ve U @ => Sur easlers pres \ @ Tk synten fom Cc label ioe Bee hiss Wha . Cv simreod Glencsel. oor “phe ee : oo S Spa, Fonchin Gt ple hich x kU 4 0 cud ur image 15 2 Fenn es ® | presen vondy LOAD_|mAGe—ANIDEPTH | if et, rehinrn, Ue-git/32-bit jage © > PF Refarn a 3 chawael cole ioge "hers fei put bes Te conesponding CO > 58 Dekun a grayscale ivage dept, sbbecuhee Convert it to 9b. © —> 40 elu The Joabed bre: aad bea). IMAGE —COLom : a5 13 Cwik alpha ep iF set, always conyect mage (_) 0 te cob v- wrt —2 Ot PAD Ace. eae iF Fst, alvays ponvect imoge fo sesete® 2©O2000000 COCOEOCOOOOQOOOO00000 ©e@e006 46 : a SP ee ate ) Day ae —> Irefins a tuple of number of wos, columns ad Channel = Ip age 15 grayscale tuple referred confuing only nander of rows ed goles. Lif wo Hird number Ker image op > image - shape gegscrleS Ly Yx,4,2] - dtype_ | will wien dae Type of jnaye | img- type . ares folgh_Peeee fae enge heeding @"| Juyort CN 2 Llnpeet naps o ee _ file eS ‘img file = ‘shuple jpegs’ ee vee gab ime ee eee if ’ saeweee ec SORE ing = C2 Imread Coarg file, C92: MRED. CaLoR) yh Coe abha Linge CN2 -invead fife. CNR IREMD_ UNCHANGED) # rye : aoe : ee gk graying > NZ. imvead Ging file, Cv IMBEAD. GRAYSCALE ) H grayscale fect fe cherechaishes P| se enen cies pt bps lng) istics of fe images gray image int TASB “shepe? * ig. shape Pass, cols, channels : frint ARSE shape! ’, alpha ing. shape eine pint ‘Gray Shope! ", fraying: shape oe pring Sing: dy inge dfype CQZ THRESH. BINDAY_/NV ° | Fre > exe Ties HE. TAUNC Le DONT: 7 > cn? TIRES H-To2ERO Oo ha tee Thre slots > Cv2- THRESH. ToRERo_ (NV 7” Oo Shs te Feld hy wt re ° b& G08 a cots whe > gag Fe fo Krad © wae has ht F lixatmg cond: fies out mort . o oO Lewecles ff wed Por ee Bireshelddng Sh ee alerhin eae Feslell fo Oouall rion FO) 5 Fa oh UHfoed vagions, of Be sane joy enn ae results Ft ty Novy lng aa vane eK p 1D a rr € 76@ OOOO OOO ODHHHHHHHHHHHOHHHOHHHHOHOO lt hos 3 Mnpuf pormmelers ad only one valent arquoreni —> Adaptive Webs. wecices low ST Nahe a tt sel. CN 2. PDAPTVE_THRESH. MEAN C > Hreshald value (2 The ream of neigh bers hood area ce. ADAPPNE_TIREB_ GAUSS/AN_ c= treshold Value rs The weighted "Se ur of neighborrhacd values Jere wthlts mea JXastion Windeus > Blick Size E Acidos the 13 oF raighbowheed oven. eee A ed en eee weighted wean Calculated a Poca nete— ie pocamefer - OTsu's _BINARVBATIONY _ tiga _— ——_ ke fast sechion foe 6 a secend. poramcfer vet Val whitch is used wher we go for Otsu's Binarizabon . [| Guathesheld | _ > tpuh ya > a etthen porave ler vi | mgs A | of) alue Iheespeldies 7 sod For ie = Sr Ou, 1 econatoly enleaede a Prerkld whe am ore Boe it will aufematica)ly calculate a Ares Nalug Fyonr mos isJe isi adalah ao For fis, cud herbal C) fanchion is used, bub an extra ¥]ey, _ 2 TWRES HH OISU i's passed, oe Kreshold vale, gi mph past 2ere, tra thveshelding is mat ised, vetVlql + same os Pe theshel d wens Te 2 pup parameter will R zero Mojules foc nage Threshalding ; Oo oo 1 fe normal simple progam for Bresbulding. tae NZ Open CM wersion VU | Fist ghee a5 if ct mney ag np numpyrndle — ba eat ‘frou weatp|otlib Inport popbt as plt jig = cv 2 imyend CSauple Jpex. yee nig te ag file nt or Re wane Trresheld Force will okt pee (2:eeA- dcedhyJ [sve 95 cuvrend direche f 2 bas! 3 Your eet Re bakes 4 “arguments att, Bresh! = 2 yesholel Cig ,)2%) 5, ee THRES P_BINAAY) rk, Beha oy Uhresbeld Cig, lar, WS 6V2.Finesy veh, Inst 3 2 cer Avesheld lag, 129, 56 ~PNARY_Incy)) i Oe Wes Taw ¢) vet yesh = v2: fhresheld Cing, 123, 285, eu 2+ Thnes cc veb, Breshs = C42. thetstold (ing , 12%, 255, ev 2- THAES H_To ZERO- INV) Htles|= [Original Image! (BINARY “BINARY NY’, ‘TRusic!, ‘Todenc’, ‘Texeho_iwV" images = Ling, Brecht, thee sh2, thresh 3, thresh 4, threshs For Ein ywange (6): > becube nt have 6 set: innges ple subplet, C23, (42, ple pushers Gmages Ci), 'gray’) wo}e tha} nt it kites a) Sued for shaw’ ing) Fea wtieksCOD), rlf ve ibs (EI) 9® inet sudiny rSbed) Fe Ineling pine Fay Lee [Soul Fo se Bre diffvenee between Ie flegs, ne raed to pleitiy Hose Brcshelds inage a ane Noone ple b with 6 vied phte and 6 ch ffeed images O Now) lets run He program | Lsclick ve aa pe et co eee we Ok MPCOOCVDDDDVCONDDDDDNDVDODDONDDO00000000000 ne brgne | eis fe iy | | fearon fue Adephec Tyesheling Inport cu 2 ; import numpy as np ) import mudale - from motplt ld impoct pyplet os plt Jing = CN imvead C'S ample -jpeg', 0) Vheeding ihm ling = eve medianBlar Ging, 5) hoe peoiing Weise Our Pros Siig SG vet tht = cv2-Byesheld Ging , 222, 255, cv. Thnesb BINARY) AFLG WSF i EZ = cv2- adepdiveThresheld Ging, 255, v2 ADAPTIVE TARESH_IERN_C,\ cy 2. on ‘obs = ex adegbiveTeshold, Cus, 265,002. PDAPD VE TaResH. GAUSS) AN. “y Ginse Mbreitbwelve THRESH BINARY, 1) 2) Flas SEG. THRESH. BINARY, Hi,2) & Gis titles = L'Orisinal bnoge!, ‘Global Tiesholding (2129)! Adaptive Mew Teeeshelding', ‘Pdaphve Gaussian Iresholding’l wunges = Ding thd, Be BS . e for T in xrange de): plt- subplot (2,2, 241), plb-inshay G 1, Grey) _ pit tip epee BD) an Wo Wee 2 xticts (FJ), ple-ytiehs (LJ aaguerent s st shal) oo ; fo ak added wid Sheree ae fun Se oe! Broshelding - | | b. | “flo Com We fir idea For cther examples you vey lace. C _ 5 Origine| [mage Global Thveshlding Cv=(24) | fi | NSagtive Mean Trreslre|di _ Adartive Caursian Theetholding o. MmASDOODOOOCODOCODCOOOODNDVOODVDNONODNOOGONN0G0N0 rel ve forn® derscen & frgenn For otsu’s Ginarizahon t _impect ne Hi nears piece ore open CF prodeile import numpy os importing a Mumpy leo rails ope paplet as os fate seahyld le te pltting wo cainag = ON? imye: Sample - 40. eading (as : wgay 7 ghbal Breshej ding (ee is tre po oe : ‘SN ett, 1 = 002: threshold Cimeg, 12% 255, cv? ines t_B/NAAY) # Otsu's Byesholdin “Cifoliling ela og Xe ay reb2,2h2 = cv2-bresheld , 6, 25S, eV 2-THRESH_BINARY +eu2 THRESH # Dtsa's Breslalding offer Gaussian Filfereg aux Sead Ve wwil\ blur = ex2- Gauss ianhur Gag, Cs,5), 0) > SNE 2FlA95 Th op, SN reh3 th3 = v2 Hrreshald Chluc, 0, 255, Ne IRE BINA IZ TREES Geers, B ple all the Wages bd their histegmus Ons i Ioveshold function on te c @ a 7 - la - a > a ¢ a C ¢ C C po i O MER imger= Zing, O, fhL, Rew OQ poe 3a She ene. Ofsu thresheldiny C : Cc C C « « @ @ @ C C bbw, C2b3 Se Pore r ne titles = L’Oniginal Noisy lage’, Wistgoon Global Threghelding Grong Dees! ‘Gaussian Filtered Image’, Histegram' “Otsu's Aresloly: fen epmnpla 2nd complefe % Foci ia xvange (3+ plt. subplot C3,3, 7% 341), plb. imshory Gmazes £243], “sray’) Neston ple. bible itl L2*3)), ple. xteicks CLI) , pl yticks CLI) subplot (5,3, (#342), plt-bist Gnages£i*33.ravel (), 256) plb. bebe ChitlesEi*3 14)) ; plt-xbrchs £3), pit. yticks (£1), plt. subplot C3,3, 1% 343), ple -imshors Cimages [é°342], ' fray!) plt-title Citlesli*3+ 2), pit. xtielss (£1) pli, gdicbs C01) plt-show O : Otsu's binavizahion vvork ower tha bis les Re hishigran ds hee porkans he dileeces Yoo ater Inages Biles L'0riginet Noisy Meage Hs eg ran’, ‘Global hres holding Cy: 122) | ‘Original Netty Image’, Histogram’, “Obs ubMresheldiins” © ‘Gaussian Bilbced Inage! ‘WShoner,, "Obou's Dyveshatl | | en te Prego ————— leet Noisy Histegraws Qleoad Tees) di D aim riginel Noisy Image Hishey raw Obsu's Therheoldrng 5 ausginn Filltced Inez __Hishegcon Obs Bresheli, = rm) | tus Bresholding 13 Far prove belter thaw nena] ae t Hefocsise we Rk Dredelding Nnlae. sisting He hey O P78 00000000000000000000000000000000000 O90 a Oe O° oO Oo oO oO Oo Oo O° Oo Oo Oo C Oo ° C oO oO C oO 0 O @ O oO é Open Ned OGject Defect \-Tr:°':''_ +> license Free © Mosecrtan bing Open Cu libenrs — SWe First have te instal Open CX library. 7 Cponc COpen Source Compufer Vision Librony) is an epen source conpulie Vision and machine learning setter library. Ope was built fo prvide 2 commen inbrashuchwe for Smpuke- Vision applestions and te accelerate He use of machine percephion ia Commercial products . A He libracy hes wert han 2500 ophirized algoriburs, Which neha a comprelensive set of bok classi anh shaft Phe ac? ccupubi “i and moching fenening aljoritims . Applicebions of nc ate defect ud recognize faces Identi#y objects () Pckssify human ackons in videos Strack camera movenonts > tencle mowing objects erhock 3D msdels of objects > follow ex movenuts Drevegnize Scenery and eshablish mackees fe overlay it wit augonted reality, ofc | N Functions Growre of te) > ineead(): It leads an image from the specified file and réluns it. Achuoly, it reaks animaze as an array of RGR values é ides Gophue £9: Class Far video Capturing from vides Piles image sepuenas cot Ni desCophare- open 6)? Opan Vidleo File or a coplicing bvice for video capburing PNidee Captioce eleese Closes video file vv caghicing dewicg NideseterC: Gefe object bo ovrite video Piles. Bales sawny any vdeo File PNideoWeifer-woeile): Weifes Fhe vox xideo Frame

Visual cufent con be prodeled ag a Witrarchy =F abstraction: MEAS rst level ove Pe raw pixels wilh color or brightness inforey fen. > fuchePpcersing yields featives such as edges, corners, Lines, curves, o ond goler vegions _ =p lute bebonchion Inger mas Conbing and interpret Bese feabes os objects and Keir alibules ae ig hest kevel ore Hie human level concepts luvoluing one vo more obfects ond velofionsbip s aveens tren. Te Select amy ideo, you wast” Frow Ke inner pact or inate levels ov mnec abstractions . ee0000000 Oo000000 | ») > Object Lelechion in videar Inuslves weeifying “he presence Fan object © in image sequences od possibly lecaling it “preiily for vegogritien. ¢ These mage Sequences will have obveof which is owing So we [eee fe locale 5 position in exch Prame,of fe video and ten ie can feck — ib of we can recognize ib . > Objet braching ts te menifer an objects spakial aud temporal changes dering a video sequence, cathe including. its prereset SRS Ky including these | Fiahees, we can frack any object. | — oO E C DOC0O000000000 ® © OOOOH OOOOOOOHOOO é | — D | ing Mprowch Using Object Dekctian Now lel’ see difftrect examples of how we con delet ebjeck i ory ides of auy image Feahue—besed Object Defecfion One op wore features ave extracted ond a objects of ialerest me modded in ferns of Kese Peahures, Lis feafioe means chanacleristics of okpect pe a red cole, shepe ea swe & ne ove dlefeching en object Losed on fe Pealnes of af object Sub-Gtegors 7D Shaped- Based defection ln order te defect ond clefermine Te becder of an object,an image May need be be preprocessed. whe peers ies oc filter clepends on FE applicotion . Di flecent- objec’ 5 such as persons, Flowers, and ainplanes May regu! O Be ees nial its Once te object 1s defected ad located, ifs boundary can be found by edgt defection and boundory-Felleding algeritms 1 ® Gor Cnsed defection iS simple Tracking melked is Lased on tracking vegions of similar os 5 cole jhe fore te frome . fi Each region is characherized by a color vector computed by sub-sampls te pels yakin tre vegion, Which “represents averaged Cel ye of pixels vikin fies region . ta our Object - Lowell subserplt Ke pixels present _Subo-Cabesoes :® Temmplale -based Object Defechon Fa pomp describing a spechc objec is available, object defechen (anes a press of Rakching fealiores Gehween tke perp lett ond ingle SEQUEL Um dey “analysis, | LataPng a Femplote sinc lee be ont objet PTO used when abject shape ale vot change rf ee a, veyect fr wiewsind angle. a D) Fixed Tenplafe Matching Fixed Teuplotes ave useful when object shapes cd wh change wit respect te The Viewing angle oF the Camera. we tajer technigues hote Leen used in Fix template mafeling. —elnage Subjiaction? n ths echuigue, Ge template position is letermined From minimizing The distance function betyeen The | template and Various positions jm Te image - — Geet 3 Matching he ances og sbzes ition of te wormalged ore ss - Correlation ween a fe and an imra, EIS bad nach * 3e De feraolale Tenplafe Matebing SB peformable template matching appre aches oe nore suibeble Foy leases whore ebjects Wy deeb rigid and nonrigid chforafions, Were variabions “can be caused & citer Hh. cbfommaion of Fe eat pore or Just by Wlerent bpd pose relative KAZ camera. Pla Bas apprach) a teup he 1 represented as a biltiap cksce tng Fe dare cleristi contour ledges of an abject Shape. Pi prebabslistic ae nthe fot toe conhur is yphtd Jo abhi Fe toap/de To Bit saliert e iw leput jnaa ak wbjectiae Oe, 5 eorteciged Heratnaely spdobng te fronshoematien poramelecs to best match te object. object shape i changing | Lisit i defrmagle - _Lesentny Coyfiating ideo Free Canery When dealing Wik Vidor Be fiat banc fimefion 1% to cphive ides Fron camcra or ge. many fi Let é OTe cyt 0 ides, a Video Gphice “abject is weded- 1 argument con elBer te WA inder or the yore of a ~ete Fue. ania dex is Just Jee numbur to specify which camera, = Is, ove comet. will be Connected - £ DCOCOODVDOVDOVDVODVODOODDVONDDNONDNVNDVDOOGCNN0N000 oO you we ie Oo | ake, comers PE . °° | So peer Lapher e - C > 0 simpy pars O Gr ~i) oO Tew om select che second canern by passing Lodse on O pete Bot, yeu com caphee Frone-by fauce 7 Biller eapheing the wide, 7 ye ts wend vr of oO You con vers Use See infernal Yer N Fpawas. 5 Vk 7 funchions on te object . ca cap bor Frane Ly © (> LapisOpencdl) >To chocle wheber — OF ing Video phe = it ts jnidielized oe not bythe mothed «1, wit ° ot poyen() 2 Te open camera "SG hirgtrlenn Oe Cap.get Gpropld) > To access Fealiwes of video woe propld ix « OQ number from © to 8. Each number denstes a property of Hy video. O > apset Cormgld, value) To medify, ‘value js Bee alue you wand o f= a © \O/ Letoaes pre 1 beperty 1D Oo ~ es can wodify any paperhy of He vider upg set finclion a Cap Weans Video caphure object © ‘aptwing Nideo from Fle : Nlidee files ow be Mp3 by cher hype © OC SEF came 05 capheing Prom Cancra, just change Camera index Oo Wik Sidee Fle name ~ Initials we parsed © bubnovs video File none @ > Aloe Wale displaying The Feome, use appropriate time for gv2- wait key J oO > rt 15 tro less ~Videe will Le vey fast and if it too high, © Nideo will & slow oo © ~~ : | ts func)! on C | spor ee Pe ess ieee een dt PS for disploying oe wet 3 Frae | | | - Lets see can example Por caphuing vides from Camara Lingort numpy os np \ lepert Open CV mada Ce Linpet cv J Wmper} nunpy todulp | Cap = cv 2. NideoGplue (6) < bate ig | UL copfae Nidew file fon Camera ae pie a E | Caphure Frame -by~ Frame ey perce cel, Prerc = caporend C) rged Fanehion & Ber cophatng 4 Dee operations on Te Krave come graye NZ ENEG bor Frame, cv 2- CoteRASRA 26RBY) WH Dieplay tke vesulbing Frame D Gomterts yor France 292 Lule Cifrwee ehee fe BSrey scale 7 if cod waitkey Ci) § O¥FF = = ord (12°) . l LyeaF Opency Fs tke seshing dene, veleose fe cagfice by ab fault Cap. Se. 2 will give yo cd destroy Bly indewss C) BGR pede! one just aki Fe Fee cisphying ie Fron wing for Nid pryperly ingles furchow Closing | our | Camera 2 fe ran Be code, ewe Camera will pen od shot recording. AF Video sail Le gray cole. | Gh else it press Pinchow +R oO Cra) +18 rye ab fe capte weidto From file , oct fle PRE oP On” Nietlaphuve (file ne 14) oo OCODDD0000000000 Oo OOOCDDDOOOOQ0CO00000 ° —hesening fo Save Video After applying, any algorBe on your video, you west hace fe save wide SB Sontinng Video > Niderifer objecF RR Output File nome Fou l€0 co Nunber of Frames per second Ctps) od frame Size. 2H isGlor Flog If it is Truk, encoder expect color Frame, ohenoise it vwecks wilt grayscale Frome . eeepc NideeWIerer gives you Your Oubpat Fileyawe and Ken ed thave fe inpuk yer FourCe code then fps, frome spe nectally if would be alee frame if if ts fue > Four Co fs a 4-byte code te speciky te video codec @® he list of aveileble codes can ean Jonrce. xg elk is platform dependent. Now leis see an example : Jugert aumpy as np . Tree are Orgect v2 wulfirle codec Twperk cv2-ew ad you ou cap = V2 Nideclaptuce Co) an BDebive The Codec ond creele VideoWciter object any fource = Cv2-cv- CV FouRce CB Kia") AIRE Frecce cole XID “out = ev2-Videoleitee C‘cutputd avi", fource, 20.0, C640, uge)) bak. ap uibile Coop-is Opened C)): A ageo Famer cil ek, enene = emp -c00h 0) aun MP slape and a] if wtes Tene SO ied Fe rn Tiros he \ding vorpal hraree < cy2 File Grane, 0) Dub ori ke Chee) oy foslins ke video frm corora in te odput veriable EQ esIoo ['Frama!, Frew IF cy2-poaitkey(i) $ OXFF cz ord LB’)! = brea. se: ponanetitihg ifanb oy Piniaed og HP uve is Pini . Wek ele ce Oe, let let Ae REE Qn oinbess TT | | | | ° “shite yeu click ven, or : Ake Camera of you sysben @ laphop wil twa on Sides ing jie colwred Wie. [Frau -a od -~ | Prevs Funchon # 6 video | te cee. | ——————— } the ani file would & sewed in R ctr divechyy . | Inewing Bet, Selection Shaferualy, a bbl, iy a repion of an image in which some properties ort congtant oc agprevivately tonshint ; al te points Ih a Mok cn) bel considered in some sense fe & similar tb each cher. IF a pecson iz walking in a shreel; Kab person umuld be considered a bhd alt a group of comedted pixels in an image Rat share some Comteon, peoperty (es grayscale value) > Openly provides a comeniont, way be defect bhbs and Filler Hem based on Pret characeristics. . Lilt pevides Re simple clars wus name is Simple Blt Deteckr CODDDDOCOCNDNDNDOVNOONDONOO0N00000 Some Jmpectent Panchions ! Gis preset jn g ings Convert The source images to sevecel OpenlV tool For Linney reaper by hresholding Te seurce image is veshelds Sinery image is Kah ivrage which is eifier while erGleck; Oor A OC 1 Iw each Lnory image , Connected white pivels are grouped Teg elec. O ) these binocy Licks. reas re of He binary blobs in Te Linney huages art eorpube, - land Ulebs leceted closer than ein DistbetweenBlels are merged, ( ) Glee K fadius Gleulation + Te centers ans endiy of fe new woeged blobs are compute ond refurned. AE rr ree multige bibs, we will fink #2 cae of each blob. PF te Wistance, loetwees Habe 1 les Bags uit em sralense GtToden blebs, Ren ne wil bist ext Bits We “nein MARAE, va Oo0000 Hy > Now let's see an eearyp le’ ByGlor? Figst yeu veed to set €:lterByGleg = | Set blebGlor= © te select darker kiabse . and bhbelr = BR 255 for lightebhbs . a is for detecting bib by Che. By Sige! You cam Filler Be Clits based on size by selling the poruméles filterByAvea =A, and apprepriale values for winAea and wax Aree Panay sie Mm porton Ben you amas nae Cuan Ae lrogine you By Shape TRdeeculority? Tis jor} wenswes haw close bo circle te Ubb i. w]e GiVfee by cicculcily, set FibterByGrculwity =1. Ken set agprepciake values for winGrouleit ma wax Grculerity . > Gonsexity? Coven is defined as the Brea of the Ble Hren of its cmvex hull). Now, Gover Hull sf a shape isthe tighlest conven shape that complelely : encses Fe shape «Jo Filter by coonexity, et FiltecByGnuexity <1, / Followed Ly seling OL min Covtely 6 4 and maxConyexity C22) Loe ectia Rabie: Tig measuts how elongated a shape is ey Pera dle BG value rs 4, for an ellipse it i between O and 1°, and for a Lue ibis ©. To filjer by mertia ratio, set filkerByhechia 21, and Geb OF minlerbiahaho AS and waxlnediakdio SS aprropriakely. YANDNDNINDI Cc - . pn Exanple C de : de C OTH Sfanderk imports : nt) ( ab) Papert ove owe Swot Salt 5 Set | import numpy as np; | cae 4e Ce ogighe es Bherd nage ewe ~ ime ev2 inread C*blob* jpg cv. IMGEAD_GRAYSCALE ) #Seb up He Wik default parameters. dehecloo= Gye: Suple Bll Detector OC) dostgelling FE detedor detect Lobs —— Fimchion fee gebhng cletector Keypoints 2 cetector. deledt Cin) We vse debeck fncdion to detect Llope HBcaw deleted blobs as ced circles. > dcawing Keypunts as red circles 4H cv2-DRAW_ MATCHES. FLAGS _DRAWRICH FEYPOINTS Cntwes FR rize of, the circle corresponds to Ke size of bbb i we C imi Kegpoiats = Cy 2+ ddan Keypoints Cin, Feypeints, np. array LI), C2,8, 288) © fas Cy 2D) MATCHES FLA GF DRA RICH Wee cee set Pungithy ha dean hom blebs ~ FEY POINTS ) wa Keypoints cy2- shies Ciheypoints Tasegtht Fey peints) Pte sha our image (N2- ait ey (2) AR aed means Mb wh: pos awelers O) je et ie seh AO Reba lt- But we com set poratrefers like Inertia vatio, droslecity, yt, Glov, conven ty fy-° OO000000008 @ to Oo oO ©GO0O QO O° °. Oo Oo Oo oO @ ww wer get to agerting Re widen hohe casing tre vider Simple Blk Dekehee Reject) _ impork ew? pete Cte ae import his impor’ mumpy os ap ee impoct imageio input outpub of image You can use vide imageio. get render (Sampled mp! ‘Pempeg’) Tyieeeig, artes “F foucce, 2 evZ-cy UACC C “iV FERS your idee File. “Hilo = cv? Videobeiter Clhgsub-mp) fource, 30, (120, |200)) (oz image io. get_weiter Chgsub-me 4” is 1% for Gouing Final 2 imagere-geEvarllie Conant) NE Yael 9 Fgbg = cv2- Background Subhractor MOG C) count = © for img in Vid: Fomask = Fgha- apply Ling) Faras N2- medianBluc Cfynask 7) Fgmask = V2 -GavssianBlur fgmask (3,3), 0) | Masl€= cx 2- erode CHfgmask, Nove, iterations =10, bordkeType=1 ) mask = cy2- dilate Cmask Nowe, iterabions 219, LocderType =4) 0- append_ data Cras k) H set up te Single Blabcletector witk cefaulk pacarelers. prem Single BleL Detecks Params () ; 2 Change thresrelds a, wrled parares ialbvesheld =o fon parats: maxDresheld = 256; # Filter by Area, | paracs Fi Be Byftrea = True an acamns. minften = JoToe - ‘ oe wat Arg =!5000 - 7 Cae false # Biller Ly Greulacity params. FilterByGreulecity =True Wis #t 95 True fecouse we parcins. min Greulacity = 2-1 hawt be change ts deFault H Filler by Cnvexity sale params PilterBs Conrerity = Jone | params. minConveriby So $F PTO | O | — LH Filter by Inertia parans.filterBy Inerbia = True params: minhnertia habe 20-5 ; params. min Dist Bebween blebs = 150-0, ace bow POND cletechoc = eN2- Simple BbDetector Cparams) YE SE puree 7 Detect Mets. imag Keogh de SP “reversemask = 25S ~ mask J flee peter \Feypoinds = detects t Geversemask) defeet YOO laine Jee Cheypoints)) ai ae wactable O55 = ieee : Lim wik_ Feypomts = €v2 clrawHeypoints Cuask Heypeints, np. array (LI), & ors i ere Ban soe fuse lube detected # Show beypeints ising dranFeyporate GHZ -inshows C“beypoints” inn wi Feypeints) oe Cin swith Feypeints) @ # print Feypomt Here we owe passing a oe Cheygeints) iso): Nideo Ket will fms iB ileke | t ip Chew | Count =eourt + len (Leyprints) IF Cov. waitkey (29) | 2-4)» break | Kis is Por displaying tre nid - close) Mlle properly - 10. close C) Final -close © | print Count |ey2. deskeyAlltyindows C) priat (Bone!) > Now run te code. @ | Lsng wideo rill tun, you con gee bleds | im which pergons ove Werr'ng . | | OOCOCOODODNDODOOOCOCOCOCVODOOGO0G0O0000 ~ Tracking Using lor Spmces a hae Tent lifer F $ colow wedels alvendy, Hs, HsV, RGB So how Cam We ee using hese wodels” 5 ast a oniring, vides, and ging Get a singe frawe of the video dee Feed fact oe Aigo "hood Free Cow? 5 Col-v mode! From ROB which Oo? uses te veprem meses by defult be HSS sre re cn OR book at jut & gl value te Aetemine Me Hue . — Apply a threshold to eliminate Get heic value &0) all pixels hak “dewt meet ove criteria TBs will leove only the object we aim to track se then te detrmns its location we can get OpencY be calculate ifs momente and \compute is cn-ardinal. position. oO | i eeetles toe Teg bing sing Color Spaces & nt eve ia OpenX and nuspy > Fe eaherelicl AEB kya inet money as np WE Eine a Rnckon toe ke excrete frame from Ka, wlan bea Pst t Frame Coop, sealing fader) Shares SE SS Rad “he camert a cone oa Vilen caplure object afc — Frome = cap read C) cacek Ht Resize Ke image eave Frame = ev 2-resize. Frame, None, f= Scaling factor Fy=3caling tack interpolation = C2. INTER. Anca) First step W comect fhe iwage to SV colorspace (oéter sthhing Wenge hyve cu2-cut Glee Grome, cv2- Colon B6R 2HSV) | conurh ts HDeFine ange of skin color in_ HSV ore | Jover = np-arcay LL 0,70, 66]) upper = 4p. acray (L$0, 150, 2sS aD) HT hesheld He FSV image be get only skin color be el | susk= 02 ahs Oy, eee, upp) Tod Roe Faschon HB itwise~AND Lefineen Be mask and original image ing. Lifwise_and = Webi twise_and Brame, frame mask= mask) H hun median blucring hrs is For gelling cur merge clear ing median blued = ev2- ethan Blan Co Dijtune ant 2) A Display he input ond oyu ‘ ees CXR -imshous C'lnput' Pease) ee Sypleging ») Cyr-Imshows C' Output’ Img median bluyred) inpul and city. # Check if the user hit tHe ‘Ese! bey C= evZ-waitkey (5) | if.c- 223: | break “H Close all be twindous. | 4 2-desfroyfll Windows s C) —eNewo ron te bede. ) DOVDDODOVOVDQGDODDOOOCOOCOVCVVGOOO0G000000 ©9008 OOHHHHHHDHOHOHOHOO®D ©0680 0@ @e@ eae We ee bro in or at Ag any teegeye cae articular image, we Picsk gureoh Hose junges For clear tracking y tee eet ” — Melheds For Smocking Inasos Averaging = This is dong by convelving e imaye wih a normalized boy Flber Ik simply takes he overage of all te pixels uncke Fone! area and replaces Ke central eloment wih tres eieraye . Tis is dene by Ke fine tion * | eve-blar() oe C42. boxFillee () | Gaussi beeing Tn Res aappronch, insPead of a bex Filter consisting of egunl filéer coefficients, a Gaussian Kewell rs used. 2 -GausstanBlur () for smocking He image CD Gaussian filtering is highly ect ne in removing Gaussian porse From Ke image. IF you want, you can create a Gaussian Fernel with Tay Punebiien, ext gel Gaussian Kernel C) SIE conputes Ke pedion ofall The pixels under Be Femel windows and the central pixel & replaced vik Kis wodien valie. > Ove interesting hing bo wete ts Bat, in KE Gaussian 8 bre fillers ha Filtered value For The central element con avelue which tay ast _ eHisE Inte origin image. However this is wal Ke case in median < filtering, since He centred elment 17 ahoays replaced hy sone pixel alu ia The image This veduces Re weise effectively It ta more ebective way, _ v2-medianBur C) —+ You hae fo ust bese jurcohying weheds bebore applying any algers tm | | | | ‘unglien: Coding for Smoothing mages @ tpt cuz import nompy as vp form wralpictlib impock pyplet os ple ; jing > ev2-impead C'F *\\ MLN images\ Vet. We reading Image blur= cv2- blur Ging, (55)) avenge mehed SSK shoe Gaussian? Cyr Gaussian Glue Ling, (5.5), 0) median = CVZ- medianklue Cing, 5) medrans—Cu2smedian Blue GugrD— use t once plt- subplot C120), plt-imshow Cng) , ple. bitle Coriginal’) ple -xticks (LI), plt-ytiets CEI) plt-subplot C122), ple inshew Chloe), pit. ditle C'B luered’) pl -wticks (LI), plé-yticks (£3) plt. show C) ple- subplot C122), plt.inshers Gaussian), plé. title Cgansrcan't) (>) plt- show C) this is fo slors the Subpot | ple subplot £122), ple. ‘mshors Gredian), pli-bitle Cwedian’) | pit -shevol) fun tee ede Original Blurred DODVDODNDDVNDDDONDNDONDVC OOOO OVOGOG00000000 @OG OOOO 809099098 OHOOD ©e@e@ O aD 7 Undersband ng Cafour Detect on pOoakouss Con be explained suply as a Corte joining olf Be continuous points Calong ie Lomdag), having same color oe infenoiby. rit i wed For shape emabns and object dedection ond recegnibien if we connact Ke points of its Loundy, we ore geling its Weife perkron. f lk OpenCV, Finding contours is like finding white object from black Lacksvound. So object t. be Found should be arcibe bite and background should be Llack. For geting fat hpe of image, wr use Oo) Brresolding —eTreshelding: IF pixel value is greater Man @ thresheld value, if es assigned me value (may be ubite), else it rs assigned ancbier vale Goa be Uack) . - | For Breshelding > ev2-thvesteldC) ; : eee. ao —> eve-find pare 0 ie Fi ie recting Those contours yeu are actually’ clefecting objec Sedalia Boe cots Sere act elt ot x | CanSlaft Blgori > [Riats te remember > > Clee space based tmehing alavs us te track colored objects, but we hose be define Ke color Fiest IF xe rae bo fed aw object in a video /. wie can use Mes alysrifim. In he algorifur, ne dev't reed fe specify any cleus. ATs i Gasiealy toed be tonck objects. ° —*Cratinuwesg Adaptive Mean Shift, >the adaption vernon of Be Jean Sli algorihuy means that first you must Fan the wean SFE algecihim eo ——_] Be tiborial For Mean Shift Algonky is Kee http ://clocs. opency-org/3-1-0 [dk/3 8/tutorinl py taonashif eh tind Mere. SUPE Aloo Poon . 5 es a . 5 - . ‘ rr x \ : ‘ ry ¢ : /, : . ' , | sete Cet \ « fo. 2 a ete . ‘ f —— ae . a7 eC lL_—rC_—llC SHH @ wind oyor How prints suc phat canter of these paints Ms tous) te Lerher of thot winkew We bok baltin hove circle shaped window. - Pe Ke jer of Bat window or circle sheuld Se porged wik Te Lerter of Kose points . , AAhe confer of the blue civde 1s Cho Luk centroid i Cie. $ your Cantears v4 wot watching wik the center oft ciccle. at's why ye have Gsflel ovr winks Poe Aron Ciecle Be colar Gcedheal are matching QDODONDDOOOVOCONDDOOOCNONDONVVCVGOGO0OG000000 ©0000 00900000000909900098 6000088 CO®O eRERA @ 2 Se we woemally pass the lishegram Lackprjedted image ard imitial teget Ce sbjecl wos, Peroealy Be pocemed reflected jn hishegeau bockpesjected imag? Ds a vesull meonshipt algoribu, moves our windeww E he new Siow wil prowinauey density. TE, iteration will confinue until Ke center of Be windon atdes Ke catecid . > Ove winds ahuase hase sane sige when car is farther away ond ibis wexy close ty Camera Liye eed fo adapt Ke window size wik sige and rotation of rhe edaphive camshift algoribua applies memsliPt first. Dnee ) raeanshiFt comege sit updates The size, of He window. —> I alse calculates Ke orientation of best fifin ellipse fo it. Again apples Ke mouslsfl wi new seeded sevch. window and previous Window Jcation. Le process is confinwed yah required accuracy is me nstialzing “jhe Video Cophure Object import cy import numpy as np BDeFing & class to haredle object tracking wghled Funct malty jolass Qbjedt Trac tee Cok Shh sre loss a def iniF— Cself, scaling fades &5) Vids \| Ht Dnhalige Be Flex caphice object we selF cag = v2NidecGyhut LD 7 Emport video be B Geyhuce he Frame From te weborn = SRP. Frame =P. cap-read b) > captive frame Frou webcam Sol H Scaling fader for the caphied rare aw se)F. scaling acfer = scaling fachr HResge the Frame Phe Tis [BH Check iF tke user has stufed selecting TR vezion Gas If self. drag _shact + i if Flags KR owz. EVENT _FLAG_LBUTToN : fo # Figs Exleact the dimension of he frame yw h, wo = selP. fnaee « shape [2 23 @ Self. Feane = cv2- resize Cell. frame, Nene, Fx=self-sealing. factor | ; Fy self. sealing fag inbecpolation = ex2. INTER AKER) # Geale a window bo diylay the Frome advonedebedacs COGCE Hacked ewe ASet the mouse eallhack Funchion to track Ke mouse ex2-gcbMeuseCallback (“Object Tracker self mouse. event ) Hbitiablge Noriable related fe rectangular region selech'ed self. seleckion = None HIntialze Variable related to vestrygutor sfochisg posihien “self. drag —slact = None [Bnitinlige sorindle related fe te shale of tracking. sell-tracking shake = © #BDeFine a meted te tinck Fa muse events (ae mouse event Cself, event, %, 3 7 Flags, pero) : # Comert x ands) coordinates inte M-kiE nunpy iadepers | x ye mp. int lO (Lx, sD F Check iP a mouse bullon clown event has ocautred IF euant == cr2. EVENT_LBUTIONQOWN ¢ Self deag_ start > C9) MFwe played en dey will slact self-tracking stale = 0 and sabe Lecomes zero # Get te mibial position Xi, 36 = selP dong shart Hak te moe and mia valves - XO, 90> pp. maximum (O, np. minimum Coch, yt] &xsIDO X21, 94 = np miniwum (Coy, hI, np maxima ¥4,9 4), Lx, 9) ~ # Reet He stledion vaniable t self. gledion = None U QOVDKDODCNDDVDDODVNONDVVOOVOVVOGO0000000000)} @ (Finalize Ke redungular selechon | iF AL-KO> © ans YL-JO D0 % | Self. selection = (x0, Jo, x4, yn) eke HE tre selection & dene , shack tencling self. Seng start > Nowe iP self-selection % nol Neng t self. Epacking shate=4 HMekod be stark tracking Ke object ef shart tracks CselP ) H Iteede untildte user presses te bse =7 HIF. Frane = IF. cap. read C) 4 Resize the input Frame © | «lt feet: resize CselP. frame, None, | Fue sell. sealing facker, Fy= elf. scaling_facker, _ . | invecpolaken > cw2- INTER AREA ) Tis | (HGeate a copy of Ke trame fet vis = self. frame- copy C) os she | A Gmvert tke Frane te HSW coleespace Feat hey = cy2- cubbolor Cself. Brame, C¥2- COLOR BGR 25) "” # Greate the mask based on predefined threshalds 25, \ mask = Cv 2, jahange Chsu, np-arraylC0,, 60., 22.)), Ted np-array (C18, 258., 258. ))) # Check if Re user has selected Ke region AATF galtscedion eid # Extack Ke wordicates of he selected rechingle alle XO, 30, x4, 94 = RIF selection NPE xtoact Re tracking winduo wed) Self track winders = Cxo, 90, x2, 39) H Extead te regions of © hey ipei = hsv [9o:99 Ao xAy mask noi = mask [50:54 , xo: xt UO # iatecest in Te HSV image hist = cv2> caleffist C Crsv-roi J, Co, mask voi, L163, fo, 1963) FB Nerwalize and yeskape the bishegran CNZ- novmalize Chist, hist, 0, 255, ev2-NeaM_ MIN MAY) ¢ sdf-hist = bist - yeshape C-1) | # Extract fhe vegion of salerest from He frane Nis-rei? vis Gyo: ya, xo: xt | # Cougute the inrage negabice Cfor display only) cve- Vhwise_ not (visor, visret vis Tmosk==0)> © H Check if tke sysfem im ke “Lrecking " node iF self. Eencking_sfale => 45 oO H Reset the selection variable - self celeckon = Nene |B Goupide the histegeam back pesjection | hsv backpes} = c¥2-calchack bject Dasw 3; Cod, | self.nist, Co, 1807, 1) # Gupte Litwise AND Lelieen histogram # Lackprajection and the mask hev_hactpre) ¥ = mask HDePine Leruination criteria for the tracker bee crit = Cov2-TERM_CpiTERIA-EPS ) cv2-TéRM CRITERIA ~CeunT 10,2) | | | | Pewute, the Weshgrar, 3 | | | H Roply CAMShIFt ow 'hey_backpro}’ | trad box, self feack windows = ¥2-CamChitt Chev. backpry, | gelf. track windevo, term crit | # Draw on ellipse avamd the object O etches Giis, track box, (0; 255,06), 2) 01 & ;.t : A Show the oufpul Dive video Tris ellipse Bunce | AAR -jmghow C ‘Object Tracker", vis) eet: aang COOODVDDVDNOVDNDVVVDNOVONN0GN0900000 Co OCOCO0000 t-—— aa iF Re user WQGR. ‘Exc’ bey = €N2. wok key CF 73 c=rz 7 « Oo break # Close all FR windows 1 name == ‘mein’: # Stack the trackee Object Tracker (). shact_ tracking 6) hun Fe cde Wer you run tke code, he webcam shows TR video of 3° @ Ike object Cperren) Pacing He cepara. You can Use your mouse te draw an ellipse around yor Face. then velaace Ie Ueld onthe mouse: Now as you mene, the ellipse will algo woce rT ] [ ~ / f OO / / / | Lica) Flow Algorikm — CLE PlgoriAu.) Optical Flew ie Tre ppalfecn oF appace: befareen bie consecedive frames caused ly the move or Gamora, L weotion 97 Te arpe 1F deneting R sl thing fh am eb fect From position 4 Brough fe : Feanes. FP Yfou how to track it's bcation in all Fe Cranes. PIs can be done very your ophical fips alzeri Aun, — Optical flaw evil! show you Ke woh'on of your object iy conse cubive fyrawes } L Le Opticol Flas in CpenC¥ LE mens Lucas Kanade a!gerifinn ee ite be Fist frnea , deleck Gone. soyaee~ se in it, Ken we itersfively track hose points using Lk optical Flevs ry, > for owe prints Sh good FealivesTe Track) leech 23 > For Optical Fino? v2. cale OpticalFlow PyrLk C) bE @ Prguments - Ke previons Frare, previous points, and next Frame ®D Pet value — next points and slafus [number which is A i F- next point is Found, else zero. We ifecatively pass these next punts las prewious points im next shy. To read move about prea IAs algeria, 9° to: eal lie: Mesemeb- wesd edu /classes Ap 0 2/tse?52/]ucas Fanad S)- pat position & in S conzecuhive (aed. objec ¢ q ¢ ¢ Cc OOO COoOoOot ooooc¢ } © @ © © @ © © © © @ @ © OOO © GO OHHOOHHHHHOHOHOO! O @ poss —hresrams of Orhical Flow Algerie Gwpect ov ) importing Wedules import numpy as np F Debine a Fandiion te track the object ckf ae O: H Initialige tRe video captive obje Cap = CN 2Video Capture Coy Capture tha video Frou system H Define the sealing fachor foc Ke frames scaling faclee 20'S — Frare will Le resized using His sealing facie # Number of Frames te brack num fremes_to_track = 5 the number 5 1s jusf choosen ** “referee # Shipping Packer fo aren num Frames— jump = 2 (jocBen hitial’ze varrables racking. palts = £9 Frame index = © B Define tracking paramelens cacking. params = dict GoinSize = CAL, 92), max level = 2 ccilecra= Covt-Ténm Critenuers ) 8% JERM Celie - CBUNT, Jo, 0-03 # Iterate until the user hits the ‘Ee’ key While True # Caphure the current Frame a, Frame = cap. read C) # Resize the frane Frame = v2 .yesize (Frame, None, Fx = Sealing. Fachor fy> scaling facteo interpolation = cv2 INTER AREA) vet/ # Gouvect te grayscale bo frame — gray = CyZ-cut Glor Frame, ev 2-CoLok £5426RA 7) HP Grable % copy of he Frane oulput ing = Frame. copy) ' iF len Ceacking_ path > ° A Geb images | 4 whol) a oc0 veh ayer er PeniiowS | Var 3K wpe ts watt Seat Oo Brun Goset Fug [fm : preveing, current ing < prey—gray, Frawe— gray Piereceties eater : Fealuce_ points _O = np-Float 82 (Ltpl-1J Fac tp in \ teaching pobsJ.c oo reshape (1,9, 2) 5 H Compute optical Flas > tren apply Oplical Flew algeribin Feafwe_ points_4, -,— = x2-cale Optical Flow RyrLk C preying, | aurert ing, Feature points 0, Nore, inching | = params) # Coupite reverse optical Flow ; Feahure _poiats~ O_rev, —,— = €¥2- Cale Optical levohy rt Courrent. ing, prev_ing, Fenlurepeiats 1, Nowe, toackiag : = params Ht Compide the ti ference belineen Forard and | | | | | Ht reveese opbical Flow | | | | | | 00 CODD000000000 @ AA featuee_ points = abs CFeatucepoints0-\ Feabie_ poiats 0. rey): reshape El, %)- max Ce) H Extract the geod points if ke difference 15 gmaller Bhan | hen good _priads = diff feature points <1 Beg ect goed H hitialize variable nan new-tracking_ pas = LI # Iberate Trough all Ke geod Featwe points | for bp, Cx,3), goed points flag in zip Céracking- pats, | Peake =points. reshape C-4,2) , goed. points): | Hp He flag ts net true, then continue | IF not geod_poiats - Flag t Continue |. F Myperd the K and Y coordinates and check iF jf Hits Leagk greater Ban the Bresheld \ tp. append (07%, 3)) @ | | | OC00000000 Oo tf Len tp) > rum frames. tertrack: del tpLeJ new tracking _paks- append Lép) OO000000 Oo ) ©@00000000 3 Oo Oo COSCOOODDOQGOOOOOO Q | # + e 8 & & noe ach ON, pe # Draw aq circle around the Feotiye prints N2.ciecle (output ing , Cx), 3, Co 255, P>, -1) | ¥ Update the Lracking paths tracking. pabis = new tracking. pals # Deaw Lines ev polylines Coutput ing , Unp.int3z Llp) for tp in\ tracking. pabs False, Co, 1S0,0)) Geo inte this ‘iP! pondition after skipping tke vighh yunber oF Frames IF not Frame index Z num frames jung! + es a Mask and ae e cavcles Mask = np-zeros_ Litt Frame | Beer 25S te Foo 2,9 in Tip, int 32 (bp C3) Far bp in tomcking paths 3: Ox 2- circle Cuesk, Od, Go-) H Compute good Features te track Teabuc. peice F ev? -geodFecduces TeTrack (Frame gray, mask = mask warComers =S500, quality Level = 3, minDistance = 7, block Size = 2) its # Check if Feature points exist. IF se, aypend them B te the tracking palks Re grees jf Featue points 1 mat Neng? points see For 9 in np. float 32 ( Fealurt points). reshage (-(, 2): ode iS fun 19 tracking_palts. append (Lb3)) H Updte voriel be actual frame index. t= 4. Reve prey gray = Fraregmy aad aysin wt will Itecat Hiough the u H Display ouput algerubn @ cyt-imskew (' Optical, Flow’, output_jng) Pr Check Fhe user hit te ‘Ese! key = Cd-mait key C2) ifesz2?: break Re gree your alse [be wetting oyefher. Ihe Corner prints aye teving because of itera fron O ieee ee ee een eee H Stack lhe tracker | slact_teacking () H Close all Ke windows eve. destroy All Windows C) Now vun #e code os peinks owe Kyat ing corner points IF object is moving, The comer geints wi)/ had ix applied im oar alyerifirn. ’ > hee Den Ar TRackiNG ce Acfection and Face vecognition ove di Feen€. oF Steg Ueteckion veeans ne ave decablon the puition of « face in a Veale Image -We saying uboter image consist of face or uel. se faa fs fhab i Froe récegnition, Tis ledue Focuses on force detechion. >} re vb) ve ical bromebric system utilizes elk face detection and Face hom de perPom Bee LE wes Face detection te locate the face and then uses face (>) eecagnition bo identity he perrea. ecbion pdb t agtection using Hace Featine hosed cascade classifiers iy an ofebive et wah COODODOCOODDOOOOOOOODDCDDDDDD0000 OF <8 proposed by aul Wola ad Michael Jeng in Hees O it tna pid Dusect Debetiln wing A Beestel Godt +B Single Pestincs” in veel. wv Heo feative Eis a machine learning based approach where a cascade funrclie 6 tmivad from a bet “of positive ad negadiWe images - eee we will werk pik face detection. lnifialy, Ke algoriten needs a Vat of positive } 5s Uh s of Facs) and negative images Guages eee ps te Clacsifiew Toon we need be extract feahwes from '€ The input 5 multiple images to brain fe classy > For his, haar Feahures ave used. They ave just lie cur convelutonal Kernel Each feative ts single value obbained by sublracting swe of pivels under white rectangle From su of pixels under black veclangl - We ae Using A mochine [earning algerie se we have te Eran ke preded wik a porhicolor dafa wich in thr case Chicas Hane feohines! @ live Feahices eg eyes | ® Edge | D Few-eecangle Rathees > We hove more fan 6000 Pabyes te check in a winders Kor face detection and Rat bask is very Line baking- - DV Se, wow wt will use cascade classifier SJuat ts we will check feates in sfages SIF a Window fail in fint stage, Useacd f and so on. Lott inks fist shege, Be medel Fails fo eter these Peaches. Ken ih will yo peborn Be vtwaining shager That's udhy Be name Cascade classifier | rhe > O ~ ( +) @ | © Cascade Clessifier Inbuilé Funchion _ O TWpert eve } import aumpy as np DBs class Kren ) a Iood fhe Haar cascode File ree - Face_ cascade = CV2- Cascade Clossifier C O° | ‘heer. cascade Pile hanr casende -Frortal face ckfaulenmt!) ~ A Check if the cascade file has Leen leaded correctly “if face cascade. enply C) + ° | raise L0Emor CUndle to load the face cascade classifier © enl file’ @ ¥ Initialize he Video caphure objest oO Cap = cv2Nideo Capture Co) we ae capticing pur vides Usag camera OQ B Define fhe scaling Factor @ (Scaling Packer = O-S , , oO H Iterafe until the user hits te ‘Esc’ key oO While True t rn 7 Q — # Gaplice tke current Frame >= | a, feane= cap.read C) rg grt capri Fane by front foun the = |B Resize be Frame oa sos : | Frame= cv2- resize Crue, Nene, fx = Scaling factor, o | Fy = scaling - Factor, Oo | _ inberpalabn=cv2-INTER AREA) | # Govert be grayscale he wider iy gotten as BGK mode! 22 Me levee O © gray cove ct Color (Foam, our Coron RoRZERNY) IMIA(@ Hhun the Face cetecter on the grayscale image oO | face reds = face cascade - ete MulScale Cray, 1-3, $) ° | BDran a yedanglk around the face O | Bee Gag, h) iy Face are cls: O oe (Frame Cx), CtWYIh) , C0, 255,32) O | #H Diplay he outpu | pots eopilh Detector’, Frame) all fee feames will be ie | Check iP the user hit he ‘Be! ke ay, just Uke Chae the user se! key le played jus @ @ OSS OOOOO SHOE HOH OOH HOH HO HONDO HOOHOOO®D b= exz. waitFey C1) ieee aaeo: break Relesse Hie video cxphine object cap. release () H Close aN Te windows eX. destreyfll Windows C) pete Ke rechangle will be Hhe leeching yor face Be end Tthe vider, click on te plus sign 0000000090000 000090009090000000900000000

You might also like