資源簡介
微信跳一跳外掛實現,原文地址:http://blog.csdn.net/xiangzhihong8/article/details/79140668

代碼片段和文件信息
import?cv2?as?cv
img?=?cv.imread(“4.png“)
player_template?=?cv.imread(‘player.png‘)
player?=?cv.matchTemplate(img?player_template?cv.TM_CCOEFF_NORMED)
min_val?max_val?min_loc?max_loc?=?cv.minMaxLoc(player)
corner_loc?=?(max_loc[0]?+?50?max_loc[1]?+?150)
player_spot?=?(max_loc[0]?+?25?max_loc[1]?+?150)
#繪制player位置標記
cv.rectangle(img?max_loc?corner_loc?(0?0?255)?5)
cv.circle(img?player_spot?10?(255?0?0)?-1)
img_blur?=?cv.GaussianBlur(img?(5?5)?0)?#高斯模糊
canny_img?=?cv.Canny(img_blur?1?10)?#邊緣檢測
height?width?=?canny_img.shape
#消除多余的頭部
for?y?in?range(max_loc[1]?max_loc[1]+150):
????for?x?in?range(max_loc[0]?max_loc[0]+50):
????????canny_img[y][x]?=?0
crop_img?=?canny_img[300:int(height/2)?0:width]?#裁切
crop_h?crop_w?=?crop_img.shape
center_x?center_y?=?0?0?#臨時變量
max_x?=?0
#計算中央點
for?y?in?range(crop_h):
????for?x?in?range(crop_w):
????????if?crop_img[y?x]?==?255:
????????????if?center_x?==?0:
????????????????center_x?=?x
????????????if?x?>?max_x:
????????????????center_y?=?y
????????????????max_x?=?x
cv.circle(crop_img?(center_x?center_y)?10?255?-1)
block_center?=?(center_x?center_y+300)?#中央點
cv.circle(img?block_center?10?255?-1)?#繪制落腳點
cv.line(img?player_spot?block_center?(0?255?0)?5)?#繪制直線
print(“玩家位置“?player_spot)
print(“落點位置“?(center_x?center_y+300))
cv.namedWindow(‘img‘?cv.WINDOW_KEEPRATIO)
cv.imshow(“img“?img)
cv.waitKey(0)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-21?22:37??OpenCV_Wechat_jump-master\
?????目錄???????????0??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\
?????文件?????????589??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\Wechat_jump.iml
?????文件?????????199??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\misc.xm
?????文件?????????274??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\modules.xm
?????文件?????????233??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\other.xm
?????文件?????????180??2018-01-21?22:37??OpenCV_Wechat_jump-master\.idea\vcs.xm
?????文件???????48152??2018-01-21?22:37??OpenCV_Wechat_jump-master\1.png
?????文件???????63536??2018-01-21?22:37??OpenCV_Wechat_jump-master\2.png
?????文件???????61327??2018-01-21?22:37??OpenCV_Wechat_jump-master\3.png
?????文件???????61729??2018-01-21?22:37??OpenCV_Wechat_jump-master\4.png
?????文件??????????22??2018-01-21?22:37??OpenCV_Wechat_jump-master\README.md
?????文件????????1522??2018-01-21?22:37??OpenCV_Wechat_jump-master\play.py
?????文件????????8701??2018-01-21?22:37??OpenCV_Wechat_jump-master\pla
?????文件??????279616??2018-01-21?22:37??OpenCV_Wechat_jump-master\test.png
- 上一篇:設計模式課后習題源代碼
- 下一篇:畫跟蹤精確度圖的程序.zip
評論
共有 條評論