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/ Traceback (most recent call last): File “C: \ Users \ JUCABALL \ Desktop \ camera_stream_openCV-master \”, 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

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('', cv2.CAP_DSHOW)  #ipwebcam address

while True:      #while true, read the camera
    ret, frame =
    ret1, frame1 =
    ret2, frame2 =

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

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


The error occurs on this line:


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):
    if (ret2):

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.

Hello madam, We have the same objective to our thesis. Have you figure it out?
We need also to synchronize the webcam and phone device to record it at the same time.
Thx for the response madam. :slight_smile: