Beispiel #1
0
def test_tanprocessing(filename):
    from facerec.preprocessing import TanTriggsPreprocessing
    path = '/Users/matti/Dropbox/Skjöl/Meistaraverkefni/server/sull'
    image = cv2.imread(os.path.join(path, filename))
    utils.show_image_and_wait_for_input(image)
    # alpha = 0.1, tau = 10.0, gamma = 0.2, sigma0 = 1.0, sigma1 = 2.0):
    t = TanTriggsPreprocessing(0.1, 10, 1.0, 3.0)
    res = t.extract(image)
    utils.show_image_and_wait_for_input(res)

    t = TanTriggsPreprocessing()
    res = t.extract(image)
    utils.show_image_and_wait_for_input(res)
Beispiel #2
0
def test_tanprocessing(filename):
    from facerec.preprocessing import TanTriggsPreprocessing
    path = '/Users/matti/Dropbox/Skjöl/Meistaraverkefni/server/sull'
    image = cv2.imread(os.path.join(path, filename))
    utils.show_image_and_wait_for_input(image)
    # alpha = 0.1, tau = 10.0, gamma = 0.2, sigma0 = 1.0, sigma1 = 2.0):
    t = TanTriggsPreprocessing(0.1, 10, 1.0, 3.0)
    res = t.extract(image)
    utils.show_image_and_wait_for_input(res)

    t = TanTriggsPreprocessing()
    res = t.extract(image)
    utils.show_image_and_wait_for_input(res)
Beispiel #3
0
def test_one_method(input_faces, test_faces, feature, classifier, chain=True):
    if chain:
        feature = ChainOperator(TanTriggsPreprocessing(), feature)

    model = PredictableModel(feature, classifier)
    id_list, face_list = zip(*input_faces)

    start = time.clock()
    model.compute(face_list, id_list)
    stop = time.clock()
    training_time = stop-start

    res_list = []
    start = time.clock()
    for id, image in test_faces:
        res = model.predict(image)
        res_list.append([id]+res)
    stop = time.clock()
    predict_time = stop-start

    return (training_time, predict_time, res_list)
Beispiel #4
0
 def __init__(
     self,
     video_src,
     dataset_fn,
     face_sz=(130, 130),
     cascade_fn="/home/philipp/projects/opencv2/OpenCV-2.3.1/data/haarcascades/haarcascade_frontalface_alt2.xml"
 ):
     self.face_sz = face_sz
     self.cam = create_capture(video_src)
     ret, self.frame = self.cam.read()
     self.detector = CascadedDetector(cascade_fn=cascade_fn,
                                      minNeighbors=5,
                                      scaleFactor=1.1)
     # define feature extraction chain & and classifier)
     feature = ChainOperator(TanTriggsPreprocessing(), LBP())
     classifier = NearestNeighbor(dist_metric=ChiSquareDistance())
     # build the predictable model
     self.predictor = PredictableModel(feature, classifier)
     # read the data & compute the predictor
     self.dataSet = DataSet(filename=dataset_fn, sz=self.face_sz)
     self.predictor.compute(self.dataSet.data, self.dataSet.labels)
Beispiel #5
0
    # check_processed_image()
    #  check_unprocessed_image()
    # test_processing()
    # test_failed_face()
    # test_reading_from_single_folder()

    # show_process_steps_of_one_picture('/Users/matti/Dropbox/Skjöl/Meistaraverkefni/sull/3078.jpg')

    # test_draw()
    # test_tanprocessing('10.png')
    # test_face_database()
    # test_base64png()

    mynd = test_one_face('simi_t1.jpg')
    from facerec.preprocessing import TanTriggsPreprocessing    
    t = TanTriggsPreprocessing(0.1, 10, 1.0, 3.0)
    res = t.extract(mynd)
    utils.show_image_and_wait_for_input(res)

    # test_one_face('simi_t2.jpg')
    # test_one_face('simi_t3.jpg')
    # test_one_face('simi_t4.jpg')
    # test_one_face('gyda_03.jpg')
    # test_one_face('3078.jpg')
    #test_compare_images(
    #    '/Users/matti/Documents/forritun/att_faces/arora_01.jpg', 
    #    '/Users/matti/Dropbox/Skjöl/Meistaraverkefni/server/test_faces_to_search_for/arora_01.png'
    #)

    """
    test_one_face('3.bmp')
Beispiel #6
0
    # check_processed_image()
    #  check_unprocessed_image()
    # test_processing()
    # test_failed_face()
    # test_reading_from_single_folder()

    # show_process_steps_of_one_picture('/Users/matti/Dropbox/Skjöl/Meistaraverkefni/sull/3078.jpg')

    # test_draw()
    # test_tanprocessing('10.png')
    # test_face_database()
    # test_base64png()

    mynd = test_one_face('simi_t1.jpg')
    from facerec.preprocessing import TanTriggsPreprocessing
    t = TanTriggsPreprocessing(0.1, 10, 1.0, 3.0)
    res = t.extract(mynd)
    utils.show_image_and_wait_for_input(res)

    # test_one_face('simi_t2.jpg')
    # test_one_face('simi_t3.jpg')
    # test_one_face('simi_t4.jpg')
    # test_one_face('gyda_03.jpg')
    # test_one_face('3078.jpg')
    #test_compare_images(
    #    '/Users/matti/Documents/forritun/att_faces/arora_01.jpg',
    #    '/Users/matti/Dropbox/Skjöl/Meistaraverkefni/server/test_faces_to_search_for/arora_01.png'
    #)
    """
    test_one_face('3.bmp')
    test_one_face('4.bmp')
