# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Looking for differences between digitial photos and screen cap images

# !tesseract -v

# !pip install --upgrade pip
# !pip install --user --upgrade "opencv-python"
# !pip install --upgrade wget
# !pip install --upgrade pytesseract

import os
import wget
import cv2 
import numpy
import time
import uuid
from matplotlib import pyplot
import pytesseract

# %cd ..
import image_utils
pyplot.rcParams['figure.dpi'] = 200


def print_matrix(matrix, title):
    print(title)
    for row in matrix:
        print(row)
    print()


def score_matrix(answer, key):
    total_correct = 0
    for row in range(0,9):
        for column in range(0,9):
            if answer[row][column] == key[row][column]:
                total_correct += 1
    return total_correct


images = [
    'IMG_1428-high.jpg',
    'IMG_1428-low.jpg',
    'IMG_1631-high.jpg',
    'IMG_1758.jpg',
    'IMG_1772.jpg',
    'IMG_1773.jpg',
    'IMG_1784.jpg',
    'IMG_1758.png',
    'sudoku2.png',
    'Sudoku-2020-10-29.png',
    'Sudoku_20200509.png',
    'sudokupuzzler.26.jpg'
]

for image_name in images:
    image_path = 'test/%s' % image_name
    image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
    print('Image: %s' % image_name)
    print('Shape: [%s, %s]' % (image.shape[0], image.shape[1]))
    print('Size: %s' % (image.shape[0]*image.shape[1]))

    color_dist = numpy.histogram(image, bins=256)
    total = color_dist[0].sum()
    color_dist_avg = numpy.zeros(len(color_dist[0]))
    for i in range(len(color_dist[0])):
        color_dist_avg[i] = color_dist[0][i]*100/total
    print('Standard deviation of counts: %s' % numpy.std(color_dist[0]))
    print('Ratio of std/size: %.2f' % (numpy.std(color_dist[0])/(image.shape[0] * image.shape[1])*1000))
    print('Standard deviation of averages: %s\n' % numpy.std(color_dist_avg))
    # print(color_dist[0])
    # print('\n')
    # print(color_dist_avg)
    # print('\n')


StarcoderdataJupyterScriptsDedupFiltered