Example #1
0
def _extraction_iterator_map(image, use_local_thresholding=False, apply_gaussian=False, n=5):

    if apply_gaussian:
        img = gaussian_filter(image, (3.0, 3.0))
    else:
        img = image

    for edges in iter_blob_contours(img, n=n):
        try:
            warped_image = geometry.warp_image_by_interp_borders(edges, img)
            sudoku, bin_image = geometry.split_image_into_sudoku_pieces_adaptive_global(
                warped_image, otsu_local=use_local_thresholding, apply_gaussian=apply_gaussian)
        except SudokuExtractError as e:
            pass
        except Exception as e:
            # Try next blob
            raise
        else:
            yield sudoku, bin_image
Example #2
0
def _extraction_iterator_corners(image, use_local_thresholding=False, apply_gaussian=False, n=5):
    # If the image is too small, then double its scale until big enough.
    img = image
    while max(img.shape) < 500:
        img = resize(img, np.array(img.shape) * 2)

    if apply_gaussian:
        img = gaussian_filter(image, (3.0, 3.0))

    for corner_points in iter_blob_extremes(img, n=n):
        try:
            warped_image = geometry.warp_image_by_corner_points_projection(corner_points, img)
            sudoku, bin_image = geometry.split_image_into_sudoku_pieces_adaptive_global(
                warped_image, otsu_local=use_local_thresholding, apply_gaussian=apply_gaussian)
        except SudokuExtractError:
            # Try next blob.
            pass
        except Exception as e:
            raise
        else:
            yield sudoku, bin_image
Example #3
0
def _extraction_iterator_map(image,
                             use_local_thresholding=False,
                             apply_gaussian=False,
                             n=5):

    if apply_gaussian:
        img = gaussian_filter(image, (3.0, 3.0))
    else:
        img = image

    for edges in iter_blob_contours(img, n=n):
        try:
            warped_image = geometry.warp_image_by_interp_borders(edges, img)
            sudoku, bin_image = geometry.split_image_into_sudoku_pieces_adaptive_global(
                warped_image,
                otsu_local=use_local_thresholding,
                apply_gaussian=apply_gaussian)
        except SudokuExtractError as e:
            pass
        except Exception as e:
            # Try next blob
            raise
        else:
            yield sudoku, bin_image