2017-07-25 15 views
9

提供されているJavaクライアントのGoogleビジョンを使用してGoogle Vision経由で画像に注釈を付けるときに例外が発生します。Google Vision Batch Javaクライアントライブラリの画像に

バッチclient.batchAnnotateImagesが発生し、特にこのコード:

public void processOCR(byte[] file) 
{ 
    List<AnnotateImageRequest> requests = new ArrayList<>(); 

     ByteString imageByteString = ByteString.copyFrom(file); 

     Image img = Image.newBuilder().setContent(imageByteString).build(); 
     Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build(); 

     AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); 
     requests.add(request); 

     try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) 
     { 

     BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); 
     List<AnnotateImageResponse> responses = response.getResponsesList(); 
     client.close(); 

     //visionResultsDTO result = new visionResultsDTO(); 
     String ParagraphText = ""; 


     for (AnnotateImageResponse res : responses) { 
      if (res.hasError()) { 
      //throw exception. 
      return; 
      } 

      // For full list of available annotations, see http://g.co/cloud/vision/docs 
      TextAnnotation annotation = res.getFullTextAnnotation(); 
      for (Page page: annotation.getPagesList()) { 
      String pageText = ""; 
      for (Block block : page.getBlocksList()) { 
      String blockText = ""; 
       for (Paragraph para : block.getParagraphsList()) { 
       String paraText = ""; 
       for (Word word: para.getWordsList()) { 
        String wordText = ""; 
       for (Symbol symbol: word.getSymbolsList()) { 
        wordText = wordText + symbol.getText(); 
        } 
       paraText = paraText + wordText; 
       } 
       // Output Example using Paragraph: 
       blockText = blockText + paraText; 
       } 
       pageText = pageText + blockText; 
      } 
      } 
      ParagraphText = annotation.getText(); 
     // result.setResultText(ParagraphText); 
     } 
     } catch (Exception e) 
     { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     } 
} 

私は、次のスタックトレース/エラーで提示されています:ここで

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; at com.google.api.gax.retrying.BasicRetryingFuture.(BasicRetryingFuture.java:77) at com.google.api.gax.retrying.CallbackChainRetryingFuture.(CallbackChainRetryingFuture.java:62) at com.google.api.gax.retrying.ScheduledRetryingExecutor.createFuture(ScheduledRetryingExecutor.java:86) at com.google.api.gax.grpc.RetryingCallable.futureCall(RetryingCallable.java:57) at com.google.api.gax.grpc.RetryingCallable.futureCall(RetryingCallable.java:42) at com.google.api.gax.grpc.AuthCallable.futureCall(AuthCallable.java:57) at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:282) at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:293) at com.google.api.gax.grpc.UnaryCallable.call(UnaryCallable.java:321) at com.google.cloud.vision.v1.ImageAnnotatorClient.batchAnnotateImages(ImageAnnotatorClient.java:201) at com.google.cloud.vision.v1.ImageAnnotatorClient.batchAnnotateImages(ImageAnnotatorClient.java:177) at za.co.thumbtribe.core.googlevision.service.impl.GoogleVisionServiceImpl.processOCR(GoogleVisionServiceImpl.java:55)

は私のPOMの依存関係です:

は、
<dependencies> 
<!-- Spring --> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <version>4.2.5.RELEASE</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>com.google.cloud</groupId> 
    <artifactId>google-cloud-vision</artifactId> 
    <version>0.20.3-beta</version> 
    <exclusions> 
    <exclusion> 
     <groupId>com.google.auth</groupId> 
     <artifactId>google-auth-library-oauth2-http</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>com.google.auth</groupId> 
     <artifactId>google-auth-library-credentials</artifactId> 
    </exclusion> 
    <exclusion> 
    <groupId>com.google.guava</groupId> 
    <artifactId>*</artifactId> 
</exclusion> 
    </exclusions> 
</dependency> 
<dependency> 
    <groupId>com.google.auth</groupId> 
    <artifactId>google-auth-library-oauth2-http</artifactId> 
    <version>0.7.0</version> 
</dependency> 
<dependency> 
    <groupId>com.google.auth</groupId> 
    <artifactId>google-auth-library-credentials</artifactId> 
    <version>0.7.0</version> 
</dependency> 

</dependencies> 

私はグアバを除外し、複数のバージョンのA PI。

表示されているコードは、Googleビジョンクライアント実装のサンプルコードです。

答えて

6

クラスの欠落したメソッドdirectExecutorは、グアバのソースに@since 18.0と注釈されています(source参照)。

私はあなたのクラスパスにバージョン19

前に、あなたが犯人を追跡するmvn dependency:analyzeを実行する必要があります表示されますグアバの古いバージョンを持っていると思います。 mvn dependency:analyze | grep guavaを入力して出力をフィルタリングすることができます。

次にあなたが古いの依存関係をインポートしたパッケージをチェックすることができます

mvn dependency:tree -Dverbose

1

は、similar question

Basicaly上を見てみましょうグアバ重複dependecyを削除します。

  1. eclipseでpom.xmlを開きます。
  2. [依存]タブに変更します。
  3. 、 "guava"という文字列です。
  4. 複数のlibバージョンがある場合は、 を右クリックし、「除外する」をクリックします。
  5. run maven clean。
  6. run maven build。最高のメモリ使用については

、私はStringBufferのOUのStringBuilderの代わりに、文字列の連結StringBuffer ou StringBuilderを使用するには、このコードの書き換え一部を示唆しています。

1

(バージョンは私が推測する古いかもしれないので)あなたはgoogle-cloud-vision依存からのグアバを除外していますが、あなたが依存関係として必要バージョン追加されていません。また、グアバのバージョンを含めている

<dependency> 
    <groupId>com.google.guava</groupId> 
    <artifactId>guava</artifactId> 
    <version>22.0</version> 
</dependency> 

google-auth-library-oauth2-httpを: com.google.guava:guava:jar:19.0:compile。私は依存関係としてguavaのバージョンを追加していますが、あなたはそれを除外したいかもしれません

関連する問題