How to stitch two screenshots with open cv and surf

Hello! Im trying to stitch two images with Stitcher


It is not stitch cause it has matches on top and bottom of screenshots, is there a way to filter unnecessary features?
My code:

            Mat pano;
            cv::Ptr<Stitcher> stitcher = Stitcher::create(mode);
        
            stitcher->setFeaturesFinder(makePtr<detail::SurfFeaturesFinder>(100,1,1));
            stitcher->setSeamFinder(makePtr<detail::VoronoiSeamFinder>());
            stitcher->setRegistrationResol(0.3); 
            stitcher->setSeamEstimationResol(0.3);   
            stitcher->setCompositingResol(0.3);   
            stitcher->setPanoConfidenceThresh(0.3);   
            stitcher->setWaveCorrection(false);
            Stitcher::Status status = stitcher->stitch(imgs, pano);
            if (status != Stitcher::OK) {
                cout << "Can't stitch images, error code = " << int(status) << endl;
                return nil;
            }
            return MatToUIImage(pano);

Well, the common parts of the image are correctly recognized; you can see the parallel lines between the photo of the sleeping dog in both images.

The problem is that the two images contain many other common things: the header and footer (you can see the horizontal lines connecting them) and the text too! (you only have 26 characters repeating over and over!)

However maybe some tricks might help to get better results, knowing that there is only a vertical translation between the images. Go through the matches, and delete those, which have:

  • same X and Y in both images (header and footer)
  • different X and Y in both images (random parts of the text matched)

Keep only the matches which have same X but different Y value.
It’s a good idea to crop the discussion (central) part of the image, otherwise you’ll have several headers/footers in the stiched image; this might also improve the matching.

Note: there are other possibilities too to match the images in this particular case (as it’s quite simple, considering that there is no rotation, scaling, just a vertical translation), but first try the suggestion above and report back.