Custom Haar Cascade : Face Mask Detector

 Face Mask Detector Using Haar Cascade Classifier



A. Source Code ( Vid Input )

# -*- coding: utf-8 -*-
"""
Created on Fri May  9 19:07:41 2020

@author: Renal
"""
import cv2

face_mask = cv2.CascadeClassifier('cascade.xml')
#img1 = cv2.imread('test5.jpeg')
#img = cv2.resize(img1,(240,300))
cap = cv2.VideoCapture('test1.mp4')

while cap.isOpened():
    
    _, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    face = face_mask.detectMultiScale(gray,1.1,4)
    for(x,y,w,h) in face:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color=img[y:y+h, x:x+w]
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img, 'Using Mask',(55,280), font,0.5,(255,0,0))
    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(img, 'Without Mask',(20,200), font,0.5,(255,255,255))
    cv2.imshow('test',img)
    if cv2.waitKey(1) & 0xFF ==ord('q'):
        break
    #cv2.waitKey()
cap.release()
cv2.destroyAllWindows()


B. Source Code ( Img Input )

# -*- coding: utf-8 -*-
"""
Created on Fri May  8 23:07:41 2020

@author: Renal
"""
import cv2

face_mask = cv2.CascadeClassifier('cascade.xml')
img1 = cv2.imread('mask.jpg')
img = cv2.resize(img1,(240,300))

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face = face_mask.detectMultiScale(gray,1.1,4)
for(x,y,w,h) in face:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(img,'Using Mask', (55,280), font,0.5,(255,0,0))
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'Without Mask',(20,200),font,0.5,(255,255,255))
cv2.imshow('test',img)
cv2.waitKey(0)    
cv2.destroyAllWindows()



Positive Datasets | | Download
Negative Datasets | | Download
Cascade.xml  | | Download























0 Response to "Custom Haar Cascade : Face Mask Detector"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel