コード例 #1
0
 def test_ground_unicode(self):
     imgf = open_image(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)
コード例 #2
0
 def test_ground_unicode(self):
     imgf = open_image(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)
コード例 #3
0
ファイル: example.py プロジェクト: ydtan123/simple-ocr-opencv
from simpleocr.files import open_image
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_image('digits1'))

test_image = open_image('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)
コード例 #4
0
from simpleocr.files import open_image
from simpleocr.grounding import UserGrounder
from simpleocr.segmentation import ContourSegmenter

segmenter = ContourSegmenter(blur_y=5, blur_x=5, block_size=11, c=10)
new_image = open_image('digits1')
segments = segmenter.process(new_image.image)

grounder = UserGrounder()
grounder.ground(new_image, segments)
new_image.ground.write()
コード例 #5
0
 def setUp(self):
     self.img = open_image('digits1')
     self.img.remove_ground()
     self.assertFalse(self.img.is_grounded)
     self.segments = ContourSegmenter().process(self.img.image)
コード例 #6
0
 def setUp(self):
     self.img = open_image('digits1')
     self.img.remove_ground()
     self.assertFalse(self.img.is_grounded)
     self.segments = ContourSegmenter().process(self.img.image)
コード例 #7
0
 def test_open_image_nonexistent(self):
     with self.assertRaises(IOError):
         open_image("inexistent")
コード例 #8
0
 def test_open_image(self):
     # in data dir, no extension
     open_image(TEST_FILE)
     # in data dir, with extension
     open_image(TEST_FILE_EXT)
     # absolute path, no extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_image(os.path.join(data_dir, TEST_FILE))
     # absolute path, with extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_image(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_image(os.path.join(data_dir_name, TEST_FILE))
         # relative path, with extension
         open_image(os.path.join(data_dir_name, TEST_FILE_EXT))
     finally:
         os.chdir(old_cwd)
コード例 #9
0
 def test_ocr_unicode(self):
     self._test_ocr(open_image('unicode1'), open_image('unicode1'))
コード例 #10
0
 def test_ocr_digits(self):
     self._test_ocr(open_image('digits1'), open_image('digits2'))
コード例 #11
0
 def test_opencv_brightness_raise(self):
     image = open_image('digits1')
     processor = opencv_utils.BrightnessProcessor(brightness=2.0)
     self.assertRaises(AssertionError, lambda: processor._process(image.image))
コード例 #12
0
 def test_opencv_brightness(self):
     image = open_image('digits1')
     processor = opencv_utils.BrightnessProcessor(brightness=0.5)
     processor._process(image.image)
コード例 #13
0
 def test_open_image_nonexistent(self):
     with self.assertRaises(IOError):
         open_image("inexistent")
コード例 #14
0
 def test_open_image(self):
     # in data dir, no extension
     open_image(TEST_FILE)
     # in data dir, with extension
     open_image(TEST_FILE_EXT)
     # absolute path, no extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_image(os.path.join(data_dir, TEST_FILE))
     # absolute path, with extension
     data_dir = simpleocr.files.DATA_DIRECTORY
     open_image(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_image(os.path.join(data_dir_name, TEST_FILE))
         # relative path, with extension
         open_image(os.path.join(data_dir_name, TEST_FILE_EXT))
     finally:
         os.chdir(old_cwd)