Image Stitching: Unexpected black blobs/smear
I tried to stitch a few images using Opencv Stitcher class, following is my code:
vector<Mat> srcImgs;
int num_images = 9;
for (int i = 0; i < num_images; i++) {
Mat pic = imread("img"+to_string(i)+".jpg");
resize(pic, pic, Size(pic.size().width/2,pic.size().height/2));
srcImgs.push_back(pic);
}
Stitcher stitcher = Stitcher::createDefault();
Mat matchMask(num_images,num_images,CV_8U,Scalar(0));
for (int i = 0; i < num_images-1; ++i)
{
matchMask.at<char>(i,i+1) =1;
}
stitcher.setMatchingMask(matchMask.getUMat(ACCESS_READ));
stitcher.setWarper(makePtr<TransverseMercatorWarper>());
stitcher.setRegistrationResol(0.1);
stitcher.setSeamEstimationResol(0.1);
Mat result;
stitcher.stitch(srcImgs, result);
imwrite("result.png", result);
namedWindow("cvWindow");
imshow("cvWindow", result);
waitKey(0);
I use opencv 3.1 and run it on Mac. Everything works fine, except the resulting image has random regions of black blobs within the stitched photo(I am not talking about the black region around the stitched image, which is completely fine). The photos are not damaged and are well loaded with no black blobs. Every time I run the program, the resulting image has different black blobs, which is quite spooky. Sometimes the result is perfect. This is very weird. The following images demonstrate what I mean. The error should very probably come from either the OpenCV SDK or because of some weird reason for running it on Mac. I tried various codes(including the simplest one without any customisation of masking masks, warpers,etc.), but it still gives me the same problem.
First Time I run the program, the result is:
Second Time I run the same program, the result is(almost perfect, still black blobs in the centre picture if you see carefully):
Third Time I run the same program, the result is perfect here:
Fourth Time, wrong again:
Fifth Time of the same program with the same exact codes and pictures, wrong:
This is just so weird. Can someone help me?
Try without the matching Mask. I've never seen that actually used, and the documentation doesn't say what it's used for. It's the only thing that doesn't look right.
I tried not using the mask, and it gave me the same result.
Is this a set of pictures you could share so I can experiment?
In the meantime, try changing the warper you use. Depending on the one I chose, I could make strange artifacts. Specifically, I think the TransverseMercator really doesn't like vertical motion. Try spherical.