python实现外挂自动学习网络课程实例
全套源碼下載地址:https://download.csdn.net/download/bvngh3247/10783804
碩士畢業后,一直從事算法工程師,具有豐富的深度學習,圖像視頻處理經驗,因此錄制了一些課程,歡迎大家觀看,有問題可以找我私聊:QQ:81664352,謝謝
基于web端的人臉識別算法視頻教程
1.掌握深度學習圖像處理(基于keras、tensorflow、opencv)
2.掌握web前后端設計(基 于flask框架)
3.開發基于web端的深度學習圖像,把web端應用與人工智能相結合
視頻教程
https://edu.csdn.net/course/detail/28400/391614?pre_view=1
聲明:只是用來學習,請不要使用非法用途,責任自負
工具
使用python 3.6版本,安裝如下庫:
安裝win32api
pip3 install pywin32
安裝PIL
pip install Pillow
安裝pyautogui
pip install pyautogui
安裝numpy
pip install numpy
安裝cv2
pip install opencv-python
安裝matplotlib
pip install matplotlib
使用SPY查看相關窗口標題, 類名。此標題唯一, 故可以以此來查找相關窗口
得到窗口句柄
window_title = '課件學習 - Google Chrome'screen_width = win32api.GetSystemMetrics(0)screen_height = win32api.GetSystemMetrics(1) hwnd = win32gui.FindWindow(win32con.NULL,window_title) if hwnd == 0 :error_exit('%s not found' % window_title)exit()else:print('hwnd = %x'%(hwnd))window_left,window_top,window_right,window_bottom = win32gui.GetWindowRect(hwnd)主循環
原理:主要通信截圖屏幕的圖片,然后通過模板圖像與之比較,如果出現我們需要的場景,那么得到對應的位置坐標,然后自動調用點擊功能,從而實現自動化操作。那么這里主要使用opencv的兩個算法,一個是圖像相似度打分算法,另一個是圖像搜索算法。
while True:grab_image = snapshot.grab_screen(deal_left,deal_top,deal_right,deal_bottom)#grab_image.show()grab_image.save(r'.\tmp_output\full_screen.png')#big pic size = 1936x1056full_screen_w = 1936full_screen_h = 1056pixel_core_x = 877.0pixel_core_y = 25.0deal_left = window_left #window_left + kejian_x / full_screen_w * window_width - 100deal_top = window_top + pixel_core_y / full_screen_h * window_height - 20deal_right = window_left + window_width#window_left + kejian_x / full_screen_w * window_width + 150 deal_bottom = window_top + pixel_core_y / full_screen_h * window_height + 20grab_image = snapshot.grab_screen(deal_left,deal_top,deal_right,deal_bottom)search_pic = r'.\tmp_output\search_kejianxuexi.png' grab_image.save(search_pic)#find kejian_temtemplate_pic = r'.\template\kejian_tem.png'num, w, h, pos_list = match.lookup_pos(template_pic, search_pic)left = 0top = 0find_kejian_flag = 0no_voice_flag = 0if num == 1:left = pos_list[0][0]top = pos_list[0][1]find_kejian_flag = 1else:print('==========warning search_kejianxuexi = ' + str(num))find_kejian_flag = 0if find_kejian_flag:img_rgb = cv2.imread(search_pic)img_rgb = img_rgb[top:top + h, left:left + w + 80, :] # h, w, ccompare_pic = r'.\tmp_output\kejianxuexi_compare.png'cv2.imwrite(compare_pic, img_rgb)temp_voice = r'.\template\kejianhua_tem_voice.png'temp_no_voice = r'.\template\kejianhua_tem_no_voice.png'no_voice_flag = match.score_pic(compare_pic, temp_voice, temp_no_voice)if no_voice_flag:print('===============find no_voice_flag')find_question_flag = find_question()if find_question_flag:#secondtime.sleep(5)find_daan()time.sleep(5)find_quding()find_chongbo_flag = find_chong_bo()if find_question_flag and find_chongbo_flag:print('========>find_chongbo_flag and find_chongbo_flag')exit()if find_chongbo_flag:weikaishi() else:print('===============every thing is ok')time.sleep(2) #exit(0)
圖像相似度打分算法
那么如何判斷一張被PS過的圖片是否與另一張圖片本質上相同呢?比較簡單、易用的解決方案是采用感知哈希算法(Perceptual Hash Algorithm)。
感知哈希算法是一類算法的總稱,包括aHash、pHash、dHash。顧名思義,感知哈希不是以嚴格的方式計算Hash值,而是以更加相對的方式計算哈希值,因為“相似”與否,就是一種相對的判定。
aHash:平均值哈希。速度比較快,但是常常不太精確。
pHash:感知哈希。精確度比較高,但是速度方面較差一些。
dHash:差異值哈希。Amazing!精確度較高,且速度也非常快。因此我就選擇了dHash作為我圖片判重的def
圖像搜索算法
使用res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
def lookup_pos(template_pic, search_pic):img_rgb = cv2.imread(search_pic)img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)img = img_gray#print(img.shape)template = cv2.imread(template_pic,0)w, h = template.shape[::-1]res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)threshold = 0.95loc = np.where( res >= threshold)num = 0left = 0top = 0pos_list = []for pt in zip(*loc[::-1]):cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)left = pt[0]top = pt[1]pos_list.append(pt)num = num + 1res = res*256cv2.imwrite(r'.\tmp_output\out.png', img_rgb)cv2.imwrite(r'.\tmp_output\res.png', res)return num, w, h, pos_list總結
以上是生活随笔為你收集整理的python实现外挂自动学习网络课程实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安装matlab时常用模块,matlab
- 下一篇: 超参数调整——网格搜索