# Exclude contour from drawing\_python

**URL:** <https://forum.opencv.org/t/exclude-contour-from-drawing-python/953>\
**Category:** Python\
**Created:** [January 19, 2021, 6:37pm UTC](https://forum.opencv.org/t/exclude-contour-from-drawing-python/953 "2021-01-19T18:37:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikaranta](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ikaranta/32/488_2.png) [@ikaranta](https://forum.opencv.org/u/ikaranta)\
**Post date:** [January 19, 2021, 6:37pm UTC](https://forum.opencv.org/t/exclude-contour-from-drawing-python/953/1 "2021-01-19T18:37:47Z")

</div>

Hello,

i have managed to crop the area inside the contour. So my result is an rgb cropped image containing a person. I want to match keypoints from this cropped image with an other cropped image containing the same person from a different angle. The problem is that the cropped image contains my blue contour as well, so my matcher also matches points from the contour. My question is how i can exclude the contour from the cropped image.

my code is:

```
    def matching(m1, m2, frame1, frame2, numL, numR):

    # Initialize the ORB detector algorithm 
    orbL = cv2.ORB_create(nfeatures = 200)
    orbR = cv2.ORB_create(nfeatures = 200)
    
    
    maskL = np.zeros_like(frame1)
    maskR = np.zeros_like(frame2)
    
    cv2.drawContours(maskL, [m1.contour], -1, (255, 255, 255), -1)
    cv2.drawContours(maskR, [m2.contour], -1, (255, 255, 255), -1)
    
    outL = np.zeros_like(frame1)
    outR = np.zeros_like(frame2)
    
    outL[maskL == 255] = frame1[maskL == 255]
    outR[maskR == 255] = frame2[maskR == 255]
    

    # Now detect the keypoints and compute 
    # the descriptors for the query image 
    # and train image 
    queryKeypoints, queryDescriptors = orbL.detectAndCompute(outL, None) 
    trainKeypoints, trainDescriptors = orbR.detectAndCompute(outR, None) 
      
    # # Initialize the Matcher for matching 
    # # the keypoints and then match the 
    # # keypoints 
    matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) 
    matches = matcher.match(queryDescriptors,trainDescriptors) 
       
    # draw the matches to the final image 
    # containing both the images the drawMatches() 
    # function takes both images and keypoints 
    # and outputs the matched query image with 
    # its train image 
    final_img = cv2.drawMatches(outL, queryKeypoints, outR, trainKeypoints, matches[:20],None) 
       
    final_img = cv2.resize(final_img, (1920,1080)) 
      
    # # Show the final image 
    cv2.imshow("Matches", final_img) 
    cv2.waitKey(1)
```

---

<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:** [January 19, 2021, 7:45pm UTC](https://forum.opencv.org/t/exclude-contour-from-drawing-python/953/2 "2021-01-19T19:45:23Z")

</div>

you _don’t_ draw the contours before you take the subregion. you take the subregion first, possibly copy it, and then you can draw the contour on the original image.

it’s probably a good idea to copy the source picture into a new picture I’d call “canvas” or something, and paint on that instead, because drawing contours appears to be purely for visualization purposes.
