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}
- right dress:
{"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}