0
# Domain-Specific Analysis
1
2
Specialized image analysis using domain-specific models for celebrity and landmark recognition. These models provide detailed information about famous people and notable landmarks when detected in images.
3
4
## Capabilities
5
6
### Celebrity Recognition
7
8
Identify famous people in images with confidence scores and face location information.
9
10
```python { .api }
11
def analyze_image_by_domain(model, url, language="en", custom_headers=None, raw=False, **operation_config):
12
"""
13
Analyze image using domain-specific model.
14
15
Args:
16
model (str): Domain model name. Available models:
17
- "celebrities": Detect and identify famous people
18
- "landmarks": Identify notable landmarks and locations
19
url (str): Publicly reachable URL of an image
20
language (str, optional): Output language for results. Default: "en"
21
custom_headers (dict, optional): Custom HTTP headers
22
raw (bool, optional): Return raw response. Default: False
23
24
Returns:
25
DomainModelResults: Domain-specific analysis results
26
27
Raises:
28
ComputerVisionErrorResponseException: API error occurred
29
"""
30
31
def analyze_image_by_domain_in_stream(model, image, language="en", custom_headers=None, raw=False, **operation_config):
32
"""
33
Domain-specific analysis from binary image stream.
34
35
Args:
36
model (str): Domain model name ("celebrities" or "landmarks")
37
image (Generator): Binary image data stream
38
language (str, optional): Output language
39
40
Returns:
41
DomainModelResults: Domain-specific analysis results
42
"""
43
44
def list_models(custom_headers=None, raw=False, **operation_config):
45
"""
46
List available domain models.
47
48
Returns:
49
ListModelsResult: Available domain models with descriptions
50
51
Note:
52
This endpoint returns information about all available domain-specific models
53
including their names and capabilities.
54
"""
55
```
56
57
## Usage Examples
58
59
### Celebrity Recognition
60
61
```python
62
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
63
from msrest.authentication import CognitiveServicesCredentials
64
65
# Initialize client
66
credentials = CognitiveServicesCredentials("your-api-key")
67
client = ComputerVisionClient("https://your-endpoint.cognitiveservices.azure.com/", credentials)
68
69
# Analyze image for celebrities
70
image_url = "https://example.com/red-carpet-photo.jpg"
71
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)
72
73
# Check if celebrities were detected
74
if celebrity_results.result and 'celebrities' in celebrity_results.result:
75
celebrities = celebrity_results.result['celebrities']
76
77
print(f"Detected {len(celebrities)} celebrities:")
78
for celebrity in celebrities:
79
print(f"\nCelebrity: {celebrity['name']}")
80
print(f"Confidence: {celebrity['confidence']:.3f}")
81
82
# Face location information
83
if 'faceRectangle' in celebrity:
84
face_rect = celebrity['faceRectangle']
85
print(f"Face location: ({face_rect['left']}, {face_rect['top']}) "
86
f"size: {face_rect['width']}x{face_rect['height']}")
87
else:
88
print("No celebrities detected in the image")
89
```
90
91
### Landmark Recognition
92
93
```python
94
# Analyze image for landmarks
95
image_url = "https://example.com/tourist-photo.jpg"
96
landmark_results = client.analyze_image_by_domain("landmarks", image_url)
97
98
# Check if landmarks were detected
99
if landmark_results.result and 'landmarks' in landmark_results.result:
100
landmarks = landmark_results.result['landmarks']
101
102
print(f"Detected {len(landmarks)} landmarks:")
103
for landmark in landmarks:
104
print(f"\nLandmark: {landmark['name']}")
105
print(f"Confidence: {landmark['confidence']:.3f}")
106
107
# Additional landmark information
108
if 'description' in landmark:
109
print(f"Description: {landmark['description']}")
110
111
if 'location' in landmark:
112
location = landmark['location']
113
print(f"Location: {location.get('name', 'Unknown')}")
114
115
else:
116
print("No landmarks detected in the image")
117
```
118
119
### Available Models Query
120
121
```python
122
# List all available domain models
123
models_result = client.list_models()
124
125
print("Available domain models:")
126
for model in models_result.models_property:
127
print(f"\nModel: {model.name}")
128
if hasattr(model, 'categories') and model.categories:
129
print(f"Categories: {', '.join(model.categories)}")
130
if hasattr(model, 'description') and model.description:
131
print(f"Description: {model.description}")
132
```
133
134
### Combined Celebrity and Landmark Analysis
135
136
```python
137
# Analyze the same image with both models
138
image_url = "https://example.com/event-photo.jpg"
139
140
print("Analyzing image with multiple domain models...")
141
142
# Celebrity analysis
143
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)
144
celebrities_found = 0
145
if celebrity_results.result and 'celebrities' in celebrity_results.result:
146
celebrities_found = len(celebrity_results.result['celebrities'])
147
148
# Landmark analysis
149
landmark_results = client.analyze_image_by_domain("landmarks", image_url)
150
landmarks_found = 0
151
if landmark_results.result and 'landmarks' in landmark_results.result:
152
landmarks_found = len(landmark_results.result['landmarks'])
153
154
print(f"\nAnalysis Summary:")
155
print(f"Celebrities detected: {celebrities_found}")
156
print(f"Landmarks detected: {landmarks_found}")
157
158
# Detailed results
159
if celebrities_found > 0:
160
print(f"\nCelebrities:")
161
for celebrity in celebrity_results.result['celebrities']:
162
print(f" - {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")
163
164
if landmarks_found > 0:
165
print(f"\nLandmarks:")
166
for landmark in landmark_results.result['landmarks']:
167
print(f" - {landmark['name']} (confidence: {landmark['confidence']:.3f})")
168
```
169
170
### Local File Domain Analysis
171
172
```python
173
# Analyze local image file for celebrities
174
with open("party_photo.jpg", "rb") as image_stream:
175
celebrity_results = client.analyze_image_by_domain_in_stream(
176
"celebrities",
177
image_stream
178
)
179
180
if celebrity_results.result and 'celebrities' in celebrity_results.result:
181
for celebrity in celebrity_results.result['celebrities']:
182
print(f"Found: {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")
183
else:
184
print("No celebrities detected in local image")
185
```
186
187
### Batch Domain Analysis
188
189
```python
190
# Process multiple images for celebrity detection
191
image_urls = [
192
"https://example.com/movie-premiere1.jpg",
193
"https://example.com/movie-premiere2.jpg",
194
"https://example.com/award-show.jpg"
195
]
196
197
all_celebrities = set()
198
199
for i, url in enumerate(image_urls, 1):
200
try:
201
print(f"Processing image {i}/{len(image_urls)}...")
202
203
celebrity_results = client.analyze_image_by_domain("celebrities", url)
204
205
if celebrity_results.result and 'celebrities' in celebrity_results.result:
206
image_celebrities = celebrity_results.result['celebrities']
207
print(f" Found {len(image_celebrities)} celebrities")
208
209
for celebrity in image_celebrities:
210
all_celebrities.add(celebrity['name'])
211
print(f" - {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")
212
else:
213
print(" No celebrities detected")
214
215
except Exception as e:
216
print(f" Error processing image: {e}")
217
218
print(f"\nUnique celebrities across all images: {len(all_celebrities)}")
219
for name in sorted(all_celebrities):
220
print(f" - {name}")
221
```
222
223
### High-Confidence Domain Analysis
224
225
```python
226
# Filter domain analysis results by confidence threshold
227
image_url = "https://example.com/group-photo.jpg"
228
confidence_threshold = 0.8
229
230
# Celebrity analysis with confidence filtering
231
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)
232
233
high_confidence_celebrities = []
234
if celebrity_results.result and 'celebrities' in celebrity_results.result:
235
high_confidence_celebrities = [
236
celebrity for celebrity in celebrity_results.result['celebrities']
237
if celebrity['confidence'] >= confidence_threshold
238
]
239
240
print(f"High-confidence celebrity detections (≥{confidence_threshold}):")
241
if high_confidence_celebrities:
242
for celebrity in high_confidence_celebrities:
243
print(f" {celebrity['name']}: {celebrity['confidence']:.3f}")
244
else:
245
print(" None found above threshold")
246
247
# Show all detections for comparison
248
if celebrity_results.result and 'celebrities' in celebrity_results.result:
249
all_celebrities = celebrity_results.result['celebrities']
250
low_confidence = [c for c in all_celebrities if c['confidence'] < confidence_threshold]
251
252
if low_confidence:
253
print(f"\nLower confidence detections:")
254
for celebrity in low_confidence:
255
print(f" {celebrity['name']}: {celebrity['confidence']:.3f}")
256
```
257
258
## Response Data Types
259
260
### DomainModelResults
261
262
```python { .api }
263
class DomainModelResults:
264
"""
265
Domain-specific analysis results.
266
267
Attributes:
268
result (dict): Domain model results containing detected entities
269
For celebrities: {'celebrities': [{'name': str, 'confidence': float, 'faceRectangle': dict}]}
270
For landmarks: {'landmarks': [{'name': str, 'confidence': float, 'description': str}]}
271
request_id (str): Request identifier
272
metadata (ImageMetadata): Image metadata (dimensions, format)
273
model_version (str): Domain model version used
274
"""
275
```
276
277
### ListModelsResult
278
279
```python { .api }
280
class ListModelsResult:
281
"""
282
Available domain models listing.
283
284
Attributes:
285
models_property (list[ModelDescription]): List of available domain models
286
"""
287
```
288
289
### ModelDescription
290
291
```python { .api }
292
class ModelDescription:
293
"""
294
Description of a domain model.
295
296
Attributes:
297
name (str): Model name (e.g., "celebrities", "landmarks")
298
categories (list[str], optional): Model categories or capabilities
299
description (str, optional): Model description and use cases
300
"""
301
```
302
303
## Domain Model Details
304
305
### Celebrity Model
306
307
**Capabilities:**
308
- Recognizes thousands of well-known celebrities from entertainment, sports, politics, and business
309
- Provides confidence scores for identity matches
310
- Returns face bounding rectangle coordinates
311
- Works with partial face visibility and various angles
312
313
**Celebrity Result Structure:**
314
```python
315
{
316
'celebrities': [
317
{
318
'name': 'Celebrity Name',
319
'confidence': 0.95,
320
'faceRectangle': {
321
'left': 100,
322
'top': 150,
323
'width': 80,
324
'height': 80
325
}
326
}
327
]
328
}
329
```
330
331
### Landmark Model
332
333
**Capabilities:**
334
- Identifies famous landmarks, monuments, and buildings worldwide
335
- Recognizes natural landmarks like mountains, lakes, and geological formations
336
- Provides location context and descriptions
337
- Works with various viewing angles and partial views
338
339
**Landmark Result Structure:**
340
```python
341
{
342
'landmarks': [
343
{
344
'name': 'Landmark Name',
345
'confidence': 0.88,
346
'description': 'Brief description of the landmark',
347
'location': {
348
'name': 'City, Country'
349
}
350
}
351
]
352
}
353
```
354
355
## Best Practices
356
357
### Celebrity Detection
358
- Works best with clear, frontal face views
359
- Can detect celebrities in group photos
360
- Confidence scores above 0.7 are generally reliable
361
- May not detect celebrities in heavy makeup, costumes, or significant aging
362
363
### Landmark Detection
364
- Requires recognizable architectural or natural features
365
- Works with various weather conditions and lighting
366
- Best results with iconic views and clear visibility
367
- May struggle with heavily modified or partially obscured landmarks
368
369
### General Tips
370
- Use appropriate confidence thresholds for your application
371
- Combine with general image analysis for comprehensive results
372
- Consider privacy implications when processing images with people
373
- Cache results for frequently analyzed images to improve performance