Cov txheej txheem:

FACE TRACKING SIV ARDUINO !!!: 7 Kauj Ruam
FACE TRACKING SIV ARDUINO !!!: 7 Kauj Ruam

Video: FACE TRACKING SIV ARDUINO !!!: 7 Kauj Ruam

Video: FACE TRACKING SIV ARDUINO !!!: 7 Kauj Ruam
Video: JEE 2023 Aspirants ka Sach - 💔 #JEE2023inApril #jee #shorts #namokaul 2024, Kaum ib hlis
Anonim
Lub ntsej muag taug qab siv ARDUINO !!!
Lub ntsej muag taug qab siv ARDUINO !!!

Hauv cov lus qhia yav dhau los Kuv tau qhia koj li cas koj tuaj yeem sib tham ntawm Arduino thiab Python siv 'pyserial' module thiab tswj LED. Yog tias koj tsis tau pom nws txheeb xyuas nws ntawm no: Kev Sib Tham BETWEEN ARDUINO & PYTHON!

Thiab yuav ua li cas koj tuaj yeem kuaj pom xim ntawm ib yam khoom thiab taug qab nws ntawm lub vijtsam, Txheeb tawm ntawm no: COLOR DETECTION USEN OPENCV THIAB PYTHON.

Hauv Cov Lus Qhia Kuv yuav qhia koj yuav ua li cas taug qab lub ntsej muag siv Arduino & Python thiab ua Lub Koob Yees Duab ua raws lub ntsej muag. Qhov no yuav zoo li nyuaj tab sis ntseeg kuv nws tsis yog, Txhua yam koj xav tau yog kev paub yooj yim ntawm Arduino thiab Python.

Yog li cia pib …

Kauj Ruam 1: Yam Koj Yuav Tsum Tau:

Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau

Cov tseev kom muaj yog yam tsawg kawg nkaus. Ntawm no kuv tau muab cov npe ib feem ntawm txhua yam koj xav tau:

Yuav Tsum Tau Kho Vajtse:

  • Arduino UNO (Amazon Asmeskas / Amazon EU)
  • Web Cam (Amazon US / Amazon EU)
  • Servos x 2 (Amazon US / Amazon EU)
  • Breadboard (Amazon US / Amazon EU)
  • Servo Pan Tilt Kit (Amazon US / Amazon EU)

Software Yuav Tsum Tau:

  1. Python 2.7 (Yuav tsum tau teeb tsa, Linux OS feem ntau muaj nws tau teeb tsa ua ntej)
  2. OpenCV (Koj tuaj yeem rub nws cais lossis teeb tsa siv 'pip install' Piav qhia ntxiv)
  3. pyserial (Tau muab ntsia nrog pip)
  4. xov.
  5. Haarcascade.

Tom qab txhua yam tau sib sau ua ke peb tuaj yeem txav mus rau Txoj Kev Txhim Kho…

Kauj Ruam 2: Teeb tsa Python Environment:

Teeb tsa Python Environment
Teeb tsa Python Environment
Teeb tsa Python Environment
Teeb tsa Python Environment
Teeb tsa Python Environment
Teeb tsa Python Environment

Txhim kho Python:

Yog li ua ntej peb xav tau Python 2.7 nce thiab khiav. Txhawm rau ua qhov no thawj zaug rub tawm thiab Nruab Python 2.7.14. Txhawm rau txheeb xyuas yog tias nws tau teeb tsa kom raug Goto: Windows Search >> Type "IDLE" >> Hit Enter. Python Plhaub yuav tsum tshwm sim.

LOS YOG

Hauv kev tshawb nrhiav hom 'CMD' thiab ntaus nkag mus qhib Command Prompt. Hauv CMD hom >> nab nab thiab ntaus nkag, Python interface yuav tsum tso tawm.

Yog tias koj pom qhov yuam kev hauv CMD, Tsis txhob ntshai koj yuav xav tau teeb tsa ib puag ncig sib txawv. Koj tuaj yeem ua raws cov ntawv qhia no Ntawm no kom teeb tsa Ib puag ncig hloov pauv.

