pyaota.ocr.digit_ocr module

MNIST-style digit OCR using a CNN.

pyaota.ocr.digit_ocr.load_digit_model(model_path=None)[source]

Load (or reuse) the MNIST-style digit classifier. If no model path is provided, use the default model from the package.

Return type:

Model

pyaota.ocr.digit_ocr.ocr_digit_nn(img_gray, model=None, target_size=(28, 28))[source]

Run the CNN digit classifier on a single grayscale crop.

Returns:

digit_str: ‘0’..’9’ or None if unreadable confidence: softmax probability of the predicted class (0..1)

Return type:

Tuple[Optional[str], float]

pyaota.ocr.digit_ocr.preprocess_digit_crop(img_gray, target_size=(28, 28))[source]

Preprocess a grayscale digit crop for the CNN:

  • ensure grayscale

  • threshold to binary (digit strokes dark)

  • resize to target_size

  • normalize to [0, 1]

  • shape: (1, H, W, 1)

Return type:

ndarray