前提・実現したいこと
iphoneのカメラ機能を使って、文字認識を行いたいです。
PCでの動作は確認できたのですが、iphoneだと上手くいきません。
【環境】
環境が特殊です。
iPhoneからオンプレミスのサーバに繋ぎます。
そこからiphoneのカメラを起動する流れとなります。
現状だと、サーバのカメラを起動させようとしてエラーが
発生しております。
発生している問題・エラーメッセージ
iphoneのカメラが起動せず、下記エラーが出ています。
読み込むものがないのでしょうか。
エラーメッセージ
'NoneType' object has no attribute 'shape'
該当のソースコード
Python
1 2#!usr/bin/env python 3 4 5import os 6import sys 7import cv2 8import time 9from PIL import Image 10import pyocr 11import pyocr.builders 12 13sys.path.append('/path/to/dir') 14 15pyocr.tesseract.TESSERACT_CMD = r'C:\Program Files\Tesseract-OCR\tesseract.exe' 16tools = pyocr.get_available_tools() # OCRエンジンのリストを取得 17 18tool = tools[0] # OCRエンジンのリストの中から、使用したいエンジンを選択 19 20langs = tool.get_available_languages() 21lang = langs[0] 22capture = cv2.VideoCapture(0) 23last_txt = "" 24while True: 25 ret, frame = capture.read() 26 orgHeight, orgWidth = frame.shape[:2] 27 size = (int(orgWidth/4), int(orgHeight/4)) 28 glay = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 29 image = cv2.resize(glay, size) 30 t = time.time() 31 txt = tool.image_to_string( 32 Image.fromarray(image), 33 lang="eng+jpn", 34 builder=pyocr.builders.TextBuilder(tesseract_layout=7) 35 ) 36 #print(time.time() - t) 37 if len(txt) != 0 and txt != last_txt: 38 last_txt = txt 39 print( txt ) 40 41 cv2.imshow("Capture", image) 42 43 if cv2.waitKey(33) >= 0: 44 break 45 46cv2.destroyAllWindows()
試したこと
iphoneのIPが関係していると思い、wifiのpassやuserを入れてみましたが
上手くいきませんでした。
初心者で申し訳ないですが、ご教授いただけると幸いです。
回答1件