TestEvaluateOcr package

Submodules

TestEvaluateOcr.ImageGenerator module

The ImageGenerator takes the images from “_font_numbers”. Pastes them together to create a random number. If desired do some modifications to make them more ‘real’. The numbers are saved in the “_testImages” folder. The filename of the created images describes the rendered number.

TestEvaluateOcr.ImageGenerator.main()

The main() function checks the available options. These options are presented to the user to pick from. The user can select his/her preference of background and font. The main() function will then call Digits() to generate the images. Once completed it will notify the user that the script is done.

Todo

  • Create the option to generate:
    • images of all backgrounds in one call
    • all digit ranges in one call
    • images of all possible fonts in one call
    • all possibilities in one call
  • Refactor code in sub functions
TestEvaluateOcr.ImageGenerator.Digits(digit_num, digit_type, amount, font, background, process)

The Digits() function creates a set of images It places those images in _testImages, which is ignored by Mercurial It creates a folder per image set that is based on font and background

It also checks if the amount given is more than the available options If it’s more than is possible to generate The script will create each possibility effectively Otherwise it will generate random numbers The images are saved immediately in the correct folder

Todo

  • Print complete numbers on 1 background, instead of combining individual numbers + backgrounds.
  • Ensure a 0 can’t be placed in front of any other number
  • Create a folder for processed and non-processed images
Parameters:
  • digit_num – The length of numbers (e.g. 3 digits == 123)
  • digit_type – Which digits are included
  • amount – The amount of images to be created
  • font – The path of the fontNumbers created by DigNumberGenerator
  • background – The background image that is selected
  • process – To evaluate if the image needs to be processed
TestEvaluateOcr.ImageGenerator.adaptImage(image)

Adapts a ‘good’ image to a ‘real’ image, by blurring, adding noise, and deforming the image (i.e., the distance between the two upper corners is smaller than the distance between the two lower corners, which is the case by the images obtained with the web cam).

Todo

  • Make different steps more flexible.
Parameters:image – The image to be adapted.
Returns:An image that is similar to a photo.
Return type:result_image

TestEvaluateOcr.DigNumberGenerator module

The DigNumberGenerator generates images of the numbers 0 - 9. The user can select the desired font and background. The images are placed in “_font_numbers” within the current directory. Under the selected font and background.

TestEvaluateOcr.DigNumberGenerator.main()

The main() function checks the possible backgrounds and fonts. It then presents these options to the user so he/she can select them. If the font is installed and the input is valid it will start. Once the generation is comlete it will close immediately.

Todo

  • Allow the fonts to be used without being installed.

TestEvaluateOcr.test_evaluate_non_pp_ocr module

The test is responsible for evaluating the accuracy of Tesseract.

Before running this test: Test images can be generated using DigNumberGenerator and ImageGenerator. (see __README__.txt)

This script iterates through all the generated images. Feeds these images to PreprocessImages.py and ReadImage.py In order to evaluate the performance of the latter. As well as the effect that the PreprocessImages module has on the OCR. If the ReadImage module achieves a higher accuracy on preprocessed images. The PreprocessImages module has a positive effect on the accuracy.

The test images stored in the folder should be named accordingly. If the image depicts the number ‘1238’, the file should be named ‘1238.png’ The extension is irrelevant as long as OpenCV can read the image (This will always be the case if the images are generated)

TestEvaluateOcr.test_evaluate_non_pp_ocr.test_evaluate_non_pp_ocr()
TestEvaluateOcr.test_evaluate_non_pp_ocr.digitTest(directory)

TestEvaluateOcr.test_evaluate_pp_ocr module

The test is responsible for evaluating the accuracy of Tesseract.

Before running this test: Test images can be generated using DigNumberGenerator and ImageGenerator. (see __README__.txt)

This script iterates through all the generated images. Feeds these images to PreprocessImages.py and ReadImage.py In order to evaluate the performance of the latter. As well as the effect that the PreprocessImages module has on the OCR. If the ReadImage module achieves a higher accuracy on preprocessed images. The PreprocessImages module has a positive effect on the accuracy.

The test images stored in the folder should be named accordingly. If the image depicts the number ‘1238’, the file should be named ‘1238.png’ The extension is irrelevant as long as OpenCV can read the image (This will always be the case if the images are generated)

The raw input image and preprocessed image are visualized using imshow() These visualizations are purely there to provide insight. The visualizations can be removed to improve the performance of the script.

The waitKey() function of OpenCV can be set to 1 to auto-iterate all images By setting it to 0 the user can control the iterations. On key-press(e.g. enter), the script will move to the next image.

TestEvaluateOcr.test_evaluate_pp_ocr.test_evaluate_pp_ocr()
TestEvaluateOcr.test_evaluate_pp_ocr.digitTest(directory)

TestEvaluateOcr.test_improve_pp module

This test will test whether the improved preprocessing increase the number of correct estimations of the pp+ocr by 10%.

This module is a script that iterates through all images in the specified folder, feeds these images through PreprocessImages.py and ReadImage.py in order to evaluate the performance of the latter, as well as the effect that the PreprocessImages module has on ReadImage. This will be done twice: first for the default preprocessing, then for the increased preprocessing.

The test succeeds if the number of correct readings with the improved preprocessor is equal or more than 2x the number of the correct readings with the default preprocessor.

The test images stored in the folder should be named according to the number depicted in it. For example, if the image depicts the number ‘1238’, the file should be named ‘1238.jpg’ or ‘1238.png’. The extension is irrelevant as long as OpenCV can read the image using it’s imread() function.

TestEvaluateOcr.test_improve_pp.test_improve_pp()
TestEvaluateOcr.test_improve_pp.digitTest(directory)