Add cv::logPolar, cv::linearPolar, and a python example
authorJohn Stowers <john.stowers@gmail.com>
Tue, 10 Sep 2013 11:35:57 +0000 (13:35 +0200)
committerJohn Stowers <john.stowers@gmail.com>
Mon, 30 Sep 2013 20:31:19 +0000 (22:31 +0200)
modules/imgproc/include/opencv2/imgproc.hpp
modules/imgproc/src/imgwarp.cpp
samples/python2/logpolar.py [new file with mode: 0644]

index 3b25719..1648833 100644 (file)
@@ -76,14 +76,15 @@ enum { MORPH_RECT    = 0,
      };
 
 //! interpolation algorithm
-enum { INTER_NEAREST    = 0, //!< nearest neighbor interpolation
-       INTER_LINEAR     = 1, //!< bilinear interpolation
-       INTER_CUBIC      = 2, //!< bicubic interpolation
-       INTER_AREA       = 3, //!< area-based (or super) interpolation
-       INTER_LANCZOS4   = 4, //!< Lanczos interpolation over 8x8 neighborhood
-
-       INTER_MAX        = 7, //!< mask for interpolation codes
-       WARP_INVERSE_MAP = 16
+enum { INTER_NEAREST        = 0, //!< nearest neighbor interpolation
+       INTER_LINEAR         = 1, //!< bilinear interpolation
+       INTER_CUBIC          = 2, //!< bicubic interpolation
+       INTER_AREA           = 3, //!< area-based (or super) interpolation
+       INTER_LANCZOS4       = 4, //!< Lanczos interpolation over 8x8 neighborhood
+
+       INTER_MAX            = 7, //!< mask for interpolation codes
+       WARP_FILL_OUTLIERS   = 8,
+       WARP_INVERSE_MAP     = 16
      };
 
 enum { INTER_BITS      = 5,
@@ -1223,6 +1224,14 @@ CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
 CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
                                  Point2f center, OutputArray patch, int patchType = -1 );
 
+//! computes the log polar transform
+CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,
+                            Point2f center, double M, int flags );
+
+//! computes the linear polar transform
+CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,
+                               Point2f center, double maxRadius, int flags );
+
 //! computes the integral image
 CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );
 
index 9e20484..c01ba26 100644 (file)
@@ -4329,6 +4329,14 @@ cvLogPolar( const CvArr* srcarr, CvArr* dstarr,
     cvRemap( src, dst, mapx, mapy, flags, cvScalarAll(0) );
 }
 
+void cv::logPolar( InputArray _src, OutputArray _dst,
+                   Point2f center, double M, int flags )
+{
+    Mat src = _src.getMat();
+    _dst.create( src.size(), src.type() );
+    CvMat c_src = src, c_dst = _dst.getMat();
+    cvLogPolar( &c_src, &c_dst, center, M, flags );
+}
 
 /****************************************************************************************
                                    Linear-Polar Transform
@@ -4424,5 +4432,13 @@ void cvLinearPolar( const CvArr* srcarr, CvArr* dstarr,
     cvRemap( src, dst, mapx, mapy, flags, cvScalarAll(0) );
 }
 
+void cv::linearPolar( InputArray _src, OutputArray _dst,
+                      Point2f center, double maxRadius, int flags )
+{
+    Mat src = _src.getMat();
+    _dst.create( src.size(), src.type() );
+    CvMat c_src = src, c_dst = _dst.getMat();
+    cvLinearPolar( &c_src, &c_dst, center, maxRadius, flags );
+}
 
 /* End of file. */
diff --git a/samples/python2/logpolar.py b/samples/python2/logpolar.py
new file mode 100644 (file)
index 0000000..6608248
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+import cv2
+
+if __name__ == '__main__':
+    import sys
+    try:
+        fn = sys.argv[1]
+    except:
+        fn = '../cpp/fruits.jpg'
+
+    img = cv2.imread(fn)
+    if img is None:
+        print 'Failed to load image file:', fn
+        sys.exit(1)
+
+    img2 = cv2.logPolar(img, (img.shape[0]/2, img.shape[1]/2), 40, cv2.WARP_FILL_OUTLIERS)
+    img3 = cv2.linearPolar(img, (img.shape[0]/2, img.shape[1]/2), 40, cv2.WARP_FILL_OUTLIERS)
+
+    cv2.imshow('before', img)
+    cv2.imshow('logpolar', img2)
+    cv2.imshow('linearpolar', img3)
+
+    cv2.waitKey(0)