Skip to content

Instantly share code, notes, and snippets.

@guilhermemauro
Created March 1, 2017 19:46
Show Gist options
  • Save guilhermemauro/5c3fd25a7b88c1117338c659a0775355 to your computer and use it in GitHub Desktop.
Save guilhermemauro/5c3fd25a7b88c1117338c659a0775355 to your computer and use it in GitHub Desktop.
#compare contour founded with the pattern in X.png and O.png files
def compareContourHSV(cnt):
global player, computer
if cnt is False:
return False
patternX = cv2.cvtColor(cv2.imread('X.png'), cv2.COLOR_BGR2GRAY)
patternX = findBiggestContour(patternX)
resX = cv2.matchShapes(patternX, cnt, 1, 0.0)
patternO = cv2.cvtColor(cv2.imread('O.png'), cv2.COLOR_BGR2GRAY)
patternO = findBiggestContour(patternO)
resO = cv2.matchShapes(patternO, cnt, 1, 0.0)
if resX < 0.9 or resO < 0.9:
if resX < resO:
player = 1
computer = 2
return player
elif resX != 0 and resO != 0:
player = 2
computer = 1
return player
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment