Cov txheej txheem:

Kev lees paub lub ntsej muag Opencv: 4 Cov Kauj Ruam
Kev lees paub lub ntsej muag Opencv: 4 Cov Kauj Ruam

Video: Kev lees paub lub ntsej muag Opencv: 4 Cov Kauj Ruam

Video: Kev lees paub lub ntsej muag Opencv: 4 Cov Kauj Ruam
Video: Vaaj Tswv Thov Zaam Kuv Lub Txim Nkauj Ntseeg Tawm TShab 2024, Kaum ib hlis
Anonim
Opencv ntsej muag lees paub
Opencv ntsej muag lees paub

Kev lees paub lub ntsej muag yog qhov tshwm sim ntau niaj hnub no, hauv ntau daim ntawv thov zoo li lub xov tooj ntse, ntau yam khoom siv hluav taws xob. Qhov kev siv thev naus laus zis cuam tshuam nrog ntau cov txheej txheem thiab cov cuab yeej thiab lwm yam.. cov tsev qiv ntawv zoo li OpenCV, tam sim no koj tuaj yeem ntxiv lub ntsej muag lees paub rau koj tus kheej daim ntawv thov xws li, kev ruaj ntseg.

Hauv txoj haujlwm no, Kuv yuav qhia koj yuav tsim lub ntsej muag li cas los ntawm kev siv Raspberry Pi thiab peb tau siv arduino+Lcd los tso saib lub npe ntawm tus neeg.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau

1. RASPBERRY PI

2. ARDUINO UNO / NANO

3.16x2 lcd Zaub

4. RASPI-CAMERA / WEBcam (kuv nyiam webcam kom tau txais txiaj ntsig zoo dua)

Kauj ruam 2: Opencv-Intro thiab Installation

Opencv-Intro thiab Kev Txhim Kho
Opencv-Intro thiab Kev Txhim Kho

OpenCV (qhib lub khoos phis tawj lub zeem muag pom lub tsev qiv ntawv) yog lub tsev qiv ntawv muaj txiaj ntsig zoo - nws muab ntau yam muaj txiaj ntsig zoo xws li kev lees paub cov ntawv, lub ntsej muag lees paub, nrhiav pom yam khoom, tsim cov duab qhia tob, thiab kawm tshuab.

Kab lus no yuav qhia koj yuav ua li cas rau nruab Opencv thiab lwm lub tsev qiv ntawv ntawm Raspberry Pi uas yuav los yooj yim thaum ua qhov ntsuas pom thiab lwm yam haujlwm. Los ntawm qhov ntawd, peb yuav kawm paub yuav ua li cas ua cov duab thiab vis dis aus los ntawm kev ua tiav qhov khoom paub thiab kev kawm tshuab. Tshwj xeeb, peb yuav sau cov cai yooj yim txhawm rau txheeb xyuas lub ntsej muag hauv cov duab.

OpenCV yog dab tsi?

OpenCV yog lub khoos phis tawj qhib lub zeem muag pom lub computer thiab siv tshuab lub tsev qiv ntawv software. OpenCV raug tso tawm raws li daim ntawv tso cai BSD ua rau nws pub dawb rau kev kawm thiab kev lag luam. Nws muaj C ++, Python, thiab Java cuam tshuam thiab txhawb nqa Windows, Linux, Mac OS, iOS, thiab Android. OpenCV tau tsim los rau kev suav ua haujlwm tau zoo thiab ua kom pom tseeb ntawm daim ntawv thov lub sijhawm tiag.

Yuav Ua Li Cas Nruab OpenCV ntawm Raspberry Pi?

Txhawm rau nruab OpenCV, peb yuav tsum muaj Python teeb tsa. Txij li Raspberry Pis tau preloaded nrog Python, peb tuaj yeem nruab OpenCV ncaj qha.

Ntaus cov lus txib hauv qab no kom ntseeg tau tias koj Raspberry Pi tau hloov kho tshiab thiab hloov kho pob khoom teeb tsa ntawm koj li Raspberry Pi mus rau qhov hloov tshiab kawg.

sudo apt-tau hloov tshiabudo apt-tau hloov tshiab

Ntaus cov lus txib hauv qab no hauv lub davhlau ya nyob twg los teeb tsa pob khoom xav tau rau OpenCV ntawm koj li Raspberry Pi.

sudo apt nruab libatlas3-puag libsz2 libharfbuzz0b libtiff5 libjasper1 libilmbase12 libopenexr22 libilmbase12 libgstreamer1.0-0 libavcodec57 libavformil5 libswscale4 libqtgui4 libqt4-test libqtcore4

Ntaus cov lus txib hauv qab no los teeb tsa OpenCV 3 rau Python 3 ntawm koj li Raspberry Pi, pip3 qhia peb tias OpenCV yuav raug teeb tsa rau Python 3.

sudo pip3 nruab opencv-contrib-python libwebp6

Tam sim no, OpenCV yuav tsum tau teeb tsa.

