79437945

Date: 2025-02-13 23:16:47
Score: 1.5
Natty:
Report link

In the same function where you draw the rectangle that indicates the face, save the coordinates to a global variable. Then, when saving the frame to the file, limit its area like this: video_frame[y:y+h, x:x+w], see detail:

def detect_bounding_box(vid): global area gray_image = cv2.cvtColor(vid, cv2.COLOR_BGR2GRAY) faces = face_classifier.detectMultiScale(gray_image, 1.1, 5, minSize=(40, 40)) for (x, y, w, h) in faces: cv2.rectangle(vid, (x, y), (x + w, y + h), (0, 255, 0), 4) area = [x, y, w, h] return faces

........

cv2.imwrite(img_name, video_frame[area[1]:area[1]+area[3], area[0]:area[0]+area[2]])

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Filler text (0.5): ........
  • Low reputation (1):
Posted by: Juan Suarez