def getAnswer(question): keyword = ''.join(question.split()) # 识别的问题文本 print(keyword) convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 print( '#########################################################################' ) for result in results: # print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 if (result.abstract == '百度软广,当前代码版本不予摘要'): pass else: print(getReData(QandA.aList, result.abstract)) print('{0}'.format(result.abstract)) # 此处应有格式化输出 print( '#########################################################################' ) count = count + 1 if (count == 3): break
def get_answer(filePath): with open(filePath, 'rb') as fp: image = fp.read() respon = client.basicGeneral(image) titles = respon['words_result'] #获取问题 ans = '' for title in titles: ans = ans +title['words'] print(ans) #打印问题 keyword = ans #识别的问题文本 convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 for result in results: #print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(result.abstract)) # 此处应有格式化输出 count=count+1 if(count == 2): #这里限制了只显示2条结果,可以自己设置 break
def getBaiduData(): global arrayAnswer print("执行获取问题") # 获取题目 region = Image.open(r"./screenshot.png").crop( (70, 300, w - 70, 800)) # 裁剪的区域 百万超人 手机1080*1920 高度范围300~600 # 保存im region.save("./crop_test1.png") # im = Image.open(r"./crop_test1.png") text = pytesseract.image_to_string(im, lang='chi_sim').replace("\n", "") print("问题是::::: " + text) keyword = ''.join(text) # 识别的问题文本 keyword = re.sub(r"\d+.", "", keyword, 1) convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 print('', end='\n\n') for result in results: abstract = result.abstract # print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(abstract), end='\n\n') # 此处应有格式化输出 flag = "" for answer in arrayAnswer: if abstract.find(answer) > 0: flag = answer print("答案1选============ " + answer, end='\n\n') # print("答案1选============ " + answer, end='\n\n') # # if flag == "": # flag.strip() # for answer in [an for an in arrayAnswer if an.strip() != '']: # na = '.*'.join([i for i in answer]) + '.*' # print('na is ', na, 'abstract is ', abstract) # if re.search(na, abstract): # print("答案2选============ " + answer, end='\n\n') count = count + 1 if (count == 2): break
def getBaiduData(): global arrayAnswer print("执行获取问题") # 获取题目 region = Image.open(r"./screenshot.png").crop((70, 300, w - 70, 800)) # 裁剪的区域 百万超人 手机1080*1920 高度范围300~600 # 保存im region.save("./crop_test1.png") # im = Image.open(r"./crop_test1.png") text = pytesseract.image_to_string(im, lang='chi_sim').replace("\n", "") print("问题是::::: " + text) keyword = ''.join(text) # 识别的问题文本 keyword = re.sub(r"\d+.", "", keyword, 1) convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 print('', end='\n\n') for result in results: abstract = result.abstract # print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(abstract), end='\n\n') # 此处应有格式化输出 flag = "" for answer in arrayAnswer: if abstract.find(answer) > 0: flag = answer print("答案1选============ " + answer, end='\n\n') # print("答案1选============ " + answer, end='\n\n') # # if flag == "": # flag.strip() # for answer in [an for an in arrayAnswer if an.strip() != '']: # na = '.*'.join([i for i in answer]) + '.*' # print('na is ', na, 'abstract is ', abstract) # if re.search(na, abstract): # print("答案2选============ " + answer, end='\n\n') count = count + 1 if (count == 2): break
def separateClassesAndPlaceName(): dbscanner_path = './utils/dbscaner_200m_10minutes_50eps_5minPts.pkl' classes_save_dir = './classes/classes_200_10_50_5/' place_name_save_path = './utils/dbscaner_200m_10minutes_50eps_5minPts.txt' dbscanner = pickle.load(open(dbscanner_path, 'r')) pointList = [] for key in dbscanner.m_reverse.keys(): print key out = [] kk = [] for i in dbscanner.m_reverse[key]: lat = dbscanner.points[i].lat lon = dbscanner.points[i].lon point = Point(lat, lon, 39755.9735300926, 'asdfasdf') string = '{},{},0,0,0,0,0'.format(lat, lon) out.append(point) kk.append(string) save_path = '{}class_{}.plt'.format(classes_save_dir, key) remove(save_path) save(kk, save_path) lat, lon = computeMeanCoord(out) pointList.append([key, lat, lon]) placeNameList = [] for item in pointList: key = item[0] lat = item[1] lon = item[2] business = search(lat, lon) result = '{}:{}'.format(key, business) placeNameList.append(result) print '{}:{}'.format(key, business) save(placeNameList, place_name_save_path)
def map_baidu(keyword, mode): # mode=1则输出搜索结果 convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) search_num = results[0] if mode == 1: count = 0 for result in results[1:]: #print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(result.abstract)) # 此处应有格式化输出 count = count + 1 if (count == 2): break return search_num
image = get_file_content(r"./crop_test1.png") respon = client.basicGeneral(image) titles = respon['words_result'] #获取问题 ans = '' for title in titles: ans = ans + title['words'] print(ans) #打印问题 keyword = ans #识别的问题文本 convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 for result in results: #print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(result.abstract)) # 此处应有格式化输出 count = count + 1 if (count == 2): #这里限制了只显示2条结果,可以自己设置 break end = time.time() print('程序用时:' + str(end - start) + '秒')
result = reduce(concat, data) + '|' + reduce(concat, labels) print result data_label.append(result) random.shuffle(data_label) index = int(len(data_label)*0.8) train_data_label = data_label[0:index] test_data_label = data_label[index:len(data_label)] save(train_data_label, train_save_path) save(test_data_label, test_save_path) if __name__ == '__main__': dbscanner = pickle.load(open('./utils/dbscaner_100m_5minutes_50eps_5minPts.pkl', 'r')) pointList = [] for key in dbscanner.m_reverse.keys(): out = [] for i in dbscanner.m_reverse[key]: lat = dbscanner.points[i].lat lon = dbscanner.points[i].lon point = Point(lat, lon, 39755.9735300926, 'asdfasdf') # string = '{},{},0,0,0,0,0'.format(lat, lon) out.append(point) save(out, './classes_100_5_50_5/class_{}.plt'.format(key)) lat, lon = computeMeanCoord(out) pointList.append([key, lat, lon]) for item in pointList: key = item[0] lat = item[1] lon = item[2] business = search(lat, lon) print '{}:{}'.format(key, business)
def autoChoose(): start_time = time.time() # screencap and pull os.system('adb shell screencap -p /sdcard/screen_shot.png') os.system('adb pull /sdcard/screen_shot.png .') # crop image image = Image.open('./screen_shot.png') image_size = image.size print image_size width = image_size[0] height = image_size[1] region = image.crop((0, height * 0.15, width, height * 0.7)) region.save('./screen_shot_crop.png') # OCR aa = AipOcr(APP_ID, API_KEY, SECRET_KEY) filepath = './screen_shot_crop.png' with open(filepath, 'rb') as fp: image = fp.read() ret = aa.basicGeneral(image) # question region if ret: ask = '' lines = ret['words_result'] if len(lines) <= 4: ask = lines[0]['words'].split('.')[-1] elif len(lines) == 5: ask = lines[0]['words'].split('.')[-1] + lines[1]['words'] elif len(lines) > 5: ask = lines[0]['words'].split( '.')[-1] + lines[1]['words'] + lines[2]['words'] if len(lines) >= 3: Coption = lines[-1]['words'] Boption = lines[-2]['words'] Aoption = lines[-3]['words'] else: Aoption, Boption, Coption = ' ', ' ', ' ' keyword = ask print keyword convey = 'n' end_time = time.time() if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 N = {'A': 0, 'B': 0, 'C': 0} for result in results: N['A'] += result.abstract.count(Aoption) N['B'] += result.abstract.count(Boption) N['C'] += result.abstract.count(Coption) # Qred = result.abstract.replace(keyword, '\033[1;30;41m' + keyword + '\033[0m')# '\033[1;30;41m' + Aoption + '\033[0m' Ared = result.abstract.replace( Aoption, '\033[1;31m' + Aoption + '\033[0m') #'\033[1;30;41m' + Aoption + '\033[0m' Bred = Ared.replace(Boption, '\033[1;32m' + Boption + '\033[0m') #'\033[1;32m' + 'Boption' + '\033[0m' Cred = Bred.replace(Coption, '\033[1;34m' + Coption + '\033[0m') #'\033[1;34m' + 'Coption' + '\033[0m' print('\033[1;30;41m' + result.title + '\033[0m') print ' ' print Cred print ' ' count = count + 1 if count == 4: break print '\033[1;31;40m', '答案: ', max(N.items(), key=lambda x: x[1])[0], '\033[0m' print(r'run time: ' + str(end_time - start_time) + 's')
response = urllib.request.urlopen(request) content = bytes.decode(response.read()) if (content): decode_json = json.loads(content) print(decode_json['textResult']) #pyperclip.copy(''.join(decode_json['textResult'].split())) keyword = ''.join(decode_json['textResult'].split()) #识别的问题文本 convey = 'n' if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 for result in results: #print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(result.abstract)) # 此处应有格式化输出 count=count+1 if(count == 2): break end = time.time() print('程序用时:'+str(end-start)+'秒')