Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 3.1 Stitch images in order they were taken

I am building an Android app to create panoramas. The user captures a set of images and those images are sent to my native stitch function that was based on https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp. Since the images are in order, I would like to match each image only to the next image in the vector.

I found an Intel article that was doing just that with following code:

vector<MatchesInfo> pairwise_matches;
BestOf2NearestMatcher matcher(try_gpu, match_conf);
Mat matchMask(features.size(),features.size(),CV_8U,Scalar(0));
for (int i = 0; i < num_images -1; ++i)
{
    matchMask.at<char>(i,i+1) =1;
}
matcher(features, pairwise_matches,matchMask);
matcher.collectGarbage();

Problem is, this wont compile. Im guessing its because im using OpenCV 3.1. Then I found somewhere that this code would do the same:

int range_width = 2;
BestOf2NearestRangeMatcher matcher(range_width, try_cuda, match_conf);
matcher(features, pairwise_matches);
matcher.collectGarbage();

And for most of my samples this works fine. However sometimes, especially when im stitching a large set of images (around 15), some objects appear on top of eachother and in places they shouldnt. I've also noticed that the "beginning" (left side) of the end result is not the first image in the vector either which is strange.

I am using "orb" as features_type and "ray" as ba_cost_func. Seems like I cant use SURF on OpenCV 3.1. The rest of my initial parameters look like this:

bool try_cuda = false;
double compose_megapix = -1; //keeps resolution for final panorama
float match_conf = 0.3f; //0.3 default for orb
string ba_refine_mask = "xxxxx";
bool do_wave_correct = true;
WaveCorrectKind wave_correct = detail::WAVE_CORRECT_HORIZ;
int blend_type = Blender::MULTI_BAND;
float blend_strength = 5;

double work_megapix = 0.6;
double seam_megapix = 0.08;
float conf_thresh = 0.5f;
int expos_comp_type = ExposureCompensator::GAIN_BLOCKS;
string seam_find_type = "dp_colorgrad";
string warp_type = "spherical";

So could anyone enlighten me as to why this is not working and how I should match my features? Any help or direction would be much appreciated!

TL;DR : I want to stitch images in the order they were taken, but above codes are not working for me, how can I do that?