I wish to be able to use a webcam and utilize MTCNN as the primary facial detector. Just as one can use Haar Cascades, I want to use MTCNN to find faces on my webcam
This video is about breaking MTCNN, but nonetheless provides insight into my goal: https://www.youtube.com/watch?v=OY70OIS8bxs
Here is my code so far. It used to be so that the plot would show and I'd have to "X" it out but now it just doesn't work
from mtcnn.mtcnn import MTCNN
import cv2 as cv
from matplotlib import pyplot
from matplotlib.patches import Rectangle
cap = cv.VideoCapture(0)
detector = MTCNN()
#face = detector.detect_faces(img)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
if (ret):
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
ax = pyplot.gca()
face = detector.detect_faces(frame)
face = pyplot.imread(frame)
x, y, width, height = face[0]['box']
rect = Rectangle((x, y), width, height, fill=False, color='red')
ax.add_patch(rect)
pyplot.imshow(frame)
cv.imshow('frame',gray)
pyplot.show()
# Display the resulting frame
#cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()
I was hoping someone could help me...