checkbox detection
checkbox detection
How can I detect if the checkbox in an image is checked or not?
Example with checkbox checked:
http://imgur.com/a/3VPuC
Example with checkbox not checked:
http://imgur.com/DwQvB4X
Note: I'm not embedding the images because the one with the checkbox checked appears weird.
Example with checkbox checked:
http://imgur.com/a/3VPuC
Example with checkbox not checked:
http://imgur.com/DwQvB4X
Note: I'm not embedding the images because the one with the checkbox checked appears weird.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: checkbox detection
First, you need to provide the version of IM you're using and let us know which platform or OS you're running it on and some more details about your needs.
If your checkbox will always be at a known location in the image, if the checked box is always black (or transparent like your example image), and if the unchecked box is always white inside, you can just test a pixel in the box with a command like this...
Code: Select all
convert image.png -format %[fx:p{12,16}] info:
There may be far better ways to do it, but we'd have to know a lot more about your situation.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: checkbox detection
Best I can suggest is crop out the box that was shaded and use compare with subimage-search to locate the best match. If the match score is low enough for the given metric such as rmse, then you have a good match.
See
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
See
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
Code: Select all
compare -metric rmse -subimage-search largeimage smallrectangle null:
Re: checkbox detection
Thanks for the replies!
I was also thinking, how can detect an actual rectangle? Like 4 edges and only white pixels "inside"?
I was also thinking, how can detect an actual rectangle? Like 4 edges and only white pixels "inside"?
Re: checkbox detection
Any ideas?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: checkbox detection
The methods mentioned above apply to empty checkboxes as well as ticked ones.
snibgo's IM pages: im.snibgo.com
Re: checkbox detection
Yeah, I was just wondering if this alternative approach is possible.
Re: checkbox detection
I had an idea, check it with histogram distribution? The checkbox with a check won't have 2 sudden drops in the histogram.
I mean:
- the edges of the rectangle have "max black pixels"
- the "inside" of the checked rectangle has "less than max black pixels"
- the "inside" of the unchecked rectangle (empty) has few black pixels (only the edges of the rectangle)
How can I do this?
I mean:
- the edges of the rectangle have "max black pixels"
- the "inside" of the checked rectangle has "less than max black pixels"
- the "inside" of the unchecked rectangle (empty) has few black pixels (only the edges of the rectangle)
How can I do this?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: checkbox detection
Do you know where the checkbox is? And how thick the borders are? If you do, then crop the image to just the inside of the box. Find the mean lightness of that area. If this is light, then there is no check. If it is somewhat dark, then there is a check.
If you don't know where the checkbox is, or how thick the borders are, the problem is harder, and the first step is to solve those problems.
If you don't know where the checkbox is, or how thick the borders are, the problem is harder, and the first step is to solve those problems.
snibgo's IM pages: im.snibgo.com
Re: checkbox detection
I know where it is but not exact to the pixel level. There might be some x, y translation.
How do I find the mean lightness?
How do I find the mean lightness?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: checkbox detection
"-format %[fx:mean]" gives the mean value, on a scale of 0.0 to 1.0. For example:
Code: Select all
f:\web\im>%IM%convert rose: -format %[fx:mean] info:
0.412341
snibgo's IM pages: im.snibgo.com
Re: checkbox detection
Tried it and while it seems to work ok most of the time, sometimes there is a small shift (translation i X or Y) in the crop of the checkbox which is problematic for accuracy.
The "[peak black pixel sum] ... [low black pixel sum] ... [peak black pixel sum]" would be better I think. Don't know how to implement this though, any ideas?
The "[peak black pixel sum] ... [low black pixel sum] ... [peak black pixel sum]" would be better I think. Don't know how to implement this though, any ideas?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: checkbox detection
I don't know what you mean by "[peak black pixel sum]" etc.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: checkbox detection
Have you tried the compare function that I suggested above?
Re: checkbox detection
I mean count (or calculate the sum of) the black black pixels on each Y.
That way it will be something like:
That way it will be something like:
Code: Select all
0%
90% +--------+
2% | |
2% | |
2% | |
2% | |
90% +--------+
0%