Search code examples
pythontypeerrorpython-3.8opencvtraceback

Traceback - TypeError: 'set' object is not subscriptable


I've been working on an AI, where it'll solve the a solitaire card game. Suddenly, after a few changes (which I do not know how) the console is giving me error, which is:

The following code, that the error refers to:

def CatchingCard(self, imageName, accurate=0.90):
    finalPath = os.path.join(os.getcwd(),
                                 self.vals.ImageDepository, imageName)
    pos = TryToFindCardInGame(
        finalPath, accurate)
    if pos[0] != -1:
        EasyCatch(finalPath, pos, "left", 0, False, offset=5)
        return True
    return False

And the TryToFindCardInGame:

def TryToFindCardInGame(image, accurate=0.8):
cardImage = pyautogui.screenshot()
if not retina_enabled:
    pass
else:
    assert isinstance(cardImage.thumbnail, object)
    cardImage.thumbnail
colorScheme = np.array(cardImage)
colorDark = cv2.cvtColor(colorScheme, cv2.COLOR_BGR2GRAY)
colorLayout = cv2.imread(image, 0)
colorLayout.shape[::-1]

cv_matching = cv2.matchTemplate(colorDark, colorLayout, cv2.TM_CCOEFF_NORMED)
max_loc: object
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(cv_matching)
assert isinstance(max_val, object)
if accurate <= max_val:
    return max_loc
return {-1, -1}

Error I am getting:

if pos[0] != -1:
TypeError: 'set' object is not subscriptable

I've been searching around, couldn't find a solution for my case. What should I look for?


Solution

  • Looks like TryToFindCardInGame returns a set, which is different from a list. https://docs.python.org/3.5/library/stdtypes.html#set-types-set-frozenset