Error: Open two cameras at the same time in Python - OPENCV (Pycharm) - error (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Hello everyone, happy day, I am trying to synchronize two cameras (my local computer) and the camera of my cell phone with IP Web cam, however when running the code it generates an error and the two cameras that I have previously opened are closed (see photo ). What would this be due to? Thanks for your help!

ERROR → C: \ Users \ JUCABALL \ AppData \ Local \ Programs \ Python \ Python39 \ python.exe C: /Users/JUCABALL/Desktop/camera_stream_openCV-master/main.py Traceback (most recent call last): File “C: \ Users \ JUCABALL \ Desktop \ camera_stream_openCV-master \ main.py”, line 20, in cv2.imshow (‘cam1’, frame1) cv2.error: OpenCV (4.5.4-dev) D: \ a \ opencv-python \ opencv-python \ opencv \ modules \ imgproc \ src \ color.cpp: 182: error: (-215: Assertion failed)! _src .empty () in function ‘cv :: cvtColor’

Process finished with exit code 1

Python 3.9
opencv-python 4.5.4.58

This is the tabs - after fews seconds tabs close [Tabs, 2 cameras][1]

This is my code

import numpy as np
import cv2


#capture the webcam
vid1 = cv2.VideoCapture(0, cv2.CAP_DSHOW)
vid2 = cv2.VideoCapture(1, cv2.CAP_DSHOW)
vid3 = cv2.VideoCapture('http://192.168.0.11:8080/video', cv2.CAP_DSHOW)  #ipwebcam address



while True:      #while true, read the camera
    ret, frame = vid1.read()
    ret1, frame1 = vid2.read()
    ret2, frame2 = vid3.read()

    if (ret):
        cv2.imshow('cam0',frame)    #frame with name and variable of the camera
        cv2.imshow('cam1',frame1)
        cv2.imshow('cam3',frame2)


    if cv2.waitKey(1) & 0xFF == ord('q'):      #to break the loop and terminate the program
        break

vid1.release()
vid2.release()
vid3.release()

The error occurs on this line:

        cv2.imshow('cam1',frame1)

and the text of the error suggests the image is empty.

You only check ret earlier, yet ret1 and ret2 may indicate failure.

So for starters I’d try writing code like:

    if (ret):
        cv2.imshow('cam0',frame)    #frame with name and variable of the camera
    if (ret1):
        cv2.imshow('cam1',frame1)
    if (ret2):
        cv2.imshow('cam3',frame2)

When an error occurs, your program is shutting down, and thus the tabs close. You could research exception handling to catch errors and keep the program running.