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?