Skip to content

Commit 6211920

Browse files
committed
reg: enable wrappers for all methods
1 parent 5146472 commit 6211920

File tree

6 files changed

+51
-26
lines changed

6 files changed

+51
-26
lines changed

modules/reg/include/opencv2/reg/mapper.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace reg {
4747
//! @addtogroup reg
4848
//! @{
4949

50-
/** @brief Base class for modelling an algorithm for calculating a
50+
/** @brief Base class for modelling an algorithm for calculating a map
5151
5252
The class is only used to define the common interface for any possible mapping algorithm.
5353
*/
@@ -60,8 +60,8 @@ class CV_EXPORTS_W Mapper
6060
* Calculate mapping between two images
6161
* \param[in] img1 Reference image
6262
* \param[in] img2 Warped image
63-
* \param[in,out] res Map from img1 to img2, stored in a smart pointer. If present as input,
64-
* it is an initial rough estimation that the mapper will try to refine.
63+
* \param[in] If present, it is an initial rough estimation that the mapper will try to refine.
64+
* \return Map from img1 to img2, stored in a smart pointer.
6565
*/
6666
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0;
6767

modules/reg/include/opencv2/reg/mapperpyramid.hpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
#define MAPPERPYRAMID_H_
4040

4141
#include "mapper.hpp"
42-
42+
#include "mapaffine.hpp"
43+
#include "mapprojec.hpp"
44+
#include "mapshift.hpp"
4345

4446
namespace cv {
4547
namespace reg {
@@ -63,14 +65,39 @@ class CV_EXPORTS_W MapperPyramid: public Mapper
6365

6466
CV_WRAP cv::Ptr<Map> getMap() const;
6567

66-
CV_WRAP unsigned numLev_; /*!< Number of levels of the pyramid */
67-
CV_WRAP unsigned numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */
68+
CV_PROP_RW int numLev_; /*!< Number of levels of the pyramid */
69+
CV_PROP_RW int numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */
6870

6971
private:
7072
MapperPyramid& operator=(const MapperPyramid&);
7173
const Mapper& baseMapper_; /*!< Mapper used in inner level */
7274
};
7375

76+
/*!
77+
* Converts a pointer to a Map returned by MapperPyramid::calculate into the specified Map pointer type
78+
*/
79+
class CV_EXPORTS_W MapTypeCaster
80+
{
81+
public:
82+
CV_WRAP static Ptr<MapAffine> toAffine(Ptr<Map> sourceMap)
83+
{
84+
MapAffine& affineMap = dynamic_cast<MapAffine&>(*sourceMap);
85+
return Ptr<MapAffine>(new MapAffine(affineMap));
86+
}
87+
88+
CV_WRAP static Ptr<MapShift> toShift(Ptr<Map> sourceMap)
89+
{
90+
MapShift& shiftMap = dynamic_cast<MapShift&>(*sourceMap);
91+
return Ptr<MapShift>(new MapShift(shiftMap));
92+
}
93+
94+
CV_WRAP static Ptr<MapProjec> toProjec(Ptr<Map> sourceMap)
95+
{
96+
MapProjec& projecMap = dynamic_cast<MapProjec&>(*sourceMap);
97+
return Ptr<MapProjec>(new MapProjec(projecMap));
98+
}
99+
};
100+
74101
//! @}
75102

76103
}} // namespace cv::reg

modules/reg/include/opencv2/reg/mapshift.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class CV_EXPORTS_W MapShift : public Map
6262
* Constructor providing explicit values
6363
* \param[in] shift Displacement
6464
*/
65-
MapShift(const cv::Vec<double, 2>& shift);
65+
66+
CV_WRAP MapShift(InputArray shift);
6667

