示例#1
0
    if not grid.is_valid():
        return False

    return grid.solve()


# Attempt to locate and solve the puzzle in the frame until a valid solution
# has been found.

while True:
    _, frame = video_capture.read()
    frame = cv2.resize(frame, (600, 600))
    clone = frame.copy()

    extractor.calculate_boxes(frame)
    draw_boxes(frame, extractor.boxes, COLOR_RED)
    valid_grid = extractor.test_boxes(frame)

    if valid_grid:
        grid_im = clone
        stop = solve_grid(grid_im, extractor, X, indices)
        if stop:
            break

    cv2.imshow('Video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# After the puzzle has been solved the solution will not be calculated again.
# The solution will only be applied to the grid in the frame when there is a