Search code examples
opencvattributespython-3.6frameshapes

rows, cols, _ = frame.shape AttributeError: 'tuple' object has no attribute 'shape'


I am trying to run a code but it gives me this error:

rows, cols, _ = frame.shape AttributeError: 'tuple' object has no attribute 'shape'

I am using OpenCV and python 3.6, I have installed NumPy as well. The application is using a camera to get frames and detects the eyes. the error is here

  import cv2
  import numpy as np
  import dlib
  cap = cv2.VideoCapture(0)

 while True:

frame = cap.read()
#frame = cv2.resize(frame, None, fx=0.8, fy=0.8)
rows, cols, _ = frame.shape
keyboard[:] = (26, 26, 26)
frames += 1
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

could you help me, please?

Thanks


Solution

  • cap.read() returns a tuple of two values. Depending on frame is read correctly/not, first value will be True/False and second value is frame array. In your case you will have to use frame = cap.read()[1]