# Remove unwanted contours with irregular shapes

**URL:** <https://forum.opencv.org/t/remove-unwanted-contours-with-irregular-shapes/6854>\
**Category:** Python\
**Created:** [December 23, 2021, 1:01am UTC](https://forum.opencv.org/t/remove-unwanted-contours-with-irregular-shapes/6854 "2021-12-23T01:01:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vijaya\_Murari](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/vijaya_murari/32/635_2.png) [@Vijaya\_Murari](https://forum.opencv.org/u/Vijaya_Murari)\
**Post date:** [December 23, 2021, 1:01am UTC](https://forum.opencv.org/t/remove-unwanted-contours-with-irregular-shapes/6854/1 "2021-12-23T01:01:12Z")

</div>

![contour_image3](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d3da6b64df19515de63a09f968b9eb76e25e7cde.jpeg)  
In the above image i want to retain the hand contour and remove all the other contours. After using findContours function, contourArea() function has been used to remove the most of the contours but still I am not able retain the required contour and eliminate other contours. The code is given below:

```auto
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('frame0.jpg', cv2.IMREAD_UNCHANGED)
#convert img to grey
img_grey = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#set a thresh
thresh = 100
#get threshold image
ret,thresh_img = cv2.threshold(img_grey, thresh, 255, cv2.THRESH_BINARY)
#find contours
im2,contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
    box=cv2.minAreaRect(c)
    #print(box)
    box=cv2.boxPoints(box)
    box=np.array(box,dtype='int')
    if cv2.contourArea(c) < 620 :
        continue
    cv2.drawContours(img, [c], -1, (0,255,0), 2)
    
    cv2.drawContours(img, [box], -1, (255,255,255), 2)
    print(box)
    for (x,y) in list(box):
        #print('(x,y):',(x,y))
        cv2.circle(img,(x,y),2,(255,0,0),2)
        #points[i]=(x,y)
        cv2.putText(img, "({},{})".format(x, y), (int(x), int(y)),
            cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255,255,255), )
cv2.imwrite('contour_image3.jpg',img)

```

So, can i know how to remove the contours in the above image which are not required using contourArea() function?

---

<div class="post-metadata">

**Author:** ![Vijaya\_Murari](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/vijaya_murari/32/635_2.png) [@Vijaya\_Murari](https://forum.opencv.org/u/Vijaya_Murari)\
**Post date:** [December 30, 2021, 1:24pm UTC](https://forum.opencv.org/t/remove-unwanted-contours-with-irregular-shapes/6854/2 "2021-12-30T13:24:41Z")

</div>

Thank you very much for the reply
