# Improving the image for 4-point contour approximation

**URL:** <https://forum.opencv.org/t/improving-the-image-for-4-point-contour-approximation/10599>\
**Category:** Python\
**Tags:** object-detection\
**Created:** [October 18, 2022, 4:15pm UTC](https://forum.opencv.org/t/improving-the-image-for-4-point-contour-approximation/10599 "2022-10-18T16:15:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaster111](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jaster111](https://forum.opencv.org/u/Jaster111)\
**Post date:** [October 18, 2022, 4:15pm UTC](https://forum.opencv.org/t/improving-the-image-for-4-point-contour-approximation/10599/1 "2022-10-18T16:15:29Z")

</div>

Hi everyone,

I’m creating a YuGiOh card detector based exclusively on OpenCV and Tesseract OCR.  
First I make a binary image and then find the contours that can be approximated with 4 points. The problem is that sometimes the edges of the borders are smoothed out as seen in the example below:

 ![dilated](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/bf7c24f0904bd0c75a09bc885bcc6787a66d5ead.png)

As you can see the edges on the card in the middle are quite smooth even though they are not in the original image which is why the 4-point approximation fails I presume.

This is the code for getting the binary image.

```auto
    #grayscale -> bluring -> canny thresholding -> dilation
    gray_img = cv2.cvtColor(img_resized, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray_img, (11,11), 0)
    thresh = cv2.Canny(blur, 50, 100)
    dilated = cv2.dilate(thresh, np.ones((11,11), dtype=np.int8))

```

This is the code for 4-point contour approximation.

```auto
    tbd = list()
    for c in contours:
        peri = cv2.arcLength(c, True)
        approx = cv2.approxPolyDP(c, 0.05 * peri, True)
        if len(approx) == 4:
            tbd.append(approx)

```

If someone could point me in the right direction to fix this type of problem I would be very grateful. Thanks in advance! 🙂
