How can I applied box function to detect face in colab?

hi , I am new to python I trying to give the prediction output with box that detect human face but after I run the video not have the box so how can I applied it in the codes?

def prediction (filepath):
  input_shape = (128, 128, 3)
  pr_data = []
  detector = dlib.get_frontal_face_detector()
  cap = cv2.VideoCapture(filepath)
  frameRate = cap.get(5)
  while cap.isOpened():
      frameId = cap.get(1)
      ret, frame =
      if ret != True:
      if frameId % ((int(frameRate)+1)*1) == 0:
          face_rects, scores, idx =, 0)
          for i, d in enumerate(face_rects):
              x1 = d.left()
              y1 =
              x2 = d.right()
              y2 = d.bottom()
              crop_img = frame[y1:y2, x1:x2]
              data = img_to_array(cv2.resize(crop_img, (128, 128))).flatten() / 255.0
              data = data.reshape(-1, 128, 128, 3)
              print((model.predict(data) > 0.5).astype("int32"))
  if ((model.predict(data) > 0.5).astype("int32")[0][0] == 0 ):
    return 'Real'
    return 'Fake'

This post was flagged by the community and is temporarily hidden.

Hi buddy, did this work for you?

please note, that opencv’s gui functions are unavailable on colab (maybe write image to disk ?)

hi sorry, I’m new with this. where I need to input cv2.rectangle and cv2.putText? after y2 = d.bottom()? or before x1 = d.left().