Exemplo n.º 1
0
def align_face_and_resize_frames():
    # segement picture
    img_index = -1
    # read in reverse becasue the sequence of pictures is generated in the descending order
    for f in os.listdir("pictures/"):

        im = cv2.imread("pictures/" + f, cv2.IMREAD_COLOR)
        print("processing " + f)
        lip_frame = fa.gen_align_lip_from_video(im)
        lip_frame = cv2.resize(lip_frame, (35, 35))  #resize
        cv2.imwrite('result_lip/' + str(img_index) + '.jpg', lip_frame)
Exemplo n.º 2
0
def align_face_and_resize_frames():
    # segement picture
    img_index = -1
    # read in reverse becasue the sequence of pictures is generated in the descending order
    for f in [
            '30.jpg', '28.jpg', '26.jpg', '24.jpg', '22.jpg', '20.jpg',
            '18.jpg', '16.jpg', '14.jpg', '12.jpg', '10.jpg', '8.jpg', '6.jpg',
            '4.jpg', '2.jpg', '2.jpg'
    ]:
        img_index += 1
        im = cv2.imread("images/" + f, cv2.IMREAD_COLOR)
        print("processing " + f)
        lip_frame = fa.gen_align_lip_from_video(im)
        lip_frame = cv2.resize(lip_frame, (35, 35))  #resize
        cv2.imwrite('result_lip/' + str(img_index) + '.jpg', lip_frame)
def align_face_and_resize_frames():
    # segement picture
    img_index = -1
    # read in reverse becasue the sequence of pictures is generated in the descending order
    for f in [
            '19.jpg', '18.jpg', '17.jpg', '16.jpg', '15.jpg', '14.jpg',
            '13.jpg', '12.jpg', '11.jpg', '10.jpg', '9.jpg', '8.jpg', '7.jpg',
            '6.jpg', '5.jpg', '4.jpg', '3.jpg', '2.jpg', '1.jpg', '0.jpg'
    ]:
        img_index += 1
        im = cv2.imread(r'D:\Thesis_App\pictures\\' + f, cv2.IMREAD_COLOR)
        print("processing " + f)
        lip_frame = fa.gen_align_lip_from_video(im)
        lip_frame = cv2.resize(lip_frame, (50, 48))  #resize
        cv2.imwrite(r'D:\Thesis_App\result_lip\\' + str(img_index) + '.jpg',
                    lip_frame)
Exemplo n.º 4
0
                 image) in enumerate(frame_buffer):  # Iterate on frame buffer
                face_rects = face_detector(image, 1)  # Detect face
                if len(face_rects) < 1:  # No face detected
                    print("No face detected: ", vid_path)
                    logfile.write(vid_path + " : No face detected \r\n")
                    break
                if len(face_rects) > 1:  # Too many face detected
                    print("Too many face: ", vid_path)
                    logfile.write(vid_path + " : Too many face detected \r\n")
                    break
                rect = face_rects[0]  # Proper number of face
                # (x, y, w, h) = rect_to_bb(rect)
                # faceAligned = fa.align(frame_buffer_color[i], image, rect)

                try:
                    cropped = fas.gen_align_lip_from_video(
                        frame_buffer_color[i])
                    if cropped is None:
                        break
                    cropped = cv2.resize(
                        cropped, (RESIZE[0], RESIZE[1]),
                        interpolation=cv2.INTER_CUBIC)  # Resize
                    # cropped_buffer.append(cropped)
                    # for (i, image) in enumerate(cropped_buffer):

                    cv2.imwrite(directory + "%d" % (i + 1) + ".jpg",
                                cropped)  # Write lip image
                except:
                    print("exception")
                # cv2.imwrite("./pictures/" + "%d" % (i + 1) + ".jpg", crop)
                # landmark = landmark_detector(faceAligned, rect)   # Detect face landmarks
                # landmark = shape_to_list(landmark)