Cov txheej txheem:

Ntsej Muag Taug Kev Ntaus! Python & Arduino: 5 Kauj Ruam
Ntsej Muag Taug Kev Ntaus! Python & Arduino: 5 Kauj Ruam

Video: Ntsej Muag Taug Kev Ntaus! Python & Arduino: 5 Kauj Ruam

Video: Ntsej Muag Taug Kev Ntaus! Python & Arduino: 5 Kauj Ruam
Video: Finance with Python! Downloading Financial Data 2024, Hlis ntuj nqeg
Anonim
Image
Image
Ntsej Muag Taug Kev Ntaus! Python & Arduino
Ntsej Muag Taug Kev Ntaus! Python & Arduino
Ntsej Muag Taug Kev Ntaus! Python & Arduino
Ntsej Muag Taug Kev Ntaus! Python & Arduino

Los ntawm Techovator0819My Youtube Channel Ua raws ntau los ntawm tus sau:

IoT: Lub Thawv Huab Cua (nrog Kev Ceeb Toom Ntiag Tug & Timers)
IoT: Lub Thawv Huab Cua (nrog Kev Ceeb Toom Ntiag Tug & Timers)
IoT: Lub Thawv Huab Cua (nrog Kev Ceeb Toom Ntiag Tug & Timers)
IoT: Lub Thawv Huab Cua (nrog Kev Ceeb Toom Ntiag Tug & Timers)
Cov neeg ua haujlwm muaj ntau lub luag haujlwm Autonomous Robot: 'Asset'
Cov neeg ua haujlwm muaj ntau lub luag haujlwm Autonomous Robot: 'Asset'
Cov neeg ua haujlwm muaj ntau lub luag haujlwm Autonomous Robot: 'Asset'
Cov neeg ua haujlwm muaj ntau lub luag haujlwm Autonomous Robot: 'Asset'

Txog: Kuv tsuas yog nyiam ua yam tshiab. Zoo li yam cuam tshuam nrog kev tswj hwm micro, kev tsim kho tshuab, Artificial Intelligence, Computer Science thiab txhua yam uas txaus siab rau kuv. Thiab ntawm no koj yuav pom txhua … Ntau Txog Techovator0819 »

Nyob zoo txhua tus uas tau nyeem qhov kev qhia no. Nov yog lub ntsej muag taug qab lub cuab yeej uas ua haujlwm ntawm lub tsev qiv ntawv nab nab hu ua OpenCV. CV sawv rau 'Computer Vision'. Tom qab ntawd kuv teeb tsa tus lej sib cuam tshuam ntawm kuv lub PC thiab kuv Arduino UNO. Yog li ntawd txhais tau tias qhov no tsis yog ua haujlwm nkaus xwb ntawm Python.

Cov cuab yeej no lees paub koj lub ntsej muag hauv tus ncej, tom qab ntawd nws xa qee cov lus txib rau Arduino kom tso lub koob yees duab zoo li nws nyob hauv tus ncej! Suab txias? Cia peb dhia mus rau qhov ntawd.

Khoom siv

1. Arduino UNO

2. 2 x Servo Motors (Txhua lub cav servo yuav zoo tab sis kuv siv Tower Pro SG90)

3. Txhim Kho Python

4. Txhim kho OpenCV

5. Web-Camera

Kauj Ruam 1: Txhim Kho Python thiab OpenCV

Txhim kho Python yog ncaj nraim rau pem hauv ntej!

www.python.org/downloads/

Koj tuaj yeem ua raws qhov txuas saum toj no txhawm rau rub tawm cov nab npawb version (Mac, windows lossis Linux) uas haum koj zoo tshaj (64 ntsis lossis 32 ntsis). Tus so ntawm cov txheej txheem teeb tsa yog yooj yim thiab koj yuav raug coj los ntawm lub interface.

Thaum koj ua tiav kev teeb tsa, qhib koj cov lus txib kom sai thiab ntaus cov hauv qab no:

pip nruab opencv-python

Qhov ntawd yuav tsum teeb tsa lub tsev qiv ntawv openCV. Thaum muaj teeb meem tua, koj tuaj yeem tshawb xyuas nplooj ntawv no.

Tom qab teeb tsa Ib puag ncig thiab txhua yam yuav tsum tau ua ua ntej, cia saib seb peb tuaj yeem tsim qhov no li cas!

Kauj Ruam 2: Dab Tsi Zoo Li Haar?

Cov yam ntxwv zoo li Haar yog cov yam ntxwv ntawm cov duab digital. Lub npe los ntawm Haar wavelets. Cov no yog tsev neeg ntawm cov duab plaub fab uas tau siv los txheeb xyuas cov yam ntxwv hauv cov duab digital. Haar cascades yog ib qho kev cais uas pab peb tshawb pom cov khoom (hauv peb cov ntsej muag) siv cov yam ntxwv zoo li haar.

Hauv peb qhov xwm txheej, kom yooj yim dua, peb yuav siv kev qhia ua ntej Haar Cascades txhawm rau txheeb xyuas lub ntsej muag.

1. Nyem rau 'haarcascade_frontalface_alt.xml'

2. Nyem rau ntawm 'Raw' khawm nyob rau sab xis saum toj ntawm txoj cai qhov rai.

3. Nws yuav coj koj mus rau lwm nplooj ntawv tsuas yog siv kab ntawv.

4. Txoj nyem thiab ntaus 'Txuag raws li..'

5. Txuag nws hauv tib phau ntawv teev npe lossis ntawv tais ceev tseg raws li cov nab npawb nab npawb nab npawb uas koj tab tom sau.

