Skip to content

cut face from video #96

@prozaklob

Description

@prozaklob

hi! I am newbie in python.

I needed a little magic (help) :)

I detect a face and save a picture from a video with a face.
But I would like to save not the whole picture, but only the part where there is a face.

What do I need to read to find a solution to my problem? thank

import cv2
from mtcnn import MTCNN
import os
import time

detector = MTCNN()

cap = cv2.VideoCapture("https://linktovideo")
while True:
    __, frame = cap.read()
    
    result = detector.detect_faces(frame)
    if result != []:
        for person in result:
            bounding_box = person['box']
            keypoints = person['keypoints']
    
            cv2.rectangle(frame,
                          (bounding_box[0], bounding_box[1]),
                          (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
                          (0,155,255),
                          2)
    
            timestr = time.strftime("%Y%m%d-%H%M%S")
            cv2.imwrite("dataset/User." + str(timestr) + '.' + str(count) + ".jpg", frame)
            
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) &0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions