forked from hunter-packages/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomography.cpp
More file actions
88 lines (74 loc) · 3.02 KB
/
homography.cpp
File metadata and controls
88 lines (74 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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 otype)
{
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(otype) {
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, otype);
}
std::swap(*H, outH);
std::swap(*inliers, outInl);
}
CATCHALL;
return AF_SUCCESS;
}