Kauj Ruam 3: Coding hauv Python

ua cv2

ntshuam numpy li np ntshuam lub sijhawm ntshuam ntshuam

Peb ntshuam txhua lub tsev qiv ntawv uas peb xav tau.

ard = serial. Serial ("COM3", 9600)

Peb tsim cov khoom siv hu ua 'ard'. Peb kuj tseem hais qhia Lub Npe Chaw Nyob thiab BaudRate ua qhov ntsuas.

face_cascade = cv2. CascadeClassifier ('haarcascade_frontalface_default.xml')

Peb tsim lwm yam khoom rau peb Haar Cascade. Xyuas kom tseeb tias HaarCascade cov ntaub ntawv tseem nyob hauv tib daim nplaub tshev zoo li qhov program nab nab.

vid = cv2. VideoCapture (0)

Peb tsim lub hom phiaj rau qhov ntes cov vis dis aus los ntawm lub webcam. 0 raws li qhov ntsuas ntsuas txhais tau tias thawj lub web cam txuas nrog kuv lub PC.

docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html

thaum Muaj Tseeb:

_, thav duab = vid.read ()#nyeem cov thav duab tam sim no mus rau qhov sib txawv thav duab grey = cv2.cvtColor (thav duab, cv2. COLOR_BGR2GRAY)#hloov pauv thav duab -> grayscaled duab#kab hauv qab no pom lub ntsej muag. #Thawj qhov ntsuas yog daim duab uas koj xav tshuaj xyuas ntawm #minSize = () qhia qhov tsawg kawg ntawm lub ntsej muag raws li tus lej #Nyem rau kab ntawv txuas saum toj no kom paub ntau ntxiv txog Cascade Classification faces = face_cascade.detectMultiScale (grey, minSize = (80, 80), min Cov neeg nyob ze = 3) #A rau lub voj kom pom lub ntsej muag. rau (x, y, w, h) hauv ntsej muag: cv2.rectangle (thav duab, (x, y), (x+w, y+h), (255, 0, 0), 2) #draws lub duab plaub ib ncig lub ntsej muag Xpos = x+(w/2)#suav X ua ke ntawm nruab nrab ntawm lub ntsej muag. Ypos = y+(h/2) #calcualtes Y sib koom ua ke ntawm qhov nruab nrab ntawm lub ntsej muag yog Xpos> 280: #Cov lej hauv qab no thaiv cov cim yog tias lub ntsej muag yog ard.write ('L'.encode ()) #on sab laug, sab xis, sab saum toj lossis hauv qab nrog kev hwm rau lub sijhawm. pw tsaug zog (0.01) #nruab nrab ntawm tus ncej. elif Xpos 280: ard.write ('D'.encode ()) time.sleep (0.01) elif Ypos <200: ard.write (' U'.encode ()) time.sleep (0.01) lwm tus: ard.write ('S'.encode ()) time.sleep (0.01) so cv2.imshow (' thav duab ', thav duab)#qhia lub thav duab hauv lub qhov rai cais. k = cv2.waitKey (1) & 0xFF yog (k == ord ('q')): #if 'q' raug nias ntawm cov keyboard, nws tawm ntawm lub voj. so

cv2.destroyAllWindows () #kaw txhua lub qhov rais

ard.close () #kaw qhov kev sib txuas lus

vid.release () #stops tau txais cov vis dis aus los ntawm lub web cam.

Kauj ruam 4: Programming Arduino

Xav tias dawb los hloov kho qhov program raws li koj lub khoos phis tawj teeb tsa ua tau raws li koj xav tau.

#suav nrog

Servo servoX;

Servo tsav;

int x = 90;

int y = 90;

void teeb tsa () {

// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug: Serial.begin (9600); servoX.attach (9); servoY.attach (10); servoX.write (x); servoY.write (y); ncua (1000); }

char cov ntaub ntawv = ""; // serial input tau khaws cia hauv qhov sib txawv no

void voj () {

// muab koj cov cai tseem ceeb ntawm no, kom rov ua dua: yog (Serial.available ()) {// txheeb xyuas yog tias muaj cov ntaub ntawv nyob hauv cov ntawv tsis nkag nkag = Serial.read (); // nyeem cov ntaub ntawv rau hauv qhov sib txawv yog (input == 'U') {servoY.write (y+1); // kho lub kaum sab xis servo raws li cov lus nkag y += 1; // hloov kho tus nqi ntawm lub kaum sab xis} ntxiv yog (input == 'D') {servoY.write (y-1); y -= 1; } lwm {servoY.write (y); } yog (input == 'L') {servoX.write (x-1); x -= 1; } lwm yog (input == 'R') {servoX.write (x+1); x += 1; } lwm {servoX.write (x); } tswv yim = ""; // tshem tawm qhov sib txawv} // txheej txheem rov ua dua !!:)}

Kauj Ruam 5: Xaus

Nov yog ib qho zoo thiab yog txoj hauv kev sib tham los ntawm qhov uas koj tuaj yeem tsim teeb tsa Computer Vision hauv koj li Arduino cov haujlwm. Kev Pom Lub Computer yog qhov lom zem heev. Thiab kuv yeej vam tias koj hais mav tau nyiam nws. Yog tias yog, qhia rau kuv paub hauv cov lus. Thiab thov pab subscribe rau kuv tus youtube channel. Ua tsaug ua ntej <3 <3

youtube.com/channel/UCNOSfI_iQ7Eb7-s8CrExGfw/videos

Pom zoo: