質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

1330閲覧

GCP google visionについて

snake2009

総合スコア12

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2021/04/21 04:09

編集2021/04/21 04:21

GCP google visionについて
以下のリンクに記載の通り、コードを実行したところ、下記のエラーが発生しました。
どのように対処すれば良いのかわからず、困っております。
お手数ですが、対処方法についてご教示お願いいたします。

https://cloud.google.com/vision/docs/pdf#vision_text_detection_pdf_gcs-python

python

1def async_detect_document(gcs_source_uri, gcs_destination_uri): 2 """OCR with PDF/TIFF as source files on GCS""" 3 import json 4 import re 5 from google.cloud import vision 6 from google.cloud import storage 7 8 # Supported mime_types are: 'application/pdf' and 'image/tiff' 9 mime_type = 'application/pdf' 10 11 # How many pages should be grouped into each json output file. 12 batch_size = 2 13 14 client = vision.ImageAnnotatorClient() 15 16 feature = vision.Feature( 17 type_=vision.Feature.Type.DOCUMENT_TEXT_DETECTION) 18 19 gcs_source = vision.GcsSource(uri=gcs_source_uri) 20 input_config = vision.InputConfig( 21 gcs_source=gcs_source, mime_type=mime_type) 22 23 gcs_destination = vision.GcsDestination(uri=gcs_destination_uri) 24 output_config = vision.OutputConfig( 25 gcs_destination=gcs_destination, batch_size=batch_size) 26 27 async_request = vision.AsyncAnnotateFileRequest( 28 features=[feature], input_config=input_config, 29 output_config=output_config) 30 31 operation = client.async_batch_annotate_files( 32 requests=[async_request]) 33 34 print('Waiting for the operation to finish.') 35 operation.result(timeout=420) 36 37 # Once the request has completed and the output has been 38 # written to GCS, we can list all the output files. 39 storage_client = storage.Client() 40 41 match = re.match(r'gs://([^/]+)/(.+)', gcs_destination_uri) 42 bucket_name = match.group(1)←ここでエラーになります。 43 prefix = match.group(2) 44 45 bucket = storage_client.get_bucket(bucket_name) 46 47 # List objects with the given prefix. 48 blob_list = list(bucket.list_blobs(prefix=prefix)) 49 print('Output files:') 50 for blob in blob_list: 51 print(blob.name) 52 53 # Process the first output file from GCS. 54 # Since we specified batch_size=2, the first response contains 55 # the first two pages of the input file. 56 output = blob_list[0] 57 58 json_string = output.download_as_string() 59 response = json.loads(json_string) 60 61 # The actual response for the first page of the input file. 62 first_page_response = response['responses'][0] 63 annotation = first_page_response['fullTextAnnotation'] 64 65 # Here we print the full text from the first page. 66 # The response contains more information: 67 # annotation/pages/blocks/paragraphs/words/symbols 68 # including confidence scores and bounding boxes 69 print('Full text:\n') 70 print(annotation['text'])

(エラー画面)

AttributeError

1<ipython-input-144-ed7251c56f06> in <module> 2 40 3 41 match = re.match(r'gs://([^/]+)/(.+)', gcs_destination_uri) 4---> 42 bucket_name = match.group(1) 5 43 prefix = match.group(2) 6 44 7 8AttributeError: 'NoneType' object has no attribute 'group' 9 10 11 12

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

re.match が None を返したわけなのでマッチしなかったということでしょう。
gcs_destination_uri に適切な文字列が入っているか print などで確認してみてください。

https://docs.python.org/ja/3/library/re.html より

文字列がパターンにマッチしなければ None を返します。

投稿2021/04/21 11:23

68user

総合スコア2005

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

snake2009

2021/04/21 13:52

ご丁寧にありがとうございます。 ご指摘いただいた内容を参考とさせていただきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問