Skip to content

Commit 1deb388

Browse files
committed
remove wxpython sample; add comment block
1 parent c0c1407 commit 1deb388

File tree

4 files changed

+43
-249
lines changed

4 files changed

+43
-249
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ To run each individual demo, point directly to the file. For example (i.e. not c
119119
1. `python samples/language/spellcheck_samples.py`
120120
2. `python samples/search/entity_search_samples.py`
121121
3. `python samples/search/video_search_samples.py`
122-
4. `python samples/vision/inkrecognizer_tkinter_sample.py`
122+
4. `python samples/vision/inkrecognizer_sample.py`
123123
124124
To see the code of each example, simply look at the examples in the Samples folder. They are written to be isolated in scope so that you can see only what you're interested in.
125125

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ azure-cognitiveservices-vision-customvision>=0.4.0 # sample won't work with pre
1717
azure-cognitiveservices-vision-face
1818
azure-cognitiveservices-anomalydetector>=0.2.0 # sample won't work with previous versions
1919
azure-cognitiveservices-inkrecognizer>=1.0.0b1
20-
wxpython>=4.0.6
2120
pandas

samples/vision/inkrecognizer_tkinter_sample.py renamed to samples/vision/inkrecognizer_sample.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from azure.cognitiveservices.inkrecognizer import InkRecognizerClient
1313

1414

15-
# Ink Recognizer Client Config
15+
import logging
16+
logging.basicConfig(level=logging.DEBUG)
17+
18+
# <InkRecognizerClientConfig>
1619
URL = "https://api.cognitive.microsoft.com/inkrecognizer"
1720
CREDENTIAL = os.environ['INK_RECOGNIZER_SUBSCRIPTION_KEY'].strip()
1821
# You can also use Azure credential instance
@@ -30,16 +33,10 @@
3033
# Default value is ApplicationKind.MIXED.
3134
# If "kind" in a stroke is specified, this will be overlaped in that stroke.
3235
APPLICATION_KIND = ApplicationKind.MIXED
36+
# </InkRecognizerClientConfig>
3337

3438

35-
# UI Config
36-
CANVAS_WIDTH = 800
37-
CANVAS_HEIGHT = 500
38-
STROKE_COLOR = "#476042" # python green
39-
STROKE_WIDTH = 3
40-
41-
42-
# Stroke Implementations
39+
# <StrokeImplementations>
4340
# Shows simple implementation of InkPoint and InkStroke
4441
InkPoint = namedtuple("InkPoint", "x y")
4542

@@ -54,17 +51,28 @@ def __init__(self,
5451
self.points = ink_points
5552
self.kind = stroke_kind
5653
self.language = stroke_language
54+
# </StrokeImplementations>
5755

5856

59-
# Sample wrapper for InkRecognizerClient that shows how to
57+
# <KeyScenarioExample>
58+
# Wrapper for InkRecognizerClient that shows how to
6059
# (1) Convert stroke unit from pixel to mm
6160
# (2) Set language recognition locale
6261
# (3) Indexing a key word from recognition results
6362
# (4) Set application kind if user know expected type of ink content
6463
class RecognitionManager:
6564
def __init__(self, pixel_per_mm):
6665
self._pixel_per_mm = pixel_per_mm
67-
self._client = InkRecognizerClient(URL, CREDENTIAL)
66+
self._client = InkRecognizerClient(
67+
URL,
68+
CREDENTIAL,
69+
# <SetApplicationKind>
70+
application_kind=APPLICATION_KIND,
71+
# </SetApplicationKind>
72+
)
73+
# Aruments in constructor becomes default arguments for each request
74+
# You can also specify these arguments in recognize_ink() requests,
75+
# which influence that request only
6876
self.reset_ink()
6977

7078
def _reset_stroke(self):
@@ -79,11 +87,13 @@ def reset_ink(self):
7987
self._reset_stroke()
8088

8189
def add_point(self, x, y):
90+
# <UnitConversion>
8291
# Convert from pixel to mm before sending to InkPoint.
8392
# You can also specify keyword argument "unit_multiple" in
8493
# InkRecognizerClient constructor or in recognize_ink() request.
8594
self._curr_stroke_points.append(
8695
InkPoint(self._pixel_to_mm(x), self._pixel_to_mm(y)))
96+
# </UnitConversion>
8797

8898
def stroke_end(self):
8999
stroke = InkStroke(len(self._ink_stroke_list), self._curr_stroke_points)
@@ -95,10 +105,10 @@ def recognize(self):
95105
try:
96106
root = self._client.recognize_ink(
97107
self._ink_stroke_list,
98-
# Pre-set recognition type
99-
application_kind=APPLICATION_KIND,
100-
# Set language recognition locale
101-
language=LANGUAGE_RECOGNITION_LOCALE
108+
# <SetRecognitionLocale>
109+
language=LANGUAGE_RECOGNITION_LOCALE,
110+
# </SetRecognitionLocale>
111+
logging_enable=True
102112
)
103113
# Aruments in request is for this request only
104114
# You can also specify these arguments in InkRecognizerClient constructor,
@@ -115,15 +125,26 @@ def recognize(self):
115125
messagebox.showinfo("Error", e)
116126

117127
def search(self, word):
118-
# Indexing a key word from recognition results
128+
# <IndexingKeyword>
119129
if self._root is not None:
120-
words = self._root.find_word(word)
121-
messagebox.showinfo("Search Result", "Find %s words" % len(words))
130+
num_words = len(self._root.find_word(word))
122131
else:
123-
messagebox.showinfo("Search Result", "Find %s words" % 0)
132+
num_words = 0
133+
search_result = "Find %s word%s" % (num_words, "s" if num_words != 1 else "")
134+
messagebox.showinfo("Search Result", search_result)
135+
# </IndexingKeyword>
136+
# </KeyScenarioExample>
137+
138+
139+
# <SampleUIConfig>
140+
CANVAS_WIDTH = 800
141+
CANVAS_HEIGHT = 500
142+
STROKE_COLOR = "#476042" # python green
143+
STROKE_WIDTH = 3
144+
# </SampleUIConfig>
124145

125146

126-
# Sample UI
147+
# <SampleUI>
127148
class InkRecognizerDemo:
128149
def __init__(self):
129150
self._master = Tk()
@@ -190,6 +211,7 @@ def _search(self):
190211

191212
def run(self):
192213
mainloop()
214+
# </SampleUI>
193215

194216

195217
if __name__ == "__main__":

samples/vision/inkrecognizer_wxpython_sample.py

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)