前幾期在抖音上同名號上為粉絲們送了幾期福利,在收集粉絲發(fā)來的郵件地址的時候,比較痛苦,上百上千的地址,然后再輸入到郵箱發(fā)送內(nèi)容,比較麻煩!所以有了以下的快捷方式: 實現(xiàn)目標 利用python+OPENCV,再結(jié)合上百度AI接口,當然另外還配合了USB攝像頭,實現(xiàn)了批量對群內(nèi)的地址進行采集,然后保存。今天我將全部源碼分享給大家: 打開pycharm開發(fā)工具,在項目中新建 demo.py 文件,文件代碼如下: from aip import AipOcrimport cv2import cv2 as cvimport reimport timeimport numpy as np''' 你的 APPID AK SK '''APP_ID = '你的ID'API_KEY = '你的KEY'SECRET_KEY = '你的SECRET'aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read()# 信息分離,只留EMAIL部分def get_emails(text): emails = re.findall(r'[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+', text) if len(emails) > 0: return emailsdef baiduApi(images): # 定義參數(shù)變量 options = { 'detect_direction': 'true', 'language_type': 'CHN_ENG', } # 調(diào)用通用文字識別接口 time.sleep(1) result = aipOcr.basicGeneral(get_file_content(images), options) words_result=result['words_result'] filename = 'email_list.txt' for i in range(len(words_result)): email = get_emails(words_result[i]['words']) if email != None: print(email[0]) with open(filename,'a',encoding='utf-8') as f: f.writelines(email[0] + '\n') print('完成當前識別任務')# 打開攝像頭拍照cap = cv2.VideoCapture(0)num = 0while True: ret,frame=cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 灰度處理 #顯示在窗口上 cv2.imshow('NO.1', frame) kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) # 銳化 dst = cv.filter2D(frame, -1, kernel=kernel) cv.imshow('NO.2', dst) if cv2.waitKey(100) & 0xff == ord('s'): #key == 's': num += 1 print('識別圖片 %s' % num) path = r'J:/python/kejian/img/' cv2.imwrite('{}{}{}'.format(path, num, '.jpg'), dst, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) # 保存圖片,質(zhì)量為100 baiduApi('{}{}{}'.format(path, num, '.jpg')) elif cv2.waitKey(100) & 0xff == ord('q'): breakcv2.destroyAllWindows()cap.release() 以上的目錄大家自行調(diào)整為自己的目錄即可。 識別結(jié)果如下: |
|