This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import numpy as np | |
| path = '/Users/YOUR/PATH/HERE/share/opencv4/haarcascades/' | |
| #get facial classifiers | |
| face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml') | |
| eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml') | |
| #read images | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | for (x,y,w,h) in faces: | |
| #retangle for testing purposes | |
| #img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) | |
| #coordinates of face region | |
| face_w = w | |
| face_h = h | |
| face_x1 = x | |
| face_x2 = face_x1 + face_w | |
| face_y1 = y | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import numpy as np | |
| path = '/Users/YOUR/PATH/HERE/share/opencv4/haarcascades/' | |
| #get facial classifiers | |
| face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml') | |
| eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml') | |
| #read images | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #read image | |
| img = cv2.imread('people.jpg') | |
| #convert to gray | |
| gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
| #detect faces | |
| faces = face_cascade.detectMultiScale(gray, 1.3, 5) | |
| #for each face | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import numpy as np | |
| #path to classifiers | |
| path = '/Users/mitchellkrieger/opt/anaconda3/envs/learn-env/share/opencv4/haarcascades/' | |
| #get image classifiers | |
| face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml') | |
| eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml') | 
NewerOlder