# Optic Marker Recognition

**URL:** <https://forum.opencv.org/t/optic-marker-recognition/14335>\
**Category:** Python\
**Tags:** imgproc\
**Created:** [August 23, 2023, 9:24pm UTC](https://forum.opencv.org/t/optic-marker-recognition/14335 "2023-08-23T21:24:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoaoPedroAssis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joaopedroassis/32/8576_2.png) [@JoaoPedroAssis](https://forum.opencv.org/u/JoaoPedroAssis)\
**Post date:** [August 23, 2023, 9:24pm UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/1 "2023-08-23T21:24:34Z")

</div>

# Optimizing image in a OMR preprocessor

I have an OMR (Optic Marker Recognition) algorithm and would like to improve its accuracy by preprocessing the input image. The pictures taken by the users are of response sheets of a test, in which the students mark the correct alternativa by filling a bubble in this sheet.

This is my input image:  
edit: I cant post two images for being a new user, but picture that image with a shadow of a hand above the markers!

And this is the desired outcome, obtained using the grayscale filter from the Adobe Scan app:

 ![Adobe Scan 23 de ago. de 2023_pages-to-jpg-0001](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/7/7d6b61e91bf7bcd740fedc1a06c5d4c3c06b927a.jpeg)

I already tried a variety of techniques, such as morphologic operations (to remove shadows, but they ended up removing the marked choices as well) or adaptive threshold. Any input from you guys would be of huge help!

Thanks!

---

<div class="post-metadata">

**Author:** ![JoaoPedroAssis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joaopedroassis/32/8576_2.png) [@JoaoPedroAssis](https://forum.opencv.org/u/JoaoPedroAssis)\
**Post date:** [August 24, 2023, 3:24am UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/2 "2023-08-24T03:24:35Z")

</div>

Trying to post the input image:

 ![sombra_26q](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d6e7435ee95d53bac1c7961f6f9d64c7058a20d0.jpeg)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 24, 2023, 8:15am UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/3 "2023-08-24T08:15:08Z")

</div>

to deal with variable lighting (the shadow), do this:

- grayscale dilation estimates illumination
- then divide the picture by the grayscale dilation

(this assumes a linear color space. usually nobody cares though.)

that gives you a picture with normalized illumination.

you can then grab an area containing each bubble, blindly, relative to the fiducials.

for each such region, you can then assess how filled in it is (sum of pixel values).

---

<div class="post-metadata">

**Author:** ![JoaoPedroAssis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joaopedroassis/32/8576_2.png) [@JoaoPedroAssis](https://forum.opencv.org/u/JoaoPedroAssis)\
**Post date:** [August 25, 2023, 5:30pm UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/4 "2023-08-25T17:30:06Z")

</div>

Thanks, I will be trying that!

---

<div class="post-metadata">

**Author:** ![JoaoPedroAssis](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/joaopedroassis/32/8576_2.png) [@JoaoPedroAssis](https://forum.opencv.org/u/JoaoPedroAssis)\
**Post date:** [August 25, 2023, 7:40pm UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/5 "2023-08-25T19:40:34Z")

</div>

@crackwitz After applying your tips I obtained a similar result, but although the shadow does indeed disappear, the marked bubbles get dimmed as well

This is the image after a few processing steps:

 ![thr_img](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/f/fecca611dacdd449a1f138d18b105b6ab526e799.jpeg)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 25, 2023, 11:27pm UTC](https://forum.opencv.org/t/optic-marker-recognition/14335/6 "2023-08-25T23:27:32Z")

</div>

> [@JoaoPedroAssis](#):
>
> the marked bubbles get dimmed as well

dilation needs a larger radius/more iterations
