0
# Image Analysis
1
2
Comprehensive image analysis capabilities that extract rich visual features from image content. The analysis pipeline supports multiple visual features in a single API call, making it efficient for applications requiring comprehensive image understanding.
3
4
## Capabilities
5
6
### Complete Image Analysis
7
8
Extract multiple visual features from images including categories, descriptions, faces, objects, brands, colors, and content classification.
9
10
```python { .api }
11
def analyze_image(url, visual_features=None, details=None, language="en", description_exclude=None, model_version="latest", custom_headers=None, raw=False, **operation_config):
12
"""
13
Extract rich visual features from image content.
14
15
Args:
16
url (str): Publicly reachable URL of an image
17
visual_features (list[VisualFeatureTypes], optional): Visual feature types to return.
18
Available values: Categories, Tags, Description, Faces, ImageType, Color, Adult, Objects, Brands
19
details (list[Details], optional): Domain-specific details to include.
20
Available values: Celebrities, Landmarks
21
language (str, optional): Output language for descriptions and tags.
22
Supported: "en", "es", "ja", "pt", "zh". Default: "en"
23
description_exclude (list[DescriptionExclude], optional): Domain models to exclude from descriptions.
24
Available values: Celebrities, Landmarks
25
model_version (str, optional): AI model version to use. Default: "latest"
26
custom_headers (dict, optional): Custom HTTP headers
27
raw (bool, optional): Return raw response. Default: False
28
29
Returns:
30
ImageAnalysis: Complete analysis results containing requested features
31
32
Raises:
33
ComputerVisionErrorResponseException: API error occurred
34
"""
35
36
def analyze_image_in_stream(image, visual_features=None, details=None, language="en", description_exclude=None, model_version="latest", custom_headers=None, raw=False, **operation_config):
37
"""
38
Analyze image from binary stream instead of URL.
39
40
Args:
41
image (Generator): Binary image data stream
42
visual_features (list[VisualFeatureTypes], optional): Same as analyze_image
43
details (list[Details], optional): Same as analyze_image
44
language (str, optional): Same as analyze_image
45
description_exclude (list[DescriptionExclude], optional): Same as analyze_image
46
model_version (str, optional): Same as analyze_image
47
48
Returns:
49
ImageAnalysis: Complete analysis results
50
"""
51
```
52
53
### Domain-Specific Analysis
54
55
Perform specialized analysis using domain-specific models for celebrity and landmark recognition.
56
57
```python { .api }
58
def analyze_image_by_domain(model, url, language="en", custom_headers=None, raw=False, **operation_config):
59
"""
60
Analyze image using domain-specific model.
61
62
Args:
63
model (str): Domain model name. Available models: "celebrities", "landmarks"
64
url (str): Publicly reachable URL of an image
65
language (str, optional): Output language. Default: "en"
66
67
Returns:
68
DomainModelResults: Domain-specific analysis results
69
"""
70
71
def analyze_image_by_domain_in_stream(model, image, language="en", custom_headers=None, raw=False, **operation_config):
72
"""
73
Domain-specific analysis from binary stream.
74
75
Args:
76
model (str): Domain model name
77
image (Generator): Binary image data stream
78
79
Returns:
80
DomainModelResults: Domain-specific analysis results
81
"""
82
```
83
84
## Usage Examples
85
86
### Basic Image Analysis
87
88
```python
89
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
90
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
91
from msrest.authentication import CognitiveServicesCredentials
92
93
# Initialize client
94
credentials = CognitiveServicesCredentials("your-api-key")
95
client = ComputerVisionClient("https://your-endpoint.cognitiveservices.azure.com/", credentials)
96
97
# Analyze image with multiple features
98
image_url = "https://example.com/photo.jpg"
99
visual_features = [
100
VisualFeatureTypes.categories,
101
VisualFeatureTypes.description,
102
VisualFeatureTypes.faces,
103
VisualFeatureTypes.objects,
104
VisualFeatureTypes.adult
105
]
106
107
analysis = client.analyze_image(image_url, visual_features=visual_features)
108
109
# Access different analysis results
110
print(f"Description: {analysis.description.captions[0].text}")
111
print(f"Confidence: {analysis.description.captions[0].confidence}")
112
113
# Categories
114
for category in analysis.categories:
115
print(f"Category: {category.name} (confidence: {category.score})")
116
117
# Detected faces
118
for face in analysis.faces:
119
print(f"Face at ({face.face_rectangle.left}, {face.face_rectangle.top})")
120
print(f"Age: {face.age}, Gender: {face.gender}")
121
122
# Objects
123
for obj in analysis.objects:
124
print(f"Object: {obj.object_property} (confidence: {obj.confidence})")
125
rect = obj.rectangle
126
print(f"Location: ({rect.x}, {rect.y}, {rect.w}, {rect.h})")
127
128
# Adult content check
129
adult = analysis.adult
130
print(f"Adult content: {adult.is_adult_content} (score: {adult.adult_score})")
131
print(f"Racy content: {adult.is_racy_content} (score: {adult.racy_score})")
132
```
133
134
### Celebrity Recognition
135
136
```python
137
# Analyze for celebrities using domain model
138
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)
139
140
if celebrity_results.result and 'celebrities' in celebrity_results.result:
141
for celebrity in celebrity_results.result['celebrities']:
142
print(f"Celebrity: {celebrity['name']}")
143
print(f"Confidence: {celebrity['confidence']}")
144
145
# Face location
146
face_rect = celebrity['faceRectangle']
147
print(f"Face location: ({face_rect['left']}, {face_rect['top']}, "
148
f"{face_rect['width']}, {face_rect['height']})")
149
```
150
151
### Binary Image Analysis
152
153
```python
154
# Analyze image from local file
155
with open("local_image.jpg", "rb") as image_stream:
156
analysis = client.analyze_image_in_stream(
157
image_stream,
158
visual_features=[VisualFeatureTypes.description, VisualFeatureTypes.tags]
159
)
160
161
print(f"Description: {analysis.description.captions[0].text}")
162
for tag in analysis.tags:
163
print(f"Tag: {tag.name} (confidence: {tag.confidence})")
164
```
165
166
## Response Data Types
167
168
### ImageAnalysis
169
170
```python { .api }
171
class ImageAnalysis:
172
"""
173
Complete image analysis results.
174
175
Attributes:
176
categories (list[Category]): Image categories with confidence scores
177
adult (AdultInfo): Adult content detection results
178
tags (list[ImageTag]): Generated tags with confidence scores
179
description (ImageDescription): Generated descriptions
180
faces (list[FaceDescription]): Detected faces with demographics
181
color (ColorInfo): Color analysis results
182
image_type (ImageType): Image type classification
183
objects (list[DetectedObject]): Detected objects with bounding boxes
184
brands (list[DetectedBrand]): Detected brands with locations
185
request_id (str): Request identifier
186
metadata (ImageMetadata): Image dimensions and format
187
model_version (str): AI model version used for analysis
188
"""
189
```
190
191
### Category
192
193
```python { .api }
194
class Category:
195
"""
196
Image category classification result.
197
198
Attributes:
199
name (str): Category name (e.g., "outdoor_", "people_group")
200
score (float): Confidence score (0.0 to 1.0)
201
detail (CategoryDetail): Additional category details
202
"""
203
```
204
205
### AdultInfo
206
207
```python { .api }
208
class AdultInfo:
209
"""
210
Adult content detection results.
211
212
Attributes:
213
is_adult_content (bool): Whether image contains adult-oriented content
214
is_racy_content (bool): Whether image contains racy/suggestive content
215
is_gory_content (bool): Whether image contains gory/violent content
216
adult_score (float): Adult content confidence score (0.0 to 1.0)
217
racy_score (float): Racy content confidence score (0.0 to 1.0)
218
gore_score (float): Gore content confidence score (0.0 to 1.0)
219
"""
220
```
221
222
### FaceDescription
223
224
```python { .api }
225
class FaceDescription:
226
"""
227
Face detection result with demographics.
228
229
Attributes:
230
age (int): Estimated age
231
gender (Gender): Gender classification (Male/Female)
232
face_rectangle (FaceRectangle): Face bounding box
233
"""
234
```
235
236
### FaceRectangle
237
238
```python { .api }
239
class FaceRectangle:
240
"""
241
Face bounding rectangle.
242
243
Attributes:
244
left (int): Left coordinate
245
top (int): Top coordinate
246
width (int): Rectangle width
247
height (int): Rectangle height
248
"""
249
```
250
251
### ColorInfo
252
253
```python { .api }
254
class ColorInfo:
255
"""
256
Image color analysis results.
257
258
Attributes:
259
dominant_color_foreground (str): Dominant foreground color
260
dominant_color_background (str): Dominant background color
261
dominant_colors (list[str]): List of dominant colors
262
accent_color (str): Accent color in hex format
263
is_bw_img (bool): Whether image is black and white
264
"""
265
```
266
267
### ImageType
268
269
```python { .api }
270
class ImageType:
271
"""
272
Image type classification.
273
274
Attributes:
275
clip_art_type (int): Clip art classification (0-3)
276
line_drawing_type (int): Line drawing classification (0-3)
277
"""
278
```
279
280
### DomainModelResults
281
282
```python { .api }
283
class DomainModelResults:
284
"""
285
Domain-specific analysis results.
286
287
Attributes:
288
result (dict): Domain model results (celebrities, landmarks)
289
request_id (str): Request identifier
290
metadata (ImageMetadata): Image metadata
291
model_version (str): Model version used
292
"""
293
```