Beispiel #1
0
Datei: main.py Projekt: d5h/pyocr
 def __init__(self, img):
     self.img = img
     self.binary_img = binary(img, invert=True)
     knn_test = KNNTest(data_path)
     self.char_test = Combiner([cont_test, mask_test, knn_test.test]).test
     self.objs = [
         ImgObj(x, self) for x in connected_components(self.binary_img) if self.good_component(x)
         ]
     self.compute_char_scores()
     self.group_words(score_threshold=0.2)
     self.spell_corrector = SpellingCorrector('/usr/share/dict/words')
Beispiel #2
0
    def generate_noise_points(self, output, num_samples):
        num_noise_points = 0
        for noise_img in self.noise_images:
            mat = cv.LoadImageM(noise_img, cv.CV_LOAD_IMAGE_GRAYSCALE)
            mat = binary(mat, invert=True)
            for com in connected_components(mat):
                if 10 < com.mask.rows and 5 < com.mask.cols:
                    num_noise_points += 1
                    output.write("\t%s\n" % float_list_to_tsv(params_from_component(com)))
                    if num_samples <= num_noise_points:
                        return num_samples

        return num_noise_points