Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion Failed on Raspberry Pi 4

Tags:

python

opencv

Have been working on basic code to run multiple cameras on raspberry pi 4 and 3

import numpy as np
import cv2

cap = cv2.VideoCapture(1)

cap2 = cv2.VideoCapture(2)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    ret, frame2 = cap2.read()

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('CAM 1',frame)
    cv2.imshow('CAM 2',frame2)
    #cv2.imshow('gray',gray)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

 # When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

I have been encountering this the following error

Traceback (most recent call last):
  File "/home/pi/Imageprocessing/webcamtest.py", line 16, in <module>
    cv2.imshow('CAM 1',frame)
cv2.error: OpenCV(3.4.3) /home/pi/opencv-3.4.3/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

Tried changing from (-1to 2 ) but no success

One of the cameras turns on but image is displayed. The cameras work on web browser.

System : Raspberry Pi 4 4GB
OS: Buster 
Python version : 2.7 and 3.7.3
Open CV version 3.4.3
Cameras: Logitech C310 720p

Even The Single camera is not working and comes up with the same error

like image 749
Ramnath Bhat Avatar asked Sep 14 '26 20:09

Ramnath Bhat


1 Answers

Try to number your cameras starting from 0 (zero):

cap = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
like image 187
lenik Avatar answered Sep 17 '26 10:09

lenik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!