Skip to content

Commit ee79c1f

Browse files
committed
Merge pull request #988 from sovrasov:reg_python_bindings
2 parents d879ea4 + 17c4553 commit ee79c1f

26 files changed

+346
-234
lines changed

modules/reg/include/opencv2/reg/map.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ namespace reg {
121121
122122
The class is only used to define the common interface for any possible map.
123123
*/
124-
class CV_EXPORTS Map
124+
class CV_EXPORTS_W Map
125125
{
126126
public:
127127
/*!
128128
* Virtual destructor
129129
*/
130-
virtual ~Map(void);
130+
virtual ~Map();
131131

132132
/*!
133133
* Warps image to a new coordinate frame. The calculation is img2(x)=img1(T^{-1}(x)), as we
@@ -136,7 +136,7 @@ class CV_EXPORTS Map
136136
* \param[in] img1 Original image
137137
* \param[out] img2 Warped image
138138
*/
139-
virtual void warp(const cv::Mat& img1, cv::Mat& img2) const;
139+
CV_WRAP virtual void warp(InputArray img1, OutputArray img2) const;
140140

141141
/*!
142142
* Warps image to a new coordinate frame. The calculation is img2(x)=img1(T(x)), so in fact
@@ -145,27 +145,27 @@ class CV_EXPORTS Map
145145
* \param[in] img1 Original image
146146
* \param[out] img2 Warped image
147147
*/
148-
virtual void inverseWarp(const cv::Mat& img1, cv::Mat& img2) const = 0;
148+
CV_WRAP virtual void inverseWarp(InputArray img1, OutputArray img2) const = 0;
149149

150150
/*!
151151
* Calculates the inverse map
152152
* \return Inverse map
153153
*/
154-
virtual cv::Ptr<Map> inverseMap(void) const = 0;
154+
CV_WRAP virtual cv::Ptr<Map> inverseMap() const = 0;
155155

156156
/*!
157157
* Changes the map composing the current transformation with the one provided in the call.
158158
* The order is first the current transformation, then the input argument.
159159
* \param[in] map Transformation to compose with.
160160
*/
161-
virtual void compose(const Map& map) = 0;
161+
CV_WRAP virtual void compose(cv::Ptr<Map> map) = 0;
162162

163163
/*!
164164
* Scales the map by a given factor as if the coordinates system is expanded/compressed
165165
* by that factor.
166166
* \param[in] factor Expansion if bigger than one, compression if smaller than one
167167
*/
168-
virtual void scale(double factor) = 0;
168+
CV_WRAP virtual void scale(double factor) = 0;
169169
};
170170

171171
//! @}

modules/reg/include/opencv2/reg/mapaffine.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ namespace reg {
4949
/*!
5050
* Defines an affine transformation
5151
*/
52-
class CV_EXPORTS MapAffine : public Map
52+
class CV_EXPORTS_W MapAffine : public Map
5353
{
5454
public:
5555
/*!
5656
* Default constructor builds an identity map
5757
*/
58-
MapAffine(void);
58+
CV_WRAP MapAffine();
5959

6060
/*!
6161
* Constructor providing explicit values
@@ -67,15 +67,15 @@ class CV_EXPORTS MapAffine : public Map
6767
/*!
6868
* Destructor
6969
*/
70-
~MapAffine(void);
70+
~MapAffine();
7171

72-
void inverseWarp(const cv::Mat& img1, cv::Mat& img2) const;
72+
CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const;
7373

74-
cv::Ptr<Map> inverseMap(void) const;
74+
CV_WRAP cv::Ptr<Map> inverseMap() const;
7575

76-
void compose(const Map& map);
76+
CV_WRAP void compose(cv::Ptr<Map> map);
7777

78-
void scale(double factor);
78+
CV_WRAP void scale(double factor);
7979

8080
/*!
8181
* Return linear part of the affine transformation
@@ -85,6 +85,10 @@ class CV_EXPORTS MapAffine : public Map
8585
return linTr_;
8686
}
8787

88+
CV_WRAP void getLinTr(OutputArray linTr) const {
89+
Mat(linTr_).copyTo(linTr);
90+
}
91+
8892
/*!
8993
* Return displacement part of the affine transformation
9094
* \return Displacement part of the affine transformation
@@ -93,6 +97,10 @@ class CV_EXPORTS MapAffine : public Map
9397
return shift_;
9498
}
9599

100+
CV_WRAP void getShift(OutputArray shift) const {
101+
Mat(shift_).copyTo(shift);
102+
}
103+
96104
private:
97105
cv::Matx<double, 2, 2> linTr_;
98106
cv::Vec<double, 2> shift_;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ 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
*/
54-
class CV_EXPORTS Mapper
54+
class CV_EXPORTS_W Mapper
5555
{
5656
public:
5757
virtual ~Mapper(void) {}
@@ -60,16 +60,16 @@ class CV_EXPORTS 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
*/
66-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const = 0;
66+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const = 0;
6767

6868
/*
6969
* Returns a map compatible with the Mapper class
7070
* \return Pointer to identity Map
7171
*/
72-
virtual cv::Ptr<Map> getMap(void) const = 0;
72+
CV_WRAP virtual cv::Ptr<Map> getMap() const = 0;
7373

7474
protected:
7575
/*

modules/reg/include/opencv2/reg/mappergradaffine.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace reg {
4949
/*!
5050
* Mapper for affine motion
5151
*/
52-
class CV_EXPORTS MapperGradAffine: public Mapper
52+
class CV_EXPORTS_W MapperGradAffine: public Mapper
5353
{
5454
public:
55-
MapperGradAffine(void);
55+
CV_WRAP MapperGradAffine();
5656
~MapperGradAffine(void);
5757

58-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
58+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
5959

60-
cv::Ptr<Map> getMap(void) const;
60+
CV_WRAP cv::Ptr<Map> getMap() const;
6161
};
6262

6363
//! @}

modules/reg/include/opencv2/reg/mappergradeuclid.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace reg {
4949
/*!
5050
* Mapper for euclidean motion: rotation plus shift
5151
*/
52-
class CV_EXPORTS MapperGradEuclid: public Mapper
52+
class CV_EXPORTS_W MapperGradEuclid: public Mapper
5353
{
5454
public:
55-
MapperGradEuclid(void);
56-
~MapperGradEuclid(void);
55+
CV_WRAP MapperGradEuclid();
56+
~MapperGradEuclid();
5757

58-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
58+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
5959

60-
cv::Ptr<Map> getMap(void) const;
60+
CV_WRAP cv::Ptr<Map> getMap() const;
6161
};
6262

6363
//! @}

modules/reg/include/opencv2/reg/mappergradproj.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace reg {
4949
/*!
5050
* Gradient mapper for a projective transformation
5151
*/
52-
class CV_EXPORTS MapperGradProj: public Mapper
52+
class CV_EXPORTS_W MapperGradProj: public Mapper
5353
{
5454
public:
55-
MapperGradProj(void);
56-
~MapperGradProj(void);
55+
CV_WRAP MapperGradProj();
56+
~MapperGradProj();
5757

58-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
58+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
5959

60-
cv::Ptr<Map> getMap(void) const;
60+
CV_WRAP cv::Ptr<Map> getMap() const;
6161
};
6262

6363
//! @}

modules/reg/include/opencv2/reg/mappergradshift.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace reg {
4949
/*!
5050
* Gradient mapper for a translation
5151
*/
52-
class CV_EXPORTS MapperGradShift: public Mapper
52+
class CV_EXPORTS_W MapperGradShift: public Mapper
5353
{
5454
public:
55-
MapperGradShift(void);
56-
virtual ~MapperGradShift(void);
55+
CV_WRAP MapperGradShift();
56+
virtual ~MapperGradShift();
5757

58-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
58+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
5959

60-
cv::Ptr<Map> getMap(void) const;
60+
CV_WRAP cv::Ptr<Map> getMap() const;
6161
};
6262

6363
//! @}

modules/reg/include/opencv2/reg/mappergradsimilar.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace reg {
4949
/*!
5050
* Calculates a similarity transformation between to images (scale, rotation, and shift)
5151
*/
52-
class CV_EXPORTS MapperGradSimilar: public Mapper
52+
class CV_EXPORTS_W MapperGradSimilar: public Mapper
5353
{
5454
public:
55-
MapperGradSimilar(void);
56-
~MapperGradSimilar(void);
55+
CV_WRAP MapperGradSimilar();
56+
~MapperGradSimilar();
5757

58-
virtual void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
58+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
5959

60-
cv::Ptr<Map> getMap(void) const;
60+
CV_WRAP cv::Ptr<Map> getMap() const;
6161
};
6262

6363
//! @}

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

Lines changed: 34 additions & 7 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 {
@@ -50,27 +52,52 @@ namespace reg {
5052
/*!
5153
* Calculates a map using a gaussian pyramid
5254
*/
53-
class CV_EXPORTS MapperPyramid: public Mapper
55+
class CV_EXPORTS_W MapperPyramid: public Mapper
5456
{
5557
public:
5658
/*
5759
* Constructor
5860
* \param[in] baseMapper Base mapper used for the refinements
5961
*/
60-
MapperPyramid(const Mapper& baseMapper);
62+
CV_WRAP MapperPyramid(Ptr<Mapper> baseMapper);
6163

62-
void calculate(const cv::Mat& img1, const cv::Mat& img2, cv::Ptr<Map>& res) const;
64+
CV_WRAP virtual cv::Ptr<Map> calculate(InputArray img1, InputArray img2, cv::Ptr<Map> init = cv::Ptr<Map>()) const;
6365

64-
cv::Ptr<Map> getMap(void) const;
66+
CV_WRAP cv::Ptr<Map> getMap() const;
6567

66-
unsigned numLev_; /*!< Number of levels of the pyramid */
67-
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/mapprojec.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ namespace reg {
5050
/*!
5151
* Defines an transformation that consists on a projective transformation
5252
*/
53-
class CV_EXPORTS MapProjec : public Map
53+
class CV_EXPORTS_W MapProjec : public Map
5454
{
5555
public:
5656
/*!
5757
* Default constructor builds an identity map
5858
*/
59-
MapProjec(void);
59+
CV_WRAP MapProjec();
6060

6161
/*!
6262
* Constructor providing explicit values
@@ -67,15 +67,15 @@ class CV_EXPORTS MapProjec : public Map
6767
/*!
6868
* Destructor
6969
*/
70-
~MapProjec(void);
70+
~MapProjec();
7171

72-
void inverseWarp(const cv::Mat& img1, cv::Mat& img2) const;
72+
CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const;
7373

74-
cv::Ptr<Map> inverseMap(void) const;
74+
CV_WRAP cv::Ptr<Map> inverseMap() const;
7575

76-
void compose(const Map& map);
76+
CV_WRAP void compose(cv::Ptr<Map> map);
7777

78-
void scale(double factor);
78+
CV_WRAP void scale(double factor);
7979

8080
/*!
8181
* Returns projection matrix
@@ -85,10 +85,14 @@ class CV_EXPORTS MapProjec : public Map
8585
return projTr_;
8686
}
8787

88+
CV_WRAP void getProjTr(OutputArray projTr) const {
89+
Mat(projTr_).copyTo(projTr);
90+
}
91+
8892
/*!
8993
* Normalizes object's homography
9094
*/
91-
void normalize(void) {
95+
CV_WRAP void normalize() {
9296
double z = 1./projTr_(2, 2);
9397
for(size_t v_i = 0; v_i < sizeof(projTr_.val)/sizeof(projTr_.val[0]); ++v_i)
9498
projTr_.val[v_i] *= z;

0 commit comments

Comments
 (0)