本文整理汇总了Python中helpers.Helpers.thresholdify方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.thresholdify方法的具体用法?Python Helpers.thresholdify怎么用?Python Helpers.thresholdify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.Helpers
的用法示例。
在下文中一共展示了Helpers.thresholdify方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Extractor
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import thresholdify [as 别名]
class Extractor(object):
'''
Stores and manipulates the input image to extract the Sudoku puzzle
all the way to the cells
'''
def __init__(self, path):
self.helpers = Helpers() # Image helpers
self.image = self.loadImage(path)
self.preprocess()
#self.helpers.show(self.image, 'After Preprocessing')
sudoku = self.cropSudoku()
#self.helpers.show(sudoku, 'After Cropping out grid')
sudoku = self.straighten(sudoku)
#self.helpers.show(sudoku, 'Final Sudoku grid')
self.cells = Cells(sudoku).cells
def loadImage(self, path):
color_img = cv2.imread(path)
if color_img is None:
raise IOError('Image not loaded')
print 'Image loaded.'
return color_img
def preprocess(self):
print 'Preprocessing...',
self.image = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)
self.image = self.helpers.thresholdify(self.image)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))
self.image = cv2.morphologyEx(self.image, cv2.MORPH_CLOSE, kernel)
print 'done.'
def cropSudoku(self):
print 'Cropping out Sudoku...',
contour = self.helpers.largestContour(self.image.copy())
sudoku = self.helpers.cut_out_sudoku_puzzle(self.image.copy(), contour)
print 'done.'
return sudoku
def straighten(self, sudoku):
print 'Straightening image...',
largest = self.helpers.largest4SideContour(sudoku.copy())
app = self.helpers.approx(largest)
corners = self.helpers.get_rectangle_corners(app)
sudoku = self.helpers.warp_perspective(corners, sudoku)
print 'done.'
return sudoku