|
1 | 1 | package pl.sudokusolver.recognizerlib;
|
2 | 2 |
|
| 3 | +import com.google.common.collect.Lists; |
| 4 | +import org.opencv.core.*; |
3 | 5 | import pl.sudokusolver.recognizerlib.exceptions.NotFoundSudokuExceptions;
|
4 | 6 | import pl.sudokusolver.recognizerlib.extractors.cells.LineCellsExtractStrategy;
|
5 | 7 | import pl.sudokusolver.recognizerlib.extractors.cells.SizeCellsExtractStrategy;
|
|
14 | 16 | import java.util.LinkedList;
|
15 | 17 | import java.util.List;
|
16 | 18 |
|
| 19 | +import static org.opencv.imgcodecs.Imgcodecs.imread; |
| 20 | +import static org.opencv.imgproc.Imgproc.*; |
| 21 | + |
17 | 22 | public class test {
|
18 | 23 |
|
19 | 24 | public static void main(String[] args) throws NotFoundSudokuExceptions {
|
20 | 25 | System.out.println("Rec Lib Test");
|
21 | 26 |
|
22 | 27 | Init.init("C:\\opencv4.0.1\\opencv\\build\\java\\x64");
|
23 | 28 |
|
| 29 | + Mat img = imread("C:\\Users\\LukMcCall\\Studia\\IO\\SudokuSolver\\Web\\RecognizerLib\\9_data.jpg",1); |
| 30 | + Mat source = img.clone(); |
| 31 | + new ToGrayFilter().apply(img); |
| 32 | + new BlurFilter().apply(img); |
| 33 | + |
| 34 | + List<MatOfPoint> countours = Lists.newArrayList(); |
| 35 | + |
| 36 | + findContours(img, countours, new Mat(), RETR_TREE , CHAIN_APPROX_SIMPLE); |
| 37 | + System.out.println(countours.size()); |
| 38 | + for (int i = 0; i < countours.size(); i++) { |
| 39 | + Rect boundingRect = boundingRect(countours.get(i)); |
| 40 | + if(boundingRect.height > 28 && boundingRect.width < 60 && boundingRect.height < 50) |
| 41 | + rectangle(source,boundingRect,new Scalar(0,0,255)); |
| 42 | +// drawContours(source, countours, i, new Scalar(0,0,255), -1); |
| 43 | + } |
| 44 | + new ResizeFilter(new Size(600,1000)).apply(source); |
| 45 | + new DisplayHelper().apply(source); |
24 | 46 | // IRecognizer ann = new ANN("RecognizerLib/ann.xml");
|
25 | 47 |
|
26 |
| - SudokuExtractor sudokuExtractor = new SudokuExtractor( |
27 |
| - new DefaultGridExtractStrategy(), |
28 |
| - new LineCellsExtractStrategy(), |
29 |
| - new ContoursDigitExtractStrategy(), |
30 |
| - new PlaceTester(), |
31 |
| - null, |
32 |
| - Arrays.asList( new ToGrayFilter(),new BlurFilter() , new DisplayHelper()), |
33 |
| - null |
34 |
| - |
35 |
| - ); |
36 |
| - sudokuExtractor.extract("../Data/sudoku2.jpg").printSudoku(); |
| 48 | +// SudokuExtractor sudokuExtractor = new SudokuExtractor( |
| 49 | +// new DefaultGridExtractStrategy(), |
| 50 | +// new LineCellsExtractStrategy(), |
| 51 | +// new ContoursDigitExtractStrategy(), |
| 52 | +// new PlaceTester(), |
| 53 | +// null, |
| 54 | +// Arrays.asList( new ToGrayFilter(),new BlurFilter() , new DisplayHelper()), |
| 55 | +// null |
| 56 | +// |
| 57 | +// ); |
| 58 | +// sudokuExtractor.extract("../Data/sudoku2.jpg").printSudoku(); |
37 | 59 |
|
38 | 60 | }
|
39 | 61 | }
|
0 commit comments