Update video_app.py
Browse files- video_app.py +2 -10
video_app.py
CHANGED
|
@@ -15,8 +15,7 @@ import matplotlib.pyplot as plt
|
|
| 15 |
import utils
|
| 16 |
from utils import app
|
| 17 |
|
| 18 |
-
|
| 19 |
-
def face_recognition_in_video(video_path, names, embeddings):
|
| 20 |
# Open the video file
|
| 21 |
cap = cv2.VideoCapture(video_path)
|
| 22 |
|
|
@@ -27,13 +26,8 @@ def face_recognition_in_video(video_path, names, embeddings):
|
|
| 27 |
|
| 28 |
# Define the codec and create VideoWriter object
|
| 29 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 30 |
-
output_path = "/tmp/output_video.mp4"
|
| 31 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 32 |
|
| 33 |
-
# Initialize FaceAnalysis app
|
| 34 |
-
app = FaceAnalysis(name='buffalo_l')
|
| 35 |
-
app.prepare(ctx_id=0, det_size=(640, 640))
|
| 36 |
-
|
| 37 |
# Process each frame of the video
|
| 38 |
while cap.isOpened():
|
| 39 |
ret, frame = cap.read()
|
|
@@ -49,7 +43,7 @@ def face_recognition_in_video(video_path, names, embeddings):
|
|
| 49 |
detected_embedding = face.normed_embedding
|
| 50 |
|
| 51 |
# Calculate similarity scores with known embeddings
|
| 52 |
-
scores = np.dot(detected_embedding,
|
| 53 |
scores = np.clip(scores, 0., 1.)
|
| 54 |
|
| 55 |
# Find the index with the highest score
|
|
@@ -75,6 +69,4 @@ def face_recognition_in_video(video_path, names, embeddings):
|
|
| 75 |
# Release everything if job is finished
|
| 76 |
cap.release()
|
| 77 |
out.release()
|
| 78 |
-
|
| 79 |
return output_path
|
| 80 |
-
|
|
|
|
| 15 |
import utils
|
| 16 |
from utils import app
|
| 17 |
|
| 18 |
+
def face_recognition_in_video(video_path, output_path, names, embeddings):
|
|
|
|
| 19 |
# Open the video file
|
| 20 |
cap = cv2.VideoCapture(video_path)
|
| 21 |
|
|
|
|
| 26 |
|
| 27 |
# Define the codec and create VideoWriter object
|
| 28 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
|
|
|
| 29 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Process each frame of the video
|
| 32 |
while cap.isOpened():
|
| 33 |
ret, frame = cap.read()
|
|
|
|
| 43 |
detected_embedding = face.normed_embedding
|
| 44 |
|
| 45 |
# Calculate similarity scores with known embeddings
|
| 46 |
+
scores = np.dot(detected_embedding, embeddings.T)
|
| 47 |
scores = np.clip(scores, 0., 1.)
|
| 48 |
|
| 49 |
# Find the index with the highest score
|
|
|
|
| 69 |
# Release everything if job is finished
|
| 70 |
cap.release()
|
| 71 |
out.release()
|
|
|
|
| 72 |
return output_path
|
|
|