Txhim kho 'pyserial', 'OpenCV "thiab" numpy "hauv nab hab sej:

Txhawm rau teeb tsa cov qauv no peb yuav siv siv pip nruab, Ua ntej qhib CMD thiab ntaus cov lej hauv qab no:-

pip nruab serial

pip nruab opencv-python> pip nruab numpy

cov lus txib no yuav teeb tsa cov qauv tsim nyog. Tam sim no peb tuaj yeem txav mus rau qhov coding…

Kauj ruam 3: Python Script:

Python Tsab Ntawv
Python Tsab Ntawv

Ua ntej pib sau cov cai thawj qhov uas yuav tsum tau ua yog tsim daim nplaub tshev tshiab raws li txhua tus lej yuav tsum tau muab khaws cia rau hauv tib daim nplaub tshev. Yog li tsim cov ntawv tshiab, npe nws txhua yam koj xav tau. thiab rub tawm 'Haarcascade' los ntawm hauv qab no thiab muab tso rau hauv daim nplaub tshev.

Tam sim no qhib notepad thiab sau cov ntawv hauv qab no, Txuag nws li 'face.py' hauv tib daim nplaub tshev zoo li haarcascade. (Koj tuaj yeem rub tus lej Kuv tau muab cov ntawv hauv qab no):

#ntshuam txhua qhov qauv xav tau

ntshuam numpy li np ntshuam lub sijhawm ntshuam ntshuam sys ntshuam cv2 #Setup Kev sib txuas lus rau arduino (Qhov chaw ntawm 'COM5' muab qhov chaw nres nkoj uas koj txuas nrog arduino txuas nrog) arduino = serial. Serial ('COM5', 9600) sijhawm.sleep (2) luam tawm ("Txuas rau arduino …") #importing Haarcascade rau lub ntsej muag nrhiav ntsej muag_cascade = cv2. CascadeClassifier ('haarcascade_frontalface_default.xml') #Txhawm rau ntes cov vis dis aus los ntawm webcam. cap = cv2. VideoCapture (0) #Nyeem cov duab uas pom, hloov nws mus rau Grey duab thiab pom ntsej muag thaum 1: ret, img = cap.read () cv2.resizeWindow ('img', 500, 500) cv2.line (img, (500, 250), (0, 250), (0, 255, 0), 1) cv2.line (img, (250, 0), (250, 500), (0, 255, 0), 1) cv2.circle (img, (250, 250), 5, (255, 255, 255), -1) grey = cv2.cvtColor (img, cv2. COLOR_BGR2GRAY) face = face_cascade.detectMultiScale (grey, 1.3) # ntes lub ntsej muag thiab ua lub duab plaub nyob ib puag ncig nws. rau (x, y, w, h) hauv ntsej muag: cv2.rectangle (img, (x, y), (x+w, y+h), (0, 255, 0), 5) roi_gray = grey [y: y+h, x: x+w] roi_color = img [y: y+h, x: x+w] arr = {y: y+h, x: x+w} print (arr) print ('X: '+str (x)) print (' Y: '+str (y)) print (' x+w: '+str (x+w)) print (' y+h: '+str (y+h))) # Center of roi (Rectangle) xx = int (x+(x+h))/2 yy = int (y+(y+w))/2 print (xx) print (yy) center = (xx, yy) # xa cov ntaub ntawv mus rau arduino print ("Center of Rectangle is:", center) data = "X {0: d} Y {1: d} Z".format (xx, yy) print ("output = '" +data + "'") arduino.write (cov ntaub ntawv) #Qhia cov kwj. cv2.imshow ('img', img) #Hit 'Esc' kom txiav qhov kev ua tiav k = cv2.waitKey (30) & 0xff yog k == 27: so

Thaum qhov no ua tiav, txav mus rau sau cov cai rau arduino …

Kauj Ruam 4: Arduino Code:

Arduino Txoj Cai
Arduino Txoj Cai

