コード例 #1
0
 def baidu_ocr(self, file):
     app_id = '19890128'
     api_key = 'BqvwEKnyBhHX6QAj0Ezc2KH7'
     secret_key = '2wQh1smTldG9qvKdUKvZe5uXhb6L1o59'
     ocr_text = ''
     if os.path.isfile(file):
         with open(file, 'rb') as f:
             image = f.read()
         ocr_ret = aip.AipOcr(app_id, api_key, secret_key).basicGeneral(image)
         words = ocr_ret.get('words_result')
         print(words)
         if words is not None and len(words):
             for word in words:
                 ocr_text += word['words'] + '\n'
             return ocr_text
     return None
コード例 #2
0
    def init(cls, next_client=False, account_file_path=None):
        # 1、账号信息
        if cls.account_df is None:
            if not account_file_path:
                cls.account_df = (Path(__file__).parent /
                                  'aipocraccount.pkl').read()

        # 2、初始化client
        if cls.client is None or next_client:
            t = cls.client_id + next_client
            if t > len(cls.account_df):
                raise ValueError(
                    '今天账号份额都用完啦!Open api daily request limit reached')
            row = cls.account_df.loc[t]
            AipOcr.client = aip.AipOcr(row.APP_ID, row.API_KEY, row.SECRET_KEY)
            AipOcr.client_id = t
        return AipOcr.client
コード例 #3
0
# -*- coding: utf-8 -*-

import aip
import config

client = aip.AipOcr(config.app_id, config.api_key, config.secret_key)


def pic_word_finder(bdata):
    resp = client.basicGeneral(bdata)
    print(resp)
    if 'words_result' in resp:
        words = []
        for kv in resp.get('words_result'):
            v = kv['words']
            words.append(v)
        r = ''.join(words)
        return r
    else:
        return "纯图片"
コード例 #4
0
import FileDialog

import aip


f = open(FileDialog.getOneFile(), 'rb')
f2 = open(FileDialog.getOneFile(), 'rb')
client = aip.AipOcr("Enter Your APP_ID", "Enter Your API_KEY", "Enter Your SECRET_KEY")
client2 = aip.AipImageClassify("Enter Your APP_ID", "Enter Your API_KEY", "Enter Your SECRET_KEY")
print(client.licensePlate(f.read(), options={})["words_result"]["number"])
print(client2.carDetect(f2.read(), options={}))