0

I'm trying to make a app that detects outside video input and automatically switches shows it, I made a system where it would make a tkinter window and show the webcam footage in it, But a Tkinter window wont show up.

I woul've used cv2.imshow but i don't want to use that for the time it takes to make the frame.

import cv2
from tkinter import *
import PIL
from PIL import Image, ImageTk

root = Tk()
root.bind('<Escape>', lambda e: root.quit())
lmain = Label(root)
lmain.pack()

print("[INFO] Making variables")
ImageSource = 0
window_name = "AutoCam"
cap = cv2.VideoCapture(ImageSource)
print("[INFO] Made variables ")


def CheckSource():
    cap = cv2.VideoCapture(ImageSource)
    while cap.isOpened():
        _, frame = cap.read()

        if cv2.waitKey(1) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            cv2.waitKey(0)
            break

        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = PIL.Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image=img)
        lmain.imgtk = imgtk
        lmain.configure(image=imgtk)
        lmain.after(10, CheckSource)

        print("[INFO] cv2.imshow done")

    else:
        print("[INFO] Looking for image source.")
        CheckSource()


CheckSource()
root.mainloop()

Any and all help would be very appreciated.

0 Answers0