Cov txheej txheem:

Raspberry Pi Object Counting: 5 Kauj Ruam
Raspberry Pi Object Counting: 5 Kauj Ruam

Video: Raspberry Pi Object Counting: 5 Kauj Ruam

Video: Raspberry Pi Object Counting: 5 Kauj Ruam
Video: Quick and Simple Method to Count People | Raspberry Pi 4 People Counting with OpenCV 2024, Kaum ib hlis
Anonim
Raspberry Pi Object Counting
Raspberry Pi Object Counting

Lub zeem muag ntawm lub computer, tsis ntseeg, yog qhov zoo tshaj plaws! Siv qhov no, lub khoos phis tawj tau txais lub peev xwm "pom" thiab paub zoo dua ib puag ncig ib puag ncig, dab tsi tso cai rau kev txhim kho cov ntawv nyuaj, muaj txiaj ntsig thiab siv tau txias. Cov ntawv thov xws li lub ntsej muag txhawm rau txheeb xyuas thiab lees paub, nrhiav cov khoom thiab tshawb pom cov khoom muaj ntau zuj zus nyob hauv peb cov haujlwm niaj hnub, ua tsaug rau lub khoos phis tawj pom kev nce qib.

Xav txog qhov ua tau zoo thiab siv tau yog lub khoos phis tawj lub zeem muag pom thiab cov cuab yeej, daim ntawv thov piav qhia hauv kab lus no haum zoo: siv Raspberry PI yooj yim thiab tsis muaj nqi thiab qhib qhov khoos phis tawj lub zeem muag pom hu ua OpenCV suav cov khoom hauv kev txav mus, ntau dua qhov tseeb cov khoom nkag mus thiab tawm ntawm ib cheeb tsam saib xyuas.

Kauj Ruam 1: Ua Kom Taus: Yuav Ua Li Cas Lub Hom Phiaj Raug Rho Tawm Hauv Duab Duab?

Ua Kom Taus: Yuav Ua Li Cas Lub Hom Phiaj Raug Rho Tawm Hauv Duab Duab?
Ua Kom Taus: Yuav Ua Li Cas Lub Hom Phiaj Raug Rho Tawm Hauv Duab Duab?

Tam sim no nws yog lub sijhawm kom nkag siab tob hauv cov duab ua cov khoom:

yuav ua li cas kom tau qee lub webcam kwj duab thiab pom tias qee yam tau txav mus rau ntawd

Nws muaj tsib qib:

Kauj Ruam 1: Ua kom pom lub hom phiaj ntawm kev txav mus los

Raws li tau hais tseg hauv cov txheej txheem physics, yuav tsum tau siv kom pom tseeb tias muaj qee yam txav mus los lossis yog tias nws tseem sawv ntsug. Ntawm no, los txiav txim siab yog qee yam tau txav mus los, nws zoo nkauj zoo ib yam: txhua lub webcam kwj tau ntes cov duab yuav muab piv rau tus qauv siv. Yog tias qee yam txawv, qee yam tau txav mus. Nws yooj yim li nws suab.

Cov kab ntawv siv no yuav tsum raug ntes hauv qhov xwm txheej zoo tshaj plaws (tsis muaj dab tsi txav mus, piv txwv). Hauv lub ntiaj teb ua cov duab, qhov kev sib piv ntawm tus ncej raug ntes thiab cov duab siv muaj nyob hauv cov txheej txheem hu ua rho tawm tom qab. Kev suav keeb kwm yav dhau suav nrog cov lej rho tawm pixel-rau-pixel cov ntaub ntawv xim los ntawm cov kab uas raug ntes thiab cov duab siv. Yog li, cov txiaj ntsig tau los ntawm qhov kev ua tiav no yuav hais qhia / qhia nrog cov ncauj lus kom ntxaws tsuas yog qhov sib txawv ntawm ob kab ntawv no (lossis, dab tsi tau hloov / tau txav mus los) thiab txhua yam ntxiv yuav dub hauv cov duab (xim xoom tus nqi ntawm cov grey -pixel loj). Tseem ceeb: teeb pom kev zoo thiab qhov zoo ntawm lub webcam duab tau ntes (vim ntes cov duab zoo) tuaj yeem sib txawv me ntsis los ntawm tus ncej mus rau tus ncej. Nws cuam tshuam tias "qhov sib npaug" los ntawm cov kab ntawv siv thiab lwm cov thav ntawv yuav tsis dub tag nrho tom qab rho tawm tom qab. Dua li ntawm tus cwj pwm no, tsis muaj qhov tshwm sim loj hauv cov kauj ruam tom ntej ua cov duab hauv qhov haujlwm no.

