Commit 51464723 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

reg: enable wrapping for all significant methods

parent 97dab3b5
......@@ -85,6 +85,10 @@ public:
return linTr_;
}
CV_WRAP void getLinTr(OutputArray linTr) const {
Mat(linTr_).copyTo(linTr);
}
/*!
* Return displacement part of the affine transformation
* \return Displacement part of the affine transformation
......@@ -93,6 +97,10 @@ public:
return shift_;
}
CV_WRAP void getShift(OutputArray shift) const {
Mat(shift_).copyTo(shift);
}
private:
cv::Matx<double, 2, 2> linTr_;
cv::Vec<double, 2> shift_;
......
......@@ -63,7 +63,7 @@ public:
* \param[in,out] res Map from img1 to img2, stored in a smart pointer. If present as input,
* it is an initial rough estimation that the mapper will try to refine.
*/
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const = 0;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0;
/*
* Returns a map compatible with the Mapper class
......
......@@ -55,7 +55,7 @@ public:
CV_WRAP MapperGradAffine();
~MapperGradAffine(void);
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
};
......
......@@ -55,7 +55,7 @@ public:
CV_WRAP MapperGradEuclid();
~MapperGradEuclid();
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
};
......
......@@ -55,7 +55,7 @@ public:
CV_WRAP MapperGradProj();
~MapperGradProj();
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
};
......
......@@ -55,7 +55,7 @@ public:
CV_WRAP MapperGradShift();
virtual ~MapperGradShift();
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
};
......
......@@ -55,7 +55,7 @@ public:
CV_WRAP MapperGradSimilar();
~MapperGradSimilar();
virtual void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
};
......
......@@ -57,9 +57,9 @@ public:
* Constructor
* \param[in] baseMapper Base mapper used for the refinements
*/
MapperPyramid(const Mapper& baseMapper);
CV_WRAP MapperPyramid(Ptr<Mapper> baseMapper);
void calculate(InputArray img1, InputArray img2, cv::Ptr<Map>& res) const;
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
CV_WRAP cv::Ptr<Map> getMap() const;
......
......@@ -85,10 +85,14 @@ public:
return projTr_;
}
CV_WRAP void getProjTr(OutputArray projTr) const {
Mat(projTr_).copyTo(projTr);
}
/*!
* Normalizes object's homography
*/
void normalize(void) {
CV_WRAP void normalize() {
double z = 1./projTr_(2, 2);
for(size_t v_i = 0; v_i < sizeof(projTr_.val)/sizeof(projTr_.val[0]); ++v_i)
projTr_.val[v_i] *= z;
......
......@@ -85,6 +85,10 @@ public:
return shift_;
}
CV_WRAP void getShift(OutputArray shift) const {
Mat(shift_).copyTo(shift);
}
private:
cv::Vec<double, 2> shift_; /*< Displacement */
};
......
......@@ -56,7 +56,7 @@ MapperGradAffine::~MapperGradAffine()
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperGradAffine::calculate(InputArray _img1, InputArray image2, cv::Ptr<Map>& res) const
cv::Ptr<Map> MapperGradAffine::calculate(InputArray _img1, InputArray image2, cv::Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat gradx, grady, imgDiff;
......@@ -66,9 +66,9 @@ void MapperGradAffine::calculate(InputArray _img1, InputArray image2, cv::Ptr<Ma
CV_DbgAssert(img1.channels() == image2.channels());
CV_DbgAssert(img1.channels() == 1 || img1.channels() == 3);
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
img2 = image2.getMat();
}
......@@ -145,11 +145,14 @@ void MapperGradAffine::calculate(InputArray _img1, InputArray image2, cv::Ptr<Ma
Matx<double, 2, 2> linTr(k(0) + 1., k(1), k(3), k(4) + 1.);
Vec<double, 2> shift(k(2), k(5));
if(res.empty()) {
res = Ptr<Map>(new MapAffine(linTr, shift));
if(init.empty()) {
return Ptr<Map>(new MapAffine(linTr, shift));
} else {
Ptr<MapAffine> newTr(new MapAffine(linTr, shift));
res->compose(newTr);
MapAffine* initPtr = dynamic_cast<MapAffine*>(init.get());
Ptr<MapAffine> oldTr(new MapAffine(initPtr->getLinTr(), initPtr->getShift()));
oldTr->compose(newTr);
return oldTr;
}
}
......
......@@ -56,8 +56,8 @@ MapperGradEuclid::~MapperGradEuclid()
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperGradEuclid::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map>& res) const
cv::Ptr<Map> MapperGradEuclid::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat gradx, grady, imgDiff;
......@@ -67,9 +67,9 @@ void MapperGradEuclid::calculate(
CV_DbgAssert(img1.channels() == image2.channels());
CV_DbgAssert(img1.channels() == 1 || img1.channels() == 3);
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
img2 = image2.getMat();
}
......@@ -112,11 +112,14 @@ void MapperGradEuclid::calculate(
Matx<double, 2, 2> linTr(cosT, -sinT, sinT, cosT);
Vec<double, 2> shift(k(0), k(1));
if(res.empty()) {
res = Ptr<Map>(new MapAffine(linTr, shift));
if(init.empty()) {
return Ptr<Map>(new MapAffine(linTr, shift));
} else {
Ptr<MapAffine> newTr(new MapAffine(linTr, shift));
res->compose(newTr);
MapAffine* initPtr = dynamic_cast<MapAffine*>(init.get());
Ptr<MapAffine> oldTr(new MapAffine(initPtr->getLinTr(), initPtr->getShift()));
oldTr->compose(newTr);
return oldTr;
}
}
......
......@@ -56,8 +56,8 @@ MapperGradProj::~MapperGradProj()
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperGradProj::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map>& res) const
cv::Ptr<Map> MapperGradProj::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat gradx, grady, imgDiff;
......@@ -67,9 +67,9 @@ void MapperGradProj::calculate(
CV_DbgAssert(img1.channels() == image2.channels());
CV_DbgAssert(img1.channels() == 1 || img1.channels() == 3);
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
img2 = image2.getMat();
}
......@@ -196,11 +196,14 @@ void MapperGradProj::calculate(
Vec<double, 8> k = A.inv(DECOMP_CHOLESKY)*b;
Matx<double, 3, 3> H(k(0) + 1., k(1), k(2), k(3), k(4) + 1., k(5), k(6), k(7), 1.);
if(res.empty()) {
res = Ptr<Map>(new MapProjec(H));
if(init.empty()) {
return Ptr<Map>(new MapProjec(H));
} else {
Ptr<MapProjec> newTr(new MapProjec(H));
res->compose(newTr);
MapProjec* initPtr = dynamic_cast<MapProjec*>(init.get());
Ptr<MapProjec> oldTr(new MapProjec(initPtr->getProjTr()));
oldTr->compose(newTr);
return oldTr;
}
}
......
......@@ -56,8 +56,8 @@ MapperGradShift::~MapperGradShift()
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperGradShift::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map>& res) const
cv::Ptr<Map> MapperGradShift::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat gradx, grady, imgDiff;
......@@ -65,9 +65,9 @@ void MapperGradShift::calculate(
CV_DbgAssert(img1.size() == image2.size());
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
img2 = image2.getMat();
}
......@@ -93,11 +93,14 @@ void MapperGradShift::calculate(
// Calculate shift. We use Cholesky decomposition, as A is symmetric.
Vec<double, 2> shift = A.inv(DECOMP_CHOLESKY)*b;
if(res.empty()) {
res = Ptr<Map>(new MapShift(shift));
if(init.empty()) {
return Ptr<Map>(new MapShift(shift));
} else {
Ptr<MapShift> newTr(new MapShift(shift));
res->compose(newTr);
MapShift* initPtr = dynamic_cast<MapShift*>(init.get());
Ptr<MapShift> oldTr(new MapShift(initPtr->getShift()));
oldTr->compose(newTr);
return oldTr;
}
}
......
......@@ -56,8 +56,8 @@ MapperGradSimilar::~MapperGradSimilar()
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperGradSimilar::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map>& res) const
cv::Ptr<Map> MapperGradSimilar::calculate(
InputArray _img1, InputArray image2, cv::Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat gradx, grady, imgDiff;
......@@ -67,9 +67,9 @@ void MapperGradSimilar::calculate(
CV_DbgAssert(img1.channels() == image2.channels());
CV_DbgAssert(img1.channels() == 1 || img1.channels() == 3);
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
img2 = image2.getMat();
}
......@@ -127,11 +127,14 @@ void MapperGradSimilar::calculate(
Matx<double, 2, 2> linTr(k(0) + 1., k(1), -k(1), k(0) + 1.);
Vec<double, 2> shift(k(2), k(3));
if(res.empty()) {
res = Ptr<Map>(new MapAffine(linTr, shift));
if(init.empty()) {
return Ptr<Map>(new MapAffine(linTr, shift));
} else {
Ptr<MapAffine> newTr(new MapAffine(linTr, shift));
res->compose(newTr);
MapAffine* initPtr = dynamic_cast<MapAffine*>(init.get());
Ptr<MapAffine> oldTr(new MapAffine(initPtr->getLinTr(), initPtr->getShift()));
oldTr->compose(newTr);
return oldTr;
}
}
......
......@@ -48,22 +48,22 @@ namespace reg {
////////////////////////////////////////////////////////////////////////////////////////////////////
MapperPyramid::MapperPyramid(const Mapper& baseMapper)
: numLev_(3), numIterPerScale_(3), baseMapper_(baseMapper)
MapperPyramid::MapperPyramid(Ptr<Mapper> baseMapper)
: numLev_(3), numIterPerScale_(3), baseMapper_(*baseMapper)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map>& res) const
Ptr<Map> MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map> init) const
{
Mat img1 = _img1.getMat();
Mat img2;
if(!res.empty()) {
if(!init.empty()) {
// We have initial values for the registration: we move img2 to that initial reference
res->inverseWarp(image2, img2);
init->inverseWarp(image2, img2);
} else {
res = baseMapper_.getMap();
init = baseMapper_.getMap();
img2 = image2.getMat();
}
......@@ -87,11 +87,12 @@ void MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map>& res
ident->scale(2.);
}
for(size_t it_i = 0; it_i < numIterPerScale_; ++it_i) {
baseMapper_.calculate(currRef, currImg, ident);
ident = baseMapper_.calculate(currRef, currImg, ident);
}
}
res->compose(ident);
init->compose(ident);
return init;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -86,10 +86,10 @@ void RegTest::testShift()
mapTest.warp(img1, img2);
// Register
MapperGradShift mapper;
Ptr<Mapper> mapper = makePtr<MapperGradShift>();
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result
MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get());
......@@ -119,10 +119,10 @@ void RegTest::testEuclidean()
mapTest.warp(img1, img2);
// Register
MapperGradEuclid mapper;
Ptr<Mapper> mapper = makePtr<MapperGradEuclid>();
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
......@@ -158,10 +158,10 @@ void RegTest::testSimilarity()
mapTest.warp(img1, img2);
// Register
MapperGradSimilar mapper;
Ptr<Mapper> mapper = makePtr<MapperGradSimilar>();
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
......@@ -194,10 +194,10 @@ void RegTest::testAffine()
mapTest.warp(img1, img2);
// Register
MapperGradAffine mapper;
Ptr<Mapper> mapper = makePtr<MapperGradAffine>();
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
......@@ -230,10 +230,10 @@ void RegTest::testProjective()
mapTest.warp(img1, img2);
// Register
MapperGradProj mapper;
Ptr<Mapper> mapper = makePtr<MapperGradProj>();
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result
MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment