當前位置: 首頁>>代碼示例>>Python>>正文


Python aip.AipOcr方法代碼示例

本文整理匯總了Python中aip.AipOcr方法的典型用法代碼示例。如果您正苦於以下問題:Python aip.AipOcr方法的具體用法?Python aip.AipOcr怎麽用?Python aip.AipOcr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aip的用法示例。


在下文中一共展示了aip.AipOcr方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: verify

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def verify(self, image, ocr=None):
        try:
            from aip import AipOcr
        except Exception as e:
            print(e, '\n請在命令行下執行: pip install baidu-aip')

        conf = ocr or {
            'appId': '11645803',
            'apiKey': 'RUcxdYj0mnvrohEz6MrEERqz',
            'secretKey': '4zRiYambxQPD1Z5HFh9VOoPXPK9AgBtZ'
        }

        ocr = AipOcr(**conf)
        try:
            r = ocr.basicGeneral(image).get('words_result')[0]['words']
        except Exception as e:
            print(e, '\n驗證碼圖片無法識別!')
            r = False
        return r 
開發者ID:Raytone-D,項目名稱:puppet,代碼行數:21,代碼來源:client.py

示例2: baidu_ocr

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def baidu_ocr(img, options, line=0):
    """
    調用百度api進行圖片識別
    :param options: 百度ocr選項
    :param img: 獲取圖片
    :param line: 選擇行數,暫時沒有用途,以防萬一留下這個變量,默認為第一行
    :return: 返回識別結果
    """
    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
    image = img
    """ 調用通用文字識別, 圖片參數為本地圖片 """
    result = client.basicGeneral(image, _options(options))

    if result["words_result_num"] > 1 or line >= 1:
        # TODO
        raise NotImplementedError
    elif result["words_result_num"] == 1:
        return result["words_result"][line]["words"]
    else:
        return "" 
開發者ID:ninthDevilHAUNSTER,項目名稱:ArknightsAutoHelper,代碼行數:22,代碼來源:baidu.py

示例3: get_verifycode

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def get_verifycode(self, client=object, imageUrl=''):

        # 填寫自己的 baidu-ocr api信息
        APP_ID = 'xxxxxxxxxx'
        API_KEY = 'xxxxxxxxxxxx'
        SECRET_KEY = 'xxxxxxxxxxxxxxx'

        options = {}
        options["recognize_granularity"] = "big"
        options["detect_direction"] = "true"

        client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
        retry_times = 3
        i = 0
        while i < retry_times:
            i += 1
            try:
                # image = get_file_content(tmpImageName)
                image = self.sess.get(imageUrl, proxies=utils.get_proxy(),
                                      headers=self.a_task.M_HEADERS,
                                      cookies=self.a_task.M_COOKIES,
                                      verify=False)
                # open('vc____.jpg', 'wb').write(image.content)
                response = client.numbers(image.content, options)
                debug_p('[get_verifycode] vc_code response=', response)
                # dict: {'log_id': 3705378724129786481, 'direction': 0, 'words_result_num': 1, 'words_result': [{'location': {'width': 78, 'top': 1, 'left': 13, 'height': 37}, 'words': '4217'}]}
                words_result = response['words_result']
                verifycode = words_result[0].get('words', '')
                if not verifycode or len(verifycode) < 4:
                    continue
                if len(verifycode) > 4:
                    verifycode = verifycode[:4]
                debug_p('[get_verifycode] verifycode=', verifycode, 'i=', i)
                return verifycode
            except Exception as e:
                # speed up
                i += 1
                debug_p('[get_verifycode] Exception', 'i=', i, 'traceback=', traceback.format_exc())
                pass
        return '0000' 
開發者ID:qmppz,項目名稱:igotolibrary,代碼行數:42,代碼來源:reserve.py

示例4: __init__

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def __init__(self, d, app_id, api_key, secrect_key):
        self._d = d
        self._APP_ID = app_id
        self._API_KEY = api_key
        self._SECRECT_KEY = secrect_key
        self._client = AipOcr(self._APP_ID, self._API_KEY, self._SECRECT_KEY) 
開發者ID:openatx,項目名稱:uiautomator2,代碼行數:8,代碼來源:baiduOCR.py

