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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
|
package face
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
import (
"context"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/Azure/go-autorest/tracing"
"github.com/gofrs/uuid"
"io"
"net/http"
)
// LargeFaceListClient is the an API for face detection, verification, and identification.
type LargeFaceListClient struct {
BaseClient
}
// NewLargeFaceListClient creates an instance of the LargeFaceListClient client.
func NewLargeFaceListClient(endpoint string) LargeFaceListClient {
return LargeFaceListClient{New(endpoint)}
}
// AddFaceFromStream add a face to a specified large face list, up to 1,000,000 faces.
// <br /> To deal with an image contains multiple faces, input face can be specified as an image with a targetFace
// rectangle. It returns a persistedFaceId representing the added face. No image will be stored. Only the extracted
// face feature will be stored on server until [LargeFaceList Face -
// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/deleteface) or [LargeFaceList -
// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/delete) is called.
// <br /> Note persistedFaceId is different from faceId generated by [Face -
// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl).
// * Higher face image quality means better recognition precision. Please consider high-quality faces: frontal, clear,
// and face size is 200x200 pixels (100 pixels between eyes) or bigger.
// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed image file size is from 1KB to 6MB.
// * "targetFace" rectangle should contain one face. Zero or multiple faces will be regarded as an error. If the
// provided "targetFace" rectangle is not returned from [Face -
// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl), there’s no guarantee to
// detect and add the face successfully.
// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or large occlusions will cause failures.
// * Adding/deleting faces to/from a same face list are processed sequentially and to/from different face lists are in
// parallel.
// * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels. Images with
// dimensions higher than 1920x1080 pixels will need a proportionally larger minimum face size.
// * Different 'detectionModel' values can be provided. To use and compare different detection models, please refer to
// [How to specify a detection
// model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
// | Model | Recommended use-case(s) |
// | ---------- | -------- |
// | 'detection_01': | The default detection model for [LargeFaceList - Add
// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/addfacefromurl). Recommend for near
// frontal face detection. For scenarios with exceptionally large angle (head-pose) faces, occluded faces or wrong
// image orientation, the faces in such cases may not be detected. |
// | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on small, side and blurry
// faces. |
//
// Quota:
// * Free-tier subscription quota: 1,000 faces per large face list.
// * S0-tier subscription quota: 1,000,000 faces per large face list.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// imageParameter - an image stream.
// userData - user-specified data about the face for any purpose. The maximum length is 1KB.
// targetFace - a face rectangle to specify the target face to be added to a person in the format of
// "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the
// image, targetFace is required to specify which face to add. No targetFace means there is only one face
// detected in the entire image.
// detectionModel - name of detection model. Detection model is used to detect faces in the submitted image. A
// detection model name can be provided when performing Face - Detect or (Large)FaceList - Add Face or
// (Large)PersonGroup - Add Face. The default value is 'detection_01', if another model is needed, please
// explicitly specify it.
func (client LargeFaceListClient) AddFaceFromStream(ctx context.Context, largeFaceListID string, imageParameter io.ReadCloser, userData string, targetFace []int32, detectionModel DetectionModel) (result PersistedFace, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.AddFaceFromStream")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}},
{TargetValue: userData,
Constraints: []validation.Constraint{{Target: "userData", Name: validation.Empty, Rule: false,
Chain: []validation.Constraint{{Target: "userData", Name: validation.MaxLength, Rule: 1024, Chain: nil}}}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "AddFaceFromStream", err.Error())
}
req, err := client.AddFaceFromStreamPreparer(ctx, largeFaceListID, imageParameter, userData, targetFace, detectionModel)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromStream", nil, "Failure preparing request")
return
}
resp, err := client.AddFaceFromStreamSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromStream", resp, "Failure sending request")
return
}
result, err = client.AddFaceFromStreamResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromStream", resp, "Failure responding to request")
return
}
return
}
// AddFaceFromStreamPreparer prepares the AddFaceFromStream request.
func (client LargeFaceListClient) AddFaceFromStreamPreparer(ctx context.Context, largeFaceListID string, imageParameter io.ReadCloser, userData string, targetFace []int32, detectionModel DetectionModel) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
queryParameters := map[string]interface{}{}
if len(userData) > 0 {
queryParameters["userData"] = autorest.Encode("query", userData)
}
if targetFace != nil && len(targetFace) > 0 {
queryParameters["targetFace"] = autorest.Encode("query", targetFace, ",")
}
if len(string(detectionModel)) > 0 {
queryParameters["detectionModel"] = autorest.Encode("query", detectionModel)
} else {
queryParameters["detectionModel"] = autorest.Encode("query", "detection_01")
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/octet-stream"),
autorest.AsPost(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces", pathParameters),
autorest.WithFile(imageParameter),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// AddFaceFromStreamSender sends the AddFaceFromStream request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) AddFaceFromStreamSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// AddFaceFromStreamResponder handles the response to the AddFaceFromStream request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) AddFaceFromStreamResponder(resp *http.Response) (result PersistedFace, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// AddFaceFromURL add a face to a specified large face list, up to 1,000,000 faces.
// <br /> To deal with an image contains multiple faces, input face can be specified as an image with a targetFace
// rectangle. It returns a persistedFaceId representing the added face. No image will be stored. Only the extracted
// face feature will be stored on server until [LargeFaceList Face -
// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/deleteface) or [LargeFaceList -
// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/delete) is called.
// <br /> Note persistedFaceId is different from faceId generated by [Face -
// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl).
// * Higher face image quality means better recognition precision. Please consider high-quality faces: frontal, clear,
// and face size is 200x200 pixels (100 pixels between eyes) or bigger.
// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed image file size is from 1KB to 6MB.
// * "targetFace" rectangle should contain one face. Zero or multiple faces will be regarded as an error. If the
// provided "targetFace" rectangle is not returned from [Face -
// Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl), there’s no guarantee to
// detect and add the face successfully.
// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or large occlusions will cause failures.
// * Adding/deleting faces to/from a same face list are processed sequentially and to/from different face lists are in
// parallel.
// * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels. Images with
// dimensions higher than 1920x1080 pixels will need a proportionally larger minimum face size.
// * Different 'detectionModel' values can be provided. To use and compare different detection models, please refer to
// [How to specify a detection
// model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
// | Model | Recommended use-case(s) |
// | ---------- | -------- |
// | 'detection_01': | The default detection model for [LargeFaceList - Add
// Face](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/addfacefromurl). Recommend for near
// frontal face detection. For scenarios with exceptionally large angle (head-pose) faces, occluded faces or wrong
// image orientation, the faces in such cases may not be detected. |
// | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on small, side and blurry
// faces. |
//
// Quota:
// * Free-tier subscription quota: 1,000 faces per large face list.
// * S0-tier subscription quota: 1,000,000 faces per large face list.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// imageURL - a JSON document with a URL pointing to the image that is to be analyzed.
// userData - user-specified data about the face for any purpose. The maximum length is 1KB.
// targetFace - a face rectangle to specify the target face to be added to a person in the format of
// "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there is more than one face in the
// image, targetFace is required to specify which face to add. No targetFace means there is only one face
// detected in the entire image.
// detectionModel - name of detection model. Detection model is used to detect faces in the submitted image. A
// detection model name can be provided when performing Face - Detect or (Large)FaceList - Add Face or
// (Large)PersonGroup - Add Face. The default value is 'detection_01', if another model is needed, please
// explicitly specify it.
func (client LargeFaceListClient) AddFaceFromURL(ctx context.Context, largeFaceListID string, imageURL ImageURL, userData string, targetFace []int32, detectionModel DetectionModel) (result PersistedFace, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.AddFaceFromURL")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}},
{TargetValue: userData,
Constraints: []validation.Constraint{{Target: "userData", Name: validation.Empty, Rule: false,
Chain: []validation.Constraint{{Target: "userData", Name: validation.MaxLength, Rule: 1024, Chain: nil}}}}},
{TargetValue: imageURL,
Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "AddFaceFromURL", err.Error())
}
req, err := client.AddFaceFromURLPreparer(ctx, largeFaceListID, imageURL, userData, targetFace, detectionModel)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromURL", nil, "Failure preparing request")
return
}
resp, err := client.AddFaceFromURLSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromURL", resp, "Failure sending request")
return
}
result, err = client.AddFaceFromURLResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "AddFaceFromURL", resp, "Failure responding to request")
return
}
return
}
// AddFaceFromURLPreparer prepares the AddFaceFromURL request.
func (client LargeFaceListClient) AddFaceFromURLPreparer(ctx context.Context, largeFaceListID string, imageURL ImageURL, userData string, targetFace []int32, detectionModel DetectionModel) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
queryParameters := map[string]interface{}{}
if len(userData) > 0 {
queryParameters["userData"] = autorest.Encode("query", userData)
}
if targetFace != nil && len(targetFace) > 0 {
queryParameters["targetFace"] = autorest.Encode("query", targetFace, ",")
}
if len(string(detectionModel)) > 0 {
queryParameters["detectionModel"] = autorest.Encode("query", detectionModel)
} else {
queryParameters["detectionModel"] = autorest.Encode("query", "detection_01")
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsPost(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces", pathParameters),
autorest.WithJSON(imageURL),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// AddFaceFromURLSender sends the AddFaceFromURL request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) AddFaceFromURLSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// AddFaceFromURLResponder handles the response to the AddFaceFromURL request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) AddFaceFromURLResponder(resp *http.Response) (result PersistedFace, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// Create create an empty large face list with user-specified largeFaceListId, name, an optional userData and
// recognitionModel.
// <br /> Large face list is a list of faces, up to 1,000,000 faces, and used by [Face - Find
// Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar).
// <br /> After creation, user should use [LargeFaceList Face -
// Add](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/addfacefromurl) to import the faces
// and [LargeFaceList - Train](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/train) to make
// it ready for [Face - Find Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar). No
// image will be stored. Only the extracted face features are stored on server until [LargeFaceList -
// Delete](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/delete) is called.
// <br /> Find Similar is used for scenario like finding celebrity-like faces, similar face filtering, or as a light
// way face identification. But if the actual use is to identify person, please use
// [PersonGroup](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup) /
// [LargePersonGroup](https://docs.microsoft.com/rest/api/cognitiveservices/face/largepersongroup) and [Face -
// Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify).
// <br/>'recognitionModel' should be specified to associate with this large face list. The default value for
// 'recognitionModel' is 'recognition_01', if the latest model needed, please explicitly specify the model you need in
// this parameter. New faces that are added to an existing large face list will use the recognition model that's
// already associated with the collection. Existing face features in a large face list can't be updated to features
// extracted by another version of recognition model.
// * 'recognition_01': The default recognition model for [LargeFaceList-
// Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/create). All those large face lists
// created before 2019 March are bonded with this recognition model.
// * 'recognition_02': Recognition model released in 2019 March.
// * 'recognition_03': Recognition model released in 2020 May. 'recognition_03' is recommended since its overall
// accuracy is improved compared with 'recognition_01' and 'recognition_02'.
//
// Large face list quota:
// * Free-tier subscription quota: 64 large face lists.
// * S0-tier subscription quota: 1,000,000 large face lists.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// body - request body for creating a large face list.
func (client LargeFaceListClient) Create(ctx context.Context, largeFaceListID string, body MetaDataContract) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.Create")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "Create", err.Error())
}
req, err := client.CreatePreparer(ctx, largeFaceListID, body)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Create", nil, "Failure preparing request")
return
}
resp, err := client.CreateSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Create", resp, "Failure sending request")
return
}
result, err = client.CreateResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Create", resp, "Failure responding to request")
return
}
return
}
// CreatePreparer prepares the Create request.
func (client LargeFaceListClient) CreatePreparer(ctx context.Context, largeFaceListID string, body MetaDataContract) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsPut(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}", pathParameters),
autorest.WithJSON(body))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// CreateSender sends the Create request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) CreateSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// CreateResponder handles the response to the Create request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) CreateResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
result.Response = resp
return
}
// Delete delete a specified large face list.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
func (client LargeFaceListClient) Delete(ctx context.Context, largeFaceListID string) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.Delete")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "Delete", err.Error())
}
req, err := client.DeletePreparer(ctx, largeFaceListID)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Delete", nil, "Failure preparing request")
return
}
resp, err := client.DeleteSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Delete", resp, "Failure sending request")
return
}
result, err = client.DeleteResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Delete", resp, "Failure responding to request")
return
}
return
}
// DeletePreparer prepares the Delete request.
func (client LargeFaceListClient) DeletePreparer(ctx context.Context, largeFaceListID string) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
preparer := autorest.CreatePreparer(
autorest.AsDelete(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}", pathParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// DeleteSender sends the Delete request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) DeleteSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// DeleteResponder handles the response to the Delete request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
result.Response = resp
return
}
// DeleteFace delete a face from a large face list by specified largeFaceListId and persistedFaceId.
// <br /> Adding/deleting faces to/from a same large face list are processed sequentially and to/from different large
// face lists are in parallel.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// persistedFaceID - id referencing a particular persistedFaceId of an existing face.
func (client LargeFaceListClient) DeleteFace(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.DeleteFace")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "DeleteFace", err.Error())
}
req, err := client.DeleteFacePreparer(ctx, largeFaceListID, persistedFaceID)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "DeleteFace", nil, "Failure preparing request")
return
}
resp, err := client.DeleteFaceSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "DeleteFace", resp, "Failure sending request")
return
}
result, err = client.DeleteFaceResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "DeleteFace", resp, "Failure responding to request")
return
}
return
}
// DeleteFacePreparer prepares the DeleteFace request.
func (client LargeFaceListClient) DeleteFacePreparer(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
"persistedFaceId": autorest.Encode("path", persistedFaceID),
}
preparer := autorest.CreatePreparer(
autorest.AsDelete(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces/{persistedFaceId}", pathParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// DeleteFaceSender sends the DeleteFace request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) DeleteFaceSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// DeleteFaceResponder handles the response to the DeleteFace request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) DeleteFaceResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
result.Response = resp
return
}
// Get retrieve a large face list’s largeFaceListId, name, userData and recognitionModel.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in
// response.
func (client LargeFaceListClient) Get(ctx context.Context, largeFaceListID string, returnRecognitionModel *bool) (result LargeFaceList, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.Get")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "Get", err.Error())
}
req, err := client.GetPreparer(ctx, largeFaceListID, returnRecognitionModel)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Get", nil, "Failure preparing request")
return
}
resp, err := client.GetSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Get", resp, "Failure sending request")
return
}
result, err = client.GetResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Get", resp, "Failure responding to request")
return
}
return
}
// GetPreparer prepares the Get request.
func (client LargeFaceListClient) GetPreparer(ctx context.Context, largeFaceListID string, returnRecognitionModel *bool) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
queryParameters := map[string]interface{}{}
if returnRecognitionModel != nil {
queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel)
} else {
queryParameters["returnRecognitionModel"] = autorest.Encode("query", false)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetSender sends the Get request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) GetSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetResponder handles the response to the Get request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) GetResponder(resp *http.Response) (result LargeFaceList, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// GetFace retrieve information about a persisted face (specified by persistedFaceId and its belonging
// largeFaceListId).
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// persistedFaceID - id referencing a particular persistedFaceId of an existing face.
func (client LargeFaceListClient) GetFace(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID) (result PersistedFace, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.GetFace")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "GetFace", err.Error())
}
req, err := client.GetFacePreparer(ctx, largeFaceListID, persistedFaceID)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetFace", nil, "Failure preparing request")
return
}
resp, err := client.GetFaceSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetFace", resp, "Failure sending request")
return
}
result, err = client.GetFaceResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetFace", resp, "Failure responding to request")
return
}
return
}
// GetFacePreparer prepares the GetFace request.
func (client LargeFaceListClient) GetFacePreparer(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
"persistedFaceId": autorest.Encode("path", persistedFaceID),
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces/{persistedFaceId}", pathParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetFaceSender sends the GetFace request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) GetFaceSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetFaceResponder handles the response to the GetFace request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) GetFaceResponder(resp *http.Response) (result PersistedFace, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// GetTrainingStatus retrieve the training status of a large face list (completed or ongoing).
// Parameters:
// largeFaceListID - id referencing a particular large face list.
func (client LargeFaceListClient) GetTrainingStatus(ctx context.Context, largeFaceListID string) (result TrainingStatus, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.GetTrainingStatus")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "GetTrainingStatus", err.Error())
}
req, err := client.GetTrainingStatusPreparer(ctx, largeFaceListID)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetTrainingStatus", nil, "Failure preparing request")
return
}
resp, err := client.GetTrainingStatusSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetTrainingStatus", resp, "Failure sending request")
return
}
result, err = client.GetTrainingStatusResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "GetTrainingStatus", resp, "Failure responding to request")
return
}
return
}
// GetTrainingStatusPreparer prepares the GetTrainingStatus request.
func (client LargeFaceListClient) GetTrainingStatusPreparer(ctx context.Context, largeFaceListID string) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/training", pathParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// GetTrainingStatusSender sends the GetTrainingStatus request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) GetTrainingStatusSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// GetTrainingStatusResponder handles the response to the GetTrainingStatus request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) GetTrainingStatusResponder(resp *http.Response) (result TrainingStatus, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// List list large face lists’ information of largeFaceListId, name, userData and recognitionModel. <br />
// To get face information inside largeFaceList use [LargeFaceList Face -
// Get](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/getface)<br />
// * Large face lists are stored in alphabetical order of largeFaceListId.
// * "start" parameter (string, optional) is a user-provided largeFaceListId value that returned entries have larger
// ids by string comparison. "start" set to empty to indicate return from the first item.
// * "top" parameter (int, optional) specifies the number of entries to return. A maximal of 1000 entries can be
// returned in one call. To fetch more, you can specify "start" with the last returned entry’s Id of the current call.
// <br />
// For example, total 5 large person lists: "list1", ..., "list5".
// <br /> "start=&top=" will return all 5 lists.
// <br /> "start=&top=2" will return "list1", "list2".
// <br /> "start=list2&top=3" will return "list3", "list4", "list5".
// Parameters:
// returnRecognitionModel - a value indicating whether the operation should return 'recognitionModel' in
// response.
func (client LargeFaceListClient) List(ctx context.Context, returnRecognitionModel *bool) (result ListLargeFaceList, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.List")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
req, err := client.ListPreparer(ctx, returnRecognitionModel)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "List", nil, "Failure preparing request")
return
}
resp, err := client.ListSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "List", resp, "Failure sending request")
return
}
result, err = client.ListResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "List", resp, "Failure responding to request")
return
}
return
}
// ListPreparer prepares the List request.
func (client LargeFaceListClient) ListPreparer(ctx context.Context, returnRecognitionModel *bool) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
queryParameters := map[string]interface{}{}
if returnRecognitionModel != nil {
queryParameters["returnRecognitionModel"] = autorest.Encode("query", *returnRecognitionModel)
} else {
queryParameters["returnRecognitionModel"] = autorest.Encode("query", false)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPath("/largefacelists"),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// ListSender sends the List request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) ListSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// ListResponder handles the response to the List request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) ListResponder(resp *http.Response) (result ListLargeFaceList, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result.Value),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// ListFaces list all faces in a large face list, and retrieve face information (including userData and
// persistedFaceIds of registered faces of the face).
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// start - starting face id to return (used to list a range of faces).
// top - number of faces to return starting with the face id indicated by the 'start' parameter.
func (client LargeFaceListClient) ListFaces(ctx context.Context, largeFaceListID string, start string, top *int32) (result ListPersistedFace, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.ListFaces")
defer func() {
sc := -1
if result.Response.Response != nil {
sc = result.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}},
{TargetValue: top,
Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
}}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "ListFaces", err.Error())
}
req, err := client.ListFacesPreparer(ctx, largeFaceListID, start, top)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "ListFaces", nil, "Failure preparing request")
return
}
resp, err := client.ListFacesSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "ListFaces", resp, "Failure sending request")
return
}
result, err = client.ListFacesResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "ListFaces", resp, "Failure responding to request")
return
}
return
}
// ListFacesPreparer prepares the ListFaces request.
func (client LargeFaceListClient) ListFacesPreparer(ctx context.Context, largeFaceListID string, start string, top *int32) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
queryParameters := map[string]interface{}{}
if len(start) > 0 {
queryParameters["start"] = autorest.Encode("query", start)
}
if top != nil {
queryParameters["top"] = autorest.Encode("query", *top)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces", pathParameters),
autorest.WithQueryParameters(queryParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// ListFacesSender sends the ListFaces request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) ListFacesSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// ListFacesResponder handles the response to the ListFaces request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) ListFacesResponder(resp *http.Response) (result ListPersistedFace, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result.Value),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// Train queue a large face list training task, the training task may not be started immediately.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
func (client LargeFaceListClient) Train(ctx context.Context, largeFaceListID string) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.Train")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "Train", err.Error())
}
req, err := client.TrainPreparer(ctx, largeFaceListID)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Train", nil, "Failure preparing request")
return
}
resp, err := client.TrainSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Train", resp, "Failure sending request")
return
}
result, err = client.TrainResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Train", resp, "Failure responding to request")
return
}
return
}
// TrainPreparer prepares the Train request.
func (client LargeFaceListClient) TrainPreparer(ctx context.Context, largeFaceListID string) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
preparer := autorest.CreatePreparer(
autorest.AsPost(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/train", pathParameters))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// TrainSender sends the Train request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) TrainSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// TrainResponder handles the response to the Train request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) TrainResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
autorest.ByClosing())
result.Response = resp
return
}
// Update update information of a large face list.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// body - request body for updating a large face list.
func (client LargeFaceListClient) Update(ctx context.Context, largeFaceListID string, body NameAndUserDataContract) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.Update")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "Update", err.Error())
}
req, err := client.UpdatePreparer(ctx, largeFaceListID, body)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Update", nil, "Failure preparing request")
return
}
resp, err := client.UpdateSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Update", resp, "Failure sending request")
return
}
result, err = client.UpdateResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "Update", resp, "Failure responding to request")
return
}
return
}
// UpdatePreparer prepares the Update request.
func (client LargeFaceListClient) UpdatePreparer(ctx context.Context, largeFaceListID string, body NameAndUserDataContract) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsPatch(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}", pathParameters),
autorest.WithJSON(body))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// UpdateSender sends the Update request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) UpdateSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// UpdateResponder handles the response to the Update request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
result.Response = resp
return
}
// UpdateFace update a persisted face's userData field.
// Parameters:
// largeFaceListID - id referencing a particular large face list.
// persistedFaceID - id referencing a particular persistedFaceId of an existing face.
// body - request body for updating persisted face.
func (client LargeFaceListClient) UpdateFace(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID, body UpdateFaceRequest) (result autorest.Response, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/LargeFaceListClient.UpdateFace")
defer func() {
sc := -1
if result.Response != nil {
sc = result.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: largeFaceListID,
Constraints: []validation.Constraint{{Target: "largeFaceListID", Name: validation.MaxLength, Rule: 64, Chain: nil},
{Target: "largeFaceListID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}}}}); err != nil {
return result, validation.NewError("face.LargeFaceListClient", "UpdateFace", err.Error())
}
req, err := client.UpdateFacePreparer(ctx, largeFaceListID, persistedFaceID, body)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "UpdateFace", nil, "Failure preparing request")
return
}
resp, err := client.UpdateFaceSender(req)
if err != nil {
result.Response = resp
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "UpdateFace", resp, "Failure sending request")
return
}
result, err = client.UpdateFaceResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "face.LargeFaceListClient", "UpdateFace", resp, "Failure responding to request")
return
}
return
}
// UpdateFacePreparer prepares the UpdateFace request.
func (client LargeFaceListClient) UpdateFacePreparer(ctx context.Context, largeFaceListID string, persistedFaceID uuid.UUID, body UpdateFaceRequest) (*http.Request, error) {
urlParameters := map[string]interface{}{
"Endpoint": client.Endpoint,
}
pathParameters := map[string]interface{}{
"largeFaceListId": autorest.Encode("path", largeFaceListID),
"persistedFaceId": autorest.Encode("path", persistedFaceID),
}
preparer := autorest.CreatePreparer(
autorest.AsContentType("application/json; charset=utf-8"),
autorest.AsPatch(),
autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
autorest.WithPathParameters("/largefacelists/{largeFaceListId}/persistedfaces/{persistedFaceId}", pathParameters),
autorest.WithJSON(body))
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// UpdateFaceSender sends the UpdateFace request. The method will close the
// http.Response Body if it receives an error.
func (client LargeFaceListClient) UpdateFaceSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// UpdateFaceResponder handles the response to the UpdateFace request. The method always
// closes the http.Response Body.
func (client LargeFaceListClient) UpdateFaceResponder(resp *http.Response) (result autorest.Response, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
result.Response = resp
return
}
|