This project processes an image of a Sudoku puzzle, extracts the puzzle using OCR, and then solves it using a C-based solver. The solution is executed via a Python script that interacts with both the OCR API and the C executable.
/CLionProjects/sudoku_solver/src/
├── image_processing
│ ├── main.py # Main Python script to handle OCR, puzzle creation, and C program execution
│ ├── sudoku_photo.jpg # Input Sudoku image
│ ├── sudoku_puzzle.txt # Generated text file containing the Sudoku puzzle
│ └── sudoku.txt # Placeholder text file (could be used for solving or debug purposes)
└── solver
├── main.c # C program source code for solving the Sudoku puzzle
├── sudoku # Compiled C executable for solving Sudoku
└── Makefile # Build instructions for the C program (optional)
- Python 3.x
- Libraries:
requestsfor making API callspython-dotenvfor loading environment variablessubprocessfor running the C program
- C Compiler:
- A C compiler like
gccorclangto compile the C program.
- A C compiler like
- Tesseract OCR: To extract the puzzle from the image.
You can install the required Python libraries using pip:
pip install -r requirements.txt-
Clone the repository:
git clone https://github.com/yourusername/sudoku_solver.git cd sudoku_solver -
Create
.envFile: In theimage_processingdirectory, create a.envfile with the following content:RAPIDAPI_KEY=your_rapidapi_key_here RAPIDAPI_HOST=sudoku-ocr.p.rapidapi.comReplace
your_rapidapi_key_herewith your actual API key from RapidAPI. -
Compile the C Program: Navigate to the
solverdirectory and compile the C program:gcc -o sudoku sudoku.c # or use 'clang' if that's your preferred compiler -
Make Sure the Executable Has Permission: Ensure that the
sudokuexecutable has the correct permissions to execute:chmod +x solver/sudoku
Run the Python script from the image_processing directory:
python3 main.pyThe script will:
- Upload the Sudoku image to the OCR API.
- Receive the extracted puzzle and generate a
sudoku_puzzle.txtfile. - Pass the generated
sudoku_puzzle.txtfile to the C solver program (sudoku). - Print the result from the C solver.
Place your Sudoku image in the image_processing directory as sudoku_photo.jpg. The script will automatically use this image for OCR.
The C program will solve the Sudoku puzzle, and the output will be printed in the terminal.