Ejemplo n.º 1
0
def search(classifier, img_path, feature_descriptors, c_backend):
    img = Image.open(img_path)
    img = img.convert("L")
    
    print "searching image"
    results = []
    count = 0
    for start, end in all_windows((0,0),
                                  (img.size[1], img.size[0])):
        
        # TODO: refactor code in faces.py so I can call that
        # instead of having this mess right here.
        window = img.crop((start[1], start[0], end[1], end[0]))
        window_pre_resize = window
        window = window.resize((16, 16))
        ar = faces.f_vec(window)
        faces.integrate_image(ar)
        int_img = faces.IntegratedImage(ar)
        
        # Yuck. Needs a little refactoring to make this cleaner.
        if 1 == list(classifier.classify([faces.Datum(
                        img_path,
                        -1,
                        faces.LazyFeatureVec(int_img,
                                             feature_descriptors,
                                             c_backend))]))[0]:
            print "match %s" % repr((start, end))

            results.append((start, end))
            if len(results) > 10:
                break

    plot_search(img, results)
Ejemplo n.º 2
0
def search(classifier, img_path, feature_descriptors, c_backend):
    img = Image.open(img_path)
    img = img.convert("L")

    print "searching image"
    results = []
    count = 0
    for start, end in all_windows((0, 0), (img.size[1], img.size[0])):

        # TODO: refactor code in faces.py so I can call that
        # instead of having this mess right here.
        window = img.crop((start[1], start[0], end[1], end[0]))
        window_pre_resize = window
        window = window.resize((16, 16))
        ar = faces.f_vec(window)
        faces.integrate_image(ar)
        int_img = faces.IntegratedImage(ar)

        # Yuck. Needs a little refactoring to make this cleaner.
        if 1 == list(
                classifier.classify([
                    faces.Datum(
                        img_path, -1,
                        faces.LazyFeatureVec(int_img, feature_descriptors,
                                             c_backend))
                ]))[0]:
            print "match %s" % repr((start, end))

            results.append((start, end))
            if len(results) > 10:
                break

    plot_search(img, results)
Ejemplo n.º 3
0
 def validate(self, ar, start, end, output):
     ar = numpy.array(ar)
     faces.integrate_image(ar)
     img = faces.IntegratedImage(ar)
     self.assertEqual(faces.feature_a(img, start, end), output)
Ejemplo n.º 4
0
 def validate(self, input, output):
     input = numpy.array(input, dtype=numpy.int64, ndmin=2)
     output = numpy.array(output, dtype=numpy.int64, ndmin=2)
     faces.integrate_image(input)
     testing.assert_equal(input, output)
Ejemplo n.º 5
0
 def validate(self, ar, start, end, output):
     ar = numpy.array(ar)
     faces.integrate_image(ar)
     img = faces.IntegratedImage(ar)
     self.assertEqual(faces.feature_a(img, start, end), output)
Ejemplo n.º 6
0
 def validate(self, input, output):
     input = numpy.array(input, dtype=numpy.int64, ndmin=2)
     output = numpy.array(output, dtype=numpy.int64, ndmin=2)
     faces.integrate_image(input)
     testing.assert_equal(input, output)