最近的答題贏錢很火爆,我也參與了幾次,有些題目確實很難答,但是10秒鐘的時間根本不夠百度的,所以寫了個輔助掛,這樣可以出現題目時自動百度,這個時間也就花掉2秒鐘,剩下的7、8秒鐘可以進行分析和作答,提升了贏錢概率。
源碼可以見我的github:點擊鏈接
原理分析下:使用adb命令,抓取手機視頻播放的界面,然后通過python的截取和ocr,獲得到題目和答案, 然后百度得到結果。這個環境怎么搭建,有需要的童鞋可以聯系我,因為使用本地的ocr所以解析不花錢,也沒有使用的限制。
github上的代碼中
ocr_bw.py,這個是自動根據題目去百度,然后打開瀏覽器,展示檢索結果
# -*- coding: utf-8 -*-import pytesseractimport timeimport webbrowserimport subprocessfrom PIL import Imagedef main(): """ 主函數 """ op = yes_or_no('請確保手機打開了 ADB 并連接了電腦,' '然后打開西瓜視頻后再用本程序,確定開始?') if not op: print('bye') return #核心遞歸 ocr_subject_parent() # for root, sub_dirs, files in os.walk('E:/臨時接收的文件/知乎答題/百萬/'): # for file in files: # print('發現圖片:' + file) # img = Image.open('E:/臨時接收的文件/知乎答題/百萬/'+file) # ocr_subject(img)def yes_or_no(prompt, true_value='y', false_value='n', default=True): """ 檢查是否已經為啟動程序做好了準備 """ default_value = true_value if default else false_value prompt = '{} {}/{} [{}]: '.format(prompt, true_value, false_value, default_value) i = input(prompt) if not i: return default while True: if i == true_value: return True elif i == false_value: return False prompt = 'Please input {} or {}: '.format(true_value, false_value) i = input(prompt)def screenImg(true_value='', default=True): prompt = '當出現題目時,請按下回車進行識別 ' i = input(prompt) if not i: return default while True: if i == true_value: return True else: return False i = input(prompt)def ocr_subject(p): # 截取 距離上530開始 940結束 # 截取 距離上260 570結束 p = cut_img(p) pytesseract.pytesseract.tesseract_cmd = 'E:/Program Files (x86)/Tesseract-OCR/tesseract' subject = pytesseract.image_to_string(p, lang='chi_sim') subject = "".join(subject.split()) subject = subject.split('.')[1] print(subject) openPage(subject) ocr_subject_parent()def ocr_subject_parent(): result = screenImg() if result: start = time.time() # screenshot.check_screenshot() process = subprocess.Popen( 'adb shell screencap -p', shell=True, stdout=subprocess.PIPE) binary_screenshot = process.stdout.read() binary_screenshot = binary_screenshot.replace(b'/r/n', b'/n') f = open('autojump.png', 'wb') f.write(binary_screenshot) f.close() # screenshot.pull_screenshot() img = Image.open('autojump.png') print("耗時:" + str(time.time() - start)) ocr_subject(img)def openPage(subject): url = 'https://www.baidu.com/s?wd={}'.format( subject) webbrowser.open(url) webbrowser.get()def cut_img(img): region = img.crop((70, 260, 1025, 570)) #region.save("temp/cut_first.png") return regionif __name__ == '__main__': main()
新聞熱點
疑難解答