在Google colab中尝试此代码,但不知道如何修复它

2024-10-01 13:40:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用了cv2_imshow

import cv2
from google.colab.patches import cv2_imshow
frameWidth = 640
frameHeight = 480
cap = cv2.VideoCapture(0)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10,150)
while True:
    success, img = cap.read()
    cv2_imshow(img)
    if cv2.waitKey(1) and 0xFF == ord('q'):
        break

得到了这个错误

AttributeError                            Traceback (most recent call last)
<ipython-input-17-8302024201cc> in <module>()
     10 while True:
     11     img = cap.read()
---> 12     cv2_imshow(img)
     13     if cv2.waitKey(1) and 0xFF == ord('q'):
     14         break

/usr/local/lib/python3.6/dist-packages/google/colab/patches/__init__.py in cv2_imshow(a)
     20       image.
     21   """
---> 22   a = a.clip(0, 255).astype('uint8')
     23   # cv2 stores colors as BGR; convert to RGB
     24   if a.ndim == 3:

AttributeError: 'tuple' object has no attribute 'clip'

Tags: importtrueimgreadifgooglecv2cap