forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_template.cpp
More file actions
118 lines (108 loc) · 4.58 KB
/
match_template.cpp
File metadata and controls
118 lines (108 loc) · 4.58 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************
* Copyright (c) 2014, 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 <backend.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <match_template.hpp>
#include <af/defines.h>
#include <af/vision.h>
using af::dim4;
using namespace detail;
template<typename inType, typename outType>
static af_array match_template(const af_array& sImg, const af_array tImg,
af_match_type mType) {
switch (mType) {
case AF_SAD:
return getHandle(match_template<inType, outType, AF_SAD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_ZSAD:
return getHandle(match_template<inType, outType, AF_ZSAD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_LSAD:
return getHandle(match_template<inType, outType, AF_LSAD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_SSD:
return getHandle(match_template<inType, outType, AF_SSD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_ZSSD:
return getHandle(match_template<inType, outType, AF_ZSSD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_LSSD:
return getHandle(match_template<inType, outType, AF_LSSD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_NCC:
return getHandle(match_template<inType, outType, AF_NCC>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_ZNCC:
return getHandle(match_template<inType, outType, AF_ZNCC>(
getArray<inType>(sImg), getArray<inType>(tImg)));
case AF_SHD:
return getHandle(match_template<inType, outType, AF_SHD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
default:
return getHandle(match_template<inType, outType, AF_SAD>(
getArray<inType>(sImg), getArray<inType>(tImg)));
}
}
af_err af_match_template(af_array* out, const af_array search_img,
const af_array template_img,
const af_match_type m_type) {
try {
ARG_ASSERT(3, (m_type >= AF_SAD && m_type <= AF_LSSD));
const ArrayInfo& sInfo = getInfo(search_img);
const ArrayInfo& tInfo = getInfo(template_img);
dim4 const sDims = sInfo.dims();
dim4 const tDims = tInfo.dims();
dim_t sNumDims = sDims.ndims();
dim_t tNumDims = tDims.ndims();
ARG_ASSERT(1, (sNumDims >= 2));
ARG_ASSERT(2, (tNumDims == 2));
af_dtype sType = sInfo.getType();
ARG_ASSERT(1, (sType == tInfo.getType()));
af_array output = 0;
switch (sType) {
case f64:
output = match_template<double, double>(search_img,
template_img, m_type);
break;
case f32:
output = match_template<float, float>(search_img, template_img,
m_type);
break;
case s32:
output = match_template<int, float>(search_img, template_img,
m_type);
break;
case u32:
output = match_template<uint, float>(search_img, template_img,
m_type);
break;
case s16:
output = match_template<short, float>(search_img, template_img,
m_type);
break;
case u16:
output = match_template<ushort, float>(search_img, template_img,
m_type);
break;
case b8:
output = match_template<char, float>(search_img, template_img,
m_type);
break;
case u8:
output = match_template<uchar, float>(search_img, template_img,
m_type);
break;
default: TYPE_ERROR(1, sType);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}