示例5: image_to_string

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def image_to_string(image, token={
    'appId': '11645803',
    'apiKey': 'RUcxdYj0mnvrohEz6MrEERqz',
    'secretKey': '4zRiYambxQPD1Z5HFh9VOoPXPK9AgBtZ'}):
    if not isinstance(image, bytes):
        buf = import_module('io').BytesIO()
        image.save(buf, 'png')
        image = buf.getvalue()
    return import_module('aip').AipOcr(**token).basicGeneral(image).get(
        'words_result')[0]['words'] 
開發者ID:Raytone-D,項目名稱:puppet,代碼行數:12,代碼來源:client.py

示例6: get_text_from_image

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def get_text_from_image(image_data, app_id, app_key, app_secret, api_version=0, timeout=3):
    """
    Get image text use baidu ocr

    :param image_data:
    :param app_id:
    :param app_key:
    :param app_secret:
    :param api_version:
    :param timeout:
    :return:
    """
    client = AipOcr(appId=app_id, apiKey=app_key, secretKey=app_secret)
    client.setConnectionTimeoutInMillis(timeout * 1000)

    options = {}
    options["language_type"] = "CHN_ENG"
    options["detect_direction"] = "true"

    if api_version == 1:
        result = client.basicAccurate(image_data, options)
    else:
        result = client.basicGeneral(image_data, options)

    if "error_code" in result:
        print("baidu api error: ", result["error_msg"])
        return ""
    return [words["words"] for words in result["words_result"]] 
開發者ID:smileboywtu,項目名稱:MillionHeroAssistant,代碼行數:30,代碼來源:baiduocr.py

示例7: create_bae

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def create_bae():
    # 百度AI配置
    APP_ID = config['bae_ai']['APP_ID']
    API_KEY = config['bae_ai']['API_KEY']
    SECRET_KEY = config['bae_ai']['SECRET_KEY']
    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
    return client

# 百度通用orc 
開發者ID:hilbp,項目名稱:app-bot,代碼行數:11,代碼來源:ai.py

示例8: __init__

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def __init__(self,app_id,api_key,secret_key):
        self.image_client = AipImageClassify(app_id,api_key,secret_key)
        self.words_client = AipOcr(app_id,api_key,secret_key) 
開發者ID:V-I-C-T-O-R,項目名稱:12306,代碼行數:5,代碼來源:baidu.py

示例9: init_baidu_ocr

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def init_baidu_ocr(baidu_ocr_config):
    app_id, api_key, secret_key = baidu_ocr_config
    client = AipOcr(app_id, api_key, secret_key)
    return client


# {'words_result': [{'words': '11.代表作之一是《蒙娜麗莎的眼'},
#                   {'words': '淚》的歌手是?'}, {'words': '林誌穎'},
#                   {'words': '林誌炫'}, {'words': '林誌玲'}],
#  'log_id': 916087026228727188, 'words_result_num': 5} 
開發者ID:wangtonghe,項目名稱:hq-answer-assist,代碼行數:12,代碼來源:baiduocr.py

示例10: main

# 需要導入模塊: import aip [as 別名]
# 或者: from aip import AipOcr [as 別名]
def main():
  start = time.time()
  os.system("adb shell /system/bin/screencap -p /sdcard/screenshot.png") 
  os.system("adb pull /sdcard/screenshot.png ")  


  im = Image.open(r"./screenshot.png")   
  img_size = im.size
  w = im.size[0]
  h = im.size[1]
  print("xx:{}".format(img_size))

  region = im.crop((70,200, w-70,1200))    #裁剪的區域
  region.save("./crop_test1.png") 

  f=open('./crop_test1.png','rb')
  image_data=f.read()

  client = AipOcr(app_id, api_key, secret_key)                #識別過程
  result = client.basicGeneral(image_data)
  if "error_code" in result:
      print("baidu api error: ", result["error_msg"])
  else:
      words_results = result['words_result']                  #得到識別結果的問題+選項
      #print (result['words_result'])   
  question = ''
  choice = ['','','','','','']
  num = 0
  choice_num = 0
  for words_result in words_results:
        num+=1
        if(num >=len(words_results)-2):
          choice[choice_num] = words_result['words']
          choice_num+=1
        else:
          question = question + words_result['words']

  
  print(question)       #打印問題
  print('  A:'+choice[0]+' B:'+choice[1]+' C:'+choice[2])       #打印選項

  s = Search(question,choice)
  s.search()
  
  end = time.time()
  print('程序用時:'+str(end-start)+'秒') 
開發者ID:yyzhou94,項目名稱:MillionHeroesAssistant,代碼行數:48,代碼來源:assistant_test.py


注:本文中的aip.AipOcr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。