Skip to content

Commit db49b6c

Browse files
author
Larry Franks
committed
writing
1 parent 364f2ff commit db49b6c

File tree

1 file changed

+78
-7
lines changed

1 file changed

+78
-7
lines changed

articles/cognitive-services/Custom-Vision-Service/rest-api-tutorial.md

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ To get the keys for your account, visit the [Custom Vision web page](https://cus
5757
5858
## Create a new project
5959
60-
The following examples create a new project named `myproject` in your Custom Vision service instance. This service defaults to the `General` domain. For more information on this request, see [CreateProject](https://southcentralus.dev.cognitive.microsoft.com/docs/services/d0e77c63c39c4259a298830c15188310/operations/5a59953940d86a0f3c7a8290).
60+
The following examples create a new project named `myproject` in your Custom Vision service instance. This service defaults to the `General` domain:
6161
6262
```bash
6363
curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects?name=myproject" -H "Training-Key: $TRAININGKEY" --data-ascii ""
@@ -67,7 +67,7 @@ curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2
6767
$resp = Invoke-WebRequest -Method 'POST' `
6868
-Uri "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects?name=myproject" `
6969
-UseBasicParsing `
70-
-Headers @{ "Training-Key"=$trainingKey }
70+
-Headers @{ "Training-Key"="$trainingKey" }
7171
$resp.Content
7272
```
7373

@@ -93,6 +93,8 @@ The response to the request is similar to the following JSON document:
9393
> [!TIP]
9494
> The `id` entry in the response is the ID of the new project. This is used in other examples later in this document.
9595
96+
For more information on this request, see [CreateProject](https://southcentralus.dev.cognitive.microsoft.com/docs/services/d0e77c63c39c4259a298830c15188310/operations/5a59953940d86a0f3c7a8290).
97+
9698
### Specific domains
9799

98100
To create a project for a specific domain, you can provide the __domain Id__ as an optional paramter. The following examples show how to retrieve a list of available domains:
@@ -105,7 +107,7 @@ curl -X GET "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.
105107
$resp = Invoke-WebRequest -Method 'GET' `
106108
-Uri "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/domains" `
107109
-UseBasicParsing `
108-
-Headers @{ "Training-Key"=$trainingKey }
110+
-Headers @{ "Training-Key"="$trainingKey" }
109111
$resp.Content
110112
```
111113

@@ -138,6 +140,8 @@ The response to the request is similar to the following JSON document:
138140
]
139141
```
140142

143+
For more information on this request, see [GetDomains](https://southcentralus.dev.cognitive.microsoft.com/docs/services/d0e77c63c39c4259a298830c15188310/operations/5a59953940d86a0f3c7a827d).
144+
141145
The following example demonstrates creating a new project that uses the __Landmarks__ domain:
142146

143147
```bash
@@ -148,15 +152,15 @@ curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2
148152
$resp = Invoke-WebRequest -Method 'POST' `
149153
-Uri "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects?name=myproject&domainId=ca455789-012d-4b50-9fec-5bb63841c793" `
150154
-UseBasicParsing `
151-
-Headers @{ "Training-Key"=$trainingKey }
155+
-Headers @{ "Training-Key"="$trainingKey" }
152156
$resp.Content
153157
```
154158

155159
## Create tags
156160

157161
When tagging images, you use a tag Id. To get a tag Id, you must create a tag or get the information for an existing tag.
158162

159-
The following example demonstrates how to create a new tag:
163+
The following example demonstrates how to create a new tag named `cat`. Replace `{projectId}` with the ID of your project. Use the `name=` parameter to specify the name of the tag:
160164

161165
```bash
162166
curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects/{projectId}/tags?name=cat" -H "Training-Key: $TRAININGKEY" --data-ascii ""
@@ -166,10 +170,77 @@ curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2
166170
$resp = Invoke-WebRequest -Method 'POST' `
167171
-Uri "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects/{projectId}/tags?name=cat" `
168172
-UseBasicParsing `
169-
-Headers @{ "Training-Key"=$trainingKey }
173+
-Headers @{ "Training-Key"="$trainingKey" }
170174
$resp.Content
171175
```
172176

177+
The response to the request is similar to the following:
178+
179+
```json
180+
{"id":"ed6f7ab6-5132-47ad-8649-3ec42ee62d43","name":"cat","description":null,"imageCount":0}
181+
```
182+
183+
Save the `id` value, as it is used when tagging images.
184+
185+
For more information on this requst, see [CreateTag](https://southcentralus.dev.cognitive.microsoft.com/docs/services/d0e77c63c39c4259a298830c15188310/operations/5a59953940d86a0f3c7a829d).
186+
173187
## Add images
174188

175-
Images can be added from files or from URLs. The following examples demonstrate
189+
The following examples demonstrate adding a file from URL. Replace `{projectId}` with the ID of your project. Replace `{tagId}` with the ID of the tag for the image:
190+
191+
```bash
192+
curl -X POST "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects/{projectId}/images/urls" -H "Training-Key: $TRAININGKEY" -H "Content-Type: application/json" --data-ascii '{"images": [{"url": "http://myimages/cat.jpg","tagIds": ["{tagId}"],"regions": [{"tagId": "{tagId}","left": 119.0,"top": 94.0,"width": 240.0,"height": 140.0}]}], "tagIds": ["{tagId}"]}'
193+
```
194+
195+
```powershell
196+
$resp = Invoke-WebRequest -Method 'POST' `
197+
-Uri "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Training/projects/{projectId}/images/urls" `
198+
-UseBasicParsing `
199+
-Headers @{ "Training-Key"="$trainingKey"; "Content-Type"="application/json" } `
200+
-Body '{"images": [{"url": "http://myimages/cat.jpg","tagIds": ["{tagId}"],"regions": [{"tagId": "{tagId}","left": 119.0,"top": 94.0,"width": 240.0,"height": 140.0}]}], "tagIds": ["{tagId}"]}'
201+
$resp.Content
202+
```
203+
204+
The response to the request is similar to the following:
205+
206+
```json
207+
{
208+
"isBatchSuccessful": true,
209+
"images": [
210+
{
211+
"sourceUrl": "http://myimages/cat.jpg",
212+
"status": "OK",
213+
"image": {
214+
"id": "081adaee-a76b-4d94-a70e-e4fd0935a28f",
215+
"created": "2018-08-13T13:24:22.0815638",
216+
"width": 640,
217+
"height": 480,
218+
"imageUri": "https://linktoimage",
219+
"thumbnailUri": "https://linktothumbnail",
220+
"tags": [
221+
{
222+
"tagId": "ed6f7ab6-5132-47ad-8649-3ec42ee62d43",
223+
"tagName": null,
224+
"created": "2018-08-13T13:24:22.104936"
225+
}
226+
],
227+
"regions": [
228+
{
229+
"regionId": "40f206a1-3f8a-4de7-a6c3-c7b4643117df",
230+
"tagName": null,
231+
"created": "2018-08-13T13:24:22.104936",
232+
"tagId": "ed6f7ab6-5132-47ad-8649-3ec42ee62d43",
233+
"left": 119,
234+
"top": 94,
235+
"width": 240,
236+
"height": 140
237+
}
238+
]
239+
}
240+
}
241+
]
242+
}
243+
```
244+
245+
For more information on this request, see [CreateImagesFromUrls](https://southcentralus.dev.cognitive.microsoft.com/docs/services/d0e77c63c39c4259a298830c15188310/operations/5a59953940d86a0f3c7a8287).
246+

0 commit comments

Comments
 (0)