Txhawm rau kom txo qis lub sijhawm ua cov duab, ua ntej ua cov keeb kwm yav dhau los cais, ntes cov duab thiab cov duab siv tau hloov pauv mus rau cov duab nplai. Tab sis.. vim li cas? Nws yog qhov teeb meem kev suav suav nrog: cov duab uas nthuav tawm ntau yam xim (xim duab) muaj peb cov ntaub ntawv ib pixel: Liab, Xiav thiab Ntsuab xim sib xyaw (qub tab sis kub RGB tus qauv). Yog li, ua lej, txhua lub pixel tuaj yeem txhais raws li peb qhov nqi sib xws, txhua tus sawv cev rau cov xim sib xyaw. Yog li ntawd, txuas ntxiv mus rau tag nrho cov duab, daim duab kawg yuav yog qhov sib xyaw ntawm peb daim duab duab: Liab, Xiav thiab Ntsuab cov duab sib xyaw.

Txhawm rau ua nws, yuav tsum ua haujlwm ntau heev! Txawm li cas los xij, hauv cov duab grey-scale, txhua lub pixel tsuas muaj ib cov lus qhia xim. Yog li, kev ua cov duab xim yog peb zaug qeeb dua li cov duab grey-scale (tsawg kawg peb zaug, nyob ntawm seb cov txheej txheem cuam tshuam nrog dab tsi). Thiab muaj ntau ntxiv: rau qee lub hom phiaj (zoo li txoj haujlwm no), txheej txheem txhua qhov xim tsis tsim nyog lossis tseem ceeb hlo li. Yog li ntawd, peb los txog qhov xaus: siv cov duab grey-teev tau pom zoo rau kev ua cov duab lub hom phiaj. Tom qab kev txheeb cais keeb kwm yav dhau, nws yog qhov tsim nyog los siv Gaussian Blur lim.

Gaussian Blur lim tau siv dua keeb kwm yav dhau los rho tawm cov duab ua kom zoo txhua qhov kev sib tw ntawm cov khoom txav mus. Kom paub meej, nws yuav pab tau hauv cov kauj ruam tom ntej ntawm kev ua cov duab.

Kauj ruam 2: Binarization

Binarization
Binarization

Feem ntau ntawm kev ua cov duab, binarization yuav luag yog qhov yuav tsum tau ua tom qab ua kom pom cov khoom / tus yam ntxwv hauv daim duab. Vim li cas: hauv daim duab binary, txhua lub xim pixel tuaj yeem xav ob qhov txiaj ntsig nkaus xwb: 0x00 (dub) lossis 0xFF (dawb). Qhov no pab tau ntau cov duab ua kom xav tau txawm tias tsawg dua "suav lub zog" los siv cov txheej txheem ua duab hauv cov kauj ruam tom ntej. Binarization tuaj yeem ua tiav sib piv txhua lub pixel xim ntawm cov duab grey-scale rau qee qhov pib. Yog tias tus nqi ntawm cov xim pixel ntau dua li qhov pib, cov xim pixel no yuav suav tias yog tus nqi dawb (0xFF), thiab yog tias tus nqi ntawm cov xim pixel qis dua qhov pib, cov xim pixel no yuav suav tias yog tus nqi dub (0x00). Hmoov tsis zoo, qhov pib tus nqi xaiv tsis yooj yim los ua. Nws nyob ntawm qhov xwm txheej ib puag ncig, xws li teeb pom kev zoo. Kev xaiv tsis raug ntawm tus nqi pib tuaj yeem ua rau puas tag nrho cov kauj ruam ntxiv. Yog li, kuv pom zoo kom koj hloov kho tus lej pib hauv qhov haujlwm rau koj rooj plaub ua ntej muaj kev nqis tes ua ntxiv. Tus nqi pib no yuav tsum ua kom ntseeg tau tias cov khoom txav tau qhia hauv duab binary. Hauv kuv qhov xwm txheej, tom qab pib qhov kev xaiv tsim nyog, ua rau pom qhov koj pom hauv daim duab 5.

Daim duab 5 - duab binary

Kauj ruam 3: Dilate

