Exclude contour from drawing_python


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) 

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.