def main(): args = parse_args() timeout = args.timeout start = time.time() text_binary = analyze_current_screen_text( directory=data_directory, compress_level=image_compress_level[0]) keyword = get_text_from_image(image_data=text_binary, ) if not keyword: print("text not recognize") return keyword = keyword_normalize(keyword) print("guess keyword: ", keyword) answers = zhidao_search(keyword=keyword, default_answer_select=default_answer_number, timeout=timeout) answers = filter(None, answers) for text in answers: print('=' * 70) text = text.replace("\u3000", "") if len(text) > 120 and text_summary: sentences = get_summary(text, summary_sentence_count) sentences = filter(None, sentences) if not sentences: print(text) else: print("\n".join(sentences)) else: print("\n".join(textwrap.wrap(text, width=45))) end = time.time() print("use {0} 秒".format(end - start)) save_screen(directory=data_directory)
def main(): args = parse_args() timeout = args.timeout start = time.time() text_binary = analyze_current_screen_text( directory=data_directory, compress_level=image_compress_level[0]) keyword = get_text_from_image(image_data=text_binary, ) if not keyword: print("text not recognize") return keyword = keyword_normalize(keyword) print("guess keyword: ", keyword) # 直接打开百度搜索结果(针对原项目增加百度搜索结果) # 构建百度搜索URL URL = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=" + keyword + "&rsv_pq=c5275ac400006206&rsv_t=934bk5QLv0mlKbgJEPtAVMjYqGoybaZuUGqUdJ2Krw%2B2qr2LsF5TvhzzmcU&rqlang=cn&rsv_enter=1&rsv_sug3=4&rsv_sug1=2&rsv_sug7=100&rsv_sug2=0&inputT=2869&rsv_sug4=3213" # 设定特定浏览器打开链接 # 替换为自己的chrome浏览器安装位置(同样支持支持火狐浏览器) # chrome_path = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" # webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path), 1) # webbrowser.get('chrome').open_new_tab(URL) # 使用默认浏览器打开链接 webbrowser.open(URL) # 原作者使用百度知道搜索结果及其后续处理 answers = zhidao_search(keyword=keyword, default_answer_select=default_answer_number, timeout=timeout) answers = filter(None, answers) for text in answers: print('=' * 70) text = text.replace("\u3000", "") if len(text) > 120 and text_summary: sentences = get_summary(text, summary_sentence_count) sentences = filter(None, sentences) if not sentences: print(text) else: print("\n".join(sentences)) else: print("\n".join(textwrap.wrap(text, width=45))) end = time.time() print("use {0} 秒".format(end - start))
def main(): args = parse_args() timeout = args.timeout start = time.time() text_binary = analyze_current_screen_text( directory=data_directory, compress_level=image_compress_level[0] ) keyword = get_text_from_image( image_data=text_binary, ) if not keyword: print("text not recognize") return keyword = keyword_normalize(keyword) print("guess keyword: ", keyword) answers = zhidao_search( keyword=keyword, default_answer_select=default_answer_number, timeout=timeout ) answers = filter(None, answers) for text in answers: print('=' * 70) text = text.replace("\u3000", "") if len(text) > 120 and text_summary: sentences = get_summary(text, summary_sentence_count) sentences = filter(None, sentences) if not sentences: print(text) else: print("\n".join(sentences)) else: print("\n".join(textwrap.wrap(text, width=45))) end = time.time() print("use {0} 秒".format(end - start))
def test_baidu_ocr(self): """ test baidu ocr :return: """ from core.ocr.baiduocr import get_text_from_image print("test baidu ocr") app_id = "10661627" app_key = "h5xcL0m4TB8fiiFWoysn7uxt" app_secret = "HGA1cgXzz80douKQUpII7K77TYWSGcfW" with open("screenshots/text_area.png", "rb") as fp: message = get_text_from_image(fp.read(), app_id, app_key, app_secret, 5) answers = zhidao_search( keyword=message, default_answer_select=default_answer_number, timeout=5) answers = filter(None, answers) print("".join(answers))
def test_baidu_ocr(self): """ test baidu ocr :return: """ from core.ocr.baiduocr import get_text_from_image print("test baidu ocr") app_id = "10661627" app_key = "h5xcL0m4TB8fiiFWoysn7uxt" app_secret = "HGA1cgXzz80douKQUpII7K77TYWSGcfW" with open("screenshots/text_area.png", "rb") as fp: message = get_text_from_image(fp.read(), app_id, app_key, app_secret, 5) answers = zhidao_search( keyword=message, default_answer_select=default_answer_number, timeout=5 ) answers = filter(None, answers) print("".join(answers))