#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Version : 1.0
# @Author : QQ736592720
# @Datetime : 2022/1/9 18:14
# @Project : opencv
# @File : opencv_HKYZhk验证破J.py
def findPic(img,rx=34,ry=32): #
'''
:param img: img截图取右半
:param rx: sm外框的一半是34
:param ry: 32
:return: (x,y)
'''
sm=np.ones((20,20),np.uint8)
sm[3:,3],sm[3, 3:]=255,255
img = cv.imread(img, 1) # 0是灰度图像 1是彩色图像'''"./":代表目前所在的目录。" .
blured = cv.GaussianBlur(img, (3, 3), 0) # sigmaX的值自动根据ksize可以计算出
gray = cv.cvtColor(blured, cv.COLOR_BGR2GRAY)
canny_ = cv.Canny(gray , 105, 210)# 这个参数比值推荐是1:2或者1:3
result = cv.matchTemplate(canny_, sm, cv.TM_CCORR_NORMED)
max_loc = cv.minMaxLoc(result)[3]
point = max_loc[0] + rx, max_loc[1] + ry
print(point)
# des=cv.rectangle(img,max_loc,answer,(0,0,255),1)
des = cv.circle(img, point, 3, (0, 0, 255), 1)
des=cv.putText(des,str(point),(35,220), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv.imshow("min_loc", des)
cv.waitKey(0)
cv.destroyAllWindows()
return point
if __name__ == '__main__':
findPic(r'ymz1 (1).bmp')
|