-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathmatch_template.cpp
More file actions
101 lines (90 loc) · 3.2 KB
/
match_template.cpp
File metadata and controls
101 lines (90 loc) · 3.2 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
/*******************************************************
* 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 <types.hpp>
#include <af/defines.h>
#include <af/vision.h>
#include <type_traits>
using af::dim4;
using detail::intl;
using detail::schar;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;
using std::conditional;
using std::is_same;
template<typename InType>
static af_array match_template(const af_array& sImg, const af_array tImg,
af_match_type mType) {
using OutType = typename conditional<is_same<InType, double>::value, double,
float>::type;
return getHandle(match_template<InType, OutType>(
getArray<InType>(sImg), getArray<InType>(tImg), mType));
}
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>(search_img, template_img, m_type);
break;
case f32:
output =
match_template<float>(search_img, template_img, m_type);
break;
case s32:
output = match_template<int>(search_img, template_img, m_type);
break;
case u32:
output = match_template<uint>(search_img, template_img, m_type);
break;
case s16:
output =
match_template<short>(search_img, template_img, m_type);
break;
case u16:
output =
match_template<ushort>(search_img, template_img, m_type);
break;
case b8:
output = match_template<char>(search_img, template_img, m_type);
break;
case s8:
output =
match_template<schar>(search_img, template_img, m_type);
break;
case u8:
output =
match_template<uchar>(search_img, template_img, m_type);
break;
default: TYPE_ERROR(1, sType);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}