Txog tam sim no, nws muaj peev xwm txheeb xyuas cov khoom txav mus los, hais qhia lawv thiab siv binarization, qhov ua rau pom cov duab zoo nkauj ntawm cov khoom txav (= zoo nkauj zoo nkauj ntawm cov khoom siv rau lub hom phiaj ua haujlwm). Kev npaj rau suav cov khoom tau ua tiav tas li. Qhov "QHOV TSEEB" ntawm no txhais tau tias muaj qee qhov kev hloov kho kom zoo ua ntej txav mus. Txog ntawm qhov no, muaj qhov yuav tshwm sim tiag tiag ntawm qhov "qhov" hauv cov khoom (cov xim dub ntau ntawm cov pixels rau hauv cov khoom uas tau hais tawm dawb). Cov qhov no tuaj yeem yog txhua yam, los ntawm cov teeb pom kev tshwj xeeb rau qee qhov ntawm cov khoom zoo. Thaum qhov tuaj yeem "tsim" cov khoom cuav hauv cov khoom tiag (nyob ntawm seb loj npaum li cas thiab lawv nyob qhov twg), qhov tshwm sim ntawm qhov muaj nyob hauv cov duab tuaj yeem ua rau muaj kev puas tsuaj rau cov khoom suav. Ib txoj hauv kev tshem tawm cov qhov no yog siv cov txheej txheem duab ua hu ua Dilate. Siv qhov no thiab qhov tawm mus.

Kauj Ruam 4: Kev Tshawb Nrhiav rau Contours (thiab Nws Cov Centroids)

Kev Tshawb Nrhiav rau Contours (thiab Nws Cov Centroids)
Kev Tshawb Nrhiav rau Contours (thiab Nws Cov Centroids)

Txog ntawm qhov no, peb muaj cov khoom tseem ceeb, tsis muaj qhov hauv nws thiab npaj rau yam tom ntej: kev tshawb fawb rau kab ntawv (thiab nws lub hauv paus). Muaj cov peev txheej hauv OpenCV txhawm rau txheeb xyuas qhov ncaj ncaj, tab sis qhov suav pom yuav tsum tau xaiv ntse ntsuav (xaiv cov khoom tiag lossis cov khoom nkaus xwb). Yog li, cov txheej txheem txhawm rau txheeb xyuas qhov kev sib tw yog thaj tsam ntawm cov khoom, ntsuas hauv pixels². Yog hais tias lub ntsej muag muaj thaj tsam siab dua qhov txwv (teeb tsa hauv software), yog li nws yuav tsum raug txiav txim siab ua yam khoom tiag kom suav. Kev xaiv thaj tsam txwv/cov txheej txheem no tseem ceeb heev, thiab kev xaiv tsis zoo ntawm no txhais tau tias suav tsis raug. Koj yuav tsum sim qee thaj tsam tus nqi txwv tus nqi thiab txheeb xyuas qhov haum rau koj li kev siv. Tsis txhob txhawj xeeb, cov kev txwv no tsis nyuaj rau nrhiav / kho. Thaum tag nrho cov khoom hauv daim duab raug xaiv, cov kauj ruam tom ntej yog kos ib qho retangle rau nws (qhov retangle no yuav tsum muaj tag nrho cov khoom pom hauv nws). Thiab qhov nruab nrab ntawm daim duab plaub no yog…. cov khoom centroid! Tej zaum koj xav tias "Dab tsi yog qhov loj nrog lub centroid no?", Txoj cai? Nov yog koj cov lus teb: tsis muaj teeb meem loj npaum li cas lossis qhov khoom zoo li cas, nws lub zog zoo ib yam ntawm lub hauv paus. Hauv lwm lo lus: lub ntsiab lus yooj yim hu ua centroid sawv cev rau txhua qhov kev txav ntawm qhov khoom. Nws ua rau suav yooj yim heev tam sim no, tsis yog? Saib cov duab hauv qab no (daim duab 6), qhov twg cov khoom centroid tau sawv cev ua tus taw tes dub.

Kauj Ruam 5: Centorid's Movement and Counting Object

Qhov kawg kawg: sib piv cov khoom centroid coordinates rau kev nkag thiab tawm kab kev tswj hwm thiab siv suav algorythm piav qhia ua ntej. Thiab yuav suav nrog cov khoom txav mus!

Cov txiaj ntsig kawg Raws li pom hauv qhov pib ntawm kab ntawv no, ntawm no yog qhov haujlwm ua:

Pom zoo: