[arrayfire] 180/248: Added homography function prototype and API

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.

commit 53d77a73087661d3d9b205bbfbbef129e22108fd
Author: Peter Andreas Entschev <peter at arrayfire.com>
Date:   Tue Nov 3 14:37:31 2015 -0500

    Added homography function prototype and API
---
 include/af/defines.h       |  5 +++
 include/af/vision.h        | 61 ++++++++++++++++++++++++++++++++
 src/api/c/homography.cpp   | 88 ++++++++++++++++++++++++++++++++++++++++++++++
 src/api/cpp/homography.cpp | 32 +++++++++++++++++
 src/api/unified/vision.cpp |  7 ++++
 5 files changed, 193 insertions(+)

diff --git a/include/af/defines.h b/include/af/defines.h
index dc36a27..ac97ad0 100644
--- a/include/af/defines.h
+++ b/include/af/defines.h
@@ -325,6 +325,11 @@ typedef enum {
     AF_FIF_RAW          = 34    ///< FreeImage Enum for RAW Camera Image File
 } af_image_format;
 
+typedef enum {
+    AF_RANSAC           = 0,    ///< Computes homography using RANSAC
+    AF_LMEDS            = 1     ///< Computes homography using Least Median of Squares
+} af_homography_type;
+
 // These enums should be 2^x
 typedef enum {
     AF_BACKEND_DEFAULT = 0,  ///< Default backend order: OpenCL -> CUDA -> CPU
diff --git a/include/af/vision.h b/include/af/vision.h
index 8df9601..bd2084c 100644
--- a/include/af/vision.h
+++ b/include/af/vision.h
@@ -280,6 +280,35 @@ AFAPI features susan(const array& in,
 AFAPI array dog(const array& in, const int radius1, const int radius2);
 #endif
 
+#if AF_API_VERSION >= 32
+/**
+   C++ Interface for Homography estimation
+
+   \param[out] H is a 3x3 array containing the estimated homography.
+   \param[out] inliers is the number of inliers that the homography was estimated to comprise,
+               in the case that htype is AF_RANSAC, a higher inlier_thr value will increase the
+               estimated inliers. Note that if the number of inliers is too low, it is likely
+               that a bad homography will be returned.
+   \param[in]  x_src x coordinates of the source points.
+   \param[in]  y_src y coordinates of the source points.
+   \param[in]  x_dst x coordinates of the destination points.
+   \param[in]  y_dst y coordinates of the destination points.
+   \param[in]  inlier_thr if htype is AF_RANSAC, this parameter will five the maximum L2-distance
+               for a point to be considered an inlier.
+   \param[in]  iterations maximum number of iterations when htype is AF_RANSAC and backend is CPU,
+               if backend is CUDA or OpenCL, iterations is the total number of iterations, an
+               iteration is a selection of 4 random points for which the homography is estimated
+               and evaluated for number of inliers.
+   \param[in]  af_homography_type can be AF_RANSAC, for which a RANdom SAmple Consensus will be
+               used to evaluate the homography quality (e.g., number of inliers), or AF_LMEDS,
+               which will use Least Median of Squares method to evaluate homography quality
+   \param[in]  dtype the array type for the homography output.
+
+   \ingroup cv_func_homography
+*/
+AFAPI void homography(array& H, int& inliers, const array& x_src, const array& y_src, const array& x_dst, const array& y_dst, const af_homography_type htype=AF_RANSAC, const float inlier_thr=3.f, const unsigned iterations=1000, const dtype type=f32);
+#endif
+
 }
 #endif
 
@@ -552,6 +581,38 @@ extern "C" {
     AFAPI af_err af_dog(af_array *out, const af_array in, const int radius1, const int radius2);
 #endif
 
+#if AF_API_VERSION >= 32
+    /**
+       C Interface wrapper for Homography estimation
+
+       \param[out] H is a 3x3 array containing the estimated homography.
+       \param[out] inliers is the number of inliers that the homography was estimated to comprise,
+                   in the case that htype is AF_RANSAC, a higher inlier_thr value will increase the
+                   estimated inliers. Note that if the number of inliers is too low, it is likely
+                   that a bad homography will be returned.
+       \param[in]  x_src x coordinates of the source points.
+       \param[in]  y_src y coordinates of the source points.
+       \param[in]  x_dst x coordinates of the destination points.
+       \param[in]  y_dst y coordinates of the destination points.
+       \param[in]  inlier_thr if htype is AF_RANSAC, this parameter will five the maximum L2-distance
+                   for a point to be considered an inlier.
+       \param[in]  iterations maximum number of iterations when htype is AF_RANSAC and backend is CPU,
+                   if backend is CUDA or OpenCL, iterations is the total number of iterations, an
+                   iteration is a selection of 4 random points for which the homography is estimated
+                   and evaluated for number of inliers.
+       \param[in]  af_homography_type can be AF_RANSAC, for which a RANdom SAmple Consensus will be
+                   used to evaluate the homography quality (e.g., number of inliers), or AF_LMEDS,
+                   which will use Least Median of Squares method to evaluate homography quality.
+       \param[in]  dtype the array type for the homography output.
+       \param[out] out is difference of smoothed inputs.
+       \return     \ref AF_SUCCESS if the computation is is successful,
+                   otherwise an appropriate error code is returned.
+
+       \ingroup cv_func_homography
+     */
+    AFAPI af_err af_homography(af_array *H, int *inliers, const af_array x_src, const af_array y_src, const af_array x_dst, const af_array y_dst, const af_homography_type htype, const float inlier_thr, const unsigned iterations, const af_dtype type);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/api/c/homography.cpp b/src/api/c/homography.cpp
new file mode 100644
index 0000000..f853ade
--- /dev/null
+++ b/src/api/c/homography.cpp
@@ -0,0 +1,88 @@
+/*******************************************************
+ * Copyright (c) 2015, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/array.h>
+#include <af/defines.h>
+#include <af/vision.h>
+#include <err_common.hpp>
+#include <handle.hpp>
+#include <backend.hpp>
+#include <ArrayInfo.hpp>
+#include <homography.hpp>
+
+using af::dim4;
+using namespace detail;
+
+template<typename T>
+static inline void homography(af_array &H, int &inliers,
+                              const af_array x_src, const af_array y_src,
+                              const af_array x_dst, const af_array y_dst,
+                              const af_homography_type htype, const float inlier_thr,
+                              const unsigned iterations)
+{
+    Array<T> bestH = createEmptyArray<T>(af::dim4(3, 3));
+
+    inliers = homography<T>(bestH,
+                            getArray<float>(x_src), getArray<float>(y_src),
+                            getArray<float>(x_dst), getArray<float>(y_dst),
+                            htype, inlier_thr, iterations);
+
+    H = getHandle<T>(bestH);
+}
+
+af_err af_homography(af_array *H, int *inliers,
+                     const af_array x_src, const af_array y_src,
+                     const af_array x_dst, const af_array y_dst,
+                     const af_homography_type htype, const float inlier_thr,
+                     const unsigned iterations, const af_dtype type)
+{
+    try {
+        ArrayInfo xsinfo = getInfo(x_src);
+        ArrayInfo ysinfo = getInfo(y_src);
+        ArrayInfo xdinfo = getInfo(x_dst);
+        ArrayInfo ydinfo = getInfo(y_dst);
+
+        af::dim4 xsdims  = xsinfo.dims();
+        af::dim4 ysdims  = ysinfo.dims();
+        af::dim4 xddims  = xdinfo.dims();
+        af::dim4 yddims  = ydinfo.dims();
+
+        af_dtype xstype = xsinfo.getType();
+        af_dtype ystype = ysinfo.getType();
+        af_dtype xdtype = xdinfo.getType();
+        af_dtype ydtype = ydinfo.getType();
+
+        if (xstype != f32) { TYPE_ERROR(1, xstype); }
+        if (ystype != f32) { TYPE_ERROR(2, ystype); }
+        if (xdtype != f32) { TYPE_ERROR(3, xdtype); }
+        if (ydtype != f32) { TYPE_ERROR(4, ydtype); }
+
+        ARG_ASSERT(1, (xsdims[0] > 0));
+        ARG_ASSERT(2, (ysdims[0] == xsdims[0]));
+        ARG_ASSERT(3, (xddims[0] > 0));
+        ARG_ASSERT(4, (yddims[0] == yddims[0]));
+
+        ARG_ASSERT(5, (inlier_thr >= 0.1f));
+        ARG_ASSERT(6, (iterations > 0));
+
+        af_array outH;
+        int outInl;
+
+        switch(type) {
+            case f32: homography<float >(outH, outInl, x_src, y_src, x_dst, y_dst, htype, inlier_thr, iterations);  break;
+            case f64: homography<double>(outH, outInl, x_src, y_src, x_dst, y_dst, htype, inlier_thr, iterations);  break;
+            default:  TYPE_ERROR(1, type);
+        }
+        std::swap(*H, outH);
+        std::swap(*inliers, outInl);
+    }
+    CATCHALL;
+
+    return AF_SUCCESS;
+}
diff --git a/src/api/cpp/homography.cpp b/src/api/cpp/homography.cpp
new file mode 100644
index 0000000..ed49b1d
--- /dev/null
+++ b/src/api/cpp/homography.cpp
@@ -0,0 +1,32 @@
+/*******************************************************
+ * Copyright (c) 2015, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/vision.h>
+#include <af/array.h>
+#include "error.hpp"
+
+namespace af
+{
+
+void homography(array &H, int &inliers,
+                const array &x_src, const array &y_src,
+                const array &x_dst, const array &y_dst,
+                const af_homography_type htype, const float inlier_thr,
+                const unsigned iterations, const af::dtype type)
+{
+    af_array outH;
+    AF_THROW(af_homography(&outH, &inliers,
+                           x_src.get(), y_src.get(),
+                           x_dst.get(), y_dst.get(),
+                           htype, inlier_thr, iterations, type));
+
+    H = array(outH);
+}
+
+}
diff --git a/src/api/unified/vision.cpp b/src/api/unified/vision.cpp
index db1cfdb..8a3ab3c 100644
--- a/src/api/unified/vision.cpp
+++ b/src/api/unified/vision.cpp
@@ -66,3 +66,10 @@ af_err af_dog(af_array *out, const af_array in, const int radius1, const int rad
 {
     return CALL(out, in, radius1, radius2);
 }
+
+af_err af_homography(af_array *H, int *inliers, const af_array x_src, const af_array y_src,
+                     const af_array x_dst, const af_array y_dst, const af_homography_type htype,
+                     const float inlier_thr, const unsigned iterations, const af_dtype type)
+{
+    return CALL(H, inliers, x_src, y_src, x_dst, y_dst, htype, inlier_thr, iterations, type);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list