i've tried to detect faces from my webcam , but it was only detect the first face which appeared in the first frame , then it will crush , i have used mtcnn to detection operation , after detecting the first face (if it exist ) then it will stop capturing and crushed and will remain on the screen, i've used jupyter notebook as editor and the notebook will remain loading ..
but it will work fine without using mtcnn
detector !
but when there is no faces in the first frame it will raise this error
whenever i use if boxes:
before for box in boxes:
IndexError: list index out of range
but if there was a face it will raise this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
but i wont use if boxes:
if there was not a face to detect
it will raise this error :
TypeError: 'NoneType' object is not iterable
and if detect a face in the first frame then it will remain loading after detecting the face!
capture = cv2.VideoCapture(0)
while(True):
ret, frame = capture.read()
frames_tracked = []
print('\rTracking frame: {}'.format(i + 1), end='')
frame_pil = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
frame_pil = Image.fromarray(frame_pil)
boxes,_ = mtcnn.detect(frame_pil)
frame_draw = frame_pil.copy()
draw = ImageDraw.Draw(frame_draw)
for box in boxes:
draw.rectangle(box.tolist(), outline=(255, 0, 0), width=6)
frames_tracked.append(frame_draw.resize((640, 360), Image.BILINEAR))
d = display.display(frames_tracked[0], display_id=True)
i = 1
try:
while True:
d.update(frames_tracked[i % len(frames_tracked)])
i += 1
except KeyboardInterrupt:
pass
if cv2.waitKey('q') == 27:
break
capture.release()
cv2.destroyAllWindows()
please i have to complete my project for my final year project