Numpy image display from esp32cam using opencv and tkinter

Hey, everyone! Iam trying to display the numpy image and make an gui using tkinter, but the code had completed succesfully and the image had not beendisplayed. Here is the code:

from tkinter import *
import cv2
from PIL import Image, ImageTk
from urllib.request import urlopen
import numpy as np
app = Tk()
app.geometry("1028x720")
app.title("WHEELS")
app.iconbitmap("disabled-sign.ico")
app.bind('<Escape>', lambda e: app.quit())
label_widget = Label(app)
label_widget.pack()
def open_camera():
    url = 'http://192.168.141.27'
    while True:
        img_resp = urlopen(url)
        imgnp = np.asarray(bytearray(img_resp.read()), dtype="uint8")
        frame = cv2.imdecode(imgnp, cv2.IMREAD_COLOR)
        if frame == None:
            print("error")
        frame = cv2.flip(frame, 1)
        opencv_image = cv2.cvtColor(frame, cv2.COLOR_RGB2BGRA)
        captured_image = Image.fromarray(opencv_image)
        photo_image = ImageTk.PhotoImage(image=captured_image)
        label_widget.photo_image = photo_image
        label_widget.configure(image=photo_image)
        label_widget.after(10, open_camera)
button1 = Button(app, text="Open Camera", command=open_camera, activeforeground="blue")
button1.pack()
app.mainloop()

The error iam getting in terminal is: File

"E:\pycharm_projects\main2.py", line 24, in open_camera
    opencv_image = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

rather use

assert frame is not None, "invalid image!"

and let it crash, where the problem is

(even IF it prints “error” (which tk likely swallowed), it’ll still fail later)

please also debug the lines above in a similar way
(did it really connect ? load an image ? succeeded to decode it ? something went wrong there !)

btw, imho, flip() should already throw an exception, but doesn’t ;(