From fb9bbf99c4e9372c1023ba4941042d584303ea7b Mon Sep 17 00:00:00 2001 From: Marc Rollins Date: Mon, 22 Sep 2014 10:58:11 -0700 Subject: [PATCH 1/3] Adding division operators to `Point_` class. Performs element-wise division. --- modules/core/include/opencv2/core/types.hpp | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 69c838ae22..b55b0c83e6 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -994,6 +994,30 @@ Point_<_Tp>& operator *= (Point_<_Tp>& a, double b) return a; } +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + template static inline double norm(const Point_<_Tp>& pt) { @@ -1080,6 +1104,30 @@ Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b) return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); } +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, int b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, float b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, double b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + //////////////////////////////// 3D Point /////////////////////////////// From f32a6fb9a1b094a9ae68bb173a4e609caf5c4036 Mon Sep 17 00:00:00 2001 From: Marc Rollins Date: Mon, 22 Sep 2014 11:59:11 -0700 Subject: [PATCH 2/3] Adding element-wise division operators to Point3_ class. --- modules/core/include/opencv2/core/types.hpp | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index b55b0c83e6..dc4c30775e 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -1235,6 +1235,33 @@ Point3_<_Tp>& operator *= (Point3_<_Tp>& a, double b) return a; } +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + template static inline double norm(const Point3_<_Tp>& pt) { @@ -1320,6 +1347,30 @@ Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b) return a * Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1); } +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, int b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, float b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, double b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + ////////////////////////////////// Size ///////////////////////////////// From c8ede7c9ea0ee916269b7b525788bc7e6d593982 Mon Sep 17 00:00:00 2001 From: Marc Rollins Date: Mon, 22 Sep 2014 12:07:16 -0700 Subject: [PATCH 3/3] Updating documentation to reflect division operations. --- modules/core/doc/basic_structures.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index 5445adc213..8f75344c23 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -96,9 +96,11 @@ operation for each of the coordinates. Besides the class members listed in the d pt1 = pt2 - pt3; pt1 = pt2 * a; pt1 = a * pt2; + pt1 = pt2 / a; pt1 += pt2; pt1 -= pt2; pt1 *= a; + pt1 /= a; double value = norm(pt); // L2 norm pt1 == pt2; pt1 != pt2;