<jupyter_start><jupyter_text>Calling the APIDone:- tag_image_in_stream- describe_image_in_stream- detect_objects_in_stream- get_area_of_interest_in_stream- analyze_image_in_streamhttps://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.operations.computervisionclientoperationsmixin?view=azure-pythonanalyze-image-in-stream-image--visual-features-none--details-none--language--en---description-exclude-none--custom-headers-none--raw-false--callback-none----operation-config-https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/category-taxonomyhttps://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/concept-object-detectionhttps://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.operations.computervisionclientoperationsmixin?view=azure-pythonanalyze-image-by-domain-in-stream-model--image--language--en---custom-headers-none--raw-false--callback-none----operation-config-https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/features<jupyter_code>from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time
subscription_key = "<Removed>"
endpoint = "https://azurehackforaccessibility.cognitiveservices.azure.com/"
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
local_image_path = "/Users/kunal/Documents/AzureCompetition/Testing_img_NEW290_.jpg"
print("===== Tag an Image - local =====")
# Open local image file
local_image = open(local_image_path, "rb")
# Call API local image
tags_result_local = computervision_client.tag_image_in_stream(local_image)
print("== OutPut ==")
for tag in tags_result_local.tags:
    print("\t'{}' with confidence {:.2f}% and with hints of {}".format(tag.name, tag.confidence * 100, tag.hint))
print("== MetaData ==")
print("\tWidth: "+str(tags_result_local.metadata.width))
print("\tHeight: "+str(tags_result_local.metadata.height))
print("\tFormat: "+tags_result_local.metadata.format)
print("\tRequest ID: "+tags_result_local.request_id)
print("===== Describe an Image - local =====")
# Open local image file
local_image = open(local_image_path, "rb")
# Call API
description_result = computervision_client.describe_image_in_stream(local_image)

# Get the captions (descriptions) from the response, with confidence level
print("== Description ==")
if (len(description_result.captions) == 0):
    print("No description detected.")
else:
    for caption in description_result.captions:
        print("\t'{}' with confidence {:.2f}%".format(caption.text, caption.confidence * 100))
print("== TAGS ==")
for i in description_result.tags:
    print("\tTags: {}".format(i))
print("REQUEST ID: {}".format(description_result.request_id))
curl -H "Ocp-Apim-Subscription-Key: <KEY>" -H "Content-Type: application/json" "https://azurehackforaccessibility.cognitiveservices.azure.com/vision/v3.1/analyze?visualFeatures=Categories,Description&details=Landmarks" -d "{\"url\":\"https://raw.githubusercontent.com/Kunal2341/testDeleteBS/main/Testing_img_NEW290_.jpg\"}"
"https://azurehackforaccessibility.cognitiveservices.azure.com/"
for i in description_result.tags:
    print(i)
'''
Detect Objects - local
This example detects different kinds of objects with bounding boxes in a local image.
'''
print("===== Detect Objects - local =====")
# Get local image with different objects in it
local_image_path_objects = local_image_path
local_image_objects = open(local_image_path_objects, "rb")
# Call API with local image
detect_objects_results_local = computervision_client.detect_objects_in_stream(local_image_objects)

# Print results of detection with bounding boxes
print("Detecting objects in local image:")
if len(detect_objects_results_local.objects) == 0:
    print("No objects detected.")
else:
    for object in detect_objects_results_local.objects:
        print("object at location {}, {}, {}, {}".format( \
        object.rectangle.x, object.rectangle.x + object.rectangle.w, \
        object.rectangle.y, object.rectangle.y + object.rectangle.h))
print("REQUEST ID: {}".format(detect_objects_results_local.request_id))
print("===== Area of Intreast for Image =====")
# Open local image file
local_image = open(local_image_path, "rb")
area_interest = computervision_client.get_area_of_interest_in_stream(local_image)

print("Area (X,Y,W,H): {},{},{},{}".format(area_interest.area_of_interest.x, area_interest.area_of_interest.y, 
                                           area_interest.area_of_interest.w, area_interest.area_of_interest.h))
print("REQUEST ID: {}".format(area_interest.request_id))
print("===== Analysis Image =====")
# Open local image file
local_image = open(local_image_path, "rb")
# Call API
categorize_results_local = computervision_client.analyze_image_in_stream(local_image)
# Print category results with confidence score
print("Categories from local image: ")
for i in categorize_results_local.categories:
    print("\tCatogory: {} == Score: {}".format(i.name, i.score))
    if i.detail != None:
        for j in i.detail:
            print(j)
            for r in j.celebrities:
                print("\t\tCelebrity: {} == Score: {}".format(r.name, r.confidence))
                print("Face rectangle")
            for r in j.landmarks:
                print("\t\tLandMark: {} == Score: {}".format(r.name, r.confidence))
                print("Face rectangle")
print("REQUEST ID: {}".format(categorize_results_local.request_id))<jupyter_output>===== Analysis Image =====
Categories from local image: 
	Catogory: outdoor_road == Score: 0.5703125
REQUEST ID: 68f404fc-c496-4211-bf30-bb494e87de11
{'fraction_non_alphanumeric': 0.13415841584158417, 'fraction_numerical': 0.008415841584158416, 'mean_word_length': 5.468516542155816, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '384704', 'license': 'MIT', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1829, 'n_words': 342, 'path': 'JupyterNotebookFiles/AZUREAPI.ipynb', 'repo_name': 'Kunal2341/AzureCompetition', 'size': '6087'}