обнаружение объекта opencv требуется целое число (получил тип кортеж) - PullRequest
2 голосов
/ 07 июня 2019

Когда я запускаю свой код, чтобы использовать мою веб-камеру для обнаружения объектов, я получаю следующее сообщение об ошибке:

 frame = cv2.rectangle(open_cv_stream, t1, br, color, 5)

TypeError: требуется целое число (получен кортеж типа)

capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

while True:
    stime = time.time()
    ret, frame = capture.read()

    if ret:
        results = tfnet.return_predict(frame)

        for color, result in zip(colors, results):
            t1 = (result['topleft']['x'], result['topleft']['y'])
            br = (result['bottomright']['x'], result['bottomright'])
            label = result['label']
            confidence = result['confidence']
            text = '{}: {:.0f}%'.format(label,confidence * 100)
            frame = cv2.rectangle(frame, t1, br, color, 5)
            frame = cv2.putText(frame, text, t1, cv2.FONT_ITALIC, 1, (0,0,0),2)
        cv2.imshow('frame',frame)
        print('FPS {:.1f}'.format(1/(time.time() - stime)))
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()

В чем может быть проблема?

Настоящим трассировка:

Building net ...
Source | Train? | Layer description                | Output size
-------+--------+----------------------------------+---------------
WARNING:tensorflow:From C:\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
       |        | input                            | (?, 608, 608, 3)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 608, 608, 32)
…
 Load  |  Yep!  | conv 1x1p0_1    linear           | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 1.0 usage
Finished in 28.833083629608154s

Traceback (most recent call last):
  File "webcam.py", line 38, in <module>
    frame = cv2.rectangle(open_cv_stream, t1, br, color, 5)
TypeError: an integer is required (got type tuple)

1 Ответ

1 голос
/ 07 июня 2019

Я заметил, что вы пропустили ['y'] в вашей переменной br.

 for color, result in zip(colors, results):
        t1 = (result['topleft']['x'], result['topleft']['y'])
        br = (result['bottomright']['x'], result['bottomright']['y'])
        label = result['label']
        confidence = result['confidence']
        text = '{}: {:.0f}%'.format(label,confidence * 100)
        frame = cv2.rectangle(frame, t1, br, color, 5)
        frame = cv2.putText(frame, text, t1, cv2.FONT_ITALIC, 1, (0,0,0),2)

Посмотрите, работает ли это!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...