code: def detect_face(
      detector: dict, img: np.ndarray, align: bool = True
  ) -> list:
      """
      Detect and align face with opencv
      Args:
          face_detector (Any): opencv face detector object
          img (np.ndarray): pre-loaded image
          align (bool): default is true
      Returns:
          list of detected and aligned faces
      """
      resp = []
  
      detected_face = None
      img_region = [0, 0, img.shape[1], img.shape[0]]
  
      faces = []
      try:
          # faces = detector["face_detector"].detectMultiScale(img, 1.3, 5)
  
          # note that, by design, opencv's haarcascade scores are >0 but not capped at 1
          faces, _, scores = detector[
              "face_detector"
          ].detectMultiScale3(img, 1.1, 10, outputRejectLevels=True)
      except:
          pass
  
      if len(faces) > 0:
          for (x, y, w, h), confidence in zip(faces, scores):
              detected_face = img[
                  int(y) : int(y + h), int(x) : int(x + w)
              ]
  
              if align:
                  detected_face = align_face(
                      detector["eye_detector"], detected_face
                  )
  
              img_region = [x, y, w, h]
  
              resp.append((detected_face, img_region, confidence))
  
      return resp
  
file_path: deepface/deepface/detectors/OpenCvWrapper.py
imports: import os
  from typing import Any
  import cv2
  import numpy
  from deepface.detectors import FaceDetector
label_desc: Use image node_id 3 for calling a global function with example usage: detect_face(detector, img, align) and returns: resp