示例#1
0
def readOneImg(path):
    oriImg = cv2.imread(path, 0)
    img = Util.binaryzation(oriImg)
    img = Util.erasePaddingInOneChar(img)
    height, width = img.shape
    #获取指定的三个分割点, 再根据分割点做分割线
    points, directions = getSpiltPoint(path[path.rindex('/'):])
    
    path1 = Util.fillPath(SpiltUtil.spiltOne(img, points[0], directions[0], 0), height)
    path2 = Util.fillPath(SpiltUtil.spiltOne(img, points[1], directions[1], 1), height)
    path3 = Util.fillPath(SpiltUtil.spiltOne(img, points[2], directions[2], 2), height)
    path0 = Util.getLeftBorder(height)
    path4 = Util.getRightBoder(width, height)
    ret = []
    
    ret.extend(Util.conventToTrainCharFromAllWrap(getOneChar(img, path0, path1)))
    ret.extend(Util.conventToTrainCharFromAllWrap(getOneChar(img, path1, path2)))
    ret.extend(Util.conventToTrainCharFromAllWrap(getOneChar(img, path2, path3)))
    ret.extend(Util.conventToTrainCharFromAllWrap(getOneChar(img, path3, path4)))
    return ret
示例#2
0
def readInput(svm, puzzle):
    oriImg = cv2.imread(puzzle, 0)
    img = Util.binaryzation(oriImg)
    img = Util.erasePaddingInOneChar(img)
    points, paths = SpiltUseBackground.getCornerPointsAndPaths(img)
    print("-------RECOGNISE--------")
    print(points)
    print("paths:")
    for p in paths:
        print(p)
    height, width = img.shape
    code = []
    #p1 = [23:39]
    path0 = Util.getLeftBorder(height)
    good_path, result = recogniseOne(svm, img, path0, paths, 0)
    print("First split point:" + str(good_path[0][0]) + " result:" +
          chr(svm.classes_[result] + ord('A')))
    code.append(chr(svm.classes_[result] + ord('A')))

    #path0 = Util.fillPath(SpiltUseCV2.spiltOne(img, p1), height)
    good_path, result = recogniseOne(svm, img, good_path, paths, 1)
    print("Second split point:" + str(good_path[0][0]) + " result:" +
          chr(svm.classes_[result] + ord('A')))
    code.append(chr(svm.classes_[result] + ord('A')))

    #path0 = Util.fillPath(SpiltUseCV2.spiltOne(img, p2), height)
    good_path, result = recogniseOne(svm, img, good_path, paths, 2)
    print("Third split point:" + str(good_path[0][0]) + " result:" +
          chr(svm.classes_[result] + ord('A')))
    code.append(chr(svm.classes_[result] + ord('A')))

    #path0 = Util.fillPath(SpiltUseCV2.spiltOne(img, p3), height)
    good_path, result = recogniseOne(svm, img, good_path, paths, 3)
    print("Fourth split point:" + str(good_path[0][0]) + " result:" +
          chr(svm.classes_[result] + ord('A')))
    code.append(chr(svm.classes_[result] + ord('A')))

    print("Result:" + str(code))
    return code