{"id":19236750,"url":"https://github.com/saharshleo/sudokusolver","last_synced_at":"2025-04-21T05:32:35.918Z","repository":{"id":111954405,"uuid":"279032691","full_name":"saharshleo/sudokuSolver","owner":"saharshleo","description":"Hello World of Computer Vision and ML","archived":false,"fork":false,"pushed_at":"2020-07-26T20:08:53.000Z","size":5657,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T10:35:34.375Z","etag":null,"topics":["backtracking","computer-vision","digit-recognition-mnist","opencv-python","sudoku-solver"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saharshleo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-12T09:32:40.000Z","updated_at":"2022-01-30T16:25:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"a15ad141-7a44-491a-87a3-f2b83d3cc618","html_url":"https://github.com/saharshleo/sudokuSolver","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saharshleo%2FsudokuSolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saharshleo%2FsudokuSolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saharshleo%2FsudokuSolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saharshleo%2FsudokuSolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saharshleo","download_url":"https://codeload.github.com/saharshleo/sudokuSolver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250002299,"owners_count":21359090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backtracking","computer-vision","digit-recognition-mnist","opencv-python","sudoku-solver"],"created_at":"2024-11-09T16:22:57.894Z","updated_at":"2025-04-21T05:32:35.900Z","avatar_url":"https://github.com/saharshleo.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sudoku Solver\nHello World of Computer Vision and Machine Learning   \n\n\u003c!-- TABLE OF CONTENTS --\u003e\n## Table of Contents\n\n* [About the Project](#about-the-project)\n  * [Tech Stack](#tech-stack)\n  * [File Structure](#file-structure)\n* [Getting Started](#getting-started)\n  * [Prerequisites](#prerequisites)\n  * [Installation](#installation)\n* [Usage](#usage)\n* [Results](#results)\n* [To Do](#to-do)\n* [Troubleshooting](#troubleshooting)\n* [Contributors](#contributors)\n* [Resources](#resources)\n* [License](#license)\n\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project \n![DemoImg](https://github.com/saharshleo/sudokuSolver/blob/master/assets/demo.png)\n\n_Solve sudoku puzzle using computer vision and machine learning. Currently(v1.0) solves sudoku from image and overlays missing digits on it_  \n***\n**Steps followed in this process:**\n1. Preprocess image (resize, grayscale, blur, threshold, dilation/opening)  \n\n|![original](https://github.com/saharshleo/sudokuSolver/blob/master/test_imgs/sudoku9.png)|![resized](https://github.com/saharshleo/sudokuSolver/blob/master/assets/resized_image.png)|![gray](https://github.com/saharshleo/sudokuSolver/blob/master/assets/gray.png)|![blur](https://github.com/saharshleo/sudokuSolver/blob/master/assets/blur.png)|![threshold](https://github.com/saharshleo/sudokuSolver/blob/master/assets/threshold.png)|![negate](https://github.com/saharshleo/sudokuSolver/blob/master/assets/negate.png)|![dilate](https://github.com/saharshleo/sudokuSolver/blob/master/assets/processed_img.png)|\n|:---:|:---:|:---:|:---:|:---:|:---:|:---:|\n|Original|Resized|GrayScale|Gaussian Blur|Adaptive Threshold|Negate|Dilation|  \n\n2. Draw external contours.  \n\n|![contour](https://github.com/saharshleo/sudokuSolver/blob/master/assets/external_contours.png)|\n|:---:|\n|External Contours|  \n\u003e Current method assumes that the sudoku has largest contour in given image  \n\n3. Infer corners of largest contour(sudoku puzzle) and Perspective transformation based on corners\n\n|![corner](https://github.com/saharshleo/sudokuSolver/blob/master/assets/corners.png)|![transform](https://github.com/saharshleo/sudokuSolver/blob/master/assets/warped_resized.png)|\n|:---:|:---:|\n|Corners|Transform|\n\n4. Infer grid from transformed image. \n\n|![grid](https://github.com/saharshleo/sudokuSolver/blob/master/assets/grid_img.png)|\n|:---:|\n|Grid|\n\u003e Current method just divides the transformed image into number of cells in sudoku puzzle i.e 81\n\n5. Extract digits from cell by finding largest connected pixel structure in mid part of cell. \nScale and centre each digit, so that it becomes apt for prediction using neural network \n\n|![digits](https://github.com/saharshleo/sudokuSolver/blob/master/assets/extracted_digits.png)|\n|:---|\n|Extracted Digits|\n\n6. Classify Digits using trained model\n7. Solve the grid using backtracking algorithm\n8. Draw the numbers on black background, inverse transform it and add it to original image\n\n|![missing_digit](https://github.com/saharshleo/sudokuSolver/blob/master/assets/digit_img.png)|![solution](https://github.com/saharshleo/sudokuSolver/blob/master/assets/final_img.png)|\n|:---:|:---:|\n|Missing Digits|Solution|\n\n### Tech Stack\n\n* [OpenCV](https://opencv.org/)\n* [Tensorflow-Keras](https://www.tensorflow.org/guide/keras/sequential_model)  \n\n\n### File Structure\n    .\n    ├── run.py                  # Driver code\n    ├── utils                   # helper classes\n    │   ├── img_processing.py   # helper functions for image processing\n    │   ├── classify_digit.py   # helper functions for digit classification\n    │   └── solve_sudoku.py     # helper functions to solve partially filled sudoku\n    ├── test_imgs               # images for testing\n    ├── assets                  # for readme\n    ├── digit_classifier        # codes to train digit classifier\n    ├── LICENSE\n    └── README.md \n    \n\u003c!-- GETTING STARTED --\u003e\n## Getting Started\n\n### Prerequisites \nTested on - \n* Tensorflow v2.2.0\n* OpenCV v4.1.0\n* numpy v1.18.5\n* scipy v1.4.1\n* tabulate v0.8.7\n\n### Installation\n1. Clone the repo\n```sh\ngit clone https://github.com/saharshleo/sudokuSolver.git\n```\n2. Download the pretrained model from releases [v1.0](https://github.com/saharshleo/sudokuSolver/releases/tag/v1.0)\n3. Extract the model inside `sudokuSolver/models/`\n\n\n\u003c!-- USAGE EXAMPLES --\u003e\n## Usage\n```\ncd /path/to/sudokuSolver\n```\n\n```\npython run.py\n```\n\u003e For viewing the journey of image\n```\npython run.py --show True\n```\n\n\n\u003c!-- RESULTS --\u003e\n## Results\n \n![**Inference**](https://github.com/saharshleo/sudokuSolver/blob/master/assets/demo2.png)    \n\n\n\u003c!-- TO DO --\u003e\n## To Do\n- [x] v1.0 Solve using Image processing and Machine learning\n- [ ] v1.1 Training on own data since model trained on mnist dataset did not gave acceptable results\n- [ ] v1.2 Solving on video stream\n- [ ] v1.3 Robust method for infering grid\n- [ ] v1.4 Different approach for extracting digits robust to lighting variations\n- [ ] v1.5 Able to recognize rotated sudoku's\n- [ ] v2.0 GUI game  \n\n\n\u003c!-- TROUBLESHOOTING --\u003e\n## Troubleshooting\n* Changing parameters like `--process`, `--resize`, `--margin` can prove to be effective for some images and models  \n\u003e Dilation for `test_imgs/sudoku5.jpg`\n\n|![corners-dilation](https://github.com/saharshleo/sudokuSolver/blob/master/assets/corners_dilation_sudoku5.png)|![grid-dilation](https://github.com/saharshleo/sudokuSolver/blob/master/assets/grid_img_dilation_sudoku5.png)|\n|:---:|:---:|\n|Corners Dilation|Infered Grid|  \n\n\u003e Opening for `test_imgs/sudoku5.jpg`\n\n|![corners-opening](https://github.com/saharshleo/sudokuSolver/blob/master/assets/corners_opening_sudoku5.png)|![grid-opening](https://github.com/saharshleo/sudokuSolver/blob/master/assets/grid_img_opening_sudoku5.png)|\n|:---:|:---:|\n|Corners Opening|Infered Grid|  \n\n\n\u003c!-- CONTRIBUTORS --\u003e\n## Contributors\n* [Saharsh Jain](https://github.com/saharshleo)\n\n\n\u003c!-- RESOURCES --\u003e\n## Resources  \n* [Nesh Patel's Sudoku Solver](https://medium.com/@neshpatel/solving-sudoku-part-ii-9a7019d196a2) \n* [Backtracking for solving](https://www.geeksforgeeks.org/sudoku-backtracking-7/)\n* [Floodfill](https://medium.com/@elvisdias/introduction-to-opencv-with-python-i-9fc72082f230)\n* [Image Processing](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_table_of_contents_imgproc/py_table_of_contents_imgproc.html)\n* [Corners from points](https://www.pyimagesearch.com/2016/03/21/ordering-coordinates-clockwise-with-python-and-opencv/)\n* [Conulutional network for digit classification](https://www.kaggle.com/dingli/digits-recognition-with-cnn-keras)\n\n\n\u003c!-- LICENSE --\u003e\n## License\nDescribe your [License](LICENSE) for your project. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaharshleo%2Fsudokusolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaharshleo%2Fsudokusolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaharshleo%2Fsudokusolver/lists"}