print("Dominant background color: {}".format(
    remote_image_analysis.color.dominant_color_background))
print("Dominant foreground color: {}".format(
    remote_image_analysis.color.dominant_color_foreground))
print("Dominant colors: {}".format(
    remote_image_analysis.color.dominant_colors))
#   END - Detect the color scheme in a remote image

#   Detect domain-specific content (celebrities/landmarks) in a local image by:
#   1. Opening the binary file for reading.
#   2. Calling the Computer Vision service's analyze_image_by_domain_in_stream with the:
#      - domain-specific content to search for
#      - image
#   3. Displaying any domain-specific content (celebrities/landmarks).
local_image = open(local_image_path, "rb")
local_image_celebs = computervision_client.analyze_image_by_domain_in_stream(
    "celebrities", local_image)

print("\nCelebrities in the local image:")
if len(local_image_celebs.result["celebrities"]) == 0:
    print("No celebrities detected.")
else:
    for celeb in local_image_celebs.result["celebrities"]:
        print(celeb["name"])

local_image = open(local_image_path, "rb")
local_image_landmarks = computervision_client.analyze_image_by_domain_in_stream(
    "landmarks", local_image)

print("\nLandmarks in the local image:")
if len(local_image_landmarks.result["landmarks"]) == 0:
    print("No landmarks detected.")
Exemple #2
0
for x in models.models_property:
    print(x)

#-----------------DOMAIN ANALYSIS BY PROVIDED NAME-------------#
print("#-----------------DOMAIN ANALYSIS BY PROVIDED NAME-------------#")
# type of prediction
image = open(path, 'rb')
domain = "landmarks"

# Public domain image of Eiffel tower
# url = "https://images.pexels.com/photos/338515/pexels-photo-338515.jpeg"

# English language response
language = "en"

analysis = client.analyze_image_by_domain_in_stream(domain, image, language)

for landmark in analysis.result["landmarks"]:
    print(landmark["name"])
    print(landmark["confidence"])

#-----------------TEXT DESCRIPTION OF IMAGE-------------#
print("#-----------------TEXT DESCRIPTION OF IMAGE-------------#")
image = open(path, 'rb')
domain = "landmarks"
# url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"
language = "en"
max_descriptions = 3

analysis = client.describe_image_in_stream(image, max_descriptions, language)
Exemple #3
0
print("Dominant colors: {}".format(detect_color_results_remote.color.dominant_colors))
# </snippet_color>
print()
'''
END - Detect Color - remote
'''

'''
Detect Domain-specific Content - local
This example detects celebrites and landmarks in local images.
'''
print("===== Detect Domain-specific Content - local =====")
# Open local image file containing a celebtriy
local_image = open(local_image_path, "rb")
# Call API with the type of content (celebrities) and local image
detect_domain_results_celebs_local = computervision_client.analyze_image_by_domain_in_stream("celebrities", local_image)

# Print which celebrities (if any) were detected
print("Celebrities in the local image:")
if len(detect_domain_results_celebs_local.result["celebrities"]) == 0:
    print("No celebrities detected.")
else:
    for celeb in detect_domain_results_celebs_local.result["celebrities"]:
        print(celeb["name"])

# Open local image file containing a landmark
local_image_path_landmark = "resources\\landmark.jpg"
local_image_landmark = open(local_image_path_landmark, "rb")
# Call API with type of content (landmark) and local image
detect_domain_results_landmark_local = computervision_client.analyze_image_by_domain_in_stream("landmarks", local_image_landmark)
print()
Exemple #4
0
SERVICE = "Computer Vision"
KEY_FILE = os.path.join(os.getcwd(), "private.txt")

# Request subscription key and endpoint from user.

subscription_key, endpoint = azkey(KEY_FILE, SERVICE, verbose=False)

# Set credentials.

credentials = CognitiveServicesCredentials(subscription_key)

# Create client.

client = ComputerVisionClient(endpoint, credentials)

# Send image to azure to analyse.

url = args.path

domain = "celebrities"

if is_url(url):
    analysis = client.analyze_image_by_domain(domain, url)
else:
    path = os.path.join(get_cmd_cwd(), url)
    with open(path, 'rb') as fstream:
        analysis = client.analyze_image_by_domain_in_stream(domain, fstream)

for celeb in analysis.result["celebrities"]:
    print(f'{celeb["confidence"]:.2f},{celeb["name"]}')