๐จ๐ผ๐ป๊ฐ๋ฐ/OpenCV
OpenCV - ํ์ด์ฌ cv2 ์ด๋ฏธ์ง ์์ ํน์ ์ด๋ฏธ์ง ๊ฐ์งํ๊ธฐ
Janger
2023. 1. 16. 12:28
728x90
def isExistImage(a, b, c=0.65):
print("์ด๋ฏธ์ง ์กด์ฌ ์ฌ๋ถ")
img_rgb = cv2.imread(a)
template = cv2.imread(b)
h, w = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = c
loc = np.where(res >= threshold)
return len( loc[0] ) != 0
print(isExistImage("screen.png", "target.png")) # True or False
def getMatchPosition(a, b, c=0.65):
print("์ด๋ฏธ์ง ์์น ๊ฐ์ ธ์ค๊ธฐ")
img_rgb = cv2.imread(a)
template = cv2.imread(b)
h, w = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = c
loc = np.where(res >= threshold)
if len( loc[0] ) == 0:
return False
x, y = loc[1][0], loc[0][0]
return (x, y)
print(getMatchPosition("screen.png", "target.png")) # (x, y) or False
์ฐธ๊ณ :
https://iagreebut.tistory.com/77
[OpenCV] ์ด๋ฏธ์ง์์ ํน์ ์ด๋ฏธ์ง ์ฐพ์๋ด๊ธฐ
๋ต์ง์์ ํด๋น ๋ต์ ์์ญ๋ง์ ์ถ์ถํ๊ธฐ ์ํด์๋ ๋ค์๊ณผ ๊ฐ์ "๋ต"์ด๋ผ๋ ์ด๋ฏธ์ง๋ฅผ ๋ต์ง ํ์ด์ง๋ด์์ ์ฐพ์๋ธ ํ ํด๋น ์ด๋ฏธ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ทธ ์๋๋ฅผ ์๋ฅด๋ฉด ๋๋ค ๊ทธ๋์ ์ผ๋จ ์ด๋ฒ ๊ฒ์๊ธ์์
iagreebut.tistory.com
728x90