您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

检测图像中的常见对象Detect common objects in images

对象检测类似于标记,但是 API 返回找到的每个对象的边框坐标(以像素为单位)。Object detection is similar to tagging, but the API returns the bounding box coordinates (in pixels) for each object found. 例如,如果图像包含狗、猫和人,检测操作将列出这些对象及其在图像中的坐标。For example, if an image contains a dog, cat and person, the Detect operation will list those objects together with their coordinates in the image. 可以使用此功能处理图像中对象之间的关系。You can use this functionality to process the relationships between the objects in an image. 还可以确定图像中是否有多个相同标记的实例。It also lets you determine whether there are multiple instances of the same tag in an image.

检测 API 根据图像中识别到的对象或生物应用标记。The Detect API applies tags based on the objects or living things identified in the image. 目前,标记分类与对象检测分类之间没有正式关系。There is currently no formal relationship between the tagging taxonomy and the object detection taxonomy. 从概念上讲,检测 API 仅查找对象和生物,而标记 API 还可以包含诸如“室内”等上下文术语,这些术语不能使用边界框进行本地化。At a conceptual level, the Detect API only finds objects and living things, while the Tag API can also include contextual terms like "indoor", which can't be localized with bounding boxes.

对象检测示例Object detection example

以下 JSON 响应表明计算机视觉在示例图像中检测对象时所返回的内容。The following JSON response illustrates what Computer Vision returns when detecting objects in the example image.

一位正在厨房中使用 Microsoft Surface 设备的女士

{
   "objects":[
      {
         "rectangle":{
            "x":730,
            "y":66,
            "w":135,
            "h":85
         },
         "object":"kitchen appliance",
         "confidence":0.501
      },
      {
         "rectangle":{
            "x":523,
            "y":377,
            "w":185,
            "h":46
         },
         "object":"computer keyboard",
         "confidence":0.51
      },
      {
         "rectangle":{
            "x":471,
            "y":218,
            "w":289,
            "h":226
         },
         "object":"Laptop",
         "confidence":0.85,
         "parent":{
            "object":"computer",
            "confidence":0.851
         }
      },
      {
         "rectangle":{
            "x":654,
            "y":0,
            "w":584,
            "h":473
         },
         "object":"person",
         "confidence":0.855
      }
   ],
   "requestId":"a7fde8fd-cc18-4f5f-99d3-897dcd07b308",
   "metadata":{
      "width":1260,
      "height":473,
      "format":"Jpeg"
   }
}

限制Limitations

请务必注意对象检测的限制,以便可以避免或缓解误报(缺少对象)和有限详细信息的影响。It's important to note the limitations of object detection so you can avoid or mitigate the effects of false negatives (missed objects) and limited detail.

  • 如果对象小(小于图像的 5%),则通常不删除对象。Objects are generally not detected if they're small (less than 5% of the image).
  • 如果对象紧密地排列在一起(例如一摞盘子),则通常不会检测到对象。Objects are generally not detected if they're arranged closely together (a stack of plates, for example).
  • 对象不区分品牌或产品名称(例如,商店货架上不同类型的苏打饮料)。Objects are not differentiated by brand or product names (different types of sodas on a store shelf, for example). 但是可以使用品牌检测功能从图像中获取品牌信息。However, you can get brand information from an image by using the Brand detection feature.

使用 APIUse the API

对象检测功能属于分析图像 API。The object detection feature is part of the Analyze Image API. 可以通过本机 SDK 或 REST 调用来调用此 API。You can call this API through a native SDK or through REST calls. Objects 包括在 visualFeatures 查询参数中。Include Objects in the visualFeatures query parameter. 然后,在获取完整 JSON 响应时,就只需分析 "objects" 部分内容的字符串。Then, when you get the full JSON response, simply parse the string for the contents of the "objects" section.