190 likes | 403 Views
Sudoku Downloader and Recognizer. Author : Pedro Evaristo González Sánchez. Main Activity ( Portrait ) . Recognizement. Custom View. Gaming. Backtracking. Board Downloader. Custom view. Paint and Canvas to draw , background , lines and numbers Adaptable ( OnSizeChanged )
E N D
Sudoku Downloader and Recognizer Author: Pedro Evaristo González Sánchez
MainActivity(Portrait) Recognizement Custom View Gaming Backtracking BoardDownloader
Customview • Paintand Canvastodraw, background, lines and numbers • Adaptable ( OnSizeChanged) • EventsSelf-management( onTouchEvent, onKeypressed ) • InteractionwithMainActivity
Custom View –MainActivity • MainActivityinstancesCustom View • Mainactivity set sensorial’smethods of theCustom View (Focusable…) • Whether a Buttonnumberispressed, MainActivityrecievesthe actual cell position iluminated • MainActivityupdatesthe Sudoku Board and orderthecustomviewto be paintedonDraw() and invalidate() )
ClassSudoku (I) • Matrix[9][9] of Integers • Constructor overload( String) toimplementthecommunicationbetweenactivities • Theclassreturn a Stringwhichcontainsthe sudoku board. Thisisveryhelpfulforseveralsituations. Forinnstance( Bundleand Activitiescommunication) • Neighborchecking( row, column and block )
Sudoku Class II ( Backtracking ) • Ifthe actual Cellis(9,9) => Ends • Ifyoufind a number, gotothenextcell ( Original Sudoku ) • Foreachvalue1..9 • Ifneighborcheckingis positive • Sudoku(i+1,j+1) • Ifyoudon’tfind a candidate, restore and go back onecell
DownloadActivity (I) • A waytoupdatetheappgame • Itexist a Sudoku boardholded in a web server • “Goodformed” Boardwithin a *.txt file. • Thegoalistorescuethisboard and takeittotheGame
3. Sudoku Recognizer • 3.0 Androidpreviousconcepts • 3.1 Image Capture • 3.2 Imageprocessing(OpenCV) • 3.3 OpticalChracterRecognition (OCR) • Tesseract
3.0 Androidpreviousconcepts • SDK and OpenCV Library (OpenCV) • NDK (NativeDeveloping Kit) ( Tesseract ) • Buildlibraries and referencethem in theapplication.
3.1 Image Capture • CallingtheIntentin charge of capturingimages of Android • Capture and savetheimage in a temporal file • Pre-processing=> Findingthe balance betweengoodqualitiy and computability
3.2 ImageProcessing (I) • Firstcontroversy, theimageis in perspective=> theboardisnot a quad, is a trapezoid • TheMainconcernis a processing in twolevels (RGB and GRAY)
ImageProcessing (II) • Border’sdetection • Next, searchingthebiggestcontourwithintheimage. (ROI)
ImageProcessing (III) • Houghalgorithm and transformtofindtheboardslines • Two fundamental concepts in line processing: • Every single line will be deletepaintingthem of whiteorblack in each case (RGB and GRAY). • Checkifthestartpointorendpoint of line isinsidesome of thefourrectcorners of theimage
ImageProcessing (IV) • Gettingthematrixthat defines theperspectivetransformationneededtoextrapolatethecorners of theboardtothecorners of theimage • Apply a WarpPerspectiveTransformationwiththe matriz obtained.
ImageProcessing (V) • At thispoint, theboardisdivided in equalcellstoprocesseachone of them
Procesamiento de la Imagen (VI) • Single cellprocessing in paralell (RGB and Gray) bearing in mindTesseractsrequeriments. Equalizing Histogram Threshold Smooth + Dilate findContours()
Tesseract ( OCR ) • ¡Don’twaitfor a miracle!. Youneedanstrongimageprocessing • Delimitingdictionarytonumbers(1..9) • Foreachnumberitisnecessaryreleasingthememoryallocatedbytheimage and bythetesseractsobject. We are on a phone and we’vegotlessmemoryresources. Tesseract 6