6768
/*!
6869
* Destructor

modules/reg/src/mapperpyramid.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ Ptr<Map> MapperPyramid::calculate(InputArray _img1, InputArray image2, Ptr<Map>
7373
vector<Mat> pyrIm1(numLev_), pyrIm2(numLev_);
7474
pyrIm1[0] = img1;
7575
pyrIm2[0] = img2;
76-
for(size_t im_i = 1; im_i < numLev_; ++im_i) {
76+
for(int im_i = 1; im_i < numLev_; ++im_i) {
7777
pyrDown(pyrIm1[im_i - 1], pyrIm1[im_i]);
7878
pyrDown(pyrIm2[im_i - 1], pyrIm2[im_i]);
7979
}
8080

8181
Mat currRef, currImg;
82-
for(size_t lv_i = 0; lv_i < numLev_; ++lv_i) {
82+
for(int lv_i = 0; lv_i < numLev_; ++lv_i) {
8383
currRef = pyrIm1[numLev_ - 1 - lv_i];
8484
currImg = pyrIm2[numLev_ - 1 - lv_i];
8585
// Scale the transformation as we are incresing the resolution in each iteration
8686
if(lv_i != 0) {
8787
ident->scale(2.);
8888
}
89-
for(size_t it_i = 0; it_i < numIterPerScale_; ++it_i) {
89+
for(int it_i = 0; it_i < numIterPerScale_; ++it_i) {
9090
ident = baseMapper_.calculate(currRef, currImg, ident);
9191
}
9292
}

modules/reg/src/mapshift.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ MapShift::MapShift() : shift_()
5151
}
5252

5353
////////////////////////////////////////////////////////////////////////////////////////////////////
54-
MapShift::MapShift(const Vec<double, 2>& shift) : shift_(shift)
54+
MapShift::MapShift(InputArray shift)
5555
{
56+
Mat shiftMat = shift.getMat();
57+
shiftMat.copyTo(shift_);
5658
}
5759

5860
////////////////////////////////////////////////////////////////////////////////////////////////////

modules/reg/test/test_reg.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ void RegTest::testShift()
8888
// Register
8989
Ptr<Mapper> mapper = makePtr<MapperGradShift>();
9090
MapperPyramid mappPyr(mapper);
91-
Ptr<Map> mapPtr;
92-
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
91+
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
9392

9493
// Print result
95-
MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get());
94+
Ptr<MapShift> mapShift = MapTypeCaster::toShift(mapPtr);
9695
#if REG_DEBUG_OUTPUT
9796
cout << endl << "--- Testing shift mapper ---" << endl;
9897
cout << Mat(shift) << endl;
@@ -121,11 +120,10 @@ void RegTest::testEuclidean()
121120
// Register
122121
Ptr<Mapper> mapper = makePtr<MapperGradEuclid>();
123122
MapperPyramid mappPyr(mapper);
124-
Ptr<Map> mapPtr;
125-
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
123+
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
126124

127125
// Print result
128-
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
126+
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
129127
#if REG_DEBUG_OUTPUT
130128
cout << endl << "--- Testing Euclidean mapper ---" << endl;
131129
cout << Mat(linTr) << endl;
@@ -160,11 +158,10 @@ void RegTest::testSimilarity()
160158
// Register
161159
Ptr<Mapper> mapper = makePtr<MapperGradSimilar>();
162160
MapperPyramid mappPyr(mapper);
163-
Ptr<Map> mapPtr;
164-
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
161+
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
165162

166163
// Print result
167-
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
164+
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
168165
#if REG_DEBUG_OUTPUT
169166
cout << endl << "--- Testing similarity mapper ---" << endl;
170167
cout << Mat(linTr) << endl;
@@ -196,11 +193,10 @@ void RegTest::testAffine()
196193
// Register
197194
Ptr<Mapper> mapper = makePtr<MapperGradAffine>();
198195
MapperPyramid mappPyr(mapper);
199-
Ptr<Map> mapPtr;
200-
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
196+
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
201197

202198
// Print result
203-
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
199+
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr);
204200
#if REG_DEBUG_OUTPUT
205201
cout << endl << "--- Testing affine mapper ---" << endl;
206202
cout << Mat(linTr) << endl;
@@ -232,11 +228,10 @@ void RegTest::testProjective()
232228
// Register
233229
Ptr<Mapper> mapper = makePtr<MapperGradProj>();
234230
MapperPyramid mappPyr(mapper);
235-
Ptr<Map> mapPtr;
236-
mapPtr = mappPyr.calculate(img1, img2, mapPtr);
231+
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
237232

238233
// Print result
239-
MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get());
234+
Ptr<MapProjec> mapProj = MapTypeCaster::toProjec(mapPtr);
240235
mapProj->normalize();
241236
#if REG_DEBUG_OUTPUT
242237
cout << endl << "--- Testing projective transformation mapper ---" << endl;

0 commit comments

Comments
 (0)