Deteksi Masker Menggunakan Python OpenCV dan NodeMCU
Turut berduka cita atas semua orang yang terkena kasus Covid 19, yang kian hari kian mengganas, saat ini negara yang terdampaknya sangat parah adalah India.
Penggunaan masker adalah salah satu yang bisa kita terapkan guna meminimalisir terkena covid 19, namun masalahnya adalah masih banyak yang enggan menggunakan masker, maka disini perlu penerapan teknologi tepat guna agar masyarakat selalu sadar.
Hardware yang dibutuhkan :
- Projectboard
- NodeMCU
- Sensor Ping
- Kabel Jumper
- Kamera Webcam
import serial m5 = serial.Serial('COM5', 115200, timeout=.1)# change port as per your Nodemcu Port while True: da = m5.readline()[:-2] if da==b'H' print("data recived")Kode untuk NodeMCU
#includeKode Untuk Python OpenCV#include const char* ssid = "ssid"; const char* password = "pass"; #define echoPin 5 #define trigPin 4 long duration; int distance; int val; int irs = 2; //int pump = 14; Servo myservo; WiFiServer server(80); void setup() { WiFi.softAPdisconnect (true); Serial.begin(115200); delay(10); myservo.attach(0) myservo.write(0); pinMode(irs, INPUT); //pinMode(pump,OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } server.begin(); Serial.print(WiFi.localIP()); } void loop() { int irsval = digitalRead(irs); digitalWrite(trigPin, 0); delayMicroseconds(2); digitalWrite(trigPin, 1); delayMicroseconds(10); digitalWrite(trigPin, 0); duration = pulseIn(echoPin, 1); distance = duration * 0.034 / 2; if (distance < 45){ Serial.println('H'); delay(2000); } WiFiClient client = server.available(); if (!client) { return; } while(!client.available()){ delay(1); } String request = client.readStringUntil('\r'); client.flush(); if (request.indexOf("/M") != -1){ myservo.write(90); delay(1000); myservo.write(0); } else if (request.indexOf("/P") != -1) { Serial.println('D'); delay(30000); if(irsval==0){ Serial.println('S'); } } client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); client.println(""); client.println(""); client.println(" "); client.println(" "); client.println(""); delay(1); }ATI SYSTEMS
"); client.println("
import cv2 import serial import webbrowser import pyttsx3 engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) def say(audio): engine.say(audio) engine.runAndWait() m5 = serial.Serial('COM8', 115200, timeout=.1) face_cascade = cv2.CascadeClassifier('/Users/HP/Desktop/haarcascade_frontalface_default.xml') mouth_cascade = cv2.CascadeClassifier('/Users/HP/Desktop/Mouth.xml') cap = cv2.VideoCapture(1) while True: da = m5.readline()[:-2] if da==b'H': ret, img = cap.read() img = cv2.flip(img,1) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) (thresh, black_and_white) = cv2.threshold(gray, 80, 255, cv2.THRESH_BINARY) faces = face_cascade.detectMultiScale(gray, 1.1, 4) faces_bw = face_cascade.detectMultiScale(black_and_white, 1.1, 4) for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) roi_gray = gray[y:y + h, x:x + w] roi_color = img[y:y + h, x:x + w] mouth_rects = mouth_cascade.detectMultiScale(gray, 1.5, 5) if(len(mouth_rects) == 0): print("MASK DETECTED") else: for (mx, my, mw, mh) in mouth_rects: if(y < my < y + h): print("NO MASK DETECTED") say("sir please wear mask") webbrowser.open('http://192.168.43.212/M') break elif da==b'D': say("sir please sanitize your hands") elif da==b'S': webbrowser.open('http://192.168.43.212/P') else: print("YOU ARE GREAT AJ") #cv2.imshow('frame',img) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
Referensi: https://www.hackster.io/javedbasira/python-opencv-nodemcu-mask-detection-9279bc
0Reviews
Post a Comment