Skip to content

Commit d2773fb

Browse files
committed
DOC: Adding missing documentation for vision.py
1 parent 6875bc3 commit d2773fb

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

arrayfire/vision.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,86 @@
66
# The complete license agreement can be obtained at:
77
# http://arrayfire.com/licenses/BSD-3-Clause
88
########################################################
9+
10+
"""
11+
Computer vision functions for arrayfire.
12+
"""
13+
914
from .library import *
1015
from .array import *
1116
from .features import *
1217

1318
def fast(image, threshold=20.0, arc_length=9, non_max=True, feature_ratio=0.05, edge=3):
19+
"""
20+
FAST feature detector.
21+
22+
Parameters
23+
----------
24+
25+
image : af.Array
26+
A 2D array representing an image.
27+
28+
threshold : scalar. optional. default: 20.0.
29+
FAST threshold for which a pixel of the circle around a central pixel is consdered.
30+
31+
arc_length : scalar. optional. default: 9
32+
The minimum length of arc length to be considered. Max length should be 16.
33+
34+
non_max : Boolean. optional. default: True
35+
A boolean flag specifying if non max suppression has to be performed.
36+
37+
feature_ratio : scalar. optional. default: 0.05 (5%)
38+
Specifies the maximum ratio of features to pixels in the image.
39+
40+
edge : scalar. optional. default: 3.
41+
Specifies the number of edge rows and columns to be ignored.
42+
43+
Returns
44+
---------
45+
features : af.Features()
46+
- x, y, and score are calculated
47+
- orientation is 0 because FAST does not compute orientation
48+
- size is 1 because FAST does not compute multiple scales
49+
50+
"""
1451
out = Features()
1552
safe_call(backend.get().af_fast(ct.pointer(out.feat),
1653
image.arr, ct.c_float(threshold), ct.c_uint(arc_length), non_max,
1754
ct.c_float(feature_ratio), ct.c_uint(edge)))
1855
return out
1956

2057
def orb(image, threshold=20.0, max_features=400, scale = 1.5, num_levels = 4, blur_image = False):
58+
"""
59+
ORB Feature descriptor.
60+
61+
Parameters
62+
----------
63+
64+
image : af.Array
65+
A 2D array representing an image.
66+
67+
threshold : scalar. optional. default: 20.0.
68+
FAST threshold for which a pixel of the circle around a central pixel is consdered.
69+
70+
max_features : scalar. optional. default: 400.
71+
Specifies the maximum number of features to be considered.
72+
73+
scale : scalar. optional. default: 1.5.
74+
Specifies the factor by which images are down scaled at each level.
75+
76+
num_levles : scalar. optional. default: 4.
77+
Specifies the number of levels used in the image pyramid.
78+
79+
blur_image : Boolean. optional. default: False.
80+
Flag specifying if the input has to be blurred before computing descriptors.
81+
A gaussian filter with sigma = 2 is applied if True.
82+
83+
84+
Returns
85+
---------
86+
(features, descriptor) : tuple of (af.Features(), af.Array)
87+
88+
"""
2189
feat = Features()
2290
desc = Array()
2391
safe_call(backend.get().af_orb(ct.pointer(feat.feat), ct.pointer(desc.arr),
@@ -26,6 +94,31 @@ def orb(image, threshold=20.0, max_features=400, scale = 1.5, num_levels = 4, bl
2694
return feat, desc
2795

2896
def hamming_matcher(query, database, dim = 0, num_nearest = 1):
97+
"""
98+
Hamming distance matcher.
99+
100+
Parameters
101+
-----------
102+
103+
query : af.Array
104+
A query feature descriptor
105+
106+
database : af.Array
107+
A multi dimensional array containing the feature descriptor database.
108+
109+
dim : scalar. optional. default: 0.
110+
Specifies the dimension along which feature descriptor lies.
111+
112+
num_neaarest: scalar. optional. default: 1.
113+
Specifies the number of nearest neighbors to find.
114+
115+
Returns
116+
---------
117+
118+
(location, distance): tuple of af.Array
119+
location and distances of closest matches.
120+
121+
"""
29122
index = Array()
30123
dist = Array()
31124
safe_call(backend.get().af_hamming_matcher(ct.pointer(idx.arr), ct.pointer(dist.arr),
@@ -34,6 +127,27 @@ def hamming_matcher(query, database, dim = 0, num_nearest = 1):
34127
return index, dist
35128

36129
def match_template(image, template, match_type = MATCH.SAD):
130+
"""
131+
Find the closest match of a template in an image.
132+
133+
Parameters
134+
----------
135+
136+
image : af.Array
137+
A multi dimensional array specifying an image or batch of images.
138+
139+
template : af.Array
140+
A multi dimensional array specifying a template or batch of templates.
141+
142+
match_type: optional: af.MATCH. default: af.MATCH.SAD
143+
Specifies the match function metric.
144+
145+
Returns
146+
--------
147+
out : af.Array
148+
An array containing the score of the match at each pixel.
149+
150+
"""
37151
out = Array()
38152
safe_call(backend.get().af_match_template(ct.pointer(out.arr), image.arr, template.arr, match_type))
39153
return out

0 commit comments

Comments
 (0)