# Split a multiple choice answer sheet

**URL:** <https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898>\
**Category:** Python\
**Created:** [May 24, 2022, 4:00pm UTC](https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898 "2022-05-24T16:00:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anas\_laouissi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anas_laouissi/32/5305_2.png) [@anas\_laouissi](https://forum.opencv.org/u/anas_laouissi)\
**Post date:** [May 24, 2022, 4:00pm UTC](https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898/1 "2022-05-24T16:00:40Z")

</div>

I have this picture below. I want to separate it into two parts, so I can work independently with every part. I added those black dots to make my algo detect the dots and separate the part but it’s detect all the elements of paper. it doesn’t work as i expected, i do not know the reason why.

I’am new in opencv and image processing

this is my code

```python
import cv2
import numpy as np

image = cv2.imread('18936-model-1.jpg')

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (23, 23), 0)
cv2.imshow("blurred", blurred)
canny = cv2.Canny(blurred, 30, 30)
cnts, _ = cv2.findContours(canny.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
print(f"Contours in the image, %d" % (len(cnts)))
shape = image.copy()
cv2.drawContours(shape, cnts, -1, (0, 255, 0), 2)
cv2.imwrite('{}.png'.format('sunflower'), shape)
cv2.imshow("Edges", shape)
cv2.waitKey(0)

```

the left image is the original one. the middle image is what i want to process. the right picture is what i get

 ![MergedImages](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/9/9ba533a506cb0dccfb650d1cda5c04d1c9026bfc.png)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 24, 2022, 4:31pm UTC](https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898/2 "2022-05-24T16:31:51Z")

</div>

> [@anas\_laouissi](#):
>
> it’ doesn’t work as i expected,

however, it’s doing exactly, what you told it to do 😉

- make your life easy. assuming, this comes from a flatbed scanner (no significant scaling) – assume, that the lower part is 3/4 of the whole – and just crop it blindly
- use the markers, luke, they’re there for a purpose …
- there’s a nice horizontal dividing line. use morphology or reduce() or check your existing contours for that
- switch Canny (ooouuch) for a plain threshold(), and remember, that opencv expects **white** contours on **black** bg, so – invert intensity before findContours() (that’s a simple `~img` or `255-img` in python)
- visualize **ALL** intermediate steps, using imshow(), to quickl find out, where things did not went “as expected”

---

<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:** [May 24, 2022, 5:44pm UTC](https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898/3 "2022-05-24T17:44:33Z")

</div>

related:

> <https://stackoverflow.com/questions/72364855/detect-edge-using-python-and-opencv2>

---

<div class="post-metadata">

**Author:** ![hamblingreg52](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/hamblingreg52/32/1788_2.png) [@hamblingreg52](https://forum.opencv.org/u/hamblingreg52)\
**Post date:** [May 26, 2022, 7:13am UTC](https://forum.opencv.org/t/split-a-multiple-choice-answer-sheet/8898/4 "2022-05-26T07:13:36Z")

</div>

@crackwitz Thanks! Reading your suggested article has proven very helpful for me.
