分析图像
100 XP
若要分析图像,可以使用 分析图像 REST 方法或 SDK 中用于首选编程语言的等效方法,并指定要包含在分析中的视觉特征。如果选择了类别,还可以选择是否包括名人或地标的详细信息。 此方法返回包含所请求信息的 JSON 文档。
using Azure.AI.Vision.ImageAnalysis;
ImageAnalysisClient client = new ImageAnalysisClient(
Environment.GetEnvironmentVariable("ENDPOINT"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("KEY")));
ImageAnalysisResult result = client.Analyze(
new Uri("<url>"),
VisualFeatures.Caption | VisualFeatures.Read,
new ImageAnalysisOptions { GenderNeutralCaption = true });
from azure.ai.vision.imageanalysis import ImageAnalysisClient
from azure.ai.vision.imageanalysis.models import VisualFeatures
from azure.core.credentials import AzureKeyCredential
client = ImageAnalysisClient(
endpoint=os.environ["ENDPOINT"],
credential=AzureKeyCredential(os.environ["KEY"])
)
result = client.analyze(
image_url="<url>",
visual_features=[VisualFeatures.CAPTION, VisualFeatures.READ],
gender_neutral_caption=True,
language="en",
)
可用视觉特性包含在 VisualFeatures
枚举中。
- VisualFeatures.Tags:识别有关图像的标记,包括对象、风景、场景和动作
- VisualFeatures.Objects:返回检测到的每个对象的边界框
- VisualFeatures.Caption:以自然语言生成图像的标题
- VisualFeatures.DenseCaptions:为检测到的对象生成更详细的标题
- VisualFeatures.People:返回检测到的人员的边界框
- VisualFeatures.SmartCrops:返回感兴趣的区域指定纵横比的边界框
- VisualFeatures.Read:提取可读文本
- VisualFeatures.TAGS:标识有关图像的标记,包括对象、风景、环境和动作
- VisualFeatures.OBJECTS:返回检测到的每个对象的边界框
- VisualFeatures.CAPTION:以自然语言生成图像的标题
- VisualFeatures.DENSE_CAPTIONS:为检测到的对象生成更加详细的说明
- VisualFeatures.PEOPLE:返回检测到的人员的包围盒
- VisualFeatures.SMART_CROPS:返回感兴趣的区域指定纵横比的边界框
- VisualFeatures.READ:提取可读文本
指定要在图像中分析的视觉特征,确定响应将包含哪些信息。 大多数响应将包含边界框(如果图像中某个位置是合理的)或置信度分数(用于标记或标题等特征)。
图像分析的 JSON 响应类似于此示例,具体取决于请求的功能:
{
"apim-request-id": "abcde-1234-5678-9012-f1g2h3i4j5k6",
"modelVersion": "<version>",
"denseCaptionsResult": {
"values": [
{
"text": "a house in the woods",
"confidence": 0.7055229544639587,
"boundingBox": {
"x": 0,
"y": 0,
"w": 640,
"h": 640
}
},
{
"text": "a trailer with a door and windows",
"confidence": 0.6675070524215698,
"boundingBox": {
"x": 214,
"y": 434,
"w": 154,
"h": 108
}
}
]
},
"metadata": {
"width": 640,
"height": 640
}
}