๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘จ๐Ÿผ‍๐Ÿ’ป๊ฐœ๋ฐœ/OpenCV

OpenCV - ํŒŒ์ด์ฌ cv2 ์ด๋ฏธ์ง€ ์†์— ํŠน์ • ์ด๋ฏธ์ง€ ๊ฐ์ง€ํ•˜๊ธฐ

by Janger 2023. 1. 16.
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
๋ฐ˜์‘ํ˜•