# Buggy code
def __init__(self, sources="streams.txt", img_size=640):
    self.mode = "stream"
    self.img_size = img_size

    if os.path.isfile(sources):
        with open(sources, "r") as f:
            sources = [
                x.strip() for x in f.read().strip().splitlines() if len(x.strip())
            ]
    else:
        sources = [sources]

    n = len(sources)
    self.imgs = [None] * n
    self.sources = sources
    for i, s in enumerate(sources):
        # Start the thread to read frames from the video stream
        print("%g/%g: %s... " % (i + 1, n, s), end="")
        cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s)
        assert cap.isOpened(), "Failed to open %s" % s
        w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        fps = cap.get(cv2.CAP_PROP_FPS) % 100
        _, self.imgs[i] = cap.read()  # guarantee first frame
        thread = Thread(target=self.update, args=([i, cap]), daemon=True)
        print(" success (%gx%g at %.2f FPS)." % (w, h, fps))
        thread.start()
    print("")  # newline

    # check for common shapes
    s = np.stack(
        [letterbox(x, new_shape=self.img_size)[0].shape for x in self.imgs], 0
    )  # inference shapes
    self.rect = np.unique(s, axis=0).shape[0] == 1  # rect inference if all shapes equal
    if not self.rect:
        print(
            "WARNING: Different stream shapes detected. For optimal performance supply similarly-shaped streams."
        )


# Traceback (RuntimeError)
** On entry to DGEBAL parameter number  3 had an illegal value
** On entry to DGEHRD  parameter number  2 had an illegal value
** On entry to DORGHR DORGQR parameter number  2 had an illegal value
** On entry to DHSEQR parameter number  4 had an illegal value
Traceback (most recent call last):
File "D:\Softwares\Python\lib\site-packages\numpy\__init__.py", line 305, in <module>
_win_os_check()
File "D:\Softwares\Python\lib\site-packages\numpy\__init__.py", line 302, in _win_os_check
raise RuntimeError(msg.format(__file__)) from None
RuntimeError: The current Numpy installation ('D:\\Softwares\\Python\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86
Traceback (most recent call last):
File ".\detect.py", line 5, in <module>
import cv2
File "D:\Softwares\Python\lib\site-packages\cv2\__init__.py", line 5, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import

# Fixed code
def __init__(self, sources="streams.txt", img_size=640):
    self.mode = "stream"
    self.img_size = img_size

    if os.path.isfile(sources):
        with open(sources, "r") as f:
            sources = [
                x.strip() for x in f.read().strip().splitlines() if len(x.strip())
            ]
    else:
        sources = [sources]

    n = len(sources)
    self.imgs = [None] * n
    self.sources = [clean_str(x) for x in sources]  # clean source names for later
    for i, s in enumerate(sources):
        # Start the thread to read frames from the video stream
        print("%g/%g: %s... " % (i + 1, n, s), end="")
        cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s)
        assert cap.isOpened(), "Failed to open %s" % s
        w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        fps = cap.get(cv2.CAP_PROP_FPS) % 100
        _, self.imgs[i] = cap.read()  # guarantee first frame
        thread = Thread(target=self.update, args=([i, cap]), daemon=True)
        print(" success (%gx%g at %.2f FPS)." % (w, h, fps))
        thread.start()
    print("")  # newline

    # check for common shapes
    s = np.stack(
        [letterbox(x, new_shape=self.img_size)[0].shape for x in self.imgs], 0
    )  # inference shapes
    self.rect = np.unique(s, axis=0).shape[0] == 1  # rect inference if all shapes equal
    if not self.rect:
        print(
            "WARNING: Different stream shapes detected. For optimal performance supply similarly-shaped streams."
        )