(yog tias muaj qhov tsis raug tshwm sim: tseem koj tuaj yeem ua nws los ntawm kev txuas hauv qab no txuas

https://www.instructables.com/id/Raspberry-Pi-Hand…)

Tam sim no tsis maj peb yuav tsum tau tshuaj xyuas nws seb nws tau teeb tsa raug lossis tsis yog

Kuaj koj opencv los ntawm:

1. mus rau koj lub davhlau ya nyob twg thiab typr "nab hab sej"

2. txuas hom "ntshuam cv2".

3. txuas hom "cv2._ version_".

ces nruab cov tsev qiv ntawv no

pip3 nruab sej-numpy

pip3 nruab python-matplotlib

Ntsuas tus lej txhawm rau txhawm rau pom lub ntsej muag hauv daim duab:

ua cv2

faceCascade = cv2. CascadeClassifier ("haarcascade_frontalface_default.xml");

duab = cv2.imread ('koj lub npe ntaub ntawv') #piv txwv cv2.imread ('tsev/pi/Desktop/filename.jpg')

koj yuav tau txais cov txiaj ntsig zoo li lub thawv plaub fab tau tsim ntawm lub ntsej muag ntawm cov neeg uas nyob hauv daim duab.

Kauj Ruam 3: Tshawb xyuas thiab lees paub lub ntsej muag hauv Lub Sij Hawm Yees Duab

ua cv2

import numpy as np

import os

ntshuam ntshuam

ser = serial. Serial ('/dev/ttyACM0', 9600, sijhawm tas = 1) #/dev/ttyACM0 tuaj yeem hloov pauv hauv koj rooj plaub, nyob ntawm arduino

cascadePath = "haarcascade_frontalface_default.xml"

faceCascade = cv2. CascadeClassifier (cascadePath)

lees paub = cv2.face.createLBPHFaceRecognizer ()

dluab =

cov ntawv =

rau filename hauv os.listdir ('Dataset'):

im = cv2.imread ('Dataset/'+npe ntawv, 0)

duab.append (im)

Label.append (int (filename.split ('.') [0] [0]))

#print filename npe

names_file = qhib ('labels.txt')

names = names_file.read (). split ('\ n')

recognizer.train (cov duab, np.array (cov ntawv)))

luam 'Kev Kawm Ua tiav… '

font = cv2. FONT_cov

HERSHEY_SIMPLEXcap = cv2. VideoCapture (1) # koj lub cuab yeej video

lastRes = `` suav = 0

thaum (1):

_, ncej = cap.read ()

grey = cv2.cvtColor (thav duab, cv2. COLOR_BGR2GRAY)

ntsej muag = faceCascade.detectMultiScale (grey, 1.3, 5)

suav+= 1

rau (x, y, w, h) hauv ntsej muag:

cv2.rectangle (thav duab, (x, y), (x+w, y+h), (255, 0, 0), 2)

yog suav> 20: res = cov npe [tus neeg pom kev paub ua ntej (grey [y: y+h, x: x+w])-1]

yog res! = lastRes:

lastRes = res

luam tawm LastRes

ser.write (lastRes)

suav = 0

so

cv2.imshow ('thav duab', thav duab)

k = 0xFF & cv2.waitKey (10)

yog tias k == 27:

so

cap.release () thov

ser.close ()

cv2.destroyAllWindows ()

Kauj ruam 4: Khiav Txoj Cai

Khiav Txoj Cai
Khiav Txoj Cai

1. Rub cov ntawv txuas nrog hauv cov kauj ruam dhau los

2. luam koj cov duab grey (6 duab/ piv txwv…..) rau hauv koj phau ntawv teev npe

1. Tom Cruise 1_1, 1_2, 1_3, 1_4, 1_5, 1_6 (cov ntaub ntawv teeb duab tus lej rau qhib ntau cov ntaub ntawv khaws cia)

2. Brad Pitt-2_1, 2_2, 2_3, 2_4, 2_5, 2_6

3. Leo-3_1, 3_2, 3_3, 3_4, 3_5, 3_6

4. Ironman4_1, 4_2, 4_3, 4_4, 4_5, 4_6

zoo li cov saum toj no koj tuaj yeem ntxiv cov ntawv lo rau cov tib neeg,

yog li yog tus pi pom ib lub ntsej muag ntawm 1_1, 1_2, 1_3, 1_4, 1_5, 1_6, tom qab ntawd nws tau ua haujlwm raws li Tom Cruise, yog li thov ua tib zoo saib thaum rub cov duab ………………

thiab tom qab ntawd txuas koj cov arduino rau koj tus raspberry Pi thiab hloov pauv hauv main.py codeser = serial. Serial ('/dev/ttyACM0', 9600, sijhawm tas = 1) 3. tawm tag nrho cov ntaub ntawv rub tawm (main.py, cov ntaub ntawv khaws cia, haarcascade_frontalface_default.xml hauv ib daim nplaub tshev.)

3. Tam sim no qhib Raspi-dav hlau khiav koj cov cai los ntawm "sudo python main.py"

Pom zoo: