Giter Site home page Giter Site logo

webcam-sudoku-solver's Introduction

webcam-sudoku-solver

Introduction

This is a project mainly to explore OpenCV. Since I don't know how to play sudoku at all, it would be nice if I could create something that can do it for me. Here it is.

How to run

Install dependencies

Make sure you have Python 2.7. Does not work with Python 3.

pip install -r requirements.txt

That should bring you all the dependencies.

Train the neural network model

cd src
python nn_train.py

This takes a while. I am using a simple NN to do the digit recognition. The result is not quite satisfactory. So here is a TODO.

Execute the program

python main.py

How does it work

First thing is of course get the video buffer from the camera, like this:

raw

Then extract the contours, try to find a sudoku board. If a qualified square contour is found, project it as an orthophoto, and do some pre-processing to it.

ortho_bw

After successfully extract the board, run Hough line transformation on it. If everything goes right, effectively each cell is determined. Then we can do the digit recognition on each cell. Empty cells are denoted as 0.

ortho_raw

Once we have a grid of digits, we can use the solver to solve it! In this project, a Z3 solver is used. Basically model the problem as a CSP, then Z3 can give the arrangment efficiently. Which bring us to the final result:

result

webcam-sudoku-solver's People

Contributors

fredwangwang avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

webcam-sudoku-solver's Issues

error while training

PS C:\Users.......\src> python nn_train.py
Traceback (most recent call last):
File "nn_train.py", line 8, in
training, validating, testing = nn_collect.load_mnist()
File "C:\Users.....\src\nn_collect.py", line 16, in load_mnist
os.curdir, 'data', 'mnist.pkl.gz'), 'rb')
File "C:\Python27\lib\gzip.py", line 34, in open
return GzipFile(filename, mode, compresslevel)
File "C:\Python27\lib\gzip.py", line 94, in init
fileobj = self.myfileobj = builtin.open(filename, mode or 'rb')
IOError: [Errno 2] No such file or directory: '.\data\mnist.pkl.gz'

Recognizing other sudokus

I was trying to test this app with an unsolved sudoku, other than the one in the example but I wasn't able to the app doesn't recognize the new ones, is there any reason why these happens?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.