예제 #1
0
def test_find_haar_features():
    img = Factory.Image(testimage)
    img1 = img.copy()
    face = HaarCascade("face.xml")  # old HaarCascade
    f = img.find_haar_features(face)
    f2 = img1.find_haar_features("face_cv2.xml")  # new cv2 HaarCascade
    assert len(f) > 0
    assert len(f2) > 0
    f.draw()
    f2.draw()
    f[0].width
    f[0].height
    f[0].length
    f[0].area

    results = [img, img1]
    name_stem = "test_find_haar_features"
    perform_diff(results, name_stem)

    # incorrect cascade name
    f3 = img.find_haar_features(cascade="incorrect_cascade.xml")
    assert_equals(f3, None)

    # incorrect cascade object
    f4 = img.find_haar_features(cascade=img1)
    assert_equals(f4, None)

    # Empty image
    img2 = Factory.Image((100, 100))
    f5 = img2.find_haar_features("face_cv2.xml")
    assert_equals(f5, None)
예제 #2
0
def test_anonymize():
    img = Factory.Image(source="lenna")
    anon_img = img.anonymize()

    # provide features
    anon_img1 = img.anonymize(features=["face.xml", "profile.xml"])

    # match both images
    assert_equals(anon_img.data, anon_img1.data)

    # transform function
    def transform_blur(img, rect):
        np_array = img
        x, y, w, h = rect
        crop_np_array = np_array[y:y + h, x:x + w]
        crop_img = Factory.Image(array=crop_np_array)
        blur_img = crop_img.blur((15, 15))
        blur_np_array = blur_img
        np_array[y:y + h, x:x + w] = blur_np_array
        return Factory.Image(array=np_array)

    # apply tranform function
    anon_img2 = img.anonymize(transform=transform_blur)

    perform_diff([anon_img1, anon_img2], "test_anonymize")
예제 #3
0
def test_find_haar_features():
    img = Factory.Image(testimage)
    img1 = img.copy()
    face = HaarCascade("face.xml")  # old HaarCascade
    f = img.find_haar_features(face)
    f2 = img1.find_haar_features("face_cv2.xml")  # new cv2 HaarCascade
    assert len(f) > 0
    assert len(f2) > 0
    f.draw()
    f2.draw()
    f[0].width
    f[0].height
    f[0].length
    f[0].area

    results = [img, img1]
    name_stem = "test_find_haar_features"
    perform_diff(results, name_stem)

    # incorrect cascade name
    f3 = img.find_haar_features(cascade="incorrect_cascade.xml")
    assert_equals(f3, None)

    # incorrect cascade object
    f4 = img.find_haar_features(cascade=img1)
    assert_equals(f4, None)

    # Empty image
    img2 = Factory.Image((100, 100))
    f5 = img2.find_haar_features("face_cv2.xml")
    assert_equals(f5, None)
예제 #4
0
def test_anonymize():
    img = Factory.Image(source="lenna")
    anon_img = img.anonymize()

    # provide features
    anon_img1 = img.anonymize(features=["face.xml", "profile.xml"])

    # match both images
    assert_equals(anon_img.data, anon_img1.data)

    # transform function
    def transform_blur(img, rect):
        np_array = img
        x, y, w, h = rect
        crop_np_array = np_array[y:y+h, x:x+w]
        crop_img = Factory.Image(array=crop_np_array)
        blur_img = crop_img.blur((15, 15))
        blur_np_array = blur_img
        np_array[y:y+h, x:x+w] = blur_np_array
        return Factory.Image(array=np_array)

    # apply tranform function
    anon_img2 = img.anonymize(transform=transform_blur)

    perform_diff([anon_img1, anon_img2], "test_anonymize")
예제 #5
0
def test_barcode_find_barcode():
    img = Factory.Image(BARCODE_IMAGE)
    featureset = img.find_barcode()
    f = featureset[0]
    img_crop = f.crop()
    result = [img_crop]
    name_stem = "test_barcode_find_barcode"
    perform_diff(result, name_stem, 0.0)
예제 #6
0
def test_barcode():
    img = Factory.Image(BARCODE_IMAGE)
    barcode = img.find_barcode()[0]
    repr_str = "%s.%s at (%d,%d), read data: %s" % (
            barcode.__class__.__module__, barcode.__class__.__name__, barcode.x, barcode.y,
        barcode.data)
    assert_equals(barcode.__repr__(), repr_str)
    barcode.draw(color=(255, 0, 0), width=5)
    assert_equals(barcode.length(),[262.0])
    assert_almost_equals(barcode.get_area(), 68644.0)
    perform_diff([img], "test_barcode", 0.0)