Transcript
Page 1: Sudoku  Downloader  and  Recognizer

Sudoku Downloader and Recognizer

Author: Pedro Evaristo González Sánchez

Page 2: Sudoku  Downloader  and  Recognizer

Main Activity(Portrait)

Recognizement

Custom View

Gaming

Backtracking

Board Downloader

Page 3: Sudoku  Downloader  and  Recognizer

Custom view

- Paint and Canvas to draw, background, lines and numbers

- Adaptable ( OnSizeChanged )

- Events Self-management( onTouchEvent, onKeypressed )

- Interaction with Main Activity

Page 4: Sudoku  Downloader  and  Recognizer

Custom View – Main Activity

Main Activity instances Custom View

Main activity set sensorial’s methods of the Custom View (Focusable…)

Whether a Button number is pressed, Main Activity recieves the actual cell position iluminated

Main Activity updates the Sudoku Board and order the custom view to be painted onDraw() and invalidate() )

Page 5: Sudoku  Downloader  and  Recognizer

Class Sudoku (I) Matrix [9][9] of Integers

Constructor overload ( String ) to implement the communication between activities

The class return a String which contains the sudoku board. This is very helpful for several situations. For innstance ( Bundle and Activities communication)

Neighbor checking ( row, column and block )

Page 6: Sudoku  Downloader  and  Recognizer

Sudoku Class II ( Backtracking )

- If the actual Cell is (9,9) => Ends

- If you find a number, go to the next cell ( Original Sudoku )

- For each value 1..9

- If neighbor checking is positive- Sudoku(i+1,j+1)

- If you don’t find a candidate, restore and go back one cell

Page 7: Sudoku  Downloader  and  Recognizer

Download Activity (I)- A way to update the app game

- It exist a Sudoku board holded in a web server

- “Good formed” Board within a *.txt file.

- The goal is to rescue this board and take it to the Game

Page 8: Sudoku  Downloader  and  Recognizer

Download Activity (II)

Page 9: Sudoku  Downloader  and  Recognizer

3. Sudoku Recognizer

3.0 Android previous concepts

3.1 Image Capture

3.2 Image processing (OpenCV)

3.3 Optical Chracter Recognition (OCR) Tesseract

Page 10: Sudoku  Downloader  and  Recognizer

3.0 Android previous concepts

SDK and OpenCV Library (OpenCV)

NDK (Native Developing Kit) ( Tesseract ) Build libraries and reference them in the application.

Page 11: Sudoku  Downloader  and  Recognizer

3.1 Image Capture

- Calling the Intent in charge of capturing images of Android

- Capture and save the image in a temporal file

- Pre-processing => Finding the balance between good qualitiy and computability

Page 12: Sudoku  Downloader  and  Recognizer

3.2 Image Processing (I) First controversy, the image is in perspective => the board is

not a quad, is a trapezoid

The Main concern is a processing in two levels (RGB and GRAY)

Page 13: Sudoku  Downloader  and  Recognizer

Border’s detection

Next, searching the biggest contour within the image. (ROI)

Image Processing (II)

Page 14: Sudoku  Downloader  and  Recognizer

Image Processing (III) Hough algorithm and transform to find the boards lines Two fundamental concepts in line processing:

Every single line will be delete painting them of white or black in each case (RGB and GRAY).

Check if the start point or end point of line is inside some of the four rect corners of the image

Page 15: Sudoku  Downloader  and  Recognizer

Image Processing (IV) Getting the matrix that defines the perspective transformation

needed to extrapolate the corners of the board to the corners of the image

Apply a WarpPerspective Transformation with the matriz obtained.

Page 16: Sudoku  Downloader  and  Recognizer

Image Processing (V)

At this point, the board is divided in equal cells to process each one of them

Page 17: Sudoku  Downloader  and  Recognizer

Procesamiento de la Imagen (VI)

Single cell processing in paralell (RGB and Gray) bearing in mind Tesseracts requeriments.

Equalizing Histogram

Threshold Smooth + Dilate

findContours()

Page 18: Sudoku  Downloader  and  Recognizer

Tesseract ( OCR )

¡Don’t wait for a miracle!. You need an strong image processing

Delimiting dictionary to numbers (1..9)

For each number it is necessary releasing the memory allocated by the image and by the tesseracts object. We are on a phone and we’ve got less memory resources.

Tesseract 6

Page 19: Sudoku  Downloader  and  Recognizer

That’s all. Thank you!!


Top Related