本文整理汇总了Python中helpers.Helpers.colShift方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.colShift方法的具体用法?Python Helpers.colShift怎么用?Python Helpers.colShift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.Helpers
的用法示例。
在下文中一共展示了Helpers.colShift方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cells
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import colShift [as 别名]
class Cells(object):
'''
Extracts each cell from the sudoku grid obtained
from the Extractor
'''
def __init__(self, sudoku):
print 'Extracting cells...',
self.helpers = Helpers()
self.cells = self.extractCells(sudoku)
print 'done.'
def extractCells(self, sudoku):
cells = []
W, H = sudoku.shape
cell_size = W / 9
i, j = 0, 0
for r in range(0, W, cell_size):
row = []
j = 0
for c in range(0, W, cell_size):
cell = sudoku[r:r + cell_size, c:c + cell_size]
cell = self.helpers.make_it_square(cell, 28)
#self.helpers.show(cell, 'Before clean')
cell = self.clean(cell)
digit = Digit(cell).digit
#self.helpers.show(digit, 'After clean')
digit = self.centerDigit(digit)
#self.helpers.show(digit, 'After centering')
row.append(digit // 255)
j += 1
cells.append(row)
i += 1
return cells
def clean(self, cell):
contour = self.helpers.largestContour(cell.copy())
x, y, w, h = cv2.boundingRect(contour)
cell = self.helpers.make_it_square(cell[y:y + h, x:x + w], 28)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))
cell = cv2.morphologyEx(cell, cv2.MORPH_CLOSE, kernel)
cell = 255 * (cell / 130)
return cell
def centerDigit(self, digit):
digit = self.centerX(digit)
digit = self.centerY(digit)
return digit
def centerX(self, digit):
topLine = self.helpers.getTopLine(digit)
bottomLine = self.helpers.getBottomLine(digit)
if topLine is None or bottomLine is None:
return digit
centerLine = (topLine + bottomLine) >> 1
imageCenter = digit.shape[0] >> 1
digit = self.helpers.rowShift(
digit, start=topLine, end=bottomLine, length=imageCenter - centerLine)
return digit
def centerY(self, digit):
leftLine = self.helpers.getLeftLine(digit)
rightLine = self.helpers.getRightLine(digit)
if leftLine is None or rightLine is None:
return digit
centerLine = (leftLine + rightLine) >> 1
imageCenter = digit.shape[1] >> 1
digit = self.helpers.colShift(
digit, start=leftLine, end=rightLine, length=imageCenter - centerLine)
return digit