使用Python的OpenCV模塊識別滑動驗證碼的缺口(推薦)
更新時間:2019年05月10日 14:14:07 作者:Linux社區(qū)
這篇文章主要介紹了使用Python的OpenCV模塊識別滑動驗證碼的缺口,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
最近終于找到一個好的方法,使用Python的OpenCV模塊識別滑動驗證碼的缺口,可以將滑動驗證碼中的缺口識別出來了。
測試使用如下兩張圖片:
target.jpg
template.png
現在想要通過“template.png”在“target.jpg”中找到對應的缺口,代碼實現如下:
# encoding=utf8 import cv2 import numpy as np def show(name): cv2.imshow('Show', name) cv2.waitKey(0) cv2.destroyAllWindows() def main(): otemp = 'template.png' oblk = 'target.jpg' target = cv2.imread(otemp, 0) template = cv2.imread(oblk, 0) w, h = target.shape[::-1] temp = 'temp.jpg' targ = 'targ.jpg' cv2.imwrite(temp, template) cv2.imwrite(targ, target) target = cv2.imread(targ) target = cv2.cvtColor(target, cv2.COLOR_BGR2GRAY) target = abs(255 - target) cv2.imwrite(targ, target) target = cv2.imread(targ) template = cv2.imread(temp) result = cv2.matchTemplate(target, template, cv2.TM_CCOEFF_NORMED) x, y = np.unravel_index(result.argmax(), result.shape) # 展示圈出來的區(qū)域 cv2.rectangle(template, (y, x), (y + w, x + h), (7, 249, 151), 2) show(template) if __name__ == '__main__':
main()運行結果見本文最上面,通過運行結果可以知道,已經正確的找到了缺口位置。
總結
以上所述是小編給大家介紹的使用Python的OpenCV模塊識別滑動驗證碼的缺口,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
相關文章
Queue隊列中join()與task_done()的關系及說明
這篇文章主要介紹了Queue隊列中join()與task_done()的關系及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02Python?pygame項目實戰(zhàn)監(jiān)聽退出事件
這篇文章主要介紹了Python?pygame項目實戰(zhàn)監(jiān)聽退出事件,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08Python?Fuzzywuzzy庫基本函數及模糊字符串匹配應用實戰(zhàn)
fuzzywuzzy?是一個用于模糊字符串匹配的?Python?庫,它基于編輯距離算法,提供了多個函數來比較字符串之間的相似性,在實際開發(fā)中,字符串匹配是一項常見但具有挑戰(zhàn)性的任務,用戶可能犯拼寫錯誤,使用縮寫或者輸入同義詞,因此,我們需要一種方法來處理這些情況2023-12-12