print "Appropriation completed in {0:.2f} seconds.\n".format(time.time() - initial_time)

#
# Set up the Haar cascade to detect (not recognize) the faces
#
#
# We're going to use the Fisherfaces face recognition module
#

initial_time = time.time()
print "Initializing Haar cascades for face, eyes, nose and mouth detection: "
#
# This was prior to using the TanTriggsPreprocessing, we can go back
#model = PredictableModel(Fisherfaces(), NearestNeighbor())

feature = ChainOperator(TanTriggsPreprocessing(), Fisherfaces())
classifier = NearestNeighbor()
model = PredictableModel(feature, classifier)

face_cascade = cv2.CascadeClassifier(haarcascade)
eye_cascade = cv2.CascadeClassifier(eyehaarcascade)
nose_cascade = cv2.CascadeClassifier(nosehaarcascade)
mouth_cascade = cv2.CascadeClassifier(mouthhaarcascade)
print "Initialization completed in {0:.2f} seconds.\n".format(time.time() - initial_time)

#
# Main loop
#   Press "l" to learn a new image
#   Press "r" to reload image database
#   Press "v" to toggle voice synthesis
#   Press "b" for best guess of image
Beispiel #8
0
    def __init__(self,
                 database_folder,
                 feature_parameter="LPQ",
                 metric="chi",
                 k=3):
        self.model = None

        handler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        logger = logging.getLogger("facerec")
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)

        path = database_folder

        start = time.clock()
        input_faces = utils.read_images_from_single_folder(path)
        stop = time.clock()

        print("read {}, images from {} in {} seconds.".format(
            len(input_faces), path, stop - start))

        feature = None
        m = {
            "fisher": Fisherfaces,
            "fisher80": Fisherfaces,
            "pca": PCA,
            "pca10": PCA,
            "lda": LDA,
            "spatial": SpatialHistogram,
            "LPQ": SpatialHistogram
        }

        if feature_parameter in m:
            if feature_parameter == 'LPQ':
                feature = SpatialHistogram(LPQ())
                self.threshold = threshold_function(71.4, 70)
            elif feature_parameter == 'fisher80':
                feature = Fisherfaces(80)
                self.threshold = threshold_function(0.61, 0.5)
            elif feature_parameter == 'fisher':
                feature = Fisherfaces()
                self.threshold = threshold_function(0.61, 0.5)
            elif feature_parameter == 'pca80':
                feature = PCA(80)
            else:
                feature = m[feature_parameter]()

        metric_param = None
        d = {
            "euclid": EuclideanDistance,
            "cosine": CosineDistance,
            "normal": NormalizedCorrelation,
            "chi": ChiSquareDistance,
            "histo": HistogramIntersection,
            "l1b": L1BinRatioDistance,
            "chibrd": ChiSquareBRD
        }
        if metric in d:
            metric_param = d[metric]()
        else:
            metric_param = ChiSquareDistance()

        classifier = NearestNeighbor(dist_metric=metric_param, k=k)
        feature = ChainOperator(TanTriggsPreprocessing(), feature)
        # feature = ChainOperator(TanTriggsPreprocessing(0.1, 10.0, 1.0, 3.0), feature)
        self.model = PredictableModel(feature, classifier)

        # images in one list, id's on another
        id_list, face_list = zip(*input_faces)

        print "Train the model"
        start = time.clock()
        # model.compute(X, y)
        self.model.compute(face_list, id_list)
        stop = time.clock()
        print "Training done in", stop - start, " next...find a face"
Beispiel #9
0
    # Define a 1-NN classifier with Euclidean Distance:
    # classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=3) # þokkalegt, [1.7472255 ,  1.80661233,  1.89985602] bara fremsta rétt
    # classifier = NearestNeighbor(dist_metric=CosineDistance(), k=3) # þokkalegt, niðurstöður sem mínus tölur ([-0.72430667, -0.65913855, -0.61865271])
    # classifier = NearestNeighbor(dist_metric=NormalizedCorrelation(), k=3) # ágætt  0.28873109,  0.35998333,  0.39835315 (bara fremsta rétt)
    classifier = NearestNeighbor(dist_metric=ChiSquareDistance(
    ), k=3)  # gott, 32.49907228,  44.53673458,  45.39480197 bara síðasta rangt
    # classifier = NearestNeighbor(dist_metric=HistogramIntersection(), k=3) # sökkar
    # classifier = NearestNeighbor(dist_metric=L1BinRatioDistance(), k=3) # nokkuð gott,  36.77156378,  47.84164013,  52.63872497] - síðasta rangt
    # classifier = NearestNeighbor(dist_metric=ChiSquareBRD(), k=3) #  36.87781902,  44.06119053,  46.40875114 - síðasta rangt

    # Define the model as the combination
    # model = PredictableModel(feature=feature, classifier=classifier)
    # Compute the model on the given data (in X) and labels (in y):

    feature = ChainOperator(TanTriggsPreprocessing(), feature)
    # classifier = NearestNeighbor()
    model = PredictableModel(feature, classifier)

    # images in one list, id's on another
    id_list, face_list = zip(*input_faces)

    print "Train the model"
    start = time.clock()
    # model.compute(X, y)
    model.compute(face_list, id_list)
    stop = time.clock()
    print "Training done in", stop - start, " next...find a face"

    # test_path = "/Users/matti/Documents/forritun/att_faces/"
    test_path = "/Users/matti/Dropbox/Skjöl/Meistaraverkefni/server/test_faces_02"