Vision API Product Search 可偵測搜尋圖片中的單一產品,並找出相符的產品;如果圖片中有多個產品,則可識別並列出相符的產品。
單一產品圖片和回應
這張搜尋圖片只包含一項產品。

gs://cloud-ai-vision-data/product-search-tutorial/images/468f782e70ba11e8941fd20059124800.jpg
使用 Vision API Product Search 搜尋類似產品時,系統會傳回回應,指出圖片中的兩個周框,一個框住產品,另一個框住整張圖片。
展開下方部分即可查看完整回覆。
完整回覆
{ "responses": [ { "productSearchResults": { "indexTime": "2018-12-04T22:33:53.673600055Z", "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id16", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 1, "image": "projects/project-id/locations/location-id/products/product_id16/referenceImages/image16" }, { "product": { "name": "projects/project-id/locations/location-id/products/product_id29", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.34263745, "image": "projects/project-id/locations/location-id/products/product_id29/referenceImages/image29" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id89", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.20485385, "image": "projects/project-id/locations/location-id/products/product_id89/referenceImages/image89" } ], "productGroupedResults": [ { "boundingPoly": { "normalizedVertices": [ { "x": 0.25610325, "y": 0.1357359 }, { "x": 0.77213204, "y": 0.1357359 }, { "x": 0.77213204, "y": 0.9287346 }, { "x": 0.25610325, "y": 0.9287346 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id16", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 1, "image": "projects/project-id/locations/location-id/products/product_id16/referenceImages/image16" }, { "product": { "name": "projects/project-id/locations/location-id/products/product_id29", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.3345438, "image": "projects/project-id/locations/location-id/products/product_id29/referenceImages/image29" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id76", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "shoe" } ] }, "score": 0.20218614, "image": "projects/project-id/locations/location-id/products/product_id76/referenceImages/image76" } ] }, { "boundingPoly": { "normalizedVertices": [ {}, { "x": 1 }, { "x": 1, "y": 1 }, { "y": 1 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id16", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 1, "image": "projects/project-id/locations/location-id/products/product_id16/referenceImages/image16" }, { "product": { "name": "projects/project-id/locations/location-id/products/product_id29", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.3507311, "image": "projects/project-id/locations/location-id/products/product_id29/referenceImages/image29" }, { "product": { "name": "projects/project-id/locations/location-id/products/product_id8", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.26709077, "image": "projects/project-id/locations/location-id/products/product_id8/referenceImages/image8" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id51", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.21597815, "image": "projects/project-id/locations/location-id/products/product_id51/referenceImages/image51" } ] } ] } } ] }
定界框和相符產品
圖片中的下列兩項產品 (定界框) 是由要求傳回的兩組頂點指定。
Vision API Product Search 識別的每個方塊都會列出相符的產品。

gs://cloud-samples-data/product_search/multiple_dresses.jpg
在 API 回應中,productGroupedResults
欄位會列出邊界方塊和相符產品結果。系統會根據圖片中偵測到的產品分組。每個 boundingPoly
項目都會列出以標準化頂點指定的區域 (以 0 到 1 的比例表示,不對應圖片的實際像素值)。系統隨後會列出該特定區域的相符產品。
回應中的下列部分對應於洋裝周圍的邊界方塊。
單一產品方塊回應部分
.... "productGroupedResults": [ { "boundingPoly": { "normalizedVertices": [ { "x": 0.25610325, "y": 0.1357359 }, { "x": 0.77213204, "y": 0.1357359 }, { "x": 0.77213204, "y": 0.9287346 }, { "x": 0.25610325, "y": 0.9287346 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id16", "displayName": " ", "productCategory": "apparel", "productLabels":... "score": 1, ...
相符產品會列在 results
欄位後方,並依相符分數遞減排序。分數範圍從 0 (無信心) 到 1 (非常有信心)。

Several matching products for the dress
回應中傳回的其他 boundingPoly
則會圍繞整個圖片。
正規化後的頂點如下:
[{},{"x": 1},{"x": 1,"y": 1},{"y": 1}]
如果座標值為 0,系統會省略該值。因此,上述指定的邊界多邊形對應至:
[{"x": 0,"y": 0},{"x": 1, "y": 0},{"x": 1,"y": 1},{"y": 1}]
接著,系統會列出這個邊界框 (整張圖片) 的相符產品。
多項產品圖片 (多重偵測) 和回應
以下搜尋圖片包含多項產品。

gs://cloud-samples-data/product_search/multiple_dresses.jpg
使用 Vision API Product Search 搜尋類似產品時,系統會傳回回應,其中會識別圖片中的多個定界框,包括整張圖片的定界框,以及三件洋裝各自的定界框。
展開下方部分即可查看完整回覆。
完整回覆
{ "responses": [ { "productSearchResults": { "indexTime": "2018-12-05T18:34:22.231193168Z", "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id89", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.40636745, "image": "projects/project-id/locations/location-id/products/product_id89/referenceImages/image89" }, { "product": { "name": "projects/project-id/locations/location-id/products/product_id56", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.35433072, "image": "projects/project-id/locations/location-id/products/product_id56/referenceImages/image56" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id92", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.30736163, "image": "projects/project-id/locations/location-id/products/product_id92/referenceImages/image92" } ], "productGroupedResults": [ { "boundingPoly": { "normalizedVertices": [ { "x": 0.38727918, "y": 0.10391616 }, { "x": 0.57177967, "y": 0.10391616 }, { "x": 0.57177967, "y": 0.94973093 }, { "x": 0.38727918, "y": 0.94973093 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id39", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.36689043, "image": "projects/project-id/locations/location-id/products/product_id39/referenceImages/image39" }, { "boundingPoly": { "normalizedVertices": [ { "x": 0.63010275, "y": 0.08650439 }, { "x": 0.88989735, "y": 0.08650439 }, { "x": 0.88989735, "y": 0.9285545 }, { "x": 0.63010275, "y": 0.9285545 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id89", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.4007347, "image": "projects/project-id/locations/location-id/products/product_id89/referenceImages/image89" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id30", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.27045864, "image": "projects/project-id/locations/location-id/products/product_id30/referenceImages/image30" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id63", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.23139484, "image": "projects/project-id/locations/location-id/products/product_id63/referenceImages/image63" } ] }, ... { "boundingPoly": { "normalizedVertices": [ {}, { "x": 1 }, { "x": 1, "y": 1 }, { "y": 1 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id30", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.39522344, "image": "projects/project-id/locations/location-id/products/product_id30/referenceImages/image30" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id4", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.34226564, "image": "projects/project-id/locations/location-id/products/product_id4/referenceImages/image4" } ] }, { "boundingPoly": { "normalizedVertices": [ { "x": 0.030102689, "y": 0.067680866 }, { "x": 0.28942674, "y": 0.067680866 }, { "x": 0.28942674, "y": 0.94973093 }, { "x": 0.030102689, "y": 0.94973093 } ] }, "results": [ { "product": { "name": "projects/project-id/locations/location-id/products/product_id89", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.42439392, "image": "projects/project-id/locations/location-id/products/product_id89/referenceImages/image89" }, ... { "product": { "name": "projects/project-id/locations/location-id/products/product_id51", "displayName": " ", "productCategory": "apparel", "productLabels": [ { "key": "style", "value": "women" }, { "key": "category", "value": "dress" } ] }, "score": 0.26797917, "image": "projects/project-id/locations/location-id/products/product_id51/referenceImages/image51" } ] } ] } } ] }
定界框和相符產品
下圖顯示 Vision API Product Search 在這張多產品圖片中識別的所有定界框。

gs://cloud-samples-data/product_search/multiple_dresses.jpg
與單一產品圖片類似,多產品圖片的回應會在 productGroupedResults
欄位中列出定界框和相符的產品結果。每個產品都會以多邊形邊界標示,並依據偵測到的產品分組。
回應中的下列部分對應於中間洋裝周圍的邊界方塊。
產品盒裝回應區段 (中長洋裝)
"productGroupedResults": [ { "boundingPoly": { "normalizedVertices": [ { "x": 0.38727918, "y": 0.10391616 }, { "x": 0.57177967, "y": 0.10391616 }, { "x": 0.57177967, "y": 0.94973093 }, { "x": 0.38727918, "y": 0.94973093 } ] }, "results": [ { "product": { "name":... "score": 0.36689043, ...
下圖顯示 Vision API Product Search 傳回的相符結果,中間的洋裝就是搜尋目標。

Several matching products for the middle dress
圖片中還有其他邊界方塊,每個方塊都有自己的相符產品清單 (未列於此):
- 左側洋裝:
{"x":0.03, "y":0.07},{"x":0.29, "y":0.07},{"x":0.29, "y":0.95},{"x":0.03, "y":0.95}
- 右側洋裝:
{"x":0.63, "y":0.09},{"x":0.89, "y":0.09},{"x":0.89, "y":0.93},{"x":0.63, "y":0.93}
- 整張圖片:
{},{"x": 1},{"x": 1,"y": 1},{"y": 1}
,也可以表示為:{"x": 0, "y": 0},{"x": 1,"y:0"},{"x": 1,"y": 1},{"x": 0,"y": 1}