code: def detect_face(
      face_detector: Any, img: np.ndarray, align: bool = True
  ) -> list:
      """
      Detect and align face with mtcnn
      Args:
          face_detector (Any): mtcnn 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]]
  
      img_rgb = cv2.cvtColor(
          img, cv2.COLOR_BGR2RGB
      )  # mtcnn expects RGB but OpenCV read BGR
      detections = face_detector.detect(
          img_rgb, landmarks=True
      )  # returns boundingbox, prob, landmark
      if len(detections[0]) > 0:
          for detection in zip(*detections):
              x, y, w, h = xyxy_to_xywh(detection[0])
              detected_face = img[
                  int(y) : int(y + h), int(x) : int(x + w)
              ]
              img_region = [x, y, w, h]
              confidence = detection[1]
  
              if align:
                  left_eye = detection[2][0]
                  right_eye = detection[2][1]
                  detected_face = FaceDetector.alignment_procedure(
                      detected_face, left_eye, right_eye
                  )
  
              resp.append((detected_face, img_region, confidence))
  
      return resp
  
imports: from typing import Any, Union
  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(face_detector, img, align) and returns: resp