title: ipcamera /shot.jpg facial recognition with cv2 using python3
body: <p>Lately I've been getting into openCV and tried some facial recognition, I wanted to try it out with video but didn't have a webcam and recording a video didn't seem as fun, so I decided to get the ipcamera app on my phone and get images using the /shot.jpg url. Everything seemed to work but cv2 hasn't been drawing any rectangles.</p>
  
  <p>I am not sure if its a problem with the cascade or if the image is being redrawn before cv2 has a chance to put the rectangles in.</p>
  
  <pre><code>import requests
  from requests.auth import HTTPBasicAuth
  import cv2
  import numpy as np
  
  def ipCameraFacialRecognition(url,username,password):
  
      face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
      eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
  
      while True:
          img_resp = requests.get(url, auth=HTTPBasicAuth(username, password))
          img_arr = np.array(bytearray(img_resp.content), dtype=np.uint8)
          img = cv2.imdecode(img_arr, -1)
  
          gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
          faces = face_cascade.detectMultiScale(gray, 1.3, 5)
          for (x,y,w,h) in faces:
              cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
              roi_gray = gray[y:y+h, x:x+w]
              roi_color = img[y:y+h, x:x+w]
              eyes = eye_cascade.detectMultiScale(roi_gray)
              for (ex,ey,ew,eh) in eyes:
              cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
  
          cv2.imshow('img',img)
  
          if cv2.waitKey(1) == 27:
              break
  </code></pre>