0

I used 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

got this error

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'
Sanket Singh
  • 1,246
  • 1
  • 9
  • 26
  • [check if this](https://stackoverflow.com/questions/37761340/python-opencv-face-detection-code-sometimes-raises-tuple-object-has-no-attrib) solves the problem – Maghil vannan Jun 25 '20 at 18:30
  • Does this answer your question? [Python OpenCV face detection code sometimes raises \`'tuple' object has no attribute 'shape'\`](https://stackoverflow.com/questions/37761340/python-opencv-face-detection-code-sometimes-raises-tuple-object-has-no-attrib) – Maghil vannan Jun 25 '20 at 18:31

1 Answers1

0

Since you are using cap = cv2.VideoCapture(0) to capture video from your webcam and colab is running in browser so you will need to use web APIs to access local hardware like a camera.

Here's an example showing how to capture an image from your local webcam in Colab: https://colab.research.google.com/notebooks/snippets/advanced_outputs.ipynb#scrollTo=2viqYx97hPMi

Mayur Deshmukh
  • 394
  • 2
  • 4