Exemplo n.º 1
0
 def test_ground_unicode(self):
     imgf = open_img(UNICODE_TEST_FILE)
     self.assertEqual(imgf.is_grounded, True)
     imgf.set_ground(imgf.ground.segments,
                     imgf.ground.classes,
                     write_file=False)
     self.assertEqual(imgf.is_grounded, True)
     imgf.remove_ground(remove_file=False)
     self.assertEqual(imgf.is_grounded, False)
Exemplo n.º 2
0
 def test_opencv_brightness_raise(self):
     image = open_img('digits1')
     processor = opencv_utils.BrightnessProcessor(brightness=2.0)
     self.assertRaises(AssertionError,
                       lambda: processor._process(image.image))
Exemplo n.º 3
0
 def test_opencv_brightness(self):
     image = open_img('digits1')
     processor = opencv_utils.BrightnessProcessor(brightness=0.5)
     processor._process(image.image)
Exemplo n.º 4
0
 def setUp(self):
     self.img = open_img('digits1')
     self.img.remove_ground()
     self.assertFalse(self.img.is_grounded)
     self.segments = ContourSegmenter().process(self.img.image)
Exemplo n.º 5
0
 def test_open_img_inexistent(self):
     with self.assertRaises(IOError):
         open_img("inexistent")
Exemplo n.º 6
0
 def test_open_img(self):
     # in data dir, no extension
     open_img(TEST_FILE)
     # in data dir, with extension
     open_img(TEST_FILE_EXT)
     # absolute path, no extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_img(os.path.join(data_dir, TEST_FILE))
     # absolute path, with extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_img(os.path.join(data_dir, TEST_FILE_EXT))
     #
     data_dir_name = os.path.basename(data_dir)
     old_cwd = os.getcwd()
     os.chdir(os.path.dirname(data_dir))  # set cwd to one above data_dir
     try:
         # relative path, no extension
         open_img(os.path.join(data_dir_name, TEST_FILE))
         # relative path, with extension
         open_img(os.path.join(data_dir_name, TEST_FILE_EXT))
     finally:
         os.chdir(old_cwd)
Exemplo n.º 7
0
from simpleocr.files import open_img
from simpleocr.segmentation import ContourSegmenter
from simpleocr.feature_extraction import SimpleFeatureExtractor
from simpleocr.classification import KNNClassifier
from simpleocr.ocr import OCR, accuracy, show_differences

segmenter = ContourSegmenter(blur_y=5, blur_x=5, block_size=11, c=10)
extractor = SimpleFeatureExtractor(feature_size=10, stretch=False)
classifier = KNNClassifier()
ocr = OCR(segmenter, extractor, classifier)

ocr.train(open_img('digits1'))

test_image = open_img('digits2')
test_chars, test_classes, test_segments = ocr.ocr(test_image, show_steps=True)

print("accuracy:", accuracy(test_image.ground.classes, test_classes))
print("OCRed text:\n", test_chars)
Exemplo n.º 8
0
 def test_ocr_unicode(self):
     self._test_ocr(open_img('unicode1'), open_img('unicode1'))
Exemplo n.º 9
0
 def test_ocr_digits(self):
     self._test_ocr(open_img('digits1'), open_img('digits2'))