Updated motions estimators in the stitching module to be able to set camera intrinsics manually
This commit is contained in:
parent
893f75444d
commit
b4f17ab79e
@ -69,7 +69,9 @@ protected:
|
|||||||
class CV_EXPORTS HomographyBasedEstimator : public Estimator
|
class CV_EXPORTS HomographyBasedEstimator : public Estimator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HomographyBasedEstimator() : is_focals_estimated_(false) {}
|
HomographyBasedEstimator(bool is_focals_estimated = false)
|
||||||
|
: is_focals_estimated_(is_focals_estimated) {}
|
||||||
|
|
||||||
bool isFocalsEstimated() const { return is_focals_estimated_; }
|
bool isFocalsEstimated() const { return is_focals_estimated_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -65,16 +65,17 @@ struct CalcRotation
|
|||||||
{
|
{
|
||||||
int pair_idx = edge.from * num_images + edge.to;
|
int pair_idx = edge.from * num_images + edge.to;
|
||||||
|
|
||||||
double f_from = cameras[edge.from].focal;
|
Mat_<double> K_from = Mat::eye(3, 3, CV_64F);
|
||||||
double f_to = cameras[edge.to].focal;
|
K_from(0,0) = cameras[edge.from].focal;
|
||||||
|
K_from(1,1) = cameras[edge.from].focal * cameras[edge.from].aspect;
|
||||||
|
K_from(0,2) = cameras[edge.from].ppx;
|
||||||
|
K_from(0,2) = cameras[edge.from].ppy;
|
||||||
|
|
||||||
Mat K_from = Mat::eye(3, 3, CV_64F);
|
Mat_<double> K_to = Mat::eye(3, 3, CV_64F);
|
||||||
K_from.at<double>(0, 0) = f_from;
|
K_to(0,0) = cameras[edge.to].focal;
|
||||||
K_from.at<double>(1, 1) = f_from;
|
K_to(1,1) = cameras[edge.to].focal * cameras[edge.to].aspect;
|
||||||
|
K_to(0,2) = cameras[edge.to].ppx;
|
||||||
Mat K_to = Mat::eye(3, 3, CV_64F);
|
K_to(0,2) = cameras[edge.to].ppy;
|
||||||
K_to.at<double>(0, 0) = f_to;
|
|
||||||
K_to.at<double>(1, 1) = f_to;
|
|
||||||
|
|
||||||
Mat R = K_from.inv() * pairwise_matches[pair_idx].H.inv() * K_to;
|
Mat R = K_from.inv() * pairwise_matches[pair_idx].H.inv() * K_to;
|
||||||
cameras[edge.to].R = cameras[edge.from].R * R;
|
cameras[edge.to].R = cameras[edge.from].R * R;
|
||||||
@ -129,12 +130,23 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Estimate focal length and set it for all cameras
|
if (!is_focals_estimated_)
|
||||||
vector<double> focals;
|
{
|
||||||
estimateFocal(features, pairwise_matches, focals);
|
// Estimate focal length and set it for all cameras
|
||||||
cameras.assign(num_images, CameraParams());
|
vector<double> focals;
|
||||||
for (int i = 0; i < num_images; ++i)
|
estimateFocal(features, pairwise_matches, focals);
|
||||||
cameras[i].focal = focals[i];
|
cameras.assign(num_images, CameraParams());
|
||||||
|
for (int i = 0; i < num_images; ++i)
|
||||||
|
cameras[i].focal = focals[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < num_images; ++i)
|
||||||
|
{
|
||||||
|
cameras[i].ppx -= 0.5 * features[i].img_size.width;
|
||||||
|
cameras[i].ppy -= 0.5 * features[i].img_size.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Restore global motion
|
// Restore global motion
|
||||||
Graph span_tree;
|
Graph span_tree;
|
||||||
@ -145,8 +157,8 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
|
|||||||
// As calculations were performed under assumption that p.p. is in image center
|
// As calculations were performed under assumption that p.p. is in image center
|
||||||
for (int i = 0; i < num_images; ++i)
|
for (int i = 0; i < num_images; ++i)
|
||||||
{
|
{
|
||||||
cameras[i].ppx = 0.5 * features[i].img_size.width;
|
cameras[i].ppx += 0.5 * features[i].img_size.width;
|
||||||
cameras[i].ppy = 0.5 * features[i].img_size.height;
|
cameras[i].ppy += 0.5 * features[i].img_size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGLN("Estimating rotations, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Estimating rotations, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
Loading…
Reference in New Issue
Block a user