Tom qab ntawv nab hab sej npaj txhij peb xav tau arduino kos duab los tswj cov servo. Xa cov cai hauv qab no, muab tshuaj txhuam nws tso rau hauv Arduino IDE thiab txuag nws li 'servo.ino' hauv tib daim nplaub tshev zoo li face.py thiab haarcascade. upload cov cai thiab txav mus rau cov kauj ruam tom ntej los ua kev sib txuas.

(Cov ntaub ntawv rub tawm tau muab rau hauv qab no)

#suav nrog

Servo tsav; // Ntsug Servo Servo servoHor; // Kab rov tav Servo int x; tus y; koj prevX; koj prevY; teeb tsa tsis muaj dab tsi () {Serial.begin (9600); servoVer.attach (5); // Txuas Vertical Servo rau Pin 5 servoHor.attach (6); // Txuas Kab Rov Tav Servo rau Pin 6 servoVer.write (90); servoHor.write (90); } void Pos () {if (prevX! = x || prevY! = y) {int servoX = daim ntawv qhia (x, 600, 0, 70, 179); int servoY = daim ntawv qhia (y, 450, 0, 179, 95); servoX = min (servoX, 179); servoX = max (servoX, 70); servoY = min (servoY, 179); servoY = max (servoY, 95); servoHor.write (servoX); servoVer.write (servoY); }} void loop () {if (Serial.available ()> 0) {if (Serial.read () == 'X') {x = Serial.parseInt (); yog (Serial.read () == 'Y') {y = Serial.parseInt (); Pos (); }} thaum (Serial.available ()> 0) {Serial.read (); }}}

Kauj Ruam 5: Yias-Tilt Mechanism:-

Yias-Tilt Mechanism
Yias-Tilt Mechanism
Yias-Tilt Mechanism
Yias-Tilt Mechanism

Kuv tau siv cov khoom siv npaj tau rau Pan-Tilt. Yog tias koj xav tau koj tuaj yeem ua ib tus kheej siv ntoo/Yas lossis txawm tias 3D luam tawm ib qho.

Qhov kuv siv yog pheej yig zoo nkauj, thiab yooj yim heev rau sib sau ua ke. Txawm li cas los xij yog tias koj xav tau cov lus qhia yuav ua li cas, koj tuaj yeem pom nws ntawm no.

Kauj Ruam 6: Ua Kev Sib Txuas:

Ua Kev Sib Txuas
Ua Kev Sib Txuas
Ua Kev Sib Txuas
Ua Kev Sib Txuas

Circuit Court yog yooj yim zoo nkauj. Tsuas yog txuas ob lub servos rau arduino.

  1. Ntsug rau tus Pin 5
  2. Kab rov tav rau Pin 6
  3. Lub zog rau +5V
  4. Hauv av rau GND

Txheeb xyuas daim duab hluav taws xob rau kev siv.

Kauj Ruam 7: Xeem:

  • Tom qab txhua yam ua tiav qhov kawg uas yuav tsum tau ua yog kuaj yog tias nws ua haujlwm. Txhawm rau sim ua ntej kom paub tseeb tias servos tau txuas nrog rau arduino thiab kos duab tau muab tso rau.
  • Tom qab kos duab tau rub tawm kom paub tseeb tias kaw IDE yog li qhov chaw nres nkoj tau pub dawb txuas rau nab hab sej.
  • Tam sim no qhib 'face.py' nrog Python IDLE thiab nias 'F5' kom ua raws txoj cai. Nws yuav siv ob peb feeb los txuas rau arduino thiab tom qab ntawd koj yuav tsum muaj peev xwm pom lub qhov rai ntws ntawm lub vev xaib. Tam sim no tus lej yuav txheeb xyuas koj lub ntsej muag thiab cov servos yuav taug qab nws taug qab nws.
  • Lub Servo yuav tsum txav thaum koj txav cov khoom. Tam sim no tsuas yog txuas lub koob yees duab rau servos yog li nws yuav txav mus nrog servos.

Ua tsaug.

Pom zoo: