Ben
Ben

Reputation: 317

Cross detection in image

I have to find the crosses in the image. What I know is the exact position of each red square. Now I have to decide, if there is a cross inside the square or not. What is the best and fastest way to do this? I am using OpenCv/c++! Well, I could try to use the SVM of OpenCv? But is it fast? Do you have any other ideas?

Upvotes: 4

Views: 4849

Answers (4)

mrgloom
mrgloom

Reputation: 21682

just find rectungles and then do simple pixel compare.

Upvotes: 0

halirutan
halirutan

Reputation: 4341

If you really have the coordinates of the center of each number-box and you maybe can adjust the image acquisition a bit, this should be a feasible task. The problem I see here is, that you have a brightness gradient in your image which you should get rid off by either taking a better picture or using a big Gaussian-filter and an image subtraction. Otherwise I'm not sure you'll find a good brightness-threshold to separate crossed from non-crossed.

Another approach you could use is to calculate the variance of your pixels. This gives you a nice local measure, whether or not a dark pen spread your pixel-distribution. A quick test looks promising

lotto processing

Note, that I didn't had the real positions of the boxes. I just divided your image into equally sized regions which is not really correct regarding the box/sub-box like structure. Therefore there are some false positives in it because of the red triangles in each upper left corner and because of some overlapping crosses.

So here's what I did:

  1. Take your image without the red channel and made it a graylevel image.
  2. Filtering this image with a Gaussian of radius 100 and subtracting this from the image.
  3. I divided your image into (7*6)x(7*2) subregions.
  4. Calculated the variance of each subregion and used a variance-threshold of about 0.017 for the above image
  5. Every box which had a larger variance was crossed.

Upvotes: 5

sastanin
sastanin

Reputation: 41551

Simple solution: if you know a-priori locations of all boxes, just calculate the average brightness of the box. Boxes with a mark will be much darker than empty boxes.

Upvotes: 5

thiton
thiton

Reputation: 36059

If not detecting red ink is an option, keep it simple: Accumulate all pixels within the red square and threshold on the "redness", i.e. the quotient of the sum of red values divided by the total color values.

Upvotes: 0

Related Questions