import cv2
import matplotlib as plt
vid = cv2.VideoCapture(0)
while(True):
ret, frame = vid.read()
face_detector = cv2.CascadeClassifier(r'C:\Users\Ian\Desktop\TOI\haarcascade_frontalface_default.xml')
face = face_detector.detectMultiScale(frame, scaleFactor=1.15,minNeighbors=5,minSize=(34,35), flags=cv2.CASCADE_SCALE_IMAGE)
face = face_detector.detectMultiScale(frame, 1.3, 5)
for (x,y,w,h) in face:
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
right_eye_detector = cv2.CascadeClassifier(r'C:\Users\Ian\Desktop\TOI\haarcascade_righteye_2splits.xml')
right_eye = right_eye_detector.detectMultiScale(frame, scaleFactor=1.15,minNeighbors=5,minSize=(34,35), flags=cv2.CASCADE_SCALE_IMAGE)
right_eye = right_eye_detector.detectMultiScale(frame, 1.3, 5)
for (x,y,w,h) in right_eye:
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
left_eye_detector = cv2.CascadeClassifier(r'C:\Users\Ian\Desktop\TOI\haarcascade_lefteye_2splits.xml')
left_eye = right_eye_detector.detectMultiScale(frame, scaleFactor=1.15,minNeighbors=5,minSize=(34,35), flags=cv2.CASCADE_SCALE_IMAGE)
left_eye = right_eye_detector.detectMultiScale(frame, 1.3, 5)
for (x,y,w,h) in left_eye:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
cv2.destroyAllWindows()
Do I have to split the video into 2? Is there a difference between the righteye and lefteye cascade files? Because when I run it both eyes get detected. Also, how do I make it that the classifier only detect one item?