Пример #1
0
            else:

                x, y, w, h = rect_generate(roi)
                digit_cut = roi[y:y + h, x:x + w]
                hip = int(math.sqrt(w**2 + h**2 + 30))
                hh = int((hip - h) / 2)
                ww = int((hip - w) / 2)
                mat = np.zeros((hip, hip)).astype('uint8')
                mat[hh:hh + h, ww:ww + w] = digit_cut
                inv = cv.bitwise_not(mat.copy(), roi.copy())

                ## Guardar los numeros en la matriz
                scale = (cv.resize(inv, (28, 28), interpolation=cv.INTER_AREA))
                norm = scale / 255
                x = norm.reshape(1, 28, 28, 1).astype('float32')
                m[i, j] = CNN.predict(x, verbose=0).argmax()

    output = trans.copy()
    k = m.copy()

    plt.imshow(trans, 'gray')
    plt.show()

    dfs = DFS(m)
    dfs.solve_sudoku()

    output = fill_image(m, k, num_array, output)
    result = cv.addWeighted(trans, 0.7, output, 0.2, 0)

    plt.imshow(result, 'gray')
    plt.show()