Skip to content

Commit e131bcb

Browse files
authored
Update README.md
1 parent b84e45f commit e131bcb

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

README.md

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
<img src="imgs/Banner.png" width=100%></img>
22

3-
43
## Table of Contents
54
- [Introduction](#introduction)
5+
- [How to use](#how-to-use)
66
- [How it works](#how-it-works)
7-
- [Getting Started](#getting-started)
7+
- [Build](#build)
88

99
## Introduction
1010

11+
This project is an android app that solves sudoku, hence the name, recognized from images using Optical Character Recognition or entered manually.
12+
13+
I've built this project the first time in early 2022 ( [v1](https://github.com/hypertensiune/Android-Sudoku-Solver-OCR/tree/v1) branch ) and this is a refresh, an update to the original project.
14+
15+
What's new:
16+
- Better image processing and sudoku board recognition
17+
- Better text recognition
18+
- Code refactoring in Kotlin
19+
- Improved documentation
20+
21+
## How to use
22+
23+
Download or [build](#build) the app yourself.
24+
Use it like a camera app, press the shutter button when the sudoku it's detected and it will be solved. You can also edit it or input it manually if you want.
25+
26+
It works on both puzzles on paper or on screen, the only requirement is there is enough light and that it's smooth.
27+
28+
<p align="center">
29+
<img src="imgs/scr1.jpeg" width=30%></img>
30+
&nbsp;&nbsp&nbsp;&nbsp&nbsp;
31+
<img src="imgs/scr2.jpeg" width=30%></img>
32+
</p>
33+
1134
## How it works
1235

1336
### Sudoku board detection
@@ -19,8 +42,6 @@ To identify the sudoku board the input image is processed as follows with [OpenC
1942

2043
The numbers are detected using [MLKit Text Recognition](https://developers.google.com/ml-kit/vision/text-recognition/v2).
2144

22-
<br>
23-
2445
<p align="center">
2546
<img src="demo/demo1.gif"></img>
2647
</p>
@@ -29,11 +50,11 @@ The numbers are detected using [MLKit Text Recognition](https://developers.googl
2950

3051
### Solving
3152
For solving the puzzle I'm using a fairly simple, brute-force algorithm that relies on backtracking to generate the valid solution.
32-
<br>
53+
3354
It goes through the whole 2D array and for each number that needs to be found it tries all possibilities and continues with the following numbers.
34-
<br>
35-
<br>
36-
For each cell there are 9 possible numbers which means the time complexity of this algorithm is O(9<sup>N</sup>).
55+
56+
57+
For each cell there are 9 possible numbers which means the time complexity of this algorithm is O(9<sup>n</sup>).
3758

3859
```
3960
private fun solve(index: Int = 0): Boolean {
@@ -64,4 +85,48 @@ private fun solve(index: Int = 0): Boolean {
6485
<span>Solve algorithm demo</span>
6586
</p>
6687

67-
## Getting Started
88+
## Build
89+
90+
- Download or clone the repository and open it in Android Studio.
91+
- Download the android version of [OpenCV](https://opencv.org/releases/). I used the latest version, 4.8.0.
92+
- Import the OpenCV module in Android Studio.
93+
* Click **File > New > Import Module**, select the **OpenCV-android-sdk/sdk** directory and change the module name to **opencv**.
94+
* Goto **File > Project Structure > Dependencies** and on the **app** module add **opencv** as a dependency.
95+
* In **opencv build.gradle** add ```android { namespace 'org.opencv' }```, change ```compileSdkVersion``` and ```targetSdkVersion``` to 33 and finally, add
96+
```
97+
kotlinOptions {
98+
jvmTarget = '1.8'
99+
}
100+
buildFeatures {
101+
buildConfig true
102+
aidl true
103+
}
104+
```
105+
* Further we need to modify the following classes in the OpenCV module:
106+
* **CameraBridgeViewBase**: add ```canvas.rotate(90f, canvas.getWidth() / 2, canvas.getHeight() / 2);``` in function ```deliverAndDrawFrame```, right before drawing the bitmap.
107+
* **JavaCameraView** add:
108+
```
109+
public void turnOnFlashlight(){
110+
Camera.Parameters params = mCamera.getParameters();
111+
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
112+
mCamera.setParameters(params);
113+
}
114+
115+
public void turnOffFlashLight(){
116+
Camera.Parameters params = mCamera.getParameters();
117+
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
118+
mCamera.setParameters(params);
119+
}
120+
```
121+
In function ```iniliazeCamera``` change
122+
```
123+
if ((getLayoutParams().width == LayoutParams.MATCH_PARENT) && (getLayoutParams().height == LayoutParams.MATCH_PARENT))
124+
mScale = Math.min(((float)height)/mFrameHeight, ((float)width)/mFrameWidth);
125+
else
126+
mScale = 0;
127+
```
128+
to
129+
```
130+
mScale = Math.max(((float)height)/mFrameHeight, ((float)width)/mFrameWidth);
131+
```
132+
- Done, you can now build the project

0 commit comments

Comments
 (0)