(旧)コダフォンの日記ブログ(移転しました)

FC2ブログに移転しました。ここいる?

Python OpenCVでスクリーンショット、画像類似度、一致度表示

極メモ

https://tat-pytone.hatenablog.com/entry/2019/03/18/221724

テンプレートマッチングで類似画像を探す

import cv2 #OpenCVのインポート

img = cv2.imread("kokushimusou.jpg") #画像を読み込む

img_gray = cv2.imread("kokushimusou.jpg",0) #画像をグレースケールで読み込む

template = cv2.imread("ton.jpg", 0) #テンプレート画像をグレースケールで読み込む

width, height = template.shape[::-1] #テンプレート画像の幅、高さを取得

result = cv2.matchTemplate(img_gray, template, cv2.TM_CCORR_NORMED) #テンプレートマッチングの実行(比較方法cv2.TM_CCORR_NORMED)

min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) #類似度が最小,最大となる画素の類似度、位置を調べ代入する

top_left = max_loc #最も似ている領域を赤で囲う

bottom_right = (top_left[0] + width, top_left[1] + height) #矩形の右下の座標計算

cv2.rectangle(img,top_left, bottom_right, (0,0,255), 2) #最も似ている領域を赤の矩形で囲う

print(max_val) #最も似ている領域の類似度を表示

cv2.imshow("result",img) #別ウィンドウ"result"を開きmgを表示

cv2.waitKey(0) #キー入力待ち

cv2.destroyAllWindows() #ウインドウを閉じる

http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_tutorials.html

OpenCV Pythonチュートリアル

http://bttb.s1.valueserver.jp/wordpress/blog/2017/08/20/pyautogui%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9-%E7%94%BB%E5%83%8F%E8%AA%8D%E8%A8%BC%E7%B7%A8/

PyAutoGUIの使い方 スクリーンショット・画像認証編

https://qiita.com/eito_2/items/1974f3cfa1f4d101378d

python スクリーンショット

https://boook24.com/?p=369

PyAutoGUIで面倒ごとを自動化しよう

画像の認識