def to_binary(self, image):
""" This method uses Adaptive Thresholding to convert
a blurred grayscale image to binary (only black and white).
The binary image is required to extract the full sudoku grid
from the image. """
if ENABLE_DEBUG:
print("DEBUG -- Attempting to apply adaptive threshold"
" and convert image to black and white.")
try:
thresh = cv2.adaptiveThreshold(image, 255, 1, 1, 11, 2)
except:
if VERBOSE_EXIT:
print("ERROR -- Unable to convert the image to black/white."
" Please contact the developer at %s and include this"
" error and the image you are using." % DEV_EMAIL)
exit()
if ENABLE_PREVIEW or ENABLE_PREVIEW_ALL:
image_preview(thresh)
if ENABLE_DEBUG:
print("DEBUG -- Image succesfully converted to binary.")
return thresh
评论列表
文章目录