Ask Your Question
0

Convert test answer key in binary matrix

asked 2016-03-24 10:50:58 -0600

Jacauna gravatar image

updated 2016-03-29 14:09:51 -0600

Hi, I need some help about how to start develop a application in Android that recognize a test answer key and convert it to a binary matrix.

The card response filled will be like this:

image description

And I wish to convert to a binary matrix to validate the responses, like this:

image description

I don't wanna convert to another image, but to a int[10][5] variable matrix to use to iterate and validate the answers from response card.

I tried tutorials that show how recognize circles, squares. But I didn't get nothing approximate to what I want and I have no idea how start with it.

Thanks!

edit retag flag offensive close merge delete

Comments

Can you reliably orient the image, so that the rows and columns are straight? If you can separate the image so that each bubble is in it's own ROI, it should be pretty easy.

Tetragramm gravatar imageTetragramm ( 2016-03-29 16:31:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-30 03:09:17 -0600

berak gravatar image

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]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-24 10:48:36 -0600

Seen: 499 times

Last updated: Mar 30 '16