<commit_before>""" This is license
"""

from pyseeta import Detector
from pyseeta import Aligner
from pyseeta import Identifier

def test():
    import cv2
    # load model
    detector = Detector('SeetaFaceEngine/model/seeta_fd_frontal_v1.0.bin')
    aligner = Aligner('SeetaFaceEngine/model/seeta_fa_v1.1.bin')
    identifier = Identifier('SeetaFaceEngine/model/seeta_fr_v1.0.bin')
    # load image
    im_color = cv2.imread('/Users/tuxiaokang/Downloads/2.png')
    im_gray = cv2.cvtColor(im_color, cv2.COLOR_BGR2GRAY)
    # detect face in image
    faces = detector.detect(im_gray)
    # extract feature of each face
    for face in faces:
        landmarks = aligner.align(im_gray, face)
        # extract feature in different way
        im_crop = identifier.crop_face(im_color, landmarks)
        # save cropped face
        # cv2.imwrite('image/crop_{}.png'.format(hash(time.time())), im_crop)
        featA = identifier.extract_feature(im_crop)
        featB = identifier.extract_feature_with_crop(im_color, landmarks)
        # calculate similarity of features
        sim = identifier.calc_similarity(featA, featB)
        print('similarity: ', sim)

    # release
    identifier.release()
    aligner.release()
    detector.release()

if __name__ == '__main__':
    test()
<commit_msg>update test.py<commit_after>""" This is license
"""

from pyseeta import Detector
from pyseeta import Aligner
from pyseeta import Identifier

def test():
    import cv2, os
    # load model
    detector = Detector('SeetaFaceEngine/model/seeta_fd_frontal_v1.0.bin')
    #aligner = Aligner('SeetaFaceEngine/model/seeta_fa_v1.1.bin')
    #identifier = Identifier('SeetaFaceEngine/model/seeta_fr_v1.0.bin')
    video_dir = '/Users/tuxiaokang/Downloads/Casia/1'
    #video_path_list =[os.path.join(video_dir, x) for x in os.listdir(video_dir)]
    video_path_list = ['/Users/tuxiaokang/Downloads/Casia/train_release/19/HR_1.avi']
    for v in video_path_list:
        cap = cv2.VideoCapture(v)
        i = 0
        while True:
            ret, frame = cap.read()
            ret, frame = cap.read()
            if not ret:
                break
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            faces = detector.detect(gray)
            if len(faces) == 0:
                i += 1
            # for face in faces:
            #     print(face.left, face.top, face.right, face.bottom)
            #     cv2.rectangle(frame, (face.left, face.top), (face.right, face.bottom), (0,255,0),3)
            # cv2.imshow('video', frame)
            # cv2.waitKey(3)
        print(i)
        cap.release()
    """
    # load image
    im_color = cv2.imread('/Users/tuxiaokang/Downloads/2.png')
    im_gray = cv2.cvtColor(im_color, cv2.COLOR_BGR2GRAY)
    # detect face in image
    faces = detector.detect(im_gray)
    # extract feature of each face
    for face in faces:
        landmarks = aligner.align(im_gray, face)
        # extract feature in different way
        im_crop = identifier.crop_face(im_color, landmarks)
        # save cropped face
        # cv2.imwrite('image/crop_{}.png'.format(hash(time.time())), im_crop)
        featA = identifier.extract_feature(im_crop)
        featB = identifier.extract_feature_with_crop(im_color, landmarks)
        # calculate similarity of features
        sim = identifier.calc_similarity(featA, featB)
        print('similarity: ', sim)
    """
    # release
    #identifier.release()
    #aligner.release()
    detector.release()

if __name__ == '__main__':
    test()

{'fraction_non_alphanumeric': 0.11293984108967083, 'fraction_numerical': 0.013337116912599319, 'mean_word_length': 2.7341101694915255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7667618', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1174, 'n_words': 238}