minor refactoring of opencv_stitching
This commit is contained in:
@@ -79,7 +79,7 @@ void printUsage()
|
|||||||
" Resolution for compositing step. Use -1 for original resolution.\n"
|
" Resolution for compositing step. Use -1 for original resolution.\n"
|
||||||
" The default is -1.\n"
|
" The default is -1.\n"
|
||||||
" --match_conf <float>\n"
|
" --match_conf <float>\n"
|
||||||
" Confidence for feature matching step. The default is 0.6.\n"
|
" Confidence for feature matching step. The default is 0.7.\n"
|
||||||
" --ba (ray|focal_ray)\n"
|
" --ba (ray|focal_ray)\n"
|
||||||
" Bundle adjustment cost function. The default is 'focal_ray'.\n"
|
" Bundle adjustment cost function. The default is 'focal_ray'.\n"
|
||||||
" --conf_thresh <float>\n"
|
" --conf_thresh <float>\n"
|
||||||
@@ -113,8 +113,7 @@ float conf_thresh = 1.f;
|
|||||||
bool wave_correct = true;
|
bool wave_correct = true;
|
||||||
int warp_type = Warper::SPHERICAL;
|
int warp_type = Warper::SPHERICAL;
|
||||||
int expos_comp_type = ExposureCompensator::GAIN;
|
int expos_comp_type = ExposureCompensator::GAIN;
|
||||||
bool user_match_conf = false;
|
float match_conf = 0.7f;
|
||||||
float match_conf = 0.6f;
|
|
||||||
int seam_find_type = SeamFinder::GC_COLOR;
|
int seam_find_type = SeamFinder::GC_COLOR;
|
||||||
int blend_type = Blender::MULTI_BAND;
|
int blend_type = Blender::MULTI_BAND;
|
||||||
int num_bands = 5;
|
int num_bands = 5;
|
||||||
@@ -129,7 +128,12 @@ int parseCmdArgs(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (string(argv[i]) == "--preview")
|
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
|
||||||
|
{
|
||||||
|
printUsage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (string(argv[i]) == "--preview")
|
||||||
{
|
{
|
||||||
preview = true;
|
preview = true;
|
||||||
}
|
}
|
||||||
@@ -168,7 +172,6 @@ int parseCmdArgs(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (string(argv[i]) == "--match_conf")
|
else if (string(argv[i]) == "--match_conf")
|
||||||
{
|
{
|
||||||
user_match_conf = true;
|
|
||||||
match_conf = static_cast<float>(atof(argv[i + 1]));
|
match_conf = static_cast<float>(atof(argv[i + 1]));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -348,7 +351,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
finder(img, features[i]);
|
finder(img, features[i]);
|
||||||
features[i].img_idx = i;
|
features[i].img_idx = i;
|
||||||
LOGLN("Features in image #" << i << ": " << features[i].keypoints.size());
|
LOGLN("Features in image #" << i+1 << ": " << features[i].keypoints.size());
|
||||||
|
|
||||||
resize(full_img, img, Size(), seam_scale, seam_scale);
|
resize(full_img, img, Size(), seam_scale, seam_scale);
|
||||||
images[i] = img.clone();
|
images[i] = img.clone();
|
||||||
@@ -359,12 +362,10 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
LOGLN("Finding features, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Finding features, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
LOGLN("Pairwise matching... ");
|
LOG("Pairwise matching");
|
||||||
t = getTickCount();
|
t = getTickCount();
|
||||||
vector<MatchesInfo> pairwise_matches;
|
vector<MatchesInfo> pairwise_matches;
|
||||||
BestOf2NearestMatcher matcher(try_gpu);
|
BestOf2NearestMatcher matcher(try_gpu, match_conf);
|
||||||
if (user_match_conf)
|
|
||||||
matcher = BestOf2NearestMatcher(try_gpu, match_conf);
|
|
||||||
matcher(features, pairwise_matches);
|
matcher(features, pairwise_matches);
|
||||||
LOGLN("Pairwise matching, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Pairwise matching, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
@@ -401,15 +402,25 @@ int main(int argc, char* argv[])
|
|||||||
Mat R;
|
Mat R;
|
||||||
cameras[i].R.convertTo(R, CV_32F);
|
cameras[i].R.convertTo(R, CV_32F);
|
||||||
cameras[i].R = R;
|
cameras[i].R = R;
|
||||||
LOGLN("Initial focal length #" << i << ": " << cameras[i].focal);
|
LOGLN("Initial focal length #" << indices[i]+1 << ": " << cameras[i].focal);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGLN("Bundle adjustment... ");
|
LOG("Bundle adjustment");
|
||||||
t = getTickCount();
|
t = getTickCount();
|
||||||
BundleAdjuster adjuster(ba_space, conf_thresh);
|
BundleAdjuster adjuster(ba_space, conf_thresh);
|
||||||
adjuster(features, pairwise_matches, cameras);
|
adjuster(features, pairwise_matches, cameras);
|
||||||
LOGLN("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
|
// Find median focal length
|
||||||
|
vector<double> focals;
|
||||||
|
for (size_t i = 0; i < cameras.size(); ++i)
|
||||||
|
{
|
||||||
|
LOGLN("Camera #" << indices[i]+1 << " focal length: " << cameras[i].focal);
|
||||||
|
focals.push_back(cameras[i].focal);
|
||||||
|
}
|
||||||
|
nth_element(focals.begin(), focals.begin() + focals.size()/2, focals.end());
|
||||||
|
float warped_image_scale = static_cast<float>(focals[focals.size() / 2]);
|
||||||
|
|
||||||
if (wave_correct)
|
if (wave_correct)
|
||||||
{
|
{
|
||||||
LOGLN("Wave correcting...");
|
LOGLN("Wave correcting...");
|
||||||
@@ -423,16 +434,6 @@ int main(int argc, char* argv[])
|
|||||||
LOGLN("Wave correcting, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Wave correcting, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find median focal length
|
|
||||||
vector<double> focals;
|
|
||||||
for (size_t i = 0; i < cameras.size(); ++i)
|
|
||||||
{
|
|
||||||
LOGLN("Camera #" << i << " focal length: " << cameras[i].focal);
|
|
||||||
focals.push_back(cameras[i].focal);
|
|
||||||
}
|
|
||||||
nth_element(focals.begin(), focals.begin() + focals.size()/2, focals.end());
|
|
||||||
float warped_image_scale = static_cast<float>(focals[focals.size() / 2]);
|
|
||||||
|
|
||||||
LOGLN("Warping images (auxiliary)... ");
|
LOGLN("Warping images (auxiliary)... ");
|
||||||
t = getTickCount();
|
t = getTickCount();
|
||||||
|
|
||||||
@@ -496,7 +497,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
||||||
{
|
{
|
||||||
LOGLN("Compositing image #" << img_idx);
|
LOGLN("Compositing image #" << indices[img_idx]+1);
|
||||||
|
|
||||||
// Read image and resize it if necessary
|
// Read image and resize it if necessary
|
||||||
full_img = imread(img_names[img_idx]);
|
full_img = imread(img_names[img_idx]);
|
||||||
|
@@ -219,6 +219,7 @@ struct MatchPairsBody
|
|||||||
for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j)
|
for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j)
|
||||||
swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx,
|
swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx,
|
||||||
pairwise_matches[dual_pair_idx].matches[j].trainIdx);
|
pairwise_matches[dual_pair_idx].matches[j].trainIdx);
|
||||||
|
LOG(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +249,7 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
|
|||||||
parallel_for(BlockedRange(0, static_cast<int>(near_pairs.size())), body);
|
parallel_for(BlockedRange(0, static_cast<int>(near_pairs.size())), body);
|
||||||
else
|
else
|
||||||
body(BlockedRange(0, static_cast<int>(near_pairs.size())));
|
body(BlockedRange(0, static_cast<int>(near_pairs.size())));
|
||||||
|
LOGLN("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -198,14 +198,15 @@ void BundleAdjuster::estimate(const vector<ImageFeatures> &features, const vecto
|
|||||||
if (_err)
|
if (_err)
|
||||||
{
|
{
|
||||||
calcError(err_);
|
calcError(err_);
|
||||||
LOGLN("Error: " << sqrt(err_.dot(err_)));
|
LOG(".");
|
||||||
count++;
|
count++;
|
||||||
CvMat matErr = err_;
|
CvMat matErr = err_;
|
||||||
cvCopy( &matErr, _err );
|
cvCopy( &matErr, _err );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOGLN("");
|
||||||
LOGLN("Bundle adjustment, final error: " << sqrt(err_.dot(err_)));
|
LOGLN("Bundle adjustment, final error: " << sqrt(err_.dot(err_)));
|
||||||
LOGLN("Bundle adjustment, iteration done: " << count);
|
LOGLN("Bundle adjustment, iterations done: " << count);
|
||||||
|
|
||||||
// Obtain global motion
|
// Obtain global motion
|
||||||
for (int i = 0; i < num_images_; ++i)
|
for (int i = 0; i < num_images_; ++i)
|
||||||
@@ -432,7 +433,8 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
|
|||||||
|
|
||||||
LOG("Removed some images, because can't match them: (");
|
LOG("Removed some images, because can't match them: (");
|
||||||
LOG(indices_removed[0]);
|
LOG(indices_removed[0]);
|
||||||
for (size_t i = 1; i < indices_removed.size(); ++i) LOG(", " << indices_removed[i]);
|
for (size_t i = 1; i < indices_removed.size(); ++i)
|
||||||
|
LOG(", " << indices_removed[i]+1);
|
||||||
LOGLN(")");
|
LOGLN(")");
|
||||||
|
|
||||||
features = features_subset;
|
features = features_subset;
|
||||||
|
Reference in New Issue
Block a user