How to video streaming using customtkinter library in class method form ? i was troubling to configure how to that, i see many examples but i dont know how to implement this on my code
# code for video streaming
def camera(self):
ret, img = cap.read()
cv2image= cv2.cvtColor(cap.read()[1],cv2.COLOR_BGR2RGB)
img = Image.fromarray(cv2image)
ImgTks = ImageTk.PhotoImage(image=img)
self.camera.imgtk = ImgTks
self.camera.configure(image=ImgTks)
self.after(20,self.camera)
if __name__ == "__main__":
app = TimeIn()
app.camera()
app.mainloop()
this is my whole code for this https://github.com/Fsociety-Mrn/videostreamingCutsomkinter
please do help me i am new to this
CodePudding user response:
Using tkinter_webcam module:-
import tkinter as tk
from tkinter_webcam import webcam
window = tk.Tk() # Sets up GUI
window.title("Example") # Titles GUI
window.geometry("1000x1000") # Sizes GUI
# Uses Box class from webcam to create video window
video = webcam.Box(window, width=450, height=450)
video.show_frames() # Show the created Box
tk.mainloop()
CodePudding user response:
The main issue is that you have used same name camera
for a label and a function. Just rename the function to other name, for example streaming()
:
...
class TimeIn(customtkinter.CTk):
...
# code for video streaming
def streaming(self):
ret, img = cap.read()
cv2image= cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB)
img = Image.fromarray(cv2image)
ImgTks = ImageTk.PhotoImage(image=img)
self.camera.imgtk = ImgTks
self.camera.configure(image=ImgTks)
self.after(20, self.streaming)
if __name__ == "__main__":
app = TimeIn()
app.streaming()
app.mainloop()