refactoring in opencv_stitching
This commit is contained in:
parent
16e6c45ed7
commit
90ece0b8e5
@ -52,7 +52,7 @@ int main(int argc, char* argv[])
|
|||||||
int blend_type = Blender::MULTI_BAND;
|
int blend_type = Blender::MULTI_BAND;
|
||||||
string result_name = "result.png";
|
string result_name = "result.png";
|
||||||
|
|
||||||
double work_scale = -1, compose_scale = -1;
|
double work_scale = 1, compose_scale = 1;
|
||||||
bool is_work_scale_set = false, is_compose_scale_set = false;
|
bool is_work_scale_set = false, is_compose_scale_set = false;
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
@ -328,11 +328,11 @@ int main(int argc, char* argv[])
|
|||||||
Ptr<Warper> warper = Warper::createByCameraFocal(camera_focal, warp_type);
|
Ptr<Warper> warper = Warper::createByCameraFocal(camera_focal, warp_type);
|
||||||
for (int i = 0; i < num_images; ++i)
|
for (int i = 0; i < num_images; ++i)
|
||||||
{
|
{
|
||||||
corners[i] = (*warper)(images[i], static_cast<float>(cameras[i].focal), cameras[i].R,
|
corners[i] = warper->warp(images[i], static_cast<float>(cameras[i].focal), cameras[i].R,
|
||||||
images_warped[i]);
|
images_warped[i]);
|
||||||
sizes[i] = images_warped[i].size();
|
sizes[i] = images_warped[i].size();
|
||||||
(*warper)(masks[i], static_cast<float>(cameras[i].focal), cameras[i].R, masks_warped[i],
|
warper->warp(masks[i], static_cast<float>(cameras[i].focal), cameras[i].R, masks_warped[i],
|
||||||
INTER_NEAREST, BORDER_CONSTANT);
|
INTER_NEAREST, BORDER_CONSTANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Mat> images_f(num_images);
|
vector<Mat> images_f(num_images);
|
||||||
@ -344,7 +344,7 @@ int main(int argc, char* argv[])
|
|||||||
LOGLN("Finding seams...");
|
LOGLN("Finding seams...");
|
||||||
t = getTickCount();
|
t = getTickCount();
|
||||||
Ptr<SeamFinder> seam_finder = SeamFinder::createDefault(seam_find_type);
|
Ptr<SeamFinder> seam_finder = SeamFinder::createDefault(seam_find_type);
|
||||||
(*seam_finder)(images_f, corners, masks_warped);
|
seam_finder->find(images_f, corners, masks_warped);
|
||||||
LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
LOGLN("Blending images...");
|
LOGLN("Blending images...");
|
||||||
|
@ -20,13 +20,6 @@ Ptr<SeamFinder> SeamFinder::createDefault(int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SeamFinder::operator ()(const vector<Mat> &src, const vector<Point> &corners,
|
|
||||||
vector<Mat> &masks)
|
|
||||||
{
|
|
||||||
find(src, corners, masks);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PairwiseSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners,
|
void PairwiseSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners,
|
||||||
vector<Mat> &masks)
|
vector<Mat> &masks)
|
||||||
{
|
{
|
||||||
|
@ -8,15 +8,9 @@ class SeamFinder
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { NO, VORONOI, GRAPH_CUT };
|
enum { NO, VORONOI, GRAPH_CUT };
|
||||||
|
|
||||||
static cv::Ptr<SeamFinder> createDefault(int type);
|
static cv::Ptr<SeamFinder> createDefault(int type);
|
||||||
|
|
||||||
virtual ~SeamFinder() {}
|
virtual ~SeamFinder() {}
|
||||||
|
|
||||||
void operator ()(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
|
||||||
std::vector<cv::Mat> &masks);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
virtual void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
||||||
std::vector<cv::Mat> &masks) = 0;
|
std::vector<cv::Mat> &masks) = 0;
|
||||||
};
|
};
|
||||||
@ -24,17 +18,17 @@ protected:
|
|||||||
|
|
||||||
class NoSeamFinder : public SeamFinder
|
class NoSeamFinder : public SeamFinder
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
void find(const std::vector<cv::Mat>&, const std::vector<cv::Point>&, std::vector<cv::Mat>&) {}
|
void find(const std::vector<cv::Mat>&, const std::vector<cv::Point>&, std::vector<cv::Mat>&) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PairwiseSeamFinder : public SeamFinder
|
class PairwiseSeamFinder : public SeamFinder
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners,
|
||||||
std::vector<cv::Mat> &masks);
|
std::vector<cv::Mat> &masks);
|
||||||
|
protected:
|
||||||
virtual void findInPair(const cv::Mat &img1, const cv::Mat &img2, cv::Point tl1, cv::Point tl2,
|
virtual void findInPair(const cv::Mat &img1, const cv::Mat &img2, cv::Point tl1, cv::Point tl2,
|
||||||
cv::Rect roi, cv::Mat &mask1, cv::Mat &mask2) = 0;
|
cv::Rect roi, cv::Mat &mask1, cv::Mat &mask2) = 0;
|
||||||
};
|
};
|
||||||
@ -53,7 +47,6 @@ class GraphCutSeamFinder : public PairwiseSeamFinder
|
|||||||
public:
|
public:
|
||||||
// TODO add COST_COLOR_GRAD support
|
// TODO add COST_COLOR_GRAD support
|
||||||
enum { COST_COLOR };
|
enum { COST_COLOR };
|
||||||
|
|
||||||
GraphCutSeamFinder(int cost_type = COST_COLOR, float terminal_cost = 10000.f,
|
GraphCutSeamFinder(int cost_type = COST_COLOR, float terminal_cost = 10000.f,
|
||||||
float bad_region_penalty = 1000.f);
|
float bad_region_penalty = 1000.f);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ Ptr<Warper> Warper::createByCameraFocal(float focal, int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProjectorBase::setCameraMatrix(const Mat &R)
|
void ProjectorBase::setTransformation(const Mat &R)
|
||||||
{
|
{
|
||||||
CV_Assert(R.size() == Size(3, 3));
|
CV_Assert(R.size() == Size(3, 3));
|
||||||
CV_Assert(R.type() == CV_32F);
|
CV_Assert(R.type() == CV_32F);
|
||||||
@ -31,13 +31,6 @@ void ProjectorBase::setCameraMatrix(const Mat &R)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Point Warper::operator ()(const Mat &src, float focal, const Mat& R, Mat &dst,
|
|
||||||
int interp_mode, int border_mode)
|
|
||||||
{
|
|
||||||
return warp(src, focal, R, dst, interp_mode, border_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PlaneWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
|
void PlaneWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
|
||||||
{
|
{
|
||||||
float tl_uf = numeric_limits<float>::max();
|
float tl_uf = numeric_limits<float>::max();
|
||||||
|
@ -8,23 +8,17 @@ class Warper
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum { PLANE, CYLINDRICAL, SPHERICAL };
|
enum { PLANE, CYLINDRICAL, SPHERICAL };
|
||||||
|
|
||||||
static cv::Ptr<Warper> createByCameraFocal(float focal, int type);
|
static cv::Ptr<Warper> createByCameraFocal(float focal, int type);
|
||||||
|
|
||||||
virtual ~Warper() {}
|
virtual ~Warper() {}
|
||||||
|
|
||||||
cv::Point operator ()(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst,
|
|
||||||
int interp_mode = cv::INTER_LINEAR, int border_mode = cv::BORDER_REFLECT);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual cv::Point warp(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst,
|
virtual cv::Point warp(const cv::Mat &src, float focal, const cv::Mat& R, cv::Mat &dst,
|
||||||
int interp_mode, int border_mode) = 0;
|
int interp_mode = cv::INTER_LINEAR, int border_mode = cv::BORDER_REFLECT) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ProjectorBase
|
struct ProjectorBase
|
||||||
{
|
{
|
||||||
void setCameraMatrix(const cv::Mat& R);
|
void setTransformation(const cv::Mat& R);
|
||||||
|
|
||||||
cv::Size size;
|
cv::Size size;
|
||||||
float focal;
|
float focal;
|
||||||
@ -37,10 +31,11 @@ struct ProjectorBase
|
|||||||
template <class P>
|
template <class P>
|
||||||
class WarperBase : public Warper
|
class WarperBase : public Warper
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
|
cv::Point warp(const cv::Mat &src, float focal, const cv::Mat &R, cv::Mat &dst,
|
||||||
int interp_mode, int border_mode);
|
int interp_mode, int border_mode);
|
||||||
|
|
||||||
|
protected:
|
||||||
// Detects ROI of the destination image. It's correct for any projection.
|
// Detects ROI of the destination image. It's correct for any projection.
|
||||||
virtual void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
|
virtual void detectResultRoi(cv::Point &dst_tl, cv::Point &dst_br);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ cv::Point WarperBase<P>::warp(const cv::Mat &src, float focal, const cv::Mat &R,
|
|||||||
|
|
||||||
projector_.size = src.size();
|
projector_.size = src.size();
|
||||||
projector_.focal = focal;
|
projector_.focal = focal;
|
||||||
projector_.setCameraMatrix(R);
|
projector_.setTransformation(R);
|
||||||
|
|
||||||
cv::Point dst_tl, dst_br;
|
cv::Point dst_tl, dst_br;
|
||||||
detectResultRoi(dst_tl, dst_br);
|
detectResultRoi(dst_tl, dst_br);
|
||||||
|
Loading…
Reference in New Issue
Block a user