ageitgey / ageitgey/face_recognition
Faster face detection on video stream
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: 1.2.2
- Python version: 3.5
- Operating System: Ubuntu 16.04
Description
Is there any way to make the face detection part run faster?
I'm running this for my rtsp camera stream and the video is very slow - each frame takes 2 seconds to process.
I managed to accelerate my video stream to 3 FPS by using "cnn" face detection method, by resizing the processing frame by a factor of 0.33 and by moving all the processing function calls into the separate thread.
I measured time it takes to process one frame - and it is somewhere around 350 ms.
But this is done in the separate thread (not the one that handles video display), so I don't understand why does this slow my video so much.
I am running this program on Nvidia Jetson TX1.
What I Did
# The main cycle part
for face_location, name in zip(face_locations, face_names):
top, right, bottom, left = face_location
cv2.rectangle(img, (left * 3, top * 3), (right * 3, bottom * 3), (0, 0, 230), 3)
if obama_available:
oth = Thread(target=obama_thread, args=[copy.deepcopy(img)])
oth.daemon = True
oth.start()
## in the other thread
def obama_thread(img):
obama_available = False
small_frame = cv2.resize(img, (0, 0), fx=0.33, fy=0.33)
rgb_small_frame = small_frame[:, :, ::-1]
face_locations_temp = face_recognition.face_locations(rgb_small_frame, 1, "cnn")
face_locations.clear()
for (top, right, bottom, left) in face_locations_temp:
face_locations.append([top, right, bottom, left])
obama_available = True
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the RTSP workload on the Nvidia Jetson TX1 and measuring the call to face_recognition.face_locations in obama_thread, including the resize and thread handoff. Compare frame-display timing with the cnn detector at the reported scale; done should mean identifying the bottleneck and documenting a verified way to improve or explain the processing speed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-vision, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100