Печать матрицы внутри функции, вызываемой в цикле for - PullRequest
0 голосов
/ 03 апреля 2020

Я пытаюсь построить игру ti c ta c toe, используя openCV и веб-камеру, у меня настроено обнаружение жестких кругов, и я могу получить из этого координаты, однако при попытке распечатать местоположение круги с использованием матрицы 3x3 Я получаю эту ошибку.

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')

Это то, что я использую.

def quadrantFinder(x, y):
    # This function will take the coordinates of a circle and find its location
    if x <= 200 & y >= 300:
        arr[2][0] = 1
        print("array quadrant 6" + arr)
    else:
        print ("none of the above")
    return

arr = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])

for (x, y, r) in circles:
    # draw the circle in the output image, then draw a rectangle in the image
    # corresponding to the center of the circle
    cv2.circle(output, (x, y), r, (0, 255, 0), 4)
    cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
    quadrantFinder(x, y) 

Я должен получить что-то вроде этого

[0,0,0,
 0,0,0,
 1,0,0]

1 Ответ

0 голосов
/ 03 апреля 2020

решил, проблема была в том, что я должен был вернуть arr в функцию quadrantFinder и распечатать эту функцию в течение l oop

, вот так

def quadrantFinder(x, y):
    # This function will take the coordinates of a circle and find its location
    if x <= 200 & y >= 300:
        arr[2][0] = 1
        return arr
    else:
        return "none of the above"

затем в для л oop

for (x, y, r) in circles:
    # draw the circle in the output image, then draw a rectangle in the image
    # corresponding to the center of the circle
    cv2.circle(output, (x, y), r, (0, 255, 0), 4)
    cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
    print(quadrantFinder(x, y))
...