@@ -486,27 +486,46 @@ func detectLogos(w io.Writer, file string) error {
486486 return err
487487 }
488488
489- f , err := os .Open (file )
489+ fileBytes , err := os .ReadFile (file )
490490 if err != nil {
491491 return err
492492 }
493- defer f .Close ()
494493
495- image , err := vision .NewImageFromReader (f )
496- if err != nil {
497- return err
494+ image := & visionpb.Image {
495+ Content : fileBytes ,
496+ }
497+
498+ feature := & visionpb.Feature {
499+ Type : visionpb .Feature_LOGO_DETECTION ,
500+ MaxResults : 10 ,
501+ }
502+
503+ request := & visionpb.BatchAnnotateImagesRequest {
504+ Requests : []* visionpb.AnnotateImageRequest {
505+ {
506+ Image : image ,
507+ Features : []* visionpb.Feature {feature },
508+ },
509+ },
498510 }
499- annotations , err := client .DetectLogos (ctx , image , nil , 10 )
511+
512+ response , err := client .BatchAnnotateImages (ctx , request )
500513 if err != nil {
501514 return err
502515 }
503516
504- if len (annotations ) == 0 {
505- fmt .Fprintln (w , "No logos found." )
506- } else {
507- fmt .Fprintln (w , "Logos:" )
508- for _ , annotation := range annotations {
509- fmt .Fprintln (w , annotation .Description )
517+ for _ , resp := range response .Responses {
518+ if resp .Error != nil {
519+ fmt .Fprintf (w , "Error: %v\n " , resp .Error )
520+ continue
521+ }
522+ if len (resp .LogoAnnotations ) == 0 {
523+ fmt .Fprintln (w , "No logos found." )
524+ } else {
525+ fmt .Fprintln (w , "Logos:" )
526+ for _ , annotation := range resp .LogoAnnotations {
527+ fmt .Fprintln (w , annotation .Description )
528+ }
510529 }
511530 }
512531
@@ -928,18 +947,45 @@ func detectLogosURI(w io.Writer, file string) error {
928947 return err
929948 }
930949
931- image := vision .NewImageFromURI (file )
932- annotations , err := client .DetectLogos (ctx , image , nil , 10 )
950+ image := & visionpb.Image {
951+ Source : & visionpb.ImageSource {
952+ // Use GcsImageUri for gs:// links
953+ // Use ImageUri for public https:// links
954+ GcsImageUri : file ,
955+ },
956+ }
957+
958+ feature := & visionpb.Feature {
959+ Type : visionpb .Feature_LOGO_DETECTION ,
960+ MaxResults : 10 ,
961+ }
962+
963+ request := & visionpb.BatchAnnotateImagesRequest {
964+ Requests : []* visionpb.AnnotateImageRequest {
965+ {
966+ Image : image ,
967+ Features : []* visionpb.Feature {feature },
968+ },
969+ },
970+ }
971+
972+ response , err := client .BatchAnnotateImages (ctx , request )
933973 if err != nil {
934974 return err
935975 }
936976
937- if len (annotations ) == 0 {
938- fmt .Fprintln (w , "No logos found." )
939- } else {
940- fmt .Fprintln (w , "Logos:" )
941- for _ , annotation := range annotations {
942- fmt .Fprintln (w , annotation .Description )
977+ for _ , resp := range response .Responses {
978+ if resp .Error != nil {
979+ fmt .Fprintf (w , "Error: %v\n " , resp .Error )
980+ continue
981+ }
982+ if len (resp .LogoAnnotations ) == 0 {
983+ fmt .Fprintln (w , "No logos found." )
984+ } else {
985+ fmt .Fprintln (w , "Logos:" )
986+ for _ , annotation := range resp .LogoAnnotations {
987+ fmt .Fprintln (w , annotation .Description )
988+ }
943989 }
944990 }
945991
0 commit comments