国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

教你用Python寫安卓游戲外掛

2020-02-22 22:51:07
字體:
供稿:網(wǎng)友

本次我們選擇的安卓游戲?qū)ο蠼小皢卧~英雄”,大家可以先下載這個(gè)游戲。

游戲的界面是這樣的:

通過選擇單詞的意思進(jìn)行攻擊,選對(duì)了就正常攻擊,選錯(cuò)了就象征性的攻擊一下。玩了一段時(shí)間之后琢磨可以做成自動(dòng)的,通過PIL識(shí)別圖片里的單詞和選項(xiàng),然后翻譯英文成中文意思,根據(jù)中文模糊匹配選擇對(duì)應(yīng)的選項(xiàng)。

查找了N多資料以后開始動(dòng)手,程序用到以下這些東西:

PIL:Python Imaging Library 大名鼎鼎的圖片處理模塊

pytesser:Python下用來驅(qū)動(dòng)tesseract-ocr來進(jìn)行識(shí)別的模塊

Tesseract-OCR:圖像識(shí)別引擎,用來把圖像識(shí)別成文字,可以識(shí)別英文和中文,以及其它語言

autopy:Python下用來模擬操作鼠標(biāo)和鍵盤的模塊。

安裝步驟(win7環(huán)境):

(1)安裝PIL,下載地址:http://www.pythonware.com/products/pil/,安裝Python Imaging Library 1.1.7 for Python 2.7。

(2)安裝pytesser,下載地址:http://code.google.com/p/pytesser/,下載解壓后直接放在
C:/Python27/Lib/site-packages下,在文件夾下建立pytesser.pth文件,內(nèi)容為C:/Python27/Lib/site-packages/pytesser_v0.0.1

(3)安裝Tesseract OCR engine,下載:https://github.com/tesseract-ocr/tesseract/wiki/Downloads,下載Windows installer of tesseract-ocr 3.02.02 (including English language data)的安裝文件,進(jìn)行安裝。

(4)安裝語言包,在https://github.com/tesseract-ocr/tessdata下載chi_sim.traineddata簡體中文語言包,放到安裝的Tesseract OCR目標(biāo)下的tessdata文件夾內(nèi),用來識(shí)別簡體中文。

(5)修改C:/Python27/Lib/site-packages/pytesser_v0.0.1下的pytesser.py的函數(shù),將原來的image_to_string函數(shù)增加語音選擇參數(shù)language,language='chi_sim'就可以用來識(shí)別中文,默認(rèn)為eng英文。

改好后的pytesser.py:

"""OCR in Python using the Tesseract engine from Googlehttp://code.google.com/p/pytesser/by Michael J.T. O'KellyV 0.0.1, 3/10/07"""import Imageimport subprocessimport utilimport errorstesseract_exe_name = 'tesseract' # Name of executable to be called at command linescratch_image_name = "temp.bmp" # This file must be .bmp or other Tesseract-compatible formatscratch_text_name_root = "temp" # Leave out the .txt extensioncleanup_scratch_flag = True # Temporary files cleaned up after OCR operationdef call_tesseract(input_filename, output_filename, language): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename, "-l", language] proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0:  errors.check_for_errors()def image_to_string(im, cleanup = cleanup_scratch_flag, language = "eng"): """Converts im to file, applies tesseract, and fetches resulting text. If cleanup=True, delete scratch files after operation.""" try:  util.image_to_scratch(im, scratch_image_name)  call_tesseract(scratch_image_name, scratch_text_name_root,language)  text = util.retrieve_text(scratch_text_name_root) finally:  if cleanup:   util.perform_cleanup(scratch_image_name, scratch_text_name_root) return textdef image_file_to_string(filename, cleanup = cleanup_scratch_flag, graceful_errors=True, language = "eng"): """Applies tesseract to filename; or, if image is incompatible and graceful_errors=True, converts to compatible format and then applies tesseract. Fetches resulting text. If cleanup=True, delete scratch files after operation.""" try:  try:   call_tesseract(filename, scratch_text_name_root, language)   text = util.retrieve_text(scratch_text_name_root)  except errors.Tesser_General_Exception:   if graceful_errors:    im = Image.open(filename)    text = image_to_string(im, cleanup)   else:    raise finally:  if cleanup:   util.perform_cleanup(scratch_image_name, scratch_text_name_root) return textif __name__=='__main__': im = Image.open('phototest.tif') text = image_to_string(im) print text try:  text = image_file_to_string('fnord.tif', graceful_errors=False) except errors.Tesser_General_Exception, value:  print "fnord.tif is incompatible filetype. Try graceful_errors=True"  print value text = image_file_to_string('fnord.tif', graceful_errors=True) print "fnord.tif contents:", text text = image_file_to_string('fonts_test.png', graceful_errors=True) print text            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 勐海县| 岳阳县| 乌苏市| 建阳市| 慈溪市| 通化市| 呼伦贝尔市| 陕西省| 沭阳县| 大城县| 漳浦县| 诸暨市| 博兴县| 洛浦县| 武强县| 甘泉县| 琼中| 确山县| 建湖县| 公主岭市| 临沂市| 桐庐县| 陕西省| 沭阳县| 丹棱县| 靖安县| 扎鲁特旗| 新巴尔虎左旗| 新兴县| 金平| 闽侯县| 蓬安县| 手机| 依安县| 凤台县| 福州市| 宜兰县| 酒泉市| 桑植县| 普兰店市| 斗六市|