Skip to content

Commit 896c2c5

Browse files
committed
Progress
1 parent 16c12c4 commit 896c2c5

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/vws/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"""
44

55
from ._version import get_versions
6-
from .query import CloudRecoService
6+
from .query import CloudRecoIncludeTargetData, CloudRecoService
77
from .vws import VWS
88

99
__all__ = [
1010
'CloudRecoService',
11+
'CloudRecoIncludeTargetData',
1112
'VWS',
1213
]
1314

src/vws/query.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import io
6+
from enum import Enum
67
from typing import Any, Dict, List
78
from urllib.parse import urljoin
89

@@ -14,6 +15,17 @@
1415
from .exceptions import MaxNumResultsOutOfRange
1516

1617

18+
class CloudRecoIncludeTargetData(Enum):
19+
"""
20+
Options for the ``include_target_data`` parameter of
21+
``CloudRecoService.query``.
22+
"""
23+
24+
TOP = 'top'
25+
NONE = 'none'
26+
ALL = 'all'
27+
28+
1729
class CloudRecoService:
1830
"""
1931
An interface to the Vuforia Cloud Recognition Web APIs.
@@ -39,6 +51,8 @@ def query(
3951
self,
4052
image: io.BytesIO,
4153
max_num_results: int = 1,
54+
include_target_data:
55+
CloudRecoIncludeTargetData = CloudRecoIncludeTargetData.TOP,
4256
) -> List[Dict[str, Any]]:
4357
"""
4458
Use the Vuforia Web Query API to make an Image Recognition Query.
@@ -49,6 +63,16 @@ def query(
4963
5064
Args:
5165
image: The image to make a query against.
66+
max_num_results: The maximum number of matching targets to be
67+
returned.
68+
include_target_data: "Indicates if target_data records shall be
69+
returned for the matched targets. Accepted values are top
70+
(default value, only return target_data for top ranked match),
71+
none (return no target_data), all (for all matched targets)".
72+
73+
Raises:
74+
MaxNumResultsOutOfRange: ``max_num_results`` is not within the
75+
range (1, 50).
5276
5377
Returns:
5478
An ordered list of target details of matching targets.
@@ -57,6 +81,8 @@ def query(
5781
body = {
5882
'image': ('image.jpeg', image_content, 'image/jpeg'),
5983
'max_num_results': (None, int(max_num_results), 'text/plain'),
84+
'include_target_data':
85+
(None, include_target_data.value, 'text/plain'),
6086
}
6187
date = rfc_1123_date()
6288
request_path = '/v1/query'

tests/test_query.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from mock_vws import MockVWS
1010
from mock_vws.database import VuforiaDatabase
1111

12-
from vws import VWS, CloudRecoService
12+
from vws import VWS, CloudRecoIncludeTargetData, CloudRecoService
1313
from vws.exceptions import MaxNumResultsOutOfRange
1414

1515

@@ -180,6 +180,9 @@ def test_default(
180180
cloud_reco_client: CloudRecoService,
181181
high_quality_image: io.BytesIO,
182182
) -> None:
183+
"""
184+
By default, target data is only returned in the top match.
185+
"""
183186
target_id = vws_client.add_target(
184187
name=uuid.uuid4().hex,
185188
width=1,
@@ -205,6 +208,10 @@ def test_top(
205208
cloud_reco_client: CloudRecoService,
206209
high_quality_image: io.BytesIO,
207210
) -> None:
211+
"""
212+
When ``CloudRecoIncludeTargetData.TOP`` is given, target data is only
213+
returned in the top match.
214+
"""
208215
target_id = vws_client.add_target(
209216
name=uuid.uuid4().hex,
210217
width=1,
@@ -220,6 +227,7 @@ def test_top(
220227
top_match, second_match = cloud_reco_client.query(
221228
image=high_quality_image,
222229
max_num_results=2,
230+
include_target_data=CloudRecoIncludeTargetData.TOP,
223231
)
224232
assert 'target_data' in top_match
225233
assert 'target_data' not in second_match
@@ -230,6 +238,10 @@ def test_none(
230238
cloud_reco_client: CloudRecoService,
231239
high_quality_image: io.BytesIO,
232240
) -> None:
241+
"""
242+
When ``CloudRecoIncludeTargetData.NONE`` is given, target data is not
243+
returned in any match.
244+
"""
233245
target_id = vws_client.add_target(
234246
name=uuid.uuid4().hex,
235247
width=1,
@@ -245,6 +257,7 @@ def test_none(
245257
top_match, second_match = cloud_reco_client.query(
246258
image=high_quality_image,
247259
max_num_results=2,
260+
include_target_data=CloudRecoIncludeTargetData.NONE,
248261
)
249262
assert 'target_data' not in top_match
250263
assert 'target_data' not in second_match
@@ -255,6 +268,10 @@ def test_all(
255268
cloud_reco_client: CloudRecoService,
256269
high_quality_image: io.BytesIO,
257270
) -> None:
271+
"""
272+
When ``CloudRecoIncludeTargetData.ALL`` is given, target data is
273+
returned in all matches.
274+
"""
258275
target_id = vws_client.add_target(
259276
name=uuid.uuid4().hex,
260277
width=1,
@@ -270,6 +287,7 @@ def test_all(
270287
top_match, second_match = cloud_reco_client.query(
271288
image=high_quality_image,
272289
max_num_results=2,
290+
include_target_data=CloudRecoIncludeTargetData.ALL,
273291
)
274292
assert 'target_data' in top_match
275293
assert 'target_data' in second_match

0 commit comments

Comments
 (0)