Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

this is basically a grid, i would not waste time to recognize anything, but rather check, if it is "filled" or not, using a simple (heuristic) threshold:

    Mat image = Imgcodecs.imread("card.png", 0); // gray
    int cell_w = 38;
    int cell_h = 32;
    Mat result = new Mat(10,5,CvType.CV_32S);
    for (int r=0; r<10; r++) {
        for (int c=0; c<5; c++) {
            Mat cell = image.submat(r*cell_h, (r+1)*cell_h, c*cell_w, (c+1)*cell_w);
            Scalar sum = Core.sumElems(cell);
            int on = sum.val[0] > 200000 ? 0 : 1;
            result.put(r,c,on);
        }
    }
    System.out.println(result.dump());    


     [java] [1, 0, 0, 0, 0;
     [java]  0, 1, 0, 0, 0;
     [java]  0, 0, 0, 0, 1;
     [java]  0, 0, 0, 1, 0;
     [java]  1, 0, 0, 0, 0;
     [java]  0, 1, 0, 0, 0;
     [java]  0, 1, 0, 0, 0;
     [java]  0, 1, 0, 0, 0;
     [java]  0, 0, 0, 0, 1;
     [java]  1, 0, 0, 0, 0]