stepacool / Eye-Tracker

Eye tracking using OpenCV, Python.
276 stars 84 forks source link

Unable to initialize camera #13

Open rsingh2083 opened 4 years ago

rsingh2083 commented 4 years ago

Changed the lines as suggested by 3 other people on the forum to

 def start_webcam(self):
        if not self.camera_is_running:
            self.capture = cv2.VideoCapture(0)  # VideoCapture(0) sometimes drops error #-1072875772
            if self.capture is None:
                self.capture = cv2.VideoCapture(0)

But still this error :--

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream: Device or resource busy
VIDEOIO ERROR: V4L: can't open camera by index 0
Traceback (most recent call last):
  File "main.py", line 45, in update_frame
    self.display_image(base_image)
  File "main.py", line 100, in display_image
    if len(img.shape) == 3:
AttributeError: 'NoneType' object has no attribute 'shape'
Aborted (core dumped)
terceranexus6 commented 3 years ago

Hi! I had the same error. The author explains in this issue it might be for the cam setting in line 28-30. I checked this stackoverflow following that clue, and simply changing the line 28 with:

self.capture = cv2.VideoCapture("/dev/video0")

did the trick (from Linux). If you are unsure check ls /dev/ | grep *video* or something like that for your cam name in devices. Good luck!