Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.opencv.core.Mat;
- import org.opencv.core.Core;
- import org.opencv.core.Point;
- import org.opencv.core.Scalar;
- import org.opencv.imgcodecs.Imgcodecs;
- import org.opencv.imgproc.Imgproc;
- public class sudoku
- {
- public static void main(String[] args)
- {
- System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
- Mat image = Imgcodecs.imread("sudoku.png", Imgcodecs.CV_LOAD_IMAGE_COLOR);
- if ((image == null) || image.empty()) {
- System.out.println("Failed to load input image.");
- System.exit(-1);
- }
- int TILES_X = 9;
- int TILES_Y = 9;
- // Estimated point coordinates from sample image...
- Point p1 = new Point(110, 128);
- Point p2 = new Point(518, 49);
- Point p3 = new Point(187, 524);
- Point p4 = new Point(611, 428);
- // Vectors representing each edge of the puzzle
- Point dx_puzzle = new Point(p2.x - p1.x, p2.y - p1.y);
- Point dy_puzzle = new Point(p3.x - p1.x, p3.y - p1.y);
- // Scaled down vectors representing edge of a single tile
- Point dx_tile = new Point(dx_puzzle.x / TILES_X, dx_puzzle.y / TILES_X);
- Point dy_tile = new Point(dy_puzzle.x / TILES_Y, dy_puzzle.y / TILES_Y);
- System.out.println(String.format("dx_puzzle = %s", dx_puzzle));
- System.out.println(String.format("dy_puzzle = %s", dy_puzzle));
- System.out.println(String.format("dx_tile = %s", dx_tile));
- System.out.println(String.format("dy_tile = %s", dy_tile));
- for (int row = 0; row < (TILES_Y + 1); row++) {
- for (int col = 0; col < (TILES_X + 1); col++) {
- double x = Math.round(p1.x + dx_tile.x * col + dy_tile.x * row);
- double y = Math.round(p1.y + dx_tile.y * col + dy_tile.y * row);
- Point p = new Point(x, y);
- System.out.println(String.format("p[%d,%d] = %s", row, col, p));
- Imgproc.circle(image, p, 3, new Scalar(255,0,255));
- }
- }
- Imgcodecs.imwrite("sudoku_out.png", image);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement