fps = FPS().start()

while True:

    frame = video_capture.read()

    if video_capture.stopped:
        break
    # reading the frame

    height, width, _ = np.shape(frame)
    # frame = imutils.resize(frame, height=height)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    try: faces = detector.CNN_face_detection(frame, 0.7)
    except ValueError: faces = []; pass

    canvas = np.zeros((height, int(width*0.33), 3), dtype="uint8")

    frameClone = frame.copy()

    if faces.shape[0] >= 1:

        for face in faces:
            (x, y, w, h) = face.astype(int)
            # print(w, h)
            cv2.rectangle(frameClone, (x, y), (x + w, y + h), (0, 0, 255), 2)
            # Extract the ROI of the face from the grayscale image, resize it to the fixed model size, and then prepare
            # the ROI for classification via the CNN
            roi = gray[y:y + h, x:x + w]
##### initialize video from file
video_path = "/Users/david/Desktop/Grimmanet/VideosClaseAI/webex.mp4"
print("[INFO] starting video file thread...")
video_capture = FileVideoStream(video_path).start()
time.sleep(2.0)

while True:

    # Capture frame-by-frame
    frame = video_capture.read()

    # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    frame = imutils.resize(frame, width=600)

    try:
        face = detector.CNN_face_detection(frame, 0.8)
    except ValueError:
        cv.imshow('Video', frame)

        if cv.waitKey(1) & 0xFF == ord('q'):
            break
        continue

    # Draw a rectangle around the faces
    (x, y, w, h) = face
    roi_face = frame[y: y+h, x: x+w]
    roi_gray = cv.cvtColor(roi_face, cv.COLOR_BGR2GRAY)

    cv.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # Detect eyes and mouth in the detected faces
#initialize detector
detector = Detection()
detector.load_cascades()
detector.load_CNN_detector()

img = cv.imread(path)
# bw = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
# gray = detector.filter_homo(img)
cv.imshow('img', gray)
cv.waitKey(0)
cv.destroyAllWindows()

faces = detector.CNN_face_detection(img, 0.8)
(x,y,w,h) = list(map(int, faces[0]))
cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]

#Eyes detection

eyes_roiBB = [0, int(h/6), w, int(h/2)]
# cv.rectangle(roi_gray, (eyes_roiBB[0], eyes_roiBB[1]), (eyes_roiBB[0]+eyes_roiBB[2], eyes_roiBB[1]+eyes_roiBB[3]), (123, 123, 123), 2)
roi_eyes = roi_gray[eyes_roiBB[1]:eyes_roiBB[1]+eyes_roiBB[3], eyes_roiBB[0]:eyes_roiBB[0]+eyes_roiBB[2]]
eyes = detector.eyes_detection(roi_eyes)
# for (ex,ey,ew,eh) in eyes:
#     cv.rectangle(roi_eyes,(ex,ey),(ex+ew,ey+eh),(255,255,255),2)
    # seg_
    # img[eyes_roiBB[1]+ey:(eyes_roiBB[1]+ey+eh), (eyes_roiBB[0]+ex):(eyes_roiBB[0]+ex+ew)] = roi_eyes[ey:ey+eh, ex:ex+ew]
Exemple #4
0
detector.load_cascades()
detector.load_CNN_detector()

for emotion in os.listdir(path):
    if not emotion == "Files.txt":
        if emotion == "fear":
            for image in os.listdir(os.path.join(path, emotion)):
                if not image.startswith('.') and image.__contains__('ray'):

                    img = cv.imread(os.path.join(path, emotion, image))
                    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

                    # gray = cv.cvtColor(fil_img, cv.COLOR_BGR2GRAY)

                    try:
                        face = detector.CNN_face_detection(img)
                    except ValueError:
                        continue

                    (x, y, w, h) = face

                    cv.rectangle(gray, (x, y), (x + w, y + h), (255, 0, 0), 2)

                    # cv.imshow('img', gray)
                    # cv.waitKey(0)
                    # cv.destroyAllWindows()

                    roi_gray = gray[y:y + h, x:x + w]
                    roi_color = img[y:y + h, x:x + w]

                    #Eyes detection