예제 #1
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(4)

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)
    vj_accuracy = None
    vj_accuracy = 100. * helper_func(labels, predictions_train) / len(labels)
    print "Prediction accuracy on training: {0:.2f}%".format(vj_accuracy)

    neg = load_images_from_dir(NEG2_DIR)

    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    vj_accuracy = None
    vj_accuracy = 100. * helper_func(real_labels, predictions_train) / len(real_labels)
    print "Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy)
예제 #2
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(5)

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)
    matching_indices = np.where(predictions == labels)[0]
    vj_accuracy = matching_indices.shape[0] / labels.shape[0]
    print("Prediction accuracy on training: {0:.2f}%".format(vj_accuracy))

    neg = load_images_from_dir(NEG2_DIR)

    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    matching_indices = np.where(predictions == real_labels)[0]
    vj_accuracy = matching_indices.shape[0] / real_labels.shape[0]
    print("Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy))
예제 #3
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(5)

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)
    vj_accuracy = None

    good = 0
    bad = 0    
    for i in range(0, len(predictions)):
        if(labels[i] == predictions[i]):
            good += 1

        else:
            bad += 1

    vj_accuracy = 100* float(good) / (good + bad)
    print "Prediction accuracy on training: {0:.2f}%".format(vj_accuracy)

    neg = load_images_from_dir(NEG2_DIR)

    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    vj_accuracy = None
    good = 0
    bad = 0
    for i in range(0, len(predictions)):
        if(real_labels[i] == predictions[i]):
            good += 1

        else:
            bad += 1

    vj_accuracy = 100* float(good) / (good + bad)
    print "Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy)
예제 #4
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(4)
    #
    # print VJ.haarFeatures[VJ.classifiers[0].feature]
    # print VJ.haarFeatures[VJ.classifiers[1].feature]

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)

    matches = [labels[i] == predictions[i] for i in range(0, len(predictions))]
    corr = np.sum(np.array([int(x) for x in matches]))

    vj_accuracy = corr / float(len(labels)) * 100

    print "Prediction accuracy on training: {0:.2f}%".format(vj_accuracy)

    neg = load_images_from_dir(NEG2_DIR)
    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    # print real_labels
    # print predictions

    matches = [
        real_labels[i] == predictions[i] for i in range(0, len(predictions))
    ]
    matches = [int(x) for x in matches]
    # print matches
    corr = np.sum(np.array([int(x) for x in matches]))
    print corr
    vj_accuracy = corr / float(len(real_labels)) * 100

    print "Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy)
예제 #5
0
def part_4_c():
    pos = load_images_from_dir(POS_DIR)[:20]
    neg = load_images_from_dir(NEG_DIR)

    images = pos + neg

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(pos, neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(4)

    image = cv2.imread(os.path.join(INPUT_DIR, "man.jpeg"), -1)
    image = cv2.resize(image, (120, 60))
    VJ.faceDetection(image, filename="ps4-4-c-1")
예제 #6
0
def part_4_c():

    pos, neg = generate_examples()

    images = pos + neg

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(pos, neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(1)

    image = cv2.imread(os.path.join(INPUT_DIR, "man.jpeg"), -1)
    image = cv2.resize(image, (120, 60))
    VJ.faceDetection(image, filename="ps6-4-c-1")
예제 #7
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(5)

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)
    vj_accuracy = None

    correct = 0.0
    for i in range(len(labels)):
        if predictions[i] == labels[i]:
            correct += 1.0

    vj_accuracy = (correct / len(labels)) * 100
    print "Prediction accuracy on training: {0:.2f}%".format(vj_accuracy)

    neg = load_images_from_dir(NEG2_DIR)

    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    vj_accuracy = None
    correct = 0.0
    for i in range(len(real_labels)):
        if predictions[i] == real_labels[i]:
            correct += 1.0

    vj_accuracy = (correct / len(real_labels)) * 100
    print "Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy)
예제 #8
0
def part_4_c():
    pos = load_images_from_dir(POS_DIR)[:20]
    neg = load_images_from_dir(NEG_DIR)

    images = pos + neg

    print('test shape: ', images[0].shape)

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(pos, neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(4)


    image = cv2.imread(os.path.join(INPUT_DIR, "man2.jpeg"), -1)
    resized_image = image.copy()
    resized_image = cv2.resize(resized_image, (120, 60))
    VJ.faceDetection(resized_image, filename="ps4-4-c-1", original_image=image)
예제 #9
0
def part_4_a_b():

    pos = load_images_from_dir(POS_DIR)
    neg = load_images_from_dir(NEG_DIR)

    train_pos = pos[:35]
    train_neg = neg[:]
    images = train_pos + train_neg
    labels = np.array(len(train_pos) * [1] + len(train_neg) * [-1])

    integral_images = ps6.convert_images_to_integral_images(images)
    VJ = ps6.ViolaJones(train_pos, train_neg, integral_images)
    VJ.createHaarFeatures()

    VJ.train(5)

    VJ.haarFeatures[VJ.classifiers[0].feature].preview(filename="ps6-4-b-1")
    VJ.haarFeatures[VJ.classifiers[1].feature].preview(filename="ps6-4-b-2")

    predictions = VJ.predict(images)
    temp_vj = np.zeros_like(predictions)
    temp_vj[predictions == labels] = 1
    vj_accuracy = 100 * float(np.sum(temp_vj) / len(temp_vj))  #None
    # raise NotImplementedError
    print("Prediction accuracy on training: {0:.2f}%".format(vj_accuracy))

    neg = load_images_from_dir(NEG2_DIR)

    test_pos = pos[35:]
    test_neg = neg[:35]
    test_images = test_pos + test_neg
    real_labels = np.array(len(test_pos) * [1] + len(test_neg) * [-1])
    predictions = VJ.predict(test_images)

    temp_vj = np.zeros_like(predictions)
    temp_vj[predictions == real_labels] = 1
    vj_accuracy = 100 * float(np.sum(temp_vj) / len(real_labels))  #None
    # raise NotImplementedError
    print("Prediction accuracy on testing: {0:.2f}%".format(vj_accuracy))