$endpoint = "https://endpinturl.cognitiveservices.azure.com/"
$headers.Add("Ocp-Apim-Subscription-Key", $key)
$headers.Add("Content-Type", "application/json")
$result = Invoke - RestMethod - Method Post `
-Uri "$endpoint/vision/v3.2/analyze?visualFeatures=Categories,Description,Objects" `
-Body $body | ConvertTo-Json -Depth 5
Write-Host("`nDescription:")
Write-Host ($caption.text)
}
foreach ($object in $analysis.objects)
Write-Host (" -", $object.object)
foreach ($tag in $analysis.description.tags)
Write-Host (" -", $tag)
Exploring Form Recognition:
$key="CvVuM7D8IfIksWxIzvrUBHLZ6rbeBjFXJ3w3AAALACOGZr3Y"
$endpoint="https://sreecognitive.cognitiveservices.azure.com/"
# Create the URL where the raw receipt image can be found
$img = "https://raw.githubusercontent.com/MicrosoftLearning/AI-900-AIFundamentals/main/data/vision/receipt.jpg"
# Create the header for the REST POST with the subscription key
# In this
example, the URL of the image will be sent instead of
# the raw
image, so the Content-Type is JSON
$headers
= @{}
$headers.Add(
"Ocp-Apim-Subscription-Key", $key )
$headers.Add( "Content-Type","application/json" )
# Create the body with the URL of the raw image
$body = "{'source': '$img'}"
# Call the
receipt analyze method with the header and body
# Must call
the Invoke-WebRequest to have acces to the header
Write-Host
"Sending
receipt..."
$response
= Invoke-WebRequest -Method Post `
-Uri "$endpoint/formrecognizer/v2.1/prebuilt/receipt/analyze" `
-Headers $headers `
-Body $body
Write-Host "...Receipt sent."
# Extract the URL from the response of the receipt anaylzer
# to call
the API to getting the analysis results
$resultUrl = $($response.Headers['Operation-Location'])
# Create the header for the REST GET with only the subscription key
$resultHeaders
= @{}
$resultHeaders.Add( "Ocp-Apim-Subscription-Key", $key )
# Get the
receipt analysis results, passing in the resultURL
# Continue to request results until the analysis is "succeeded"
Write-Host
"Getting
results..."
Do {
$result = Invoke-RestMethod -Method Get `
-Uri $resultUrl `
-Headers $resultHeaders |
ConvertTo-Json -Depth 10
$analysis = ($result | ConvertFrom-Json)
} while ($analysis.status -ne "succeeded")
Write-Host "...Done`n"
# Access the relevant fields from the analysis
$analysisFields = $analysis.analyzeResult.documentResults.fields
# Print out all of the properties of the receipt analysis
Write-Host
("Receipt Type:
",
$($analysisFields.ReceiptType.valueString))
Write-Host
("Merchant
Address: ",
$($analysisFields.MerchantAddress.text))
Write-Host
("Merchant
Phone: ",
$($analysisFields.MerchantPhoneNumber.text))
Write-Host
("Transaction
Date: ",
$($analysisFields.TransactionDate.valueDate))
Write-Host
("Transaction
Time: ",
$($analysisFields.TransactionTime.text))
Write-Host ("Receipt Items: ")
# Access the individual items from the analysis
$receiptItems = $($analysisFields.Items.valueArray)
for (($idx = 0); $idx -lt
$receiptItems.Length; $idx++) {
$item = $receiptItems[$idx]
Write-Host ("Item #", ($idx+1))
Write-Host (" -
Name: ",
$($item.valueObject.Name.valueString))
Write-Host (" -
Price: ",$($item.valueObject.TotalPrice.valueNumber))
}
Write-Host
("Subtotal:
",
$($analysisFields.Subtotal.text))
Write-Host
("Tax: ", $($analysisFields.Tax.text))
Write-Host ("Total: ", $($analysisFields.Total.text))
OutPut:
Exploring Optical Character Recognition:
$endpoint="https://mysreecompvision1.cognitiveservices.azure.com/"
$headers.Add( "Ocp-Apim-Subscription-Key", $key )
$result = Invoke-Webrequest -Method Post `
-Uri "$endpoint/vision/v3.2/read/analyze?language=en" `
-Body $body
$resultHeaders.Add( "Ocp-Apim-Subscription-Key", $key )
Do {
$result = Invoke-RestMethod -Method Get `
-Uri $resultUrl `
-Headers $resultHeaders | ConvertTo-Json -Depth 10
} while ($analysis.status -ne "succeeded")
foreach($dict in $listofdict)
Write-Host ("Text:", $($dict.text), "| Text Bounding Box:", $($dict.boundingBox))
}
$key="8oOnmgDqT5BTfAxQC5V32OM5tg8aEYr00g7JHDKdN6BzYfDMVLiqJQQJ99BAACYeBjFXJ3w3AAAFACOGMoYe"
$endpoint="https://mysreecompvision1.cognitiveservices.azure.com/"
$headers.Add( "Ocp-Apim-Subscription-Key", $key )
$headers.Add( "Content-Type","application/json" )
$result = Invoke-Webrequest -Method Post `
-Uri "$endpoint/vision/v3.2/read/analyze?language=en" `
-Body $body
$resultHeaders.Add( "Ocp-Apim-Subscription-Key", $key )
$body = "{'url' : '$img'}"
Do {
$result = Invoke-RestMethod -Method Get `
-Uri $resultUrl `
-Headers $resultHeaders | ConvertTo-Json -Depth 10
} while ($analysis.status -ne "succeeded")
foreach($dict in $listofdict)
Write-Host ("Text:", $($dict.text), "| Text Bounding Box:", $($dict.boundingBox))
}
OutPut:
Exploring Face detection:
Exploring Face detection:
$endpoint = "https://sreefaceai1.cognitiveservices.azure.com/"
$headers.Add("Ocp-Apim-Subscription-Key", $key)
$headers.Add("Content-Type", "application/json")
$result = Invoke - RestMethod - Method Post `
-Uri "$endpoint/face/v1.0/detect?detectionModel=detection_01" `
-Body $body | ConvertTo-Json -Depth 5
Write-Host ("`nFrom June 21st 2022, Face service capabilities that return personally identifiable features are restricted.`nSee https://azure.microsoft.com/blog/responsible-ai-investments-and-safeguards-for-facial-recognition/ for details.`nThis code is restricted to returning the location of any faces detected:`n")
Write-Host("Face location: $($face.faceRectangle)`n")
OutPut:
No comments:
Post a Comment