Commit 6211920c authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

reg: enable wrappers for all methods

parent 51464723
...@@ -47,7 +47,7 @@ namespace reg { ...@@ -47,7 +47,7 @@ namespace reg {
//! @addtogroup reg //! @addtogroup reg
//! @{ //! @{
/** @brief Base class for modelling an algorithm for calculating a /** @brief Base class for modelling an algorithm for calculating a map
The class is only used to define the common interface for any possible mapping algorithm. The class is only used to define the common interface for any possible mapping algorithm.
*/ */
...@@ -60,8 +60,8 @@ public: ...@@ -60,8 +60,8 @@ public:
* Calculate mapping between two images * Calculate mapping between two images
* \param[in] img1 Reference image * \param[in] img1 Reference image
* \param[in] img2 Warped image * \param[in] img2 Warped image
* \param[in,out] res Map from img1 to img2, stored in a smart pointer. If present as input, * \param[in] If present, it is an initial rough estimation that the mapper will try to refine.
* it is an initial rough estimation that the mapper will try to refine. * \return Map from img1 to img2, stored in a smart pointer.
*/ */
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0; CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0;
......
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
#define MAPPERPYRAMID_H_ #define MAPPERPYRAMID_H_
#include "mapper.hpp" #include "mapper.hpp"
#include "mapaffine.hpp"
#include "mapprojec.hpp"
#include "mapshift.hpp"
namespace cv { namespace cv {
namespace reg { namespace reg {
...@@ -63,14 +65,39 @@ public: ...@@ -63,14 +65,39 @@ public:
CV_WRAP cv::Ptr<Map> getMap() const; CV_WRAP cv::Ptr<Map> getMap() const;
CV_WRAP unsigned numLev_; /*!< Number of levels of the pyramid */ CV_PROP_RW int numLev_; /*!< Number of levels of the pyramid */
CV_WRAP unsigned numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */ CV_PROP_RW int numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */
private: private:
MapperPyramid& operator=(const MapperPyramid&); MapperPyramid& operator=(const MapperPyramid&);
const Mapper& baseMapper_; /*!< Mapper used in inner level */ const Mapper& baseMapper_; /*!< Mapper used in inner level */
}; };
/*!
* Converts a pointer to a Map returned by MapperPyramid::calculate into the specified Map pointer type
*/
class CV_EXPORTS_W MapTypeCaster
{
public:
CV_WRAP static Ptr<MapAffine> toAffine(Ptr<Map> sourceMap)
{
MapAffine& affineMap = dynamic_cast<MapAffine&>(*sourceMap);
return Ptr<MapAffine>(new MapAffine(affineMap));
}
CV_WRAP static Ptr<MapShift> toShift(Ptr<Map> sourceMap)
{
MapShift& shiftMap = dynamic_cast<MapShift&>(*sourceMap);
return Ptr<MapShift>(new MapShift(shiftMap));
}
CV_WRAP static Ptr<MapProjec> toProjec(Ptr<Map> sourceMap)
{
MapProjec& projecMap = dynamic_cast<MapProjec&>(*sourceMap);
return Ptr<MapProjec>(new MapProjec(projecMap));
}
};
//! @} //! @}
}} // namespace cv::reg }} // namespace cv::reg
......
...@@ -62,7 +62,8 @@ public: ...@@ -62,7 +62,8 @@ public:
* Constructor providing explicit values * Constructor providing explicit values
* \param[in] shift Displacement * \param[in] shift Displacement
*/ */
MapShift(const cv::Vec<double, 2>& shift);
CV_WRAP MapShift(InputArray shift);
/*! /*!
* Destructor * Destructor
......
...@@ -73,20 +73,20 @@ Ptr<Map> MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map> ...@@ -73,20 +73,20 @@ Ptr<Map> MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map>
vector<Mat> pyrIm1(numLev_), pyrIm2(numLev_); vector<Mat> pyrIm1(numLev_), pyrIm2(numLev_);
pyrIm1[0] = img1; pyrIm1[0] = img1;
pyrIm2[0] = img2; pyrIm2[0] = img2;
for(size_t im_i = 1; im_i < numLev_; ++im_i) { for(int im_i = 1; im_i < numLev_; ++im_i) {
pyrDown(pyrIm1[im_i - 1], pyrIm1[im_i]); pyrDown(pyrIm1[im_i - 1], pyrIm1[im_i]);
pyrDown(pyrIm2[im_i - 1], pyrIm2[im_i]); pyrDown(pyrIm2[im_i - 1], pyrIm2[im_i]);
} }
Mat currRef, currImg; Mat currRef, currImg;
for(size_t lv_i = 0; lv_i < numLev_; ++lv_i) { for(int lv_i = 0; lv_i < numLev_; ++lv_i) {
currRef = pyrIm1[numLev_ - 1 - lv_i]; currRef = pyrIm1[numLev_ - 1 - lv_i];
currImg = pyrIm2[numLev_ - 1 - lv_i]; currImg = pyrIm2[numLev_ - 1 - lv_i];
// Scale the transformation as we are incresing the resolution in each iteration // Scale the transformation as we are incresing the resolution in each iteration
if(lv_i != 0) { if(lv_i != 0) {
ident->scale(2.); ident->scale(2.);
} }
for(size_t it_i = 0; it_i < numIterPerScale_; ++it_i) { for(int it_i = 0; it_i < numIterPerScale_; ++it_i) {
ident = baseMapper_.calculate(currRef, currImg, ident); ident = baseMapper_.calculate(currRef, currImg, ident);
} }
} }
......
...@@ -51,8 +51,10 @@ MapShift::MapShift() : shift_() ...@@ -51,8 +51,10 @@ MapShift::MapShift() : shift_()
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
MapShift::MapShift(const Vec<double, 2>& shift) : shift_(shift) MapShift::MapShift(InputArray shift)
{ {
Mat shiftMat = shift.getMat();
shiftMat.copyTo(shift_);
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -88,11 +88,10 @@ void RegTest::testShift() ...@@ -88,11 +88,10 @@ void RegTest::testShift()
// Register // Register
Ptr<Mapper> mapper = makePtr<MapperGradShift>(); Ptr<Mapper> mapper = makePtr<MapperGradShift>();
MapperPyramid mappPyr(mapper); MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr; Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result // Print result
MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get()); Ptr<MapShift> mapShift = MapTypeCaster::toShift(mapPtr);
#if REG_DEBUG_OUTPUT #if REG_DEBUG_OUTPUT
cout << endl << "--- Testing shift mapper ---" << endl; cout << endl << "--- Testing shift mapper ---" << endl;
cout << Mat(shift) << endl; cout << Mat(shift) << endl;
...@@ -121,11 +120,10 @@ void RegTest::testEuclidean() ...@@ -121,11 +120,10 @@ void RegTest::testEuclidean()
// Register // Register
Ptr<Mapper> mapper = makePtr<MapperGradEuclid>(); Ptr<Mapper> mapper = makePtr<MapperGradEuclid>();
MapperPyramid mappPyr(mapper); MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr; Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result // Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
#if REG_DEBUG_OUTPUT #if REG_DEBUG_OUTPUT
cout << endl << "--- Testing Euclidean mapper ---" << endl; cout << endl << "--- Testing Euclidean mapper ---" << endl;
cout << Mat(linTr) << endl; cout << Mat(linTr) << endl;
...@@ -160,11 +158,10 @@ void RegTest::testSimilarity() ...@@ -160,11 +158,10 @@ void RegTest::testSimilarity()
// Register // Register
Ptr<Mapper> mapper = makePtr<MapperGradSimilar>(); Ptr<Mapper> mapper = makePtr<MapperGradSimilar>();
MapperPyramid mappPyr(mapper); MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr; Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result // Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
#if REG_DEBUG_OUTPUT #if REG_DEBUG_OUTPUT
cout << endl << "--- Testing similarity mapper ---" << endl; cout << endl << "--- Testing similarity mapper ---" << endl;
cout << Mat(linTr) << endl; cout << Mat(linTr) << endl;
...@@ -196,11 +193,10 @@ void RegTest::testAffine() ...@@ -196,11 +193,10 @@ void RegTest::testAffine()
// Register // Register
Ptr<Mapper> mapper = makePtr<MapperGradAffine>(); Ptr<Mapper> mapper = makePtr<MapperGradAffine>();
MapperPyramid mappPyr(mapper); MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr; Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result // Print result
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
#if REG_DEBUG_OUTPUT #if REG_DEBUG_OUTPUT
cout << endl << "--- Testing affine mapper ---" << endl; cout << endl << "--- Testing affine mapper ---" << endl;
cout << Mat(linTr) << endl; cout << Mat(linTr) << endl;
...@@ -232,11 +228,10 @@ void RegTest::testProjective() ...@@ -232,11 +228,10 @@ void RegTest::testProjective()
// Register // Register
Ptr<Mapper> mapper = makePtr<MapperGradProj>(); Ptr<Mapper> mapper = makePtr<MapperGradProj>();
MapperPyramid mappPyr(mapper); MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr; Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
// Print result // Print result
MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get()); Ptr<MapProjec> mapProj = MapTypeCaster::toProjec(mapPtr);
mapProj->normalize(); mapProj->normalize();
#if REG_DEBUG_OUTPUT #if REG_DEBUG_OUTPUT
cout << endl << "--- Testing projective transformation mapper ---" << endl; cout << endl << "--- Testing projective transformation mapper ---" << endl;
......
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