ageitgey / ageitgey/face_recognition
face_encodings method can not run on asynchronous threads
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:
- Python version: 3.4
- Operating System: windows 7
Description
I want to use face_recognition.face_encodings method on asynchronous threads, Because it causes my webcam to be unsmooth, but when I use it on asynchronous threads, It has no effect at all
class CompareByThreadPool(object):
executor = ThreadPoolExecutor(max_workers=1)
def __init__(self):
self.mutex = QMutex()
self.obama_img = []
self.obama_face_encoding = []
self.face_locations = []
self.face_encodings = []
self.face_names = []
self.process_this_frame = False
self.can_begain_compare = False
self.can_begain_encoding = False
self.frame=numpy.arange(0)
future = self.executor.submit(self.cricleRun,self.frame)
def set_frame(self,frame):
self.frame = frame
def cricleRun(self,frame):
while True:
print('self.frame.size: ',self.frame.size)
if self.frame.size > 0:
self.face_rec(self.frame)
time.sleep(0.4)
def face_rec(self,frame):
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1]
# rgb_small_frame = small_frame
self.face_locations = face_recognition.face_locations(rgb_small_frame)
rec_begain_time = time.time()
print('begain time: ',rec_begain_time)
if self.process_this_frame:
self.face_encodings = face_recognition.face_encodings(rgb_small_frame, self.face_locations)
self.process_this_frame = not self.process_this_frame
print('face_rec compareFlag: ',self.can_begain_compare)
if self.can_begain_compare:
face_names = []
for face_encoding in self.face_encodings:
#match = face_recognition.compare_faces([obama_face_encoding], face_encoding,0.5)
face_distances = face_recognition.face_distance([self.obama_face_encoding],face_encoding);
print("face_distance: ",face_distances[0]);
#if match[0]:
if face_distances[0] < 0.6:
name = "Success"
else:
name = "unknown"
rec_end_time= time.time()
face_names.append(name)
print("name : {0} time: {1} ".format(name,rec_end_time-rec_begain_time))
What I Did
Can it run on asynchronous threads , Please tell me how can I make my webcam smooth
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 with the face_recognition.face_encodings call and the ThreadPoolExecutor-based CompareByThreadPool example in the issue, then examine how frames and shared attributes are passed through cricleRun and face_rec. Reproduce the behavior on the stated Python 3.4 and Windows 7 setup; done would require a confirmed explanation or documented change that makes asynchronous processing affect webcam smoothness.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100