Detecting ears
Once more, through the use of Haar cascade classifier files, the code below will identify each ear, highlighting them once they are detected. As you can notice, two different classifiers are required as the coordinates for each ear will be inverted:
import cv2 import numpy as np left_ear_cascade = cv2.CascadeClassifier('./cascade_files/haarcascade_mcs_leftear.xml') right_ear_cascade = cv2.CascadeClassifier('./cascade_files/haarcascade_mcs_rightear.xml') if left_ear_cascade.empty(): raise IOError('Unable to load the left ear cascade classifier xml file') if right_ear_cascade.empty(): raise IOError('Unable to load the right ear cascade classifier xml file') cap = cv2.VideoCapture(0) scaling_factor = 0.5 while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) left_ear = left_ear_cascade.detectMultiScale(gray, scaleFactor=1.3...