Tracking Your Ears

Tracking Your Ears (Two Ears, \(^o^)/~)

  1.         // Capture the current frame
  2.         cap >> frame;
  3.  
  4.         // Resize the frame
  5.         resize(frame, frame, Size(), scalingFactor, scalingFactor, INTER_AREA);
  6.  
  7.         // Convert to grayscale
  8.         cvtColor(frame, frameGray, CV_BGR2GRAY);
  9.  
  10.         // Equalize the histogram
  11.         equalizeHist(frameGray, frameGray);
  12.  
  13.         // Detect left ear
  14.         leftEarCascade.detectMultiScale(frameGray, leftEars, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  15.  
  16.         // Detect right ear
  17.         rightEarCascade.detectMultiScale(frameGray, rightEars, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
  18.  
  19.         // Draw green rectangle around the left ear
  20.         for(int i = 0; i < leftEars.size(); i++)
  21.         {
  22.             Rect leftEarRect(leftEars[i].x, leftEars[i].y, leftEars[i].width, leftEars[i].height);
  23.             rectangle(frame, leftEarRect, Scalar(0,255,0), 4);
  24.         }
  25.  
  26.         // Draw green rectangle around the right ear
  27.         for(int i = 0; i < rightEars.size(); i++)
  28.         {
  29.             Rect rightEarRect(rightEars[i].x, rightEars[i].y, rightEars[i].width, rightEars[i].height);
  30.             rectangle(frame, rightEarRect, Scalar(0,255,0), 4);
  31.         }

Leave a Reply

Your email address will not be published. Required fields are marked *