ageitgey / ageitgey/face_recognition

Examples problem

Open
#651 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
56.8k
Forks
13.7k
PR merge metrics
No merged PRs in 30d

Description

  • face_recognition version: latest
  • Python version: 3.7
  • Operating System: high sierra
Description

Playing with the examples thought I would combine them or modify them for my needs.
Wanted the one where it blurs out the face on camera to blur out the face in a video.

What I Did

Modified VideoCapture(0) to video_capture = cv2.VideoCapture("hamilton_clip.mp4") in the face blur example.
But the faces are not blurred in the output window.
Also tried to output as a file and replaced the example from facerec_from_video_file with my own data(a 2MB mp4 file and 2 faces for the detection) but the resulting file is corrupted I think. Comes out at 10KB and can't open.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

This is what I tried by combining the two examples but sadly it didn't work, the output video doesn't have any blurred faces.

import face_recognition
import cv2

# This is a demo of running face recognition on a video file and saving the results to a new video file.
#
# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.

# Open the input movie file
input_movie = cv2.VideoCapture("test2.mp4")
length = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))

# Create an output movie file (make sure resolution/frame rate matches input video!)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
output_movie = cv2.VideoWriter('test2.avi', fourcc, 10, (1920, 1080))



# Initialize some variables
face_locations = []

frame_number = 0

while True:
    # Grab a single frame of video
    ret, frame = input_movie.read()
    frame_number += 1

    # Quit when the input video file ends
    if not ret:
        break

    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
  

    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)


    # Find all the faces and face encodings in the current frame of video
    face_locations = face_recognition.face_locations(small_frame, model="cnn")
 
    # Label the results
    for top, right, bottom, left in face_locations:
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        face_image = frame[top:bottom, left:right]
        face_image = cv2.GaussianBlur(face_image, (99, 99), 30)
        frame[top:bottom, left:right] = face_image



    # Write the resulting image to the output video file
    print("Writing frame {} / {}".format(frame_number, length))
    output_movie.write(frame)

# All done!
input_movie.release()
cv2.destroyAllWindows()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the face blur example and the facerec_from_video_file example, then compare their video input and output handling with the provided script. Reproduce the missing blur and unreadable output using the mentioned MP4 files; done means faces are blurred and the saved video can be opened.

Written by the indexing model from the issue text.

Assessment

Tech stack
opencv, python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.