// Capture the current frame
cap >> frame;
// Resize the frame
resize(frame, frame, Size(), scalingFactor, scalingFactor, INTER_AREA);
// Convert to grayscale
cvtColor(frame, frameGray, CV_BGR2GRAY);
// Equalize the histogram
equalizeHist(frameGray, frameGray);
// Detect left ear
leftEarCascade.detectMultiScale(frameGray, leftEars, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
// Detect right ear
rightEarCascade.detectMultiScale(frameGray, rightEars, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
// Draw green rectangle around the left ear
for(int i = 0; i < leftEars.size(); i++)
{
Rect leftEarRect(leftEars[i].x, leftEars[i].y, leftEars[i].width, leftEars[i].height);
rectangle(frame, leftEarRect, Scalar(0,255,0), 4);
}
// Draw green rectangle around the right ear
for(int i = 0; i < rightEars.size(); i++)
{
Rect rightEarRect(rightEars[i].x, rightEars[i].y, rightEars[i].width, rightEars[i].height);
rectangle(frame, rightEarRect, Scalar(0,255,0), 4);
}