登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎
建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
// detectLogos gets logos from the Vision API for an image at the given file path.funcdetectLogos(wio.Writer,filestring)error{ctx:=context.Background()client,err:=vision.NewImageAnnotatorClient(ctx)iferr!=nil{returnerr}fileBytes,err:=os.ReadFile(file)iferr!=nil{returnerr}image:=&visionpb.Image{Content:fileBytes,}feature:=&visionpb.Feature{Type:visionpb.Feature_LOGO_DETECTION,MaxResults:10,}request:=&visionpb.BatchAnnotateImagesRequest{Requests:[]*visionpb.AnnotateImageRequest{{Image:image,Features:[]*visionpb.Feature{feature},},},}response,err:=client.BatchAnnotateImages(ctx,request)iferr!=nil{returnerr}for_,resp:=rangeresponse.Responses{ifresp.Error!=nil{fmt.Fprintf(w,"Error: %v\n",resp.Error)continue}iflen(resp.LogoAnnotations)==0{fmt.Fprintln(w,"No logos found.")}else{fmt.Fprintln(w,"Logos:")for_,annotation:=rangeresp.LogoAnnotations{fmt.Fprintln(w,annotation.Description